-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
399 additions
and
2 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
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 @@ | ||
{ | ||
"blurb": "How to handle errors inside application. Different styles and when to apply them.", | ||
"authors": ["loziniak"], | ||
"contributors": [] | ||
} |
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,3 @@ | ||
# About | ||
|
||
> Provide more detailed information about the Concept for a student who has completed the corresponding Concept Exercise to learn from and refer back to. |
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,3 @@ | ||
# Introduction | ||
|
||
> Provide a brief introduction to a student who has not yet completed the corresponding concept exercise. |
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,2 @@ | ||
[ | ||
] |
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 @@ | ||
{ | ||
"blurb": "How to run same code multiple times based on the data.", | ||
"authors": ["loziniak"], | ||
"contributors": [] | ||
} |
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,3 @@ | ||
# About | ||
|
||
> Provide more detailed information about the Concept for a student who has completed the corresponding Concept Exercise to learn from and refer back to. |
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,3 @@ | ||
# Introduction | ||
|
||
> Provide a brief introduction to a student who has not yet completed the corresponding concept exercise. |
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,2 @@ | ||
[ | ||
] |
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
14 changes: 14 additions & 0 deletions
14
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Instructions | ||
|
||
Given a string of digits, calculate the largest product for a contiguous | ||
substring of digits of length n. | ||
|
||
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). | ||
|
||
Note that these series are only required to occupy *adjacent positions* | ||
in the input; the digits need not be *numerically consecutive*. | ||
|
||
For the input `'73167176531330624919225119674426574742355349194934'`, | ||
the largest product for a series of 6 digits is 23520. |
18 changes: 18 additions & 0 deletions
18
exercises/practice/largest-series-product/.meta/config.json
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,18 @@ | ||
{ | ||
"blurb": "Given a string of digits, calculate the largest product for a contiguous substring of digits of length n.", | ||
"authors": [ | ||
"loziniak" | ||
], | ||
"contributors": [], | ||
"files": { | ||
"solution": [ | ||
"largest-series-product.red" | ||
], | ||
"test": [ | ||
"largest-series-product-test.red" | ||
], | ||
"example": [ | ||
".meta/example.red" | ||
] | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
exercises/practice/largest-series-product/.meta/example.red
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,43 @@ | ||
Red [ | ||
description: {"Largest Series Product" exercise solution for exercism platform} | ||
author: "loziniak" | ||
] | ||
|
||
largest-product: function [ | ||
digits [string!] | ||
span [integer!] | ||
return: [integer!] | ||
] [ | ||
if span > length? digits [ | ||
throw #(error: "span must be smaller than string length") ;-- 'throw / 'catch is one method of error control… | ||
] | ||
if span < 0 [ | ||
cause-error 'user 'message ["span must be greater than zero"] ;-- …and 'cause-error / 'try is another one. | ||
] | ||
integers: copy [] | ||
foreach digit digits [ | ||
if any [digit < #"0" digit > #"9"] [ | ||
cause-error 'user 'message ["digits input must only contain digits"] | ||
] | ||
append integers to integer! (digit - #"0") | ||
] | ||
|
||
max-product: either zero? span [1] [0] | ||
|
||
len: length? integers | ||
forall integers [ | ||
if (span - 1 + index? integers) > len [ | ||
break | ||
] | ||
;probe integers | ||
product: 1 | ||
foreach int copy/part integers span [ | ||
product: product * int | ||
] | ||
if max-product < product [ | ||
max-product: product | ||
] | ||
] | ||
|
||
max-product | ||
] |
47 changes: 47 additions & 0 deletions
47
exercises/practice/largest-series-product/.meta/tests.toml
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,47 @@ | ||
[canonical-tests] | ||
|
||
# finds the largest product if span equals length | ||
"7c82f8b7-e347-48ee-8a22-f672323324d4" = true | ||
|
||
# can find the largest product of 2 with numbers in order | ||
"88523f65-21ba-4458-a76a-b4aaf6e4cb5e" = true | ||
|
||
# can find the largest product of 2 | ||
"f1376b48-1157-419d-92c2-1d7e36a70b8a" = true | ||
|
||
# can find the largest product of 3 with numbers in order | ||
"46356a67-7e02-489e-8fea-321c2fa7b4a4" = true | ||
|
||
# can find the largest product of 3 | ||
"a2dcb54b-2b8f-4993-92dd-5ce56dece64a" = true | ||
|
||
# can find the largest product of 5 with numbers in order | ||
"673210a3-33cd-4708-940b-c482d7a88f9d" = true | ||
|
||
# can get the largest product of a big number | ||
"02acd5a6-3bbf-46df-8282-8b313a80a7c9" = true | ||
|
||
# reports zero if the only digits are zero | ||
"76dcc407-21e9-424c-a98e-609f269622b5" = true | ||
|
||
# reports zero if all spans include zero | ||
"6ef0df9f-52d4-4a5d-b210-f6fae5f20e19" = true | ||
|
||
# rejects span longer than string length | ||
"5d81aaf7-4f67-4125-bf33-11493cc7eab7" = true | ||
|
||
# reports 1 for empty string and empty product (0 span) | ||
"06bc8b90-0c51-4c54-ac22-3ec3893a079e" = true | ||
|
||
# reports 1 for nonempty string and empty product (0 span) | ||
"3ec0d92e-f2e2-4090-a380-70afee02f4c0" = true | ||
|
||
# rejects empty string and nonzero span | ||
"6d96c691-4374-4404-80ee-2ea8f3613dd4" = true | ||
|
||
# rejects invalid character in digits | ||
"7a38f2d6-3c35-45f6-8d6f-12e6e32d4d74" = true | ||
|
||
# rejects negative span | ||
"5fe3c0e5-a945-49f2-b584-f0814b4dd1ef" = true | ||
|
Oops, something went wrong.