forked from exercism/red
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync largest-series-product docs with problem-specifications (exercis…
…m#87) * 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
Showing
12 changed files
with
451 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 21 additions & 9 deletions
30
exercises/practice/largest-series-product/.docs/instructions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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**. |
5 changes: 5 additions & 0 deletions
5
exercises/practice/largest-series-product/.docs/introduction.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,4 +44,3 @@ | |
|
||
# rejects negative span | ||
"5fe3c0e5-a945-49f2-b584-f0814b4dd1ef" = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Instructions | ||
|
||
Given a year, report if it is a leap year. | ||
|
||
The tricky thing here is that a leap year in the Gregorian calendar occurs: | ||
|
||
```text | ||
on every year that is evenly divisible by 4 | ||
except every year that is evenly divisible by 100 | ||
unless the year is also evenly divisible by 400 | ||
``` | ||
|
||
For example, 1997 is not a leap year, but 1996 is. | ||
1900 is not a leap year, but 2000 is. | ||
|
||
## Notes | ||
|
||
Though our exercise adopts some very simple rules, there is more to learn! | ||
|
||
For a delightful, four minute explanation of the whole leap year phenomenon, go watch [this youtube video][video]. | ||
|
||
[video]: https://www.youtube.com/watch?v=xX96xng7sAE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"authors": ["BNAndras"], | ||
"files": { | ||
"solution": [ | ||
"leap.red" | ||
], | ||
"test": [ | ||
"leap-test.red" | ||
], | ||
"example": [ | ||
".meta/example.red" | ||
] | ||
}, | ||
"blurb": "Given a year, report if it is a leap year.", | ||
"source": "CodeRanch Cattle Drive, Assignment 3", | ||
"source_url": "https://coderanch.com/t/718816/Leap" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Red [ | ||
description: {"Leap" exercise solution for exercism platform} | ||
author: "BNAndras" | ||
] | ||
|
||
leap: function [ | ||
year | ||
] [ | ||
divisible?: func [n] [zero? year // n] | ||
to logic! any [all [divisible? 4 not divisible? 100] divisible? 400] | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[6466b30d-519c-438e-935d-388224ab5223] | ||
description = "year not divisible by 4 in common year" | ||
|
||
[ac227e82-ee82-4a09-9eb6-4f84331ffdb0] | ||
description = "year divisible by 2, not divisible by 4 in common year" | ||
|
||
[4fe9b84c-8e65-489e-970b-856d60b8b78e] | ||
description = "year divisible by 4, not divisible by 100 in leap year" | ||
|
||
[7fc6aed7-e63c-48f5-ae05-5fe182f60a5d] | ||
description = "year divisible by 4 and 5 is still a leap year" | ||
|
||
[78a7848f-9667-4192-ae53-87b30c9a02dd] | ||
description = "year divisible by 100, not divisible by 400 in common year" | ||
|
||
[9d70f938-537c-40a6-ba19-f50739ce8bac] | ||
description = "year divisible by 100 but not by 3 is still not a leap year" | ||
|
||
[42ee56ad-d3e6-48f1-8e3f-c84078d916fc] | ||
description = "year divisible by 400 is leap year" | ||
|
||
[57902c77-6fe9-40de-8302-587b5c27121e] | ||
description = "year divisible by 400 but not by 125 is still a leap year" | ||
|
||
[c30331f6-f9f6-4881-ad38-8ca8c12520c1] | ||
description = "year divisible by 200, not divisible by 400 in common year" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
Red [ | ||
description: {Tests for Largest Series Product Exercism exercise} | ||
author: "BNAndras" | ||
] | ||
|
||
#include %testlib.red | ||
|
||
test-init/limit %leap.red 1 | ||
; test-init/limit %.meta/example.red 1 ; test example solution | ||
|
||
canonical-cases: [#( | ||
description: "year not divisible by 4 in common year" | ||
input: #( | ||
year: 2015 | ||
) | ||
expected: false | ||
function: "leap" | ||
uuid: "6466b30d-519c-438e-935d-388224ab5223" | ||
) #( | ||
description: "year divisible by 2, not divisible by 4 in common year" | ||
input: #( | ||
year: 1970 | ||
) | ||
expected: false | ||
function: "leap" | ||
uuid: "ac227e82-ee82-4a09-9eb6-4f84331ffdb0" | ||
) #( | ||
description: "year divisible by 4, not divisible by 100 in leap year" | ||
input: #( | ||
year: 1996 | ||
) | ||
expected: true | ||
function: "leap" | ||
uuid: "4fe9b84c-8e65-489e-970b-856d60b8b78e" | ||
) #( | ||
description: "year divisible by 4 and 5 is still a leap year" | ||
input: #( | ||
year: 1960 | ||
) | ||
expected: true | ||
function: "leap" | ||
uuid: "7fc6aed7-e63c-48f5-ae05-5fe182f60a5d" | ||
) #( | ||
description: "year divisible by 100, not divisible by 400 in common year" | ||
input: #( | ||
year: 2100 | ||
) | ||
expected: false | ||
function: "leap" | ||
uuid: "78a7848f-9667-4192-ae53-87b30c9a02dd" | ||
) #( | ||
description: "year divisible by 100 but not by 3 is still not a leap year" | ||
input: #( | ||
year: 1900 | ||
) | ||
expected: false | ||
function: "leap" | ||
uuid: "9d70f938-537c-40a6-ba19-f50739ce8bac" | ||
) #( | ||
description: "year divisible by 400 is leap year" | ||
input: #( | ||
year: 2000 | ||
) | ||
expected: true | ||
function: "leap" | ||
uuid: "42ee56ad-d3e6-48f1-8e3f-c84078d916fc" | ||
) #( | ||
description: "year divisible by 400 but not by 125 is still a leap year" | ||
input: #( | ||
year: 2400 | ||
) | ||
expected: true | ||
function: "leap" | ||
uuid: "57902c77-6fe9-40de-8302-587b5c27121e" | ||
) #( | ||
description: "year divisible by 400 but not by 125 is still a leap year" | ||
input: #( | ||
year: 1800 | ||
) | ||
expected: false | ||
function: "leap" | ||
uuid: "c30331f6-f9f6-4881-ad38-8ca8c12520c1" | ||
)] | ||
|
||
|
||
foreach c-case canonical-cases [ | ||
expect-code: compose [ | ||
(to word! c-case/function) (values-of c-case/input) | ||
] | ||
case-code: reduce | ||
either all [ | ||
map? c-case/expected | ||
string? c-case/expected/error | ||
] [ | ||
['expect-error/message quote 'user expect-code c-case/expected/error] | ||
] [ | ||
['expect c-case/expected expect-code] | ||
] | ||
|
||
test c-case/description case-code | ||
] | ||
|
||
test-results/print |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Red [ | ||
description: {"Leap" exercise solution for exercism platform} | ||
author: "" ; you can write your name here, in quotes | ||
] | ||
|
||
leap: function [ | ||
year | ||
] [ | ||
cause-error 'user 'message ["You need to implement this function."] | ||
] | ||
|
Oops, something went wrong.