Skip to content

Commit

Permalink
Sync largest-series-product docs with problem-specifications (#1683)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
kytrinyx authored May 16, 2023
1 parent a24bd64 commit 7e7d31a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
30 changes: 21 additions & 9 deletions exercises/practice/largest-series-product/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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**.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,6 @@ fn a_span_is_longer_than_number_is_an_error() {
assert_eq!(Err(Error::SpanTooLong), lsp("123", 4));
}

// 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]
#[ignore]
fn an_empty_string_and_no_span_returns_one() {
assert_eq!(Ok(1), lsp("", 0));
}

#[test]
#[ignore]
fn a_non_empty_string_and_no_span_returns_one() {
assert_eq!(Ok(1), lsp("123", 0));
}

#[test]
#[ignore]
fn empty_string_and_non_zero_span_is_an_error() {
Expand Down

0 comments on commit 7e7d31a

Please sign in to comment.