Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exercises #127

Merged
merged 10 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
},
Expand Down
14 changes: 14 additions & 0 deletions exercises/practice/armstrong-numbers/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions exercises/practice/armstrong-numbers/.meta/config.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 2 additions & 0 deletions exercises/practice/armstrong-numbers/.meta/example.ijs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

is_armstrong_number=: = [: +/ ([: (^ #) 10&#.^:_1)
43 changes: 43 additions & 0 deletions exercises/practice/armstrong-numbers/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions exercises/practice/armstrong-numbers/armstrong-numbers.ijs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'general/unittest'

is_armstrong_number =: 'You need to implement this verb.'13!:8 (55)
120 changes: 120 additions & 0 deletions exercises/practice/armstrong-numbers/test.ijs
Original file line number Diff line number Diff line change
@@ -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
)

52 changes: 52 additions & 0 deletions exercises/practice/diamond/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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····
```
19 changes: 19 additions & 0 deletions exercises/practice/diamond/.meta/config.json
Original file line number Diff line number Diff line change
@@ -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/"
}
11 changes: 11 additions & 0 deletions exercises/practice/diamond/.meta/example.ijs
Original file line number Diff line number Diff line change
@@ -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
}}
25 changes: 25 additions & 0 deletions exercises/practice/diamond/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions exercises/practice/diamond/diamond.ijs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'general/unittest'

rows =: 'You need to implement this verb.'13!:8 (55)
Loading