From b902899fb472fa7752d62831e570ed1dd471800a Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Wed, 12 Apr 2023 11:39:09 +0200 Subject: [PATCH 1/2] Sync largest-series-product docs with problem-specifications The largest-series-product exercise has been overhauled as part of a project to make practice exercises more consistent and friendly. For more context, please see the discussion in the forum, as well as the pull request that updated the exercise in the problem-specifications repository: - https://forum.exercism.org/t/new-project-making-practice-exercises-more-consistent-and-human-across-exercism/3943 - https://github.com/exercism/problem-specifications/pull/2246 --- .../.docs/instructions.md | 31 ++++++++++++------- .../.docs/introduction.md | 5 +++ 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 exercises/practice/largest-series-product/.docs/introduction.md diff --git a/exercises/practice/largest-series-product/.docs/instructions.md b/exercises/practice/largest-series-product/.docs/instructions.md index 08fe481f..f297b57f 100644 --- a/exercises/practice/largest-series-product/.docs/instructions.md +++ b/exercises/practice/largest-series-product/.docs/instructions.md @@ -1,19 +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 -For a series of zero digits, you need to return the empty product (the result of multiplying no numbers), which is 1. +Let's work through an example, with the input `"63915"`. -~~~~exercism/advanced -You do not need to understand why the empty product is 1 to solve this problem, -but in case you are interested, here is an informal argument: if we split a list of numbers `A` into two new lists `B` and `C`, then we expect `product(A) == product(B) * product(C)` because we don't expect the order that you multiply things to matter; now if we split a list containing only the number 3 into the empty list and a list containing the number 3 then the product of the empty list has to be 1 for `product([3]) == product([]) * product([3])` to be true. - -The same kind of argument justifies why the sum of no numbers is 0. -~~~~ +- 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 00000000..597bb5fa --- /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. From 6ece2c9a34d6de7ad2f260001c7a9ce4ca8810d7 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Wed, 12 Apr 2023 11:39:25 +0200 Subject: [PATCH 2/2] Delete test cases from largest-series-product This deletes two deprecated test cases so that we can dramatically simplify the instructions for this exercise. --- .../largest-series-product/.meta/tests.toml | 2 ++ .../largest_series_product.bats | 32 ------------------- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/exercises/practice/largest-series-product/.meta/tests.toml b/exercises/practice/largest-series-product/.meta/tests.toml index 6c111adf..88316925 100644 --- a/exercises/practice/largest-series-product/.meta/tests.toml +++ b/exercises/practice/largest-series-product/.meta/tests.toml @@ -41,9 +41,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/largest_series_product.bats b/exercises/practice/largest-series-product/largest_series_product.bats index 4cc8c32d..3c77b84b 100644 --- a/exercises/practice/largest-series-product/largest_series_product.bats +++ b/exercises/practice/largest-series-product/largest_series_product.bats @@ -76,38 +76,6 @@ load bats-extra assert_output "$expected" } -# There may be some confusion about whether this should be 1 or error. -# The reasoning for it being 1 is this: -# There is one 0-character string contained in the empty string. -# That's the empty string itself. -# The empty product is 1 (the identity for multiplication). -# Therefore LSP('', 0) is 1. -# It's NOT the case that LSP('', 0) takes max of an empty list. -# So there is no error. -# Compare against LSP('123', 4): -# There are zero 4-character strings in '123'. -# So LSP('123', 4) really DOES take the max of an empty list. -# So LSP('123', 4) errors and LSP('', 0) does NOT. - -@test "reports 1 for empty string and empty product (0 span)" { - [[ $BATS_RUN_SKIPPED == "true" ]] || skip - run bash largest_series_product.sh 0 - expected=1 - assert_success - assert_output "$expected" -} - -# As above, there is one 0-character string in '123'. -# So again no error. It's the empty product, 1. - -@test "reports 1 for nonempty string and empty product (0 span)" { - [[ $BATS_RUN_SKIPPED == "true" ]] || skip - run bash largest_series_product.sh 123 0 - expected=1 - assert_success - assert_output "$expected" -} - # error cases @test "rejects span longer than string length" {