diff --git a/exercises/practice/largest-series-product/.docs/instructions.md b/exercises/practice/largest-series-product/.docs/instructions.md index 8ddbc60..f297b57 100644 --- a/exercises/practice/largest-series-product/.docs/instructions.md +++ b/exercises/practice/largest-series-product/.docs/instructions.md @@ -1,14 +1,26 @@ # Instructions -Given a string of digits, calculate the largest product for a contiguous -substring of digits of length n. +Your task is to look for patterns in the long sequence of digits in the encrypted signal. -For example, for the input `'1027839564'`, the largest product for a -series of 3 digits is 270 (9 * 5 * 6), and the largest product for a -series of 5 digits is 7560 (7 * 8 * 3 * 9 * 5). +The technique you're going to use here is called the largest series product. -Note that these series are only required to occupy *adjacent positions* -in the input; the digits need not be *numerically consecutive*. +Let's define a few terms, first. -For the input `'73167176531330624919225119674426574742355349194934'`, -the largest product for a series of 6 digits is 23520. +- **input**: the sequence of digits that you need to analyze +- **series**: a sequence of adjacent digits (those that are next to each other) that is contained within the input +- **span**: how many digits long each series is +- **product**: what you get when you multiply numbers together + +Let's work through an example, with the input `"63915"`. + +- To form a series, take adjacent digits in the original input. +- If you are working with a span of `3`, there will be three possible series: + - `"639"` + - `"391"` + - `"915"` +- Then we need to calculate the product of each series: + - The product of the series `"639"` is 162 (`6 × 3 × 9 = 162`) + - The product of the series `"391"` is 27 (`3 × 9 × 1 = 27`) + - The product of the series `"915"` is 45 (`9 × 1 × 5 = 45`) +- 162 is bigger than both 27 and 45, so the largest series product of `"63915"` is from the series `"639"`. + So the answer is **162**. diff --git a/exercises/practice/largest-series-product/.docs/introduction.md b/exercises/practice/largest-series-product/.docs/introduction.md new file mode 100644 index 0000000..597bb5f --- /dev/null +++ b/exercises/practice/largest-series-product/.docs/introduction.md @@ -0,0 +1,5 @@ +# Introduction + +You work for a government agency that has intercepted a series of encrypted communication signals from a group of bank robbers. +The signals contain a long sequence of digits. +Your team needs to use various digital signal processing techniques to analyze the signals and identify any patterns that may indicate the planning of a heist. diff --git a/exercises/practice/largest-series-product/.meta/tests.toml b/exercises/practice/largest-series-product/.meta/tests.toml index 931c941..00956d8 100644 --- a/exercises/practice/largest-series-product/.meta/tests.toml +++ b/exercises/practice/largest-series-product/.meta/tests.toml @@ -34,9 +34,11 @@ description = "rejects span longer than string length" [06bc8b90-0c51-4c54-ac22-3ec3893a079e] description = "reports 1 for empty string and empty product (0 span)" +include = false [3ec0d92e-f2e2-4090-a380-70afee02f4c0] description = "reports 1 for nonempty string and empty product (0 span)" +include = false [6d96c691-4374-4404-80ee-2ea8f3613dd4] description = "rejects empty string and nonzero span" diff --git a/exercises/practice/largest-series-product/test/largest_series_product_test.clj b/exercises/practice/largest-series-product/test/largest_series_product_test.clj index fab4beb..9a8c6e0 100644 --- a/exercises/practice/largest-series-product/test/largest_series_product_test.clj +++ b/exercises/practice/largest-series-product/test/largest_series_product_test.clj @@ -33,10 +33,6 @@ (is (= 0 (lsp/largest-product 3 "99099")))) (testing "rejects span longer than string length" (is (thrown? Throwable (lsp/largest-product 4 "123")))) - (testing "reports 1 for empty string and empty product (0 span)" - (is (= 1 (lsp/largest-product 0 "")))) - (testing "reports 1 for nonempty string and empty product (0 span)" - (is (= 1 (lsp/largest-product 0 "123")))) (testing "rejects empty string and nonzero span" (is (thrown? Throwable (lsp/largest-product 1 "")))) (testing "rejects invalid character in digits"