From 646ce7a27ca04a3c9dd3c683ca1e62abafd833c9 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Mon, 23 Jun 2014 17:25:12 +0100 Subject: [PATCH] Tweaked the keyword break slides --- slides/keyword-break.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/slides/keyword-break.html b/slides/keyword-break.html index 4a2772c..49160bb 100644 --- a/slides/keyword-break.html +++ b/slides/keyword-break.html @@ -86,6 +86,28 @@ But before we get there, a couple of diversions... --- +# DRYing code + +Three cipher breaking tasks so far. + +All working on the same principle: + +``` +find a way to enumerate all the possible keys +initialise 'best so far' +for each key: + decipher message with this key + score it + if it's better than the best so far: + update best so far +``` + +Repetition of code is a bad smell. + +Separate the 'try all keys, keep the best' logic from the 'score this one key' logic. + +--- + # map() A common task is to apply a function to each item in a sequence, returning a sequence of the results. -- 2.34.1