Skip to content

Commit 6ce146c

Browse files
authored
Sync largest-series-product docs with problem-specifications (#625)
* 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 - exercism/problem-specifications#2246 * Delete test cases from largest-series-product This deletes two deprecated test cases so that we can dramatically simplify the instructions for this exercise.
1 parent 3bc96f3 commit 6ce146c

File tree

4 files changed

+26
-44
lines changed

4 files changed

+26
-44
lines changed
Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
# Instructions
22

3-
Given a string of digits, calculate the largest product for a contiguous substring of digits of length n.
3+
Your task is to look for patterns in the long sequence of digits in the encrypted signal.
44

5-
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)`.
5+
The technique you're going to use here is called the largest series product.
66

7-
Note that these series are only required to occupy *adjacent positions* in the input; the digits need not be *numerically consecutive*.
7+
Let's define a few terms, first.
88

9-
For the input `'73167176531330624919225119674426574742355349194934'`,
10-
the largest product for a series of 6 digits is 23520.
9+
- **input**: the sequence of digits that you need to analyze
10+
- **series**: a sequence of adjacent digits (those that are next to each other) that is contained within the input
11+
- **span**: how many digits long each series is
12+
- **product**: what you get when you multiply numbers together
1113

12-
For a series of zero digits, you need to return the empty product (the result of multiplying no numbers), which is 1.
14+
Let's work through an example, with the input `"63915"`.
1315

14-
~~~~exercism/advanced
15-
You do not need to understand why the empty product is 1 to solve this problem,
16-
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.
17-
18-
The same kind of argument justifies why the sum of no numbers is 0.
19-
~~~~
16+
- To form a series, take adjacent digits in the original input.
17+
- If you are working with a span of `3`, there will be three possible series:
18+
- `"639"`
19+
- `"391"`
20+
- `"915"`
21+
- Then we need to calculate the product of each series:
22+
- The product of the series `"639"` is 162 (`6 × 3 × 9 = 162`)
23+
- The product of the series `"391"` is 27 (`3 × 9 × 1 = 27`)
24+
- The product of the series `"915"` is 45 (`9 × 1 × 5 = 45`)
25+
- 162 is bigger than both 27 and 45, so the largest series product of `"63915"` is from the series `"639"`.
26+
So the answer is **162**.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Introduction
2+
3+
You work for a government agency that has intercepted a series of encrypted communication signals from a group of bank robbers.
4+
The signals contain a long sequence of digits.
5+
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.

exercises/practice/largest-series-product/.meta/tests.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ description = "rejects span longer than string length"
4141

4242
[06bc8b90-0c51-4c54-ac22-3ec3893a079e]
4343
description = "reports 1 for empty string and empty product (0 span)"
44+
include = false
4445

4546
[3ec0d92e-f2e2-4090-a380-70afee02f4c0]
4647
description = "reports 1 for nonempty string and empty product (0 span)"
48+
include = false
4749

4850
[6d96c691-4374-4404-80ee-2ea8f3613dd4]
4951
description = "rejects empty string and nonzero span"

exercises/practice/largest-series-product/largest_series_product.bats

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,38 +76,6 @@ load bats-extra
7676
assert_output "$expected"
7777
}
7878

79-
# There may be some confusion about whether this should be 1 or error.
80-
# The reasoning for it being 1 is this:
81-
# There is one 0-character string contained in the empty string.
82-
# That's the empty string itself.
83-
# The empty product is 1 (the identity for multiplication).
84-
# Therefore LSP('', 0) is 1.
85-
# It's NOT the case that LSP('', 0) takes max of an empty list.
86-
# So there is no error.
87-
# Compare against LSP('123', 4):
88-
# There are zero 4-character strings in '123'.
89-
# So LSP('123', 4) really DOES take the max of an empty list.
90-
# So LSP('123', 4) errors and LSP('', 0) does NOT.
91-
92-
@test "reports 1 for empty string and empty product (0 span)" {
93-
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
94-
run bash largest_series_product.sh 0
95-
expected=1
96-
assert_success
97-
assert_output "$expected"
98-
}
99-
100-
# As above, there is one 0-character string in '123'.
101-
# So again no error. It's the empty product, 1.
102-
103-
@test "reports 1 for nonempty string and empty product (0 span)" {
104-
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
105-
run bash largest_series_product.sh 123 0
106-
expected=1
107-
assert_success
108-
assert_output "$expected"
109-
}
110-
11179
# error cases
11280

11381
@test "rejects span longer than string length" {

0 commit comments

Comments
 (0)