diff --git a/config.json b/config.json index 0e22222..154b00a 100644 --- a/config.json +++ b/config.json @@ -313,6 +313,70 @@ "practices": [], "prerequisites": [], "difficulty": 1 + }, + { + "slug": "grade-school", + "name": "Grade School", + "uuid": "0d0bd1b7-48e4-41b4-9bd5-5c5311b0da22", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, + { + "slug": "eliuds-eggs", + "name": "Eliud's Eggs", + "uuid": "23e999e2-b2cb-44f8-be94-98dde25d5467", + "practices": [], + "prerequisites": [], + "difficulty": 1 + }, + { + "slug": "run-length-encoding", + "name": "Run-Length Encoding", + "uuid": "4b4189ba-578b-4cbf-bffa-443fc49e73ac", + "practices": [], + "prerequisites": [], + "difficulty": 1 + }, + { + "slug": "armstrong-numbers", + "name": "Armstrong Numbers", + "uuid": "3349bf31-c174-47a1-82c1-bc91b5d490c3", + "practices": [], + "prerequisites": [], + "difficulty": 3 + }, + { + "slug": "diamond", + "name": "Diamond", + "uuid": "05bb2b80-0521-473f-b39e-c09e8d81d16f", + "practices": [], + "prerequisites": [], + "difficulty": 5 + }, + { + "slug": "largest-series-product", + "name": "Largest Series Product", + "uuid": "0eca7e0d-f897-48d8-83da-316f92a09749", + "practices": [], + "prerequisites": [], + "difficulty": 4 + }, + { + "slug": "sieve", + "name": "Sieve", + "uuid": "9081e8b6-6bfb-4239-ac08-6f3aa1450991", + "practices": [], + "prerequisites": [], + "difficulty": 1 + }, + { + "slug": "food-chain", + "name": "Food Chain", + "uuid": "1a1465ba-e0db-4abe-bd70-ba505ff6408e", + "practices": [], + "prerequisites": [], + "difficulty": 3 } ] }, diff --git a/exercises/practice/armstrong-numbers/.docs/instructions.md b/exercises/practice/armstrong-numbers/.docs/instructions.md new file mode 100644 index 0000000..5e56bbe --- /dev/null +++ b/exercises/practice/armstrong-numbers/.docs/instructions.md @@ -0,0 +1,14 @@ +# Instructions + +An [Armstrong number][armstrong-number] is a number that is the sum of its own digits each raised to the power of the number of digits. + +For example: + +- 9 is an Armstrong number, because `9 = 9^1 = 9` +- 10 is _not_ an Armstrong number, because `10 != 1^2 + 0^2 = 1` +- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153` +- 154 is _not_ an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190` + +Write some code to determine whether a number is an Armstrong number. + +[armstrong-number]: https://en.wikipedia.org/wiki/Narcissistic_number diff --git a/exercises/practice/armstrong-numbers/.meta/config.json b/exercises/practice/armstrong-numbers/.meta/config.json new file mode 100644 index 0000000..d625a38 --- /dev/null +++ b/exercises/practice/armstrong-numbers/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "eNascimento178" + ], + "files": { + "solution": [ + "armstrong-numbers.ijs" + ], + "test": [ + "test.ijs" + ], + "example": [ + ".meta/example.ijs" + ] + }, + "blurb": "Determine if a number is an Armstrong number.", + "source": "Wikipedia", + "source_url": "https://en.wikipedia.org/wiki/Narcissistic_number" +} diff --git a/exercises/practice/armstrong-numbers/.meta/example.ijs b/exercises/practice/armstrong-numbers/.meta/example.ijs new file mode 100644 index 0000000..f5a85d3 --- /dev/null +++ b/exercises/practice/armstrong-numbers/.meta/example.ijs @@ -0,0 +1,2 @@ + +is_armstrong_number=: = [: +/ ([: (^ #) 10&#.^:_1) diff --git a/exercises/practice/armstrong-numbers/.meta/tests.toml b/exercises/practice/armstrong-numbers/.meta/tests.toml new file mode 100644 index 0000000..b3f09e4 --- /dev/null +++ b/exercises/practice/armstrong-numbers/.meta/tests.toml @@ -0,0 +1,43 @@ +# 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. + +[c1ed103c-258d-45b2-be73-d8c6d9580c7b] +description = "Zero is an Armstrong number" + +[579e8f03-9659-4b85-a1a2-d64350f6b17a] +description = "Single-digit numbers are Armstrong numbers" + +[2d6db9dc-5bf8-4976-a90b-b2c2b9feba60] +description = "There are no two-digit Armstrong numbers" + +[509c087f-e327-4113-a7d2-26a4e9d18283] +description = "Three-digit number that is an Armstrong number" + +[7154547d-c2ce-468d-b214-4cb953b870cf] +description = "Three-digit number that is not an Armstrong number" + +[6bac5b7b-42e9-4ecb-a8b0-4832229aa103] +description = "Four-digit number that is an Armstrong number" + +[eed4b331-af80-45b5-a80b-19c9ea444b2e] +description = "Four-digit number that is not an Armstrong number" + +[f971ced7-8d68-4758-aea1-d4194900b864] +description = "Seven-digit number that is an Armstrong number" + +[7ee45d52-5d35-4fbd-b6f1-5c8cd8a67f18] +description = "Seven-digit number that is not an Armstrong number" + +[5ee2fdf8-334e-4a46-bb8d-e5c19c02c148] +description = "Armstrong number containing seven zeroes" + +[12ffbf10-307a-434e-b4ad-c925680e1dd4] +description = "The largest and last Armstrong number" diff --git a/exercises/practice/armstrong-numbers/armstrong-numbers.ijs b/exercises/practice/armstrong-numbers/armstrong-numbers.ijs new file mode 100644 index 0000000..d98ee50 --- /dev/null +++ b/exercises/practice/armstrong-numbers/armstrong-numbers.ijs @@ -0,0 +1,3 @@ +require 'general/unittest' + +is_armstrong_number =: 'You need to implement this verb.'13!:8 (55) diff --git a/exercises/practice/armstrong-numbers/test.ijs b/exercises/practice/armstrong-numbers/test.ijs new file mode 100644 index 0000000..5d13b51 --- /dev/null +++ b/exercises/practice/armstrong-numbers/test.ijs @@ -0,0 +1,120 @@ +load 'armstrong-numbers.ijs' + + +before_all=: monad define + (]Description =: (3 : 'descriptions=: i.0')`(3 : 'descriptions=: descriptions , < y'))@.0 '' + (]Order =: (3 : 'order=: i.0')`(3 : 'order=: order , < y'))@.0 '' + (]Task =: (3 : 'tasks=: i.0')`(3 : 'tasks=: tasks , < y'))@.0 '' +) + + +armstrong_numbers_test_01_ignore=: 0 +test_armstrong_numbers_test_01 =: monad define + Description@.1 ('Zero is an Armstrong number') + Order@.1 (1) + + NB. number=. 0 + NB. expected=. 1 + assert 1 -: is_armstrong_number 0 +) + +armstrong_numbers_test_02_ignore=: 1 NB. Change this value to 0 to run this test +test_armstrong_numbers_test_02 =: monad define + Description@.1 ('Single-digit numbers are Armstrong numbers') + Order@.1 (2) + + NB. number=. 5 + NB. expected=. 1 + assert 1 -: is_armstrong_number 5 +) + +armstrong_numbers_test_03_ignore=: 1 NB. Change this value to 0 to run this test +test_armstrong_numbers_test_03 =: monad define + Description@.1 ('There are no two-digit Armstrong numbers') + Order@.1 (3) + + NB. number=. 10 + NB. expected=. 0 + assert 0 -: is_armstrong_number 10 +) + +armstrong_numbers_test_04_ignore=: 1 NB. Change this value to 0 to run this test +test_armstrong_numbers_test_04 =: monad define + Description@.1 ('Three-digit number that is an Armstrong number') + Order@.1 (4) + + NB. number=. 153 + NB. expected=. 1 + assert 1 -: is_armstrong_number 153 +) + +armstrong_numbers_test_05_ignore=: 1 NB. Change this value to 0 to run this test +test_armstrong_numbers_test_05 =: monad define + Description@.1 ('Three-digit number that is not an Armstrong number') + Order@.1 (5) + + NB. number=. 100 + NB. expected=. 0 + assert 0 -: is_armstrong_number 100 +) + +armstrong_numbers_test_06_ignore=: 1 NB. Change this value to 0 to run this test +test_armstrong_numbers_test_06 =: monad define + Description@.1 ('Four-digit number that is an Armstrong number') + Order@.1 (6) + + NB. number=. 9474 + NB. expected=. 1 + assert 1 -: is_armstrong_number 9474 +) + +armstrong_numbers_test_07_ignore=: 1 NB. Change this value to 0 to run this test +test_armstrong_numbers_test_07 =: monad define + Description@.1 ('Four-digit number that is not an Armstrong number') + Order@.1 (7) + + NB. number=. 9475 + NB. expected=. 0 + assert 0 -: is_armstrong_number 9475 +) + +armstrong_numbers_test_08_ignore=: 1 NB. Change this value to 0 to run this test +test_armstrong_numbers_test_08 =: monad define + Description@.1 ('Seven-digit number that is an Armstrong number') + Order@.1 (8) + + NB. number=. 9926315 + NB. expected=. 1 + assert 1 -: is_armstrong_number 9926315 +) + +armstrong_numbers_test_09_ignore=: 1 NB. Change this value to 0 to run this test +test_armstrong_numbers_test_09 =: monad define + Description@.1 ('Seven-digit number that is not an Armstrong number') + Order@.1 (9) + + NB. number=. 9926314 + NB. expected=. 0 + assert 0 -: is_armstrong_number 9926314 +) + +armstrong_numbers_test_10_ignore=: 1 NB. Change this value to 0 to run this test +test_armstrong_numbers_test_10 =: monad define + Description@.1 ('Armstrong number containing seven zeroes') + Order@.1 (10) + + NB. number=. 186709961001538790100634132976990 + NB. expected=. 1 + assert 1 -: is_armstrong_number 186709961001538790100634132976990x +) + +armstrong_numbers_test_11_ignore=: 1 NB. Change this value to 0 to run this test +test_armstrong_numbers_test_11 =: monad define + Description@.1 ('The largest and last Armstrong number') + Order@.1 (11) + + NB. number=. 115132219018763992565095597973971522401 + NB. expected=. 1 + assert 1 -: is_armstrong_number 115132219018763992565095597973971522401x +) + diff --git a/exercises/practice/diamond/.docs/instructions.md b/exercises/practice/diamond/.docs/instructions.md new file mode 100644 index 0000000..3034802 --- /dev/null +++ b/exercises/practice/diamond/.docs/instructions.md @@ -0,0 +1,52 @@ +# Instructions + +The diamond kata takes as its input a letter, and outputs it in a diamond shape. +Given a letter, it prints a diamond starting with 'A', with the supplied letter at the widest point. + +## Requirements + +- The first row contains one 'A'. +- The last row contains one 'A'. +- All rows, except the first and last, have exactly two identical letters. +- All rows have as many trailing spaces as leading spaces. (This might be 0). +- The diamond is horizontally symmetric. +- The diamond is vertically symmetric. +- The diamond has a square shape (width equals height). +- The letters form a diamond shape. +- The top half has the letters in ascending order. +- The bottom half has the letters in descending order. +- The four corners (containing the spaces) are triangles. + +## Examples + +In the following examples, spaces are indicated by `·` characters. + +Diamond for letter 'A': + +```text +A +``` + +Diamond for letter 'C': + +```text +··A·· +·B·B· +C···C +·B·B· +··A·· +``` + +Diamond for letter 'E': + +```text +····A···· +···B·B··· +··C···C·· +·D·····D· +E·······E +·D·····D· +··C···C·· +···B·B··· +····A···· +``` diff --git a/exercises/practice/diamond/.meta/config.json b/exercises/practice/diamond/.meta/config.json new file mode 100644 index 0000000..99e3081 --- /dev/null +++ b/exercises/practice/diamond/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "eNascimento178" + ], + "files": { + "solution": [ + "diamond.ijs" + ], + "test": [ + "test.ijs" + ], + "example": [ + ".meta/example.ijs" + ] + }, + "blurb": "Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.", + "source": "Seb Rose", + "source_url": "https://web.archive.org/web/20220807163751/http://claysnow.co.uk/recycling-tests-in-tdd/" +} diff --git a/exercises/practice/diamond/.meta/example.ijs b/exercises/practice/diamond/.meta/example.ijs new file mode 100644 index 0000000..13953b0 --- /dev/null +++ b/exercises/practice/diamond/.meta/example.ijs @@ -0,0 +1,11 @@ +rows=:{{ + alphabet =. (>: _65 + a. i. y){.65}.a. + matrix =. $~ 2 # # + identity =. =/~ @: i. @: # + + right =. (identity (' '"_^:(0=[)"0 0) matrix) alphabet + left =. }:@|."1 right + top =. left,.right + bottom =. }.@|. top + top,bottom +}} diff --git a/exercises/practice/diamond/.meta/tests.toml b/exercises/practice/diamond/.meta/tests.toml new file mode 100644 index 0000000..4e7802e --- /dev/null +++ b/exercises/practice/diamond/.meta/tests.toml @@ -0,0 +1,25 @@ +# 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. + +[202fb4cc-6a38-4883-9193-a29d5cb92076] +description = "Degenerate case with a single 'A' row" + +[bd6a6d78-9302-42e9-8f60-ac1461e9abae] +description = "Degenerate case with no row containing 3 distinct groups of spaces" + +[af8efb49-14ed-447f-8944-4cc59ce3fd76] +description = "Smallest non-degenerate case with odd diamond side length" + +[e0c19a95-9888-4d05-86a0-fa81b9e70d1d] +description = "Smallest non-degenerate case with even diamond side length" + +[82ea9aa9-4c0e-442a-b07e-40204e925944] +description = "Largest possible diamond" diff --git a/exercises/practice/diamond/diamond.ijs b/exercises/practice/diamond/diamond.ijs new file mode 100644 index 0000000..957f375 --- /dev/null +++ b/exercises/practice/diamond/diamond.ijs @@ -0,0 +1,3 @@ +require 'general/unittest' + +rows =: 'You need to implement this verb.'13!:8 (55) diff --git a/exercises/practice/diamond/test.ijs b/exercises/practice/diamond/test.ijs new file mode 100644 index 0000000..8891b6e --- /dev/null +++ b/exercises/practice/diamond/test.ijs @@ -0,0 +1,60 @@ +load 'diamond.ijs' + + +before_all=: monad define + (]Description =: (3 : 'descriptions=: i.0')`(3 : 'descriptions=: descriptions , < y'))@.0 '' + (]Order =: (3 : 'order=: i.0')`(3 : 'order=: order , < y'))@.0 '' + (]Task =: (3 : 'tasks=: i.0')`(3 : 'tasks=: tasks , < y'))@.0 '' +) + + +diamond_test_01_ignore=: 0 +test_diamond_test_01 =: monad define + Description@.1 ('Degenerate case with a single ''A'' row') + Order@.1 (1) + + NB. letter=. 'A' + NB. expected=. 1 1$'A' + assert (1 1$'A') =&> rows 'A' +) + +diamond_test_02_ignore=: 1 NB. Change this value to 0 to run this test +test_diamond_test_02 =: monad define + Description@.1 ('Degenerate case with no row containing 3 distinct groups of spaces') + Order@.1 (2) + + NB. letter=. 'B' + NB. expected=. 3 3$' A B B A ' + assert (3 3$' A B B A ') =&> rows 'B' +) + +diamond_test_03_ignore=: 1 NB. Change this value to 0 to run this test +test_diamond_test_03 =: monad define + Description@.1 ('Smallest non-degenerate case with odd diamond side length') + Order@.1 (3) + + NB. letter=. 'C' + NB. expected=. 5 5$' A B B C C B B A ' + assert (5 5$' A B B C C B B A ') =&> rows 'C' +) + +diamond_test_04_ignore=: 1 NB. Change this value to 0 to run this test +test_diamond_test_04 =: monad define + Description@.1 ('Smallest non-degenerate case with even diamond side length') + Order@.1 (4) + + NB. letter=. 'D' + NB. expected=. 7 7$' A B B C C D D C C B B A ' + assert (7 7$' A B B C C D D C C B B A ') =&> rows 'D' +) + +diamond_test_05_ignore=: 1 NB. Change this value to 0 to run this test +test_diamond_test_05 =: monad define + Description@.1 ('Largest possible diamond') + Order@.1 (5) + + NB. letter=. 'Z' + NB. expected=. 51 51$' A B B C C D D E E F F G G H H I I J J K K L L M M N N O O P P Q Q R R S S T T U U V V W W X X Y Y Z Z Y Y X X W W V V U U T T S S R R Q Q P P O O N N M M L L K K J J I I H H G G F F E E D D C C B B A ' + assert (51 51$' A B B C C D D E E F F G G H H I I J J K K L L M M N N O O P P Q Q R R S S T T U U V V W W X X Y Y Z Z Y Y X X W W V V U U T T S S R R Q Q P P O O N N M M L L K K J J I I H H G G F F E E D D C C B B A ') =&> rows 'Z' +) + diff --git a/exercises/practice/eliuds-eggs/.docs/instructions.md b/exercises/practice/eliuds-eggs/.docs/instructions.md new file mode 100644 index 0000000..b0c2df5 --- /dev/null +++ b/exercises/practice/eliuds-eggs/.docs/instructions.md @@ -0,0 +1,8 @@ +# Instructions + +Your task is to count the number of 1 bits in the binary representation of a number. + +## Restrictions + +Keep your hands off that bit-count functionality provided by your standard library! +Solve this one yourself using other basic tools instead. diff --git a/exercises/practice/eliuds-eggs/.docs/introduction.md b/exercises/practice/eliuds-eggs/.docs/introduction.md new file mode 100644 index 0000000..49eaffd --- /dev/null +++ b/exercises/practice/eliuds-eggs/.docs/introduction.md @@ -0,0 +1,47 @@ +# Introduction + +Your friend Eliud inherited a farm from her grandma Tigist. +Her granny was an inventor and had a tendency to build things in an overly complicated manner. +The chicken coop has a digital display showing an encoded number representing the positions of all eggs that could be picked up. + +Eliud is asking you to write a program that shows the actual number of eggs in the coop. + +The position information encoding is calculated as follows: + +1. Scan the potential egg-laying spots and mark down a `1` for an existing egg or a `0` for an empty spot. +2. Convert the number from binary to decimal. +3. Show the result on the display. + +Example 1: + +```text +Chicken Coop: + _ _ _ _ _ _ _ +|E| |E|E| | |E| + +Resulting Binary: + 1 0 1 1 0 0 1 + +Decimal number on the display: +89 + +Actual eggs in the coop: +4 +``` + +Example 2: + +```text +Chicken Coop: + _ _ _ _ _ _ _ _ +| | | |E| | | | | + +Resulting Binary: + 0 0 0 1 0 0 0 0 + +Decimal number on the display: +16 + +Actual eggs in the coop: +1 +``` diff --git a/exercises/practice/eliuds-eggs/.meta/config.json b/exercises/practice/eliuds-eggs/.meta/config.json new file mode 100644 index 0000000..8d65c77 --- /dev/null +++ b/exercises/practice/eliuds-eggs/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "eNascimento178" + ], + "files": { + "solution": [ + "eliuds-eggs.ijs" + ], + "test": [ + "test.ijs" + ], + "example": [ + ".meta/example.ijs" + ] + }, + "blurb": "Help Eliud count the number of eggs in her chicken coop by counting the number of 1 bits in a binary representation.", + "source": "Christian Willner, Eric Willigers", + "source_url": "https://forum.exercism.org/t/new-exercise-suggestion-pop-count/7632/5" +} diff --git a/exercises/practice/eliuds-eggs/.meta/example.ijs b/exercises/practice/eliuds-eggs/.meta/example.ijs new file mode 100644 index 0000000..42bfe04 --- /dev/null +++ b/exercises/practice/eliuds-eggs/.meta/example.ijs @@ -0,0 +1 @@ +eggcount=: +/ @ (#.^:_1) diff --git a/exercises/practice/eliuds-eggs/.meta/tests.toml b/exercises/practice/eliuds-eggs/.meta/tests.toml new file mode 100644 index 0000000..e11683c --- /dev/null +++ b/exercises/practice/eliuds-eggs/.meta/tests.toml @@ -0,0 +1,22 @@ +# 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. + +[559e789d-07d1-4422-9004-3b699f83bca3] +description = "0 eggs" + +[97223282-f71e-490c-92f0-b3ec9e275aba] +description = "1 egg" + +[1f8fd18f-26e9-4144-9a0e-57cdfc4f4ff5] +description = "4 eggs" + +[0c18be92-a498-4ef2-bcbb-28ac4b06cb81] +description = "13 eggs" diff --git a/exercises/practice/eliuds-eggs/eliuds-eggs.ijs b/exercises/practice/eliuds-eggs/eliuds-eggs.ijs new file mode 100644 index 0000000..1208170 --- /dev/null +++ b/exercises/practice/eliuds-eggs/eliuds-eggs.ijs @@ -0,0 +1,3 @@ +require 'general/unittest' + +eggcount =: 'You need to implement this verb.'13!:8 (55) diff --git a/exercises/practice/eliuds-eggs/test.ijs b/exercises/practice/eliuds-eggs/test.ijs new file mode 100644 index 0000000..2d07673 --- /dev/null +++ b/exercises/practice/eliuds-eggs/test.ijs @@ -0,0 +1,50 @@ +load 'eliuds-eggs.ijs' + + +before_all=: monad define + (]Description =: (3 : 'descriptions=: i.0')`(3 : 'descriptions=: descriptions , < y'))@.0 '' + (]Order =: (3 : 'order=: i.0')`(3 : 'order=: order , < y'))@.0 '' + (]Task =: (3 : 'tasks=: i.0')`(3 : 'tasks=: tasks , < y'))@.0 '' +) + + +eliuds_eggs_test_01_ignore=: 0 +test_eliuds_eggs_test_01 =: monad define + Description@.1 ('0 eggs') + Order@.1 (1) + + NB. number=. 0 + NB. expected=. 0 + assert 0 -: eggcount 0 +) + +eliuds_eggs_test_02_ignore=: 1 NB. Change this value to 0 to run this test +test_eliuds_eggs_test_02 =: monad define + Description@.1 ('1 egg') + Order@.1 (2) + + NB. number=. 16 + NB. expected=. 1 + assert 1 -: eggcount 16 +) + +eliuds_eggs_test_03_ignore=: 1 NB. Change this value to 0 to run this test +test_eliuds_eggs_test_03 =: monad define + Description@.1 ('4 eggs') + Order@.1 (3) + + NB. number=. 89 + NB. expected=. 4 + assert 4 -: eggcount 89 +) + +eliuds_eggs_test_04_ignore=: 1 NB. Change this value to 0 to run this test +test_eliuds_eggs_test_04 =: monad define + Description@.1 ('13 eggs') + Order@.1 (4) + + NB. number=. 2000000000 + NB. expected=. 13 + assert 13 -: eggcount 2000000000 +) + diff --git a/exercises/practice/food-chain/.docs/instructions.md b/exercises/practice/food-chain/.docs/instructions.md new file mode 100644 index 0000000..125820e --- /dev/null +++ b/exercises/practice/food-chain/.docs/instructions.md @@ -0,0 +1,64 @@ +# Instructions + +Generate the lyrics of the song 'I Know an Old Lady Who Swallowed a Fly'. + +While you could copy/paste the lyrics, or read them from a file, this problem is much more interesting if you approach it algorithmically. + +This is a [cumulative song][cumulative-song] of unknown origin. + +This is one of many common variants. + +```text +I know an old lady who swallowed a fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a spider. +It wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a bird. +How absurd to swallow a bird! +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a cat. +Imagine that, to swallow a cat! +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a dog. +What a hog, to swallow a dog! +She swallowed the dog to catch the cat. +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a goat. +Just opened her throat and swallowed a goat! +She swallowed the goat to catch the dog. +She swallowed the dog to catch the cat. +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a cow. +I don't know how she swallowed a cow! +She swallowed the cow to catch the goat. +She swallowed the goat to catch the dog. +She swallowed the dog to catch the cat. +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a horse. +She's dead, of course! +``` + +[cumulative-song]: https://en.wikipedia.org/wiki/Cumulative_song diff --git a/exercises/practice/food-chain/.meta/config.json b/exercises/practice/food-chain/.meta/config.json new file mode 100644 index 0000000..38e4e55 --- /dev/null +++ b/exercises/practice/food-chain/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "eNascimento178" + ], + "files": { + "solution": [ + "food-chain.ijs" + ], + "test": [ + "test.ijs" + ], + "example": [ + ".meta/example.ijs" + ] + }, + "blurb": "Generate the lyrics of the song 'I Know an Old Lady Who Swallowed a Fly'.", + "source": "Wikipedia", + "source_url": "https://en.wikipedia.org/wiki/There_Was_an_Old_Lady_Who_Swallowed_a_Fly" +} diff --git a/exercises/practice/food-chain/.meta/example.ijs b/exercises/practice/food-chain/.meta/example.ijs new file mode 100644 index 0000000..e455a2b --- /dev/null +++ b/exercises/practice/food-chain/.meta/example.ijs @@ -0,0 +1,51 @@ +NB. Adapted from this approach: https://exercism.org/tracks/scala/exercises/food-chain/approaches/move-complexity-to-data +recite=:{{)m + 's e'=. y + mask=. 1 (s + i. >: e - s)} 9#0 + LF joinstring mask # verses +}} + +backwash=: {{)d + 's e'=. y + joinstring (e - s) {. s }. (<;.2 x) +}} + +fly=:{{)nI know an old lady who swallowed a fly. +I don't know why she swallowed the fly. Perhaps she'll die. +}} + +spider=:{{)nI know an old lady who swallowed a spider. +It wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +}} , fly backwash 1 2 + +bird=:{{)nI know an old lady who swallowed a bird. +How absurd to swallow a bird! +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +}} , spider backwash 2 4 + +cat=:{{)nI know an old lady who swallowed a cat. +Imagine that, to swallow a cat! +She swallowed the cat to catch the bird. +}} , bird backwash 2 5 + +dog=:{{)nI know an old lady who swallowed a dog. +What a hog, to swallow a dog! +She swallowed the dog to catch the cat. +}} , cat backwash 2 6 + +goat=:{{)nI know an old lady who swallowed a goat. +Just opened her throat and swallowed a goat! +She swallowed the goat to catch the dog. +}} , dog backwash 2 7 + +cow=:{{)nI know an old lady who swallowed a cow. +I don't know how she swallowed a cow! +She swallowed the cow to catch the goat. +}} , goat backwash 2 8 + +horse=:{{)nI know an old lady who swallowed a horse. +She's dead, of course! +}} + +verses=: '';fly;spider;bird;cat;dog;goat;cow;horse diff --git a/exercises/practice/food-chain/.meta/tests.toml b/exercises/practice/food-chain/.meta/tests.toml new file mode 100644 index 0000000..30c5b98 --- /dev/null +++ b/exercises/practice/food-chain/.meta/tests.toml @@ -0,0 +1,40 @@ +# 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. + +[751dce68-9412-496e-b6e8-855998c56166] +description = "fly" + +[6c56f861-0c5e-4907-9a9d-b2efae389379] +description = "spider" + +[3edf5f33-bef1-4e39-ae67-ca5eb79203fa] +description = "bird" + +[e866a758-e1ff-400e-9f35-f27f28cc288f] +description = "cat" + +[3f02c30e-496b-4b2a-8491-bc7e2953cafb] +description = "dog" + +[4b3fd221-01ea-46e0-825b-5734634fbc59] +description = "goat" + +[1b707da9-7001-4fac-941f-22ad9c7a65d4] +description = "cow" + +[3cb10d46-ae4e-4d2c-9296-83c9ffc04cdc] +description = "horse" + +[22b863d5-17e4-4d1e-93e4-617329a5c050] +description = "multiple verses" + +[e626b32b-745c-4101-bcbd-3b13456893db] +description = "full song" diff --git a/exercises/practice/food-chain/food-chain.ijs b/exercises/practice/food-chain/food-chain.ijs new file mode 100644 index 0000000..a098d6e --- /dev/null +++ b/exercises/practice/food-chain/food-chain.ijs @@ -0,0 +1,3 @@ +require 'general/unittest' + +recite =: 'You need to implement this verb.'13!:8 (55) diff --git a/exercises/practice/food-chain/test.ijs b/exercises/practice/food-chain/test.ijs new file mode 100644 index 0000000..01a7274 --- /dev/null +++ b/exercises/practice/food-chain/test.ijs @@ -0,0 +1,332 @@ +load 'food-chain.ijs' + + +before_all=: monad define + (]Description =: (3 : 'descriptions=: i.0')`(3 : 'descriptions=: descriptions , < y'))@.0 '' + (]Order =: (3 : 'order=: i.0')`(3 : 'order=: order , < y'))@.0 '' + (]Task =: (3 : 'tasks=: i.0')`(3 : 'tasks=: tasks , < y'))@.0 '' +) + + +food_chain_test_01_ignore=: 0 +test_food_chain_test_01 =: monad define + Description@.1 ('fly') + Order@.1 (1) + + NB. startverse=. 1 + NB. endverse=. 1 + NB. expected=.{{)nI know an old lady who swallowed a fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. }} + assert {{)nI know an old lady who swallowed a fly. +I don't know why she swallowed the fly. Perhaps she'll die. +}} = recite 1 1 +) + +food_chain_test_02_ignore=: 1 NB. Change this value to 0 to run this test +test_food_chain_test_02 =: monad define + Description@.1 ('spider') + Order@.1 (2) + + NB. startverse=. 2 + NB. endverse=. 2 + NB. expected=.{{)nI know an old lady who swallowed a spider. +NB. It wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. }} + assert {{)nI know an old lady who swallowed a spider. +It wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. +}} = recite 2 2 +) + +food_chain_test_03_ignore=: 1 NB. Change this value to 0 to run this test +test_food_chain_test_03 =: monad define + Description@.1 ('bird') + Order@.1 (3) + + NB. startverse=. 3 + NB. endverse=. 3 + NB. expected=.{{)nI know an old lady who swallowed a bird. +NB. How absurd to swallow a bird! +NB. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. }} + assert {{)nI know an old lady who swallowed a bird. +How absurd to swallow a bird! +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. +}} = recite 3 3 +) + +food_chain_test_04_ignore=: 1 NB. Change this value to 0 to run this test +test_food_chain_test_04 =: monad define + Description@.1 ('cat') + Order@.1 (4) + + NB. startverse=. 4 + NB. endverse=. 4 + NB. expected=.{{)nI know an old lady who swallowed a cat. +NB. Imagine that, to swallow a cat! +NB. She swallowed the cat to catch the bird. +NB. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. }} + assert {{)nI know an old lady who swallowed a cat. +Imagine that, to swallow a cat! +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. +}} = recite 4 4 +) + +food_chain_test_05_ignore=: 1 NB. Change this value to 0 to run this test +test_food_chain_test_05 =: monad define + Description@.1 ('dog') + Order@.1 (5) + + NB. startverse=. 5 + NB. endverse=. 5 + NB. expected=.{{)nI know an old lady who swallowed a dog. +NB. What a hog, to swallow a dog! +NB. She swallowed the dog to catch the cat. +NB. She swallowed the cat to catch the bird. +NB. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. }} + assert {{)nI know an old lady who swallowed a dog. +What a hog, to swallow a dog! +She swallowed the dog to catch the cat. +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. +}} = recite 5 5 +) + +food_chain_test_06_ignore=: 1 NB. Change this value to 0 to run this test +test_food_chain_test_06 =: monad define + Description@.1 ('goat') + Order@.1 (6) + + NB. startverse=. 6 + NB. endverse=. 6 + NB. expected=.{{)nI know an old lady who swallowed a goat. +NB. Just opened her throat and swallowed a goat! +NB. She swallowed the goat to catch the dog. +NB. She swallowed the dog to catch the cat. +NB. She swallowed the cat to catch the bird. +NB. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. }} + assert {{)nI know an old lady who swallowed a goat. +Just opened her throat and swallowed a goat! +She swallowed the goat to catch the dog. +She swallowed the dog to catch the cat. +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. +}} = recite 6 6 +) + +food_chain_test_07_ignore=: 1 NB. Change this value to 0 to run this test +test_food_chain_test_07 =: monad define + Description@.1 ('cow') + Order@.1 (7) + + NB. startverse=. 7 + NB. endverse=. 7 + NB. expected=.{{)nI know an old lady who swallowed a cow. +NB. I don't know how she swallowed a cow! +NB. She swallowed the cow to catch the goat. +NB. She swallowed the goat to catch the dog. +NB. She swallowed the dog to catch the cat. +NB. She swallowed the cat to catch the bird. +NB. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. }} + assert {{)nI know an old lady who swallowed a cow. +I don't know how she swallowed a cow! +She swallowed the cow to catch the goat. +She swallowed the goat to catch the dog. +She swallowed the dog to catch the cat. +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. +}} = recite 7 7 +) + +food_chain_test_08_ignore=: 1 NB. Change this value to 0 to run this test +test_food_chain_test_08 =: monad define + Description@.1 ('horse') + Order@.1 (8) + + NB. startverse=. 8 + NB. endverse=. 8 + NB. expected=.{{)nI know an old lady who swallowed a horse. +NB. She's dead, of course! +NB. }} + assert {{)nI know an old lady who swallowed a horse. +She's dead, of course! +}} = recite 8 8 +) + +food_chain_test_09_ignore=: 1 NB. Change this value to 0 to run this test +test_food_chain_test_09 =: monad define + Description@.1 ('multiple verses') + Order@.1 (9) + + NB. startverse=. 1 + NB. endverse=. 3 + NB. expected=.{{)nI know an old lady who swallowed a fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. +NB. I know an old lady who swallowed a spider. +NB. It wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. +NB. I know an old lady who swallowed a bird. +NB. How absurd to swallow a bird! +NB. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. }} + assert {{)nI know an old lady who swallowed a fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a spider. +It wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a bird. +How absurd to swallow a bird! +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. +}} = recite 1 3 +) + +food_chain_test_10_ignore=: 1 NB. Change this value to 0 to run this test +test_food_chain_test_10 =: monad define + Description@.1 ('full song') + Order@.1 (10) + + NB. startverse=. 1 + NB. endverse=. 8 + NB. expected=.{{)nI know an old lady who swallowed a fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. +NB. I know an old lady who swallowed a spider. +NB. It wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. +NB. I know an old lady who swallowed a bird. +NB. How absurd to swallow a bird! +NB. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. +NB. I know an old lady who swallowed a cat. +NB. Imagine that, to swallow a cat! +NB. She swallowed the cat to catch the bird. +NB. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. +NB. I know an old lady who swallowed a dog. +NB. What a hog, to swallow a dog! +NB. She swallowed the dog to catch the cat. +NB. She swallowed the cat to catch the bird. +NB. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. +NB. I know an old lady who swallowed a goat. +NB. Just opened her throat and swallowed a goat! +NB. She swallowed the goat to catch the dog. +NB. She swallowed the dog to catch the cat. +NB. She swallowed the cat to catch the bird. +NB. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. +NB. I know an old lady who swallowed a cow. +NB. I don't know how she swallowed a cow! +NB. She swallowed the cow to catch the goat. +NB. She swallowed the goat to catch the dog. +NB. She swallowed the dog to catch the cat. +NB. She swallowed the cat to catch the bird. +NB. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +NB. She swallowed the spider to catch the fly. +NB. I don't know why she swallowed the fly. Perhaps she'll die. +NB. +NB. I know an old lady who swallowed a horse. +NB. She's dead, of course! +NB. }} + assert {{)nI know an old lady who swallowed a fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a spider. +It wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a bird. +How absurd to swallow a bird! +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a cat. +Imagine that, to swallow a cat! +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a dog. +What a hog, to swallow a dog! +She swallowed the dog to catch the cat. +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a goat. +Just opened her throat and swallowed a goat! +She swallowed the goat to catch the dog. +She swallowed the dog to catch the cat. +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a cow. +I don't know how she swallowed a cow! +She swallowed the cow to catch the goat. +She swallowed the goat to catch the dog. +She swallowed the dog to catch the cat. +She swallowed the cat to catch the bird. +She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. +She swallowed the spider to catch the fly. +I don't know why she swallowed the fly. Perhaps she'll die. + +I know an old lady who swallowed a horse. +She's dead, of course! +}} = recite 1 8 +) + diff --git a/exercises/practice/grade-school/.docs/instructions.md b/exercises/practice/grade-school/.docs/instructions.md new file mode 100644 index 0000000..9a63e39 --- /dev/null +++ b/exercises/practice/grade-school/.docs/instructions.md @@ -0,0 +1,21 @@ +# Instructions + +Given students' names along with the grade that they are in, create a roster for the school. + +In the end, you should be able to: + +- Add a student's name to the roster for a grade + - "Add Jim to grade 2." + - "OK." +- Get a list of all students enrolled in a grade + - "Which students are in grade 2?" + - "We've only got Jim just now." +- Get a sorted list of all students in all grades. + Grades should sort as 1, 2, 3, etc., and students within a grade should be sorted alphabetically by name. + - "Who all is enrolled in school right now?" + - "Let me think. + We have Anna, Barb, and Charlie in grade 1, Alex, Peter, and Zoe in grade 2 and Jim in grade 5. + So the answer is: Anna, Barb, Charlie, Alex, Peter, Zoe and Jim" + +Note that all our students only have one name (It's a small town, what do you want?) and each student cannot be added more than once to a grade or the roster. +In fact, when a test attempts to add the same student more than once, your implementation should indicate that this is incorrect. diff --git a/exercises/practice/grade-school/.meta/config.json b/exercises/practice/grade-school/.meta/config.json new file mode 100644 index 0000000..aefebeb --- /dev/null +++ b/exercises/practice/grade-school/.meta/config.json @@ -0,0 +1,18 @@ +{ + "authors": [ + "eNascimento178" + ], + "files": { + "solution": [ + "grade-school.ijs" + ], + "test": [ + "test.ijs" + ], + "example": [ + ".meta/example.ijs" + ] + }, + "blurb": "Given students' names along with the grade that they are in, create a roster for the school.", + "source": "A pairing session with Phil Battos at gSchool" +} diff --git a/exercises/practice/grade-school/.meta/example.ijs b/exercises/practice/grade-school/.meta/example.ijs new file mode 100644 index 0000000..645a864 --- /dev/null +++ b/exercises/practice/grade-school/.meta/example.ijs @@ -0,0 +1,12 @@ + +roster =:{{ + if. '' -: y do. y return. end. + ; (/:~ @}.)each /:~ (>@{:"1 <@;/.. {."1) (add # |:) y +}} + +add =: ~:@{.^:(-.@-:&'') + +grade =:{{ + add=. |: (add # |:) x NB. alternatively `(~:@{. #&.(a:`|:) ]) y` + /:~ add ({.@[ #~ <@] = {:@[) y +}} diff --git a/exercises/practice/grade-school/.meta/tests.toml b/exercises/practice/grade-school/.meta/tests.toml new file mode 100644 index 0000000..50c9e2e --- /dev/null +++ b/exercises/practice/grade-school/.meta/tests.toml @@ -0,0 +1,86 @@ +# 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. + +[a3f0fb58-f240-4723-8ddc-e644666b85cc] +description = "Roster is empty when no student is added" + +[9337267f-7793-4b90-9b4a-8e3978408824] +description = "Add a student" + +[6d0a30e4-1b4e-472e-8e20-c41702125667] +description = "Student is added to the roster" + +[73c3ca75-0c16-40d7-82f5-ed8fe17a8e4a] +description = "Adding multiple students in the same grade in the roster" + +[233be705-dd58-4968-889d-fb3c7954c9cc] +description = "Multiple students in the same grade are added to the roster" + +[87c871c1-6bde-4413-9c44-73d59a259d83] +description = "Cannot add student to same grade in the roster more than once" + +[c125dab7-2a53-492f-a99a-56ad511940d8] +description = "A student can't be in two different grades" +include = false + +[a0c7b9b8-0e89-47f8-8b4a-c50f885e79d1] +description = "A student can only be added to the same grade in the roster once" +include = false +reimplements = "c125dab7-2a53-492f-a99a-56ad511940d8" + +[d7982c4f-1602-49f6-a651-620f2614243a] +description = "Student not added to same grade in the roster more than once" +reimplements = "a0c7b9b8-0e89-47f8-8b4a-c50f885e79d1" + +[e70d5d8f-43a9-41fd-94a4-1ea0fa338056] +description = "Adding students in multiple grades" + +[75a51579-d1d7-407c-a2f8-2166e984e8ab] +description = "Students in multiple grades are added to the roster" + +[7df542f1-57ce-433c-b249-ff77028ec479] +description = "Cannot add same student to multiple grades in the roster" + +[6a03b61e-1211-4783-a3cc-fc7f773fba3f] +description = "A student cannot be added to more than one grade in the sorted roster" +include = false +reimplements = "c125dab7-2a53-492f-a99a-56ad511940d8" + +[c7ec1c5e-9ab7-4d3b-be5c-29f2f7a237c5] +description = "Student not added to multiple grades in the roster" +reimplements = "6a03b61e-1211-4783-a3cc-fc7f773fba3f" + +[d9af4f19-1ba1-48e7-94d0-dabda4e5aba6] +description = "Students are sorted by grades in the roster" + +[d9fb5bea-f5aa-4524-9d61-c158d8906807] +description = "Students are sorted by name in the roster" + +[180a8ff9-5b94-43fc-9db1-d46b4a8c93b6] +description = "Students are sorted by grades and then by name in the roster" + +[5e67aa3c-a3c6-4407-a183-d8fe59cd1630] +description = "Grade is empty if no students in the roster" + +[1e0cf06b-26e0-4526-af2d-a2e2df6a51d6] +description = "Grade is empty if no students in that grade" + +[2bfc697c-adf2-4b65-8d0f-c46e085f796e] +description = "Student not added to same grade more than once" + +[66c8e141-68ab-4a04-a15a-c28bc07fe6b9] +description = "Student not added to multiple grades" + +[c9c1fc2f-42e0-4d2c-b361-99271f03eda7] +description = "Student not added to other grade for multiple grades" + +[1bfbcef1-e4a3-49e8-8d22-f6f9f386187e] +description = "Students are sorted by name in a grade" diff --git a/exercises/practice/grade-school/grade-school.ijs b/exercises/practice/grade-school/grade-school.ijs new file mode 100644 index 0000000..6b91276 --- /dev/null +++ b/exercises/practice/grade-school/grade-school.ijs @@ -0,0 +1,5 @@ +require 'general/unittest' + +roster =: 'You need to implement this verb.'13!:8 (55) +add =: 'You need to implement this verb.'13!:8 (55) +grade =: 'You need to implement this verb.'13!:8 (55) diff --git a/exercises/practice/grade-school/test.ijs b/exercises/practice/grade-school/test.ijs new file mode 100644 index 0000000..001692b --- /dev/null +++ b/exercises/practice/grade-school/test.ijs @@ -0,0 +1,214 @@ +load 'grade-school.ijs' + + +before_all=: monad define + (]Description =: (3 : 'descriptions=: i.0')`(3 : 'descriptions=: descriptions , < y'))@.0 '' + (]Order =: (3 : 'order=: i.0')`(3 : 'order=: order , < y'))@.0 '' + (]Task =: (3 : 'tasks=: i.0')`(3 : 'tasks=: tasks , < y'))@.0 '' +) + + +grade_school_test_01_ignore=: 0 +test_grade_school_test_01 =: monad define + Description@.1 ('Roster is empty when no student is added') + Order@.1 (1) + + NB. students=. '' + NB. expected=. '' + assert '' -: roster '' +) + +grade_school_test_02_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_02 =: monad define + Description@.1 ('Add a student') + Order@.1 (2) + + NB. students=. 'Aimee' ; 2 + NB. expected=. ,1 + assert (,1) = add (<'Aimee') ,: < 2 +) + +grade_school_test_03_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_03 =: monad define + Description@.1 ('Student is added to the roster') + Order@.1 (3) + + NB. students=. 'Aimee' ; 2 + NB. expected=. (,<'Aimee') + assert (,<'Aimee') = roster (<'Aimee') ,: < 2 +) + +grade_school_test_04_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_04 =: monad define + Description@.1 ('Adding multiple students in the same grade in the roster') + Order@.1 (4) + + NB. students=. (;:'Blair James Paul'),: <"0 (2 2 2) + NB. expected=. 1 1 1 + assert 1 1 1 -: add (;:'Blair James Paul'),: <"0 (2 2 2) +) + +grade_school_test_05_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_05 =: monad define + Description@.1 ('Multiple students in the same grade are added to the roster') + Order@.1 (5) + + NB. students=. (;:'Blair James Paul'),: <"0 (2 2 2) + NB. expected=. 'Blair James Paul' + assert (;:'Blair James Paul') -: roster (;:'Blair James Paul'),: <"0 (2 2 2) +) + +grade_school_test_06_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_06 =: monad define + Description@.1 ('Cannot add student to same grade in the roster more than once') + Order@.1 (6) + + NB. students=. (;:'Blair James James Paul'),: <"0 (2 2 2 2) + NB. expected=. 1 1 0 1 + assert 1 1 0 1 -: add (;:'Blair James James Paul'),: <"0 (2 2 2 2) +) + +grade_school_test_09_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_09 =: monad define + Description@.1 ('Student not added to same grade in the roster more than once') + Order@.1 (9) + + NB. expected=. 'Blair James Paul' + assert (;:'Blair James Paul') -: roster (;:'Blair James James Paul'),: <"0 (2 2 2 2) +) + +grade_school_test_10_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_10 =: monad define + Description@.1 ('Adding students in multiple grades') + Order@.1 (10) + + NB. students=. (;:'Chelsea Logan'),: <"0 (3 7) + NB. expected=. 1 1 + assert 1 1 -: add (;:'Chelsea Logan'),: <"0 (3 7) +) + +grade_school_test_11_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_11 =: monad define + Description@.1 ('Students in multiple grades are added to the roster') + Order@.1 (11) + + NB. students=. (;:'Chelsea Logan'),: <"0 (3 7) + NB. expected=. 'Chelsea Logan' + assert (;:'Chelsea Logan') -: roster (;:'Chelsea Logan'),: <"0 (3 7) +) + +grade_school_test_12_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_12 =: monad define + Description@.1 ('Cannot add same student to multiple grades in the roster') + Order@.1 (12) + + NB. students=. (;:'Blair James James Paul'),: <"0 (2 2 3 3) + NB. expected=. 1 1 0 1 + assert 1 1 0 1 -: add (;:'Blair James James Paul'),: <"0 (2 2 3 3) +) + +grade_school_test_14_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_14 =: monad define + Description@.1 ('Student not added to multiple grades in the roster') + Order@.1 (14) + + NB. students=. (;:'Blair James James Paul'),: <"0 (2 2 3 3) + NB. expected=. 'Blair James Paul' + assert (;:'Blair James Paul') -: roster (;:'Blair James James Paul'),: <"0 (2 2 3 3) +) + +grade_school_test_15_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_15 =: monad define + Description@.1 ('Students are sorted by grades in the roster') + Order@.1 (15) + + NB. students=. (;:'Jim Peter Anna'),: <"0 (3 2 1) + NB. expected=. 'Anna Peter Jim' + assert (;:'Anna Peter Jim') -: roster (;:'Jim Peter Anna'),: <"0 (3 2 1) +) + +grade_school_test_16_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_16 =: monad define + Description@.1 ('Students are sorted by name in the roster') + Order@.1 (16) + + NB. students=. (;:'Peter Zoe Alex'),: <"0 (2 2 2) + NB. expected=. 'Alex Peter Zoe' + assert (;:'Alex Peter Zoe') -: roster (;:'Peter Zoe Alex'),: <"0 (2 2 2) +) + +grade_school_test_17_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_17 =: monad define + Description@.1 ('Students are sorted by grades and then by name in the roster') + Order@.1 (17) + + NB. students=. (;:'Peter Anna Barb Zoe Alex Jim Charlie'),: <"0 (2 1 1 2 2 3 1) + NB. expected=. 'Anna Barb Charlie Alex Peter Zoe Jim' + assert (;:'Anna Barb Charlie Alex Peter Zoe Jim') -: roster (;:'Peter Anna Barb Zoe Alex Jim Charlie'),: <"0 (2 1 1 2 2 3 1) +) + +grade_school_test_18_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_18 =: monad define + Description@.1 ('Grade is empty if no students in the roster') + Order@.1 (18) + + NB. students=. '' + NB. desiredGrade=. 1 + NB. expected=. '' + assert '' -: '' grade 1 +) + +grade_school_test_19_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_19 =: monad define + Description@.1 ('Grade is empty if no students in that grade') + Order@.1 (19) + + NB. students=. (;:'Peter Zoe Alex Jim'),: <"0 (2 2 2 3) + NB. desiredGrade=. 1 + NB. expected=. '' + assert '' -: ((;:'Peter Zoe Alex Jim'),: <"0 (2 2 2 3)) grade 1 +) + +grade_school_test_20_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_20 =: monad define + Description@.1 ('Student not added to same grade more than once') + Order@.1 (20) + + NB. students=. (;:'Blair James James Paul'),: <"0 (2 2 2 2) + NB. desiredGrade=. 2 + NB. expected=. 'Blair James Paul' + assert (;:'Blair James Paul') -: ((;:'Blair James James Paul'),: <"0 (2 2 2 2)) grade 2 +) + +grade_school_test_21_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_21 =: monad define + Description@.1 ('Student not added to multiple grades') + Order@.1 (21) + + NB. students=. (;:'Blair James James Paul'),: <"0 (2 2 3 3) + NB. desiredGrade=. 2 + NB. expected=. 'Blair James' + assert (;:'Blair James') -: ((;:'Blair James James Paul'),: <"0 (2 2 3 3)) grade 2 +) + +grade_school_test_22_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_22 =: monad define + Description@.1 ('Student not added to other grade for multiple grades') + Order@.1 (22) + + NB. students=. (;:'Blair James James Paul'),: <"0 (2 2 3 3) + NB. desiredGrade=. 3 + NB. expected=. (,<'Paul') + assert (,<'Paul') = ((;:'Blair James James Paul'),: <"0 (2 2 3 3)) grade 3 +) + +grade_school_test_23_ignore=: 1 NB. Change this value to 0 to run this test +test_grade_school_test_23 =: monad define + Description@.1 ('Students are sorted by name in a grade') + Order@.1 (23) + + NB. students=. (;:'Franklin Bradley Jeff'),: <"0 (5 5 1) + NB. desiredGrade=. 5 + NB. expected=. 'Bradley Franklin' + assert (;:'Bradley Franklin') -: ((;:'Franklin Bradley Jeff'),: <"0 (5 5 1)) grade 5 +) diff --git a/exercises/practice/largest-series-product/.docs/instructions.md b/exercises/practice/largest-series-product/.docs/instructions.md new file mode 100644 index 0000000..f297b57 --- /dev/null +++ b/exercises/practice/largest-series-product/.docs/instructions.md @@ -0,0 +1,26 @@ +# Instructions + +Your task is to look for patterns in the long sequence of digits in the encrypted signal. + +The technique you're going to use here is called the largest series product. + +Let's define a few terms, first. + +- **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**. 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 0000000..597bb5f --- /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. diff --git a/exercises/practice/largest-series-product/.meta/config.json b/exercises/practice/largest-series-product/.meta/config.json new file mode 100644 index 0000000..1cf3303 --- /dev/null +++ b/exercises/practice/largest-series-product/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "eNascimento178" + ], + "files": { + "solution": [ + "largest-series-product.ijs" + ], + "test": [ + "test.ijs" + ], + "example": [ + ".meta/example.ijs" + ] + }, + "blurb": "Given a string of digits, calculate the largest product for a contiguous substring of digits of length n.", + "source": "A variation on Problem 8 at Project Euler", + "source_url": "https://projecteuler.net/problem=8" +} diff --git a/exercises/practice/largest-series-product/.meta/example.ijs b/exercises/practice/largest-series-product/.meta/example.ijs new file mode 100644 index 0000000..978f1b4 --- /dev/null +++ b/exercises/practice/largest-series-product/.meta/example.ijs @@ -0,0 +1,4 @@ +largest_product=: {{ + if. 0 = x do. 1 return. end. + x (>./ @: (*/"1) @: ("."0) @ (]\)) y +}} diff --git a/exercises/practice/largest-series-product/.meta/tests.toml b/exercises/practice/largest-series-product/.meta/tests.toml new file mode 100644 index 0000000..89cf392 --- /dev/null +++ b/exercises/practice/largest-series-product/.meta/tests.toml @@ -0,0 +1,63 @@ +# 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. + +[7c82f8b7-e347-48ee-8a22-f672323324d4] +description = "finds the largest product if span equals length" + +[88523f65-21ba-4458-a76a-b4aaf6e4cb5e] +description = "can find the largest product of 2 with numbers in order" + +[f1376b48-1157-419d-92c2-1d7e36a70b8a] +description = "can find the largest product of 2" + +[46356a67-7e02-489e-8fea-321c2fa7b4a4] +description = "can find the largest product of 3 with numbers in order" + +[a2dcb54b-2b8f-4993-92dd-5ce56dece64a] +description = "can find the largest product of 3" + +[673210a3-33cd-4708-940b-c482d7a88f9d] +description = "can find the largest product of 5 with numbers in order" + +[02acd5a6-3bbf-46df-8282-8b313a80a7c9] +description = "can get the largest product of a big number" + +[76dcc407-21e9-424c-a98e-609f269622b5] +description = "reports zero if the only digits are zero" + +[6ef0df9f-52d4-4a5d-b210-f6fae5f20e19] +description = "reports zero if all spans include zero" + +[5d81aaf7-4f67-4125-bf33-11493cc7eab7] +description = "rejects span longer than string length" +include = false + +[06bc8b90-0c51-4c54-ac22-3ec3893a079e] +description = "reports 1 for empty string and empty product (0 span)" + +[3ec0d92e-f2e2-4090-a380-70afee02f4c0] +description = "reports 1 for nonempty string and empty product (0 span)" + +[6d96c691-4374-4404-80ee-2ea8f3613dd4] +description = "rejects empty string and nonzero span" +include = false + +[7a38f2d6-3c35-45f6-8d6f-12e6e32d4d74] +description = "rejects invalid character in digits" +include = false + +[5fe3c0e5-a945-49f2-b584-f0814b4dd1ef] +description = "rejects negative span" +include = false + +[c859f34a-9bfe-4897-9c2f-6d7f8598e7f0] +description = "rejects negative span" +reimplements = "5fe3c0e5-a945-49f2-b584-f0814b4dd1ef" diff --git a/exercises/practice/largest-series-product/largest-series-product.ijs b/exercises/practice/largest-series-product/largest-series-product.ijs new file mode 100644 index 0000000..a88ad5b --- /dev/null +++ b/exercises/practice/largest-series-product/largest-series-product.ijs @@ -0,0 +1,3 @@ +require 'general/unittest' + +largest_product =: 'You need to implement this verb.'13!:8 (55) diff --git a/exercises/practice/largest-series-product/test.ijs b/exercises/practice/largest-series-product/test.ijs new file mode 100644 index 0000000..284160e --- /dev/null +++ b/exercises/practice/largest-series-product/test.ijs @@ -0,0 +1,130 @@ +load 'largest-series-product.ijs' + + +before_all=: monad define + (]Description =: (3 : 'descriptions=: i.0')`(3 : 'descriptions=: descriptions , < y'))@.0 '' + (]Order =: (3 : 'order=: i.0')`(3 : 'order=: order , < y'))@.0 '' + (]Task =: (3 : 'tasks=: i.0')`(3 : 'tasks=: tasks , < y'))@.0 '' +) + + +largest_series_product_test_01_ignore=: 0 +test_largest_series_product_test_01 =: monad define + Description@.1 ('finds the largest product if span equals length') + Order@.1 (1) + + NB. digits=. '29' + NB. span=. 2 + NB. expected=. 18 + assert 18 -: 2 largest_product '29' +) + +largest_series_product_test_02_ignore=: 1 NB. Change this value to 0 to run this test +test_largest_series_product_test_02 =: monad define + Description@.1 ('can find the largest product of 2 with numbers in order') + Order@.1 (2) + + NB. digits=. '0123456789' + NB. span=. 2 + NB. expected=. 72 + assert 72 -: 2 largest_product '0123456789' +) + +largest_series_product_test_03_ignore=: 1 NB. Change this value to 0 to run this test +test_largest_series_product_test_03 =: monad define + Description@.1 ('can find the largest product of 2') + Order@.1 (3) + + NB. digits=. '576802143' + NB. span=. 2 + NB. expected=. 48 + assert 48 -: 2 largest_product '576802143' +) + +largest_series_product_test_04_ignore=: 1 NB. Change this value to 0 to run this test +test_largest_series_product_test_04 =: monad define + Description@.1 ('can find the largest product of 3 with numbers in order') + Order@.1 (4) + + NB. digits=. '0123456789' + NB. span=. 3 + NB. expected=. 504 + assert 504 -: 3 largest_product '0123456789' +) + +largest_series_product_test_05_ignore=: 1 NB. Change this value to 0 to run this test +test_largest_series_product_test_05 =: monad define + Description@.1 ('can find the largest product of 3') + Order@.1 (5) + + NB. digits=. '1027839564' + NB. span=. 3 + NB. expected=. 270 + assert 270 -: 3 largest_product '1027839564' +) + +largest_series_product_test_06_ignore=: 1 NB. Change this value to 0 to run this test +test_largest_series_product_test_06 =: monad define + Description@.1 ('can find the largest product of 5 with numbers in order') + Order@.1 (6) + + NB. digits=. '0123456789' + NB. span=. 5 + NB. expected=. 15120 + assert 15120 -: 5 largest_product '0123456789' +) + +largest_series_product_test_07_ignore=: 1 NB. Change this value to 0 to run this test +test_largest_series_product_test_07 =: monad define + Description@.1 ('can get the largest product of a big number') + Order@.1 (7) + + NB. digits=. '73167176531330624919225119674426574742355349194934' + NB. span=. 6 + NB. expected=. 23520 + assert 23520 -: 6 largest_product '73167176531330624919225119674426574742355349194934' +) + +largest_series_product_test_08_ignore=: 1 NB. Change this value to 0 to run this test +test_largest_series_product_test_08 =: monad define + Description@.1 ('reports zero if the only digits are zero') + Order@.1 (8) + + NB. digits=. '0000' + NB. span=. 2 + NB. expected=. 0 + assert 0 -: 2 largest_product '0000' +) + +largest_series_product_test_09_ignore=: 1 NB. Change this value to 0 to run this test +test_largest_series_product_test_09 =: monad define + Description@.1 ('reports zero if all spans include zero') + Order@.1 (9) + + NB. digits=. '99099' + NB. span=. 3 + NB. expected=. 0 + assert 0 -: 3 largest_product '99099' +) + +largest_series_product_test_11_ignore=: 1 NB. Change this value to 0 to run this test +test_largest_series_product_test_11 =: monad define + Description@.1 ('reports 1 for empty string and empty product (0 span)') + Order@.1 (11) + + NB. digits=. '' + NB. span=. 0 + NB. expected=. 1 + assert 1 -: 0 largest_product '' +) + +largest_series_product_test_12_ignore=: 1 NB. Change this value to 0 to run this test +test_largest_series_product_test_12 =: monad define + Description@.1 ('reports 1 for nonempty string and empty product (0 span)') + Order@.1 (12) + + NB. digits=. '123' + NB. span=. 0 + NB. expected=. 1 + assert 1 -: 0 largest_product '123' +) diff --git a/exercises/practice/run-length-encoding/.docs/instructions.md b/exercises/practice/run-length-encoding/.docs/instructions.md new file mode 100644 index 0000000..fc8ce05 --- /dev/null +++ b/exercises/practice/run-length-encoding/.docs/instructions.md @@ -0,0 +1,20 @@ +# Instructions + +Implement run-length encoding and decoding. + +Run-length encoding (RLE) is a simple form of data compression, where runs (consecutive data elements) are replaced by just one data value and count. + +For example we can represent the original 53 characters with only 13. + +```text +"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB" -> "12WB12W3B24WB" +``` + +RLE allows the original data to be perfectly reconstructed from the compressed data, which makes it a lossless data compression. + +```text +"AABCCCDEEEE" -> "2AB3CD4E" -> "AABCCCDEEEE" +``` + +For simplicity, you can assume that the unencoded string will only contain the letters A through Z (either lower or upper case) and whitespace. +This way data to be encoded will never contain any numbers and numbers inside data to be decoded always represent the count for the following character. diff --git a/exercises/practice/run-length-encoding/.meta/config.json b/exercises/practice/run-length-encoding/.meta/config.json new file mode 100644 index 0000000..688b3d8 --- /dev/null +++ b/exercises/practice/run-length-encoding/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "eNascimento178" + ], + "files": { + "solution": [ + "run-length-encoding.ijs" + ], + "test": [ + "test.ijs" + ], + "example": [ + ".meta/example.ijs" + ] + }, + "blurb": "Implement run-length encoding and decoding.", + "source": "Wikipedia", + "source_url": "https://en.wikipedia.org/wiki/Run-length_encoding" +} diff --git a/exercises/practice/run-length-encoding/.meta/example.ijs b/exercises/practice/run-length-encoding/.meta/example.ijs new file mode 100644 index 0000000..9fecb02 --- /dev/null +++ b/exercises/practice/run-length-encoding/.meta/example.ijs @@ -0,0 +1,4 @@ +rem =: ":@(''"_^:(1&=)) NB. if the count is one remove it +frets =: 1 , 2&(~:/\) NB. get the frets by taking the nub sieve of the partitions and append 1 +encode =: ; @: (frets ((rem@# ; {.));.1 ]) :: '' NB. if y is empty returns empty +decode =: '\d+[a-zA-Z ]'&((1&".@}: # {:)rxapply) diff --git a/exercises/practice/run-length-encoding/.meta/tests.toml b/exercises/practice/run-length-encoding/.meta/tests.toml new file mode 100644 index 0000000..7bdb808 --- /dev/null +++ b/exercises/practice/run-length-encoding/.meta/tests.toml @@ -0,0 +1,49 @@ +# 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. + +[ad53b61b-6ffc-422f-81a6-61f7df92a231] +description = "run-length encode a string -> empty string" + +[52012823-b7e6-4277-893c-5b96d42f82de] +description = "run-length encode a string -> single characters only are encoded without count" + +[b7868492-7e3a-415f-8da3-d88f51f80409] +description = "run-length encode a string -> string with no single characters" + +[859b822b-6e9f-44d6-9c46-6091ee6ae358] +description = "run-length encode a string -> single characters mixed with repeated characters" + +[1b34de62-e152-47be-bc88-469746df63b3] +description = "run-length encode a string -> multiple whitespace mixed in string" + +[abf176e2-3fbd-40ad-bb2f-2dd6d4df721a] +description = "run-length encode a string -> lowercase characters" + +[7ec5c390-f03c-4acf-ac29-5f65861cdeb5] +description = "run-length decode a string -> empty string" + +[ad23f455-1ac2-4b0e-87d0-b85b10696098] +description = "run-length decode a string -> single characters only" + +[21e37583-5a20-4a0e-826c-3dee2c375f54] +description = "run-length decode a string -> string with no single characters" + +[1389ad09-c3a8-4813-9324-99363fba429c] +description = "run-length decode a string -> single characters with repeated characters" + +[3f8e3c51-6aca-4670-b86c-a213bf4706b0] +description = "run-length decode a string -> multiple whitespace mixed in string" + +[29f721de-9aad-435f-ba37-7662df4fb551] +description = "run-length decode a string -> lowercase string" + +[2a762efd-8695-4e04-b0d6-9736899fbc16] +description = "encode and then decode -> encode followed by decode gives original string" diff --git a/exercises/practice/run-length-encoding/run-length-encoding.ijs b/exercises/practice/run-length-encoding/run-length-encoding.ijs new file mode 100644 index 0000000..f5c1dc0 --- /dev/null +++ b/exercises/practice/run-length-encoding/run-length-encoding.ijs @@ -0,0 +1,4 @@ +require 'general/unittest' + +encode =: 'You need to implement this verb.'13!:8 (55) +decode =: 'You need to implement this verb.'13!:8 (55) diff --git a/exercises/practice/run-length-encoding/test.ijs b/exercises/practice/run-length-encoding/test.ijs new file mode 100644 index 0000000..2b87e0e --- /dev/null +++ b/exercises/practice/run-length-encoding/test.ijs @@ -0,0 +1,140 @@ +load 'run-length-encoding.ijs' + + +before_all=: monad define + (]Description =: (3 : 'descriptions=: i.0')`(3 : 'descriptions=: descriptions , < y'))@.0 '' + (]Order =: (3 : 'order=: i.0')`(3 : 'order=: order , < y'))@.0 '' + (]Task =: (3 : 'tasks=: i.0')`(3 : 'tasks=: tasks , < y'))@.0 '' +) + + +run_length_encoding_test_01_ignore=: 0 +test_run_length_encoding_test_01 =: monad define + Description@.1 ('empty string') + Order@.1 (1) + + NB. string=. '' + NB. expected=. '' + assert '' -: encode '' +) + +run_length_encoding_test_02_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_02 =: monad define + Description@.1 ('single characters only are encoded without count') + Order@.1 (2) + + NB. string=. 'XYZ' + NB. expected=. 'XYZ' + assert 'XYZ' -: encode 'XYZ' +) + +run_length_encoding_test_03_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_03 =: monad define + Description@.1 ('string with no single characters') + Order@.1 (3) + + NB. string=. 'AABBBCCCC' + NB. expected=. '2A3B4C' + assert '2A3B4C' -: encode 'AABBBCCCC' +) + +run_length_encoding_test_04_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_04 =: monad define + Description@.1 ('single characters mixed with repeated characters') + Order@.1 (4) + + NB. string=. 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB' + NB. expected=. '12WB12W3B24WB' + assert '12WB12W3B24WB' -: encode 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB' +) + +run_length_encoding_test_05_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_05 =: monad define + Description@.1 ('multiple whitespace mixed in string') + Order@.1 (5) + + NB. string=. ' hsqq qww ' + NB. expected=. '2 hs2q q2w2 ' + assert '2 hs2q q2w2 ' -: encode ' hsqq qww ' +) + +run_length_encoding_test_06_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_06 =: monad define + Description@.1 ('lowercase characters') + Order@.1 (6) + + NB. string=. 'aabbbcccc' + NB. expected=. '2a3b4c' + assert '2a3b4c' -: encode 'aabbbcccc' +) + +run_length_encoding_test_07_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_07 =: monad define + Description@.1 ('empty string') + Order@.1 (7) + + NB. string=. '' + NB. expected=. '' + assert '' -: decode '' +) + +run_length_encoding_test_08_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_08 =: monad define + Description@.1 ('single characters only') + Order@.1 (8) + + NB. string=. 'XYZ' + NB. expected=. 'XYZ' + assert 'XYZ' -: decode 'XYZ' +) + +run_length_encoding_test_09_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_09 =: monad define + Description@.1 ('string with no single characters') + Order@.1 (9) + + NB. string=. '2A3B4C' + NB. expected=. 'AABBBCCCC' + assert 'AABBBCCCC' -: decode '2A3B4C' +) + +run_length_encoding_test_10_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_10 =: monad define + Description@.1 ('single characters with repeated characters') + Order@.1 (10) + + NB. string=. '12WB12W3B24WB' + NB. expected=. 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB' + assert 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB' -: decode '12WB12W3B24WB' +) + +run_length_encoding_test_11_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_11 =: monad define + Description@.1 ('multiple whitespace mixed in string') + Order@.1 (11) + + NB. string=. '2 hs2q q2w2 ' + NB. expected=. ' hsqq qww ' + assert ' hsqq qww ' -: decode '2 hs2q q2w2 ' +) + +run_length_encoding_test_12_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_12 =: monad define + Description@.1 ('lowercase string') + Order@.1 (12) + + NB. string=. '2a3b4c' + NB. expected=. 'aabbbcccc' + assert 'aabbbcccc' -: decode '2a3b4c' +) + +run_length_encoding_test_13_ignore=: 1 NB. Change this value to 0 to run this test +test_run_length_encoding_test_13 =: monad define + Description@.1 ('encode followed by decode gives original string') + Order@.1 (13) + + NB. string=. 'zzz ZZ zZ' + NB. expected=. 'zzz ZZ zZ' + assert 'zzz ZZ zZ' -: decode@encode 'zzz ZZ zZ' +) + diff --git a/exercises/practice/sieve/.docs/instructions.md b/exercises/practice/sieve/.docs/instructions.md new file mode 100644 index 0000000..085c0a5 --- /dev/null +++ b/exercises/practice/sieve/.docs/instructions.md @@ -0,0 +1,42 @@ +# Instructions + +Your task is to create a program that implements the Sieve of Eratosthenes algorithm to find all prime numbers less than or equal to a given number. + +A prime number is a number larger than 1 that is only divisible by 1 and itself. +For example, 2, 3, 5, 7, 11, and 13 are prime numbers. +By contrast, 6 is _not_ a prime number as it not only divisible by 1 and itself, but also by 2 and 3. + +To use the Sieve of Eratosthenes, you first create a list of all the numbers between 2 and your given number. +Then you repeat the following steps: + +1. Find the next unmarked number in your list (skipping over marked numbers). + This is a prime number. +2. Mark all the multiples of that prime number as **not** prime. + +You keep repeating these steps until you've gone through every number in your list. +At the end, all the unmarked numbers are prime. + +~~~~exercism/note +The tests don't check that you've implemented the algorithm, only that you've come up with the correct list of primes. +To check you are implementing the Sieve correctly, a good first test is to check that you do not use division or remainder operations. +~~~~ + +## Example + +Let's say you're finding the primes less than or equal to 10. + +- List out 2, 3, 4, 5, 6, 7, 8, 9, 10, leaving them all unmarked. +- 2 is unmarked and is therefore a prime. + Mark 4, 6, 8 and 10 as "not prime". +- 3 is unmarked and is therefore a prime. + Mark 6 and 9 as not prime _(marking 6 is optional - as it's already been marked)_. +- 4 is marked as "not prime", so we skip over it. +- 5 is unmarked and is therefore a prime. + Mark 10 as not prime _(optional - as it's already been marked)_. +- 6 is marked as "not prime", so we skip over it. +- 7 is unmarked and is therefore a prime. +- 8 is marked as "not prime", so we skip over it. +- 9 is marked as "not prime", so we skip over it. +- 10 is marked as "not prime", so we stop as there are no more numbers to check. + +You've examined all numbers and found 2, 3, 5, and 7 are still unmarked, which means they're the primes less than or equal to 10. diff --git a/exercises/practice/sieve/.docs/introduction.md b/exercises/practice/sieve/.docs/introduction.md new file mode 100644 index 0000000..f6c1cf7 --- /dev/null +++ b/exercises/practice/sieve/.docs/introduction.md @@ -0,0 +1,7 @@ +# Introduction + +You bought a big box of random computer parts at a garage sale. +You've started putting the parts together to build custom computers. + +You want to test the performance of different combinations of parts, and decide to create your own benchmarking program to see how your computers compare. +You choose the famous "Sieve of Eratosthenes" algorithm, an ancient algorithm, but one that should push your computers to the limits. diff --git a/exercises/practice/sieve/.meta/config.json b/exercises/practice/sieve/.meta/config.json new file mode 100644 index 0000000..76dd968 --- /dev/null +++ b/exercises/practice/sieve/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "eNascimento178" + ], + "files": { + "solution": [ + "sieve.ijs" + ], + "test": [ + "test.ijs" + ], + "example": [ + ".meta/example.ijs" + ] + }, + "blurb": "Use the Sieve of Eratosthenes to find all the primes from 2 up to a given number.", + "source": "Sieve of Eratosthenes at Wikipedia", + "source_url": "https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" +} diff --git a/exercises/practice/sieve/.meta/example.ijs b/exercises/practice/sieve/.meta/example.ijs new file mode 100644 index 0000000..014b557 --- /dev/null +++ b/exercises/practice/sieve/.meta/example.ijs @@ -0,0 +1 @@ +primes=: [: i.&.(p:^:_1) >: diff --git a/exercises/practice/sieve/.meta/tests.toml b/exercises/practice/sieve/.meta/tests.toml new file mode 100644 index 0000000..fec5e1a --- /dev/null +++ b/exercises/practice/sieve/.meta/tests.toml @@ -0,0 +1,25 @@ +# 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. + +[88529125-c4ce-43cc-bb36-1eb4ddd7b44f] +description = "no primes under two" + +[4afe9474-c705-4477-9923-840e1024cc2b] +description = "find first prime" + +[974945d8-8cd9-4f00-9463-7d813c7f17b7] +description = "find primes up to 10" + +[2e2417b7-3f3a-452a-8594-b9af08af6d82] +description = "limit is prime" + +[92102a05-4c7c-47de-9ed0-b7d5fcd00f21] +description = "find primes up to 1000" diff --git a/exercises/practice/sieve/sieve.ijs b/exercises/practice/sieve/sieve.ijs new file mode 100644 index 0000000..b33bf29 --- /dev/null +++ b/exercises/practice/sieve/sieve.ijs @@ -0,0 +1,3 @@ +require 'general/unittest' + +primes =: 'You need to implement this verb.'13!:8 (55) diff --git a/exercises/practice/sieve/test.ijs b/exercises/practice/sieve/test.ijs new file mode 100644 index 0000000..5911f82 --- /dev/null +++ b/exercises/practice/sieve/test.ijs @@ -0,0 +1,60 @@ +load 'sieve.ijs' + + +before_all=: monad define + (]Description =: (3 : 'descriptions=: i.0')`(3 : 'descriptions=: descriptions , < y'))@.0 '' + (]Order =: (3 : 'order=: i.0')`(3 : 'order=: order , < y'))@.0 '' + (]Task =: (3 : 'tasks=: i.0')`(3 : 'tasks=: tasks , < y'))@.0 '' +) + + +sieve_test_01_ignore=: 0 +test_sieve_test_01 =: monad define + Description@.1 ('no primes under two') + Order@.1 (1) + + NB. limit=. 1 + NB. expected=. '' + assert '' = primes 1 +) + +sieve_test_02_ignore=: 1 NB. Change this value to 0 to run this test +test_sieve_test_02 =: monad define + Description@.1 ('find first prime') + Order@.1 (2) + + NB. limit=. 2 + NB. expected=. ,2 + assert (,2) = primes 2 +) + +sieve_test_03_ignore=: 1 NB. Change this value to 0 to run this test +test_sieve_test_03 =: monad define + Description@.1 ('find primes up to 10') + Order@.1 (3) + + NB. limit=. 10 + NB. expected=. 2 3 5 7 + assert 2 3 5 7 = primes 10 +) + +sieve_test_04_ignore=: 1 NB. Change this value to 0 to run this test +test_sieve_test_04 =: monad define + Description@.1 ('limit is prime') + Order@.1 (4) + + NB. limit=. 13 + NB. expected=. 2 3 5 7 11 13 + assert 2 3 5 7 11 13 = primes 13 +) + +sieve_test_05_ignore=: 1 NB. Change this value to 0 to run this test +test_sieve_test_05 =: monad define + Description@.1 ('find primes up to 1000') + Order@.1 (5) + + NB. limit=. 1000 + NB. expected=. 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 + assert 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 = primes 1000 +) +