Skip to content
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
2 changes: 2 additions & 0 deletions concepts/assocs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ set-at ( value key assoc -- )
delete-at ( key assoc -- )
inc-at ( key assoc -- )
change-at ( key assoc quot -- )
keys ( assoc -- keys )
values ( assoc -- values )
>alist ( assoc -- alist )
```

Expand Down
126 changes: 114 additions & 12 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1011,18 +1011,6 @@
],
"difficulty": 3
},
{
"slug": "robot-name",
"name": "Robot Name",
"uuid": "1f3cded8-c357-448d-9640-63e8e6ea8efe",
"practices": [],
"prerequisites": [
"dynamic-variables",
"randomness",
"hash-sets"
],
"difficulty": 3
},
{
"slug": "rotational-cipher",
"name": "Rotational Cipher",
Expand Down Expand Up @@ -1053,6 +1041,20 @@
],
"difficulty": 3
},
{
"slug": "series",
"name": "Series",
"uuid": "3bb91e4a-d234-40e9-b56c-fb06a9d84985",
"practices": [],
"prerequisites": [
"strings",
"sequences",
"combinators",
"locals",
"errors"
],
"difficulty": 3
},
{
"slug": "sum-of-multiples",
"name": "Sum of Multiples",
Expand Down Expand Up @@ -1147,6 +1149,19 @@
],
"difficulty": 4
},
{
"slug": "diamond",
"name": "Diamond",
"uuid": "3da8114d-a1d4-4b45-9cb6-30bbef6624d3",
"practices": [],
"prerequisites": [
"strings",
"tabulation",
"higher-order-sequences",
"locals"
],
"difficulty": 4
},
{
"slug": "flatten-array",
"name": "Flatten Array",
Expand All @@ -1162,6 +1177,21 @@
],
"difficulty": 4
},
{
"slug": "grade-school",
"name": "Grade School",
"uuid": "fb1fe9a5-d2ce-4e44-850f-7c0518e0422c",
"practices": [],
"prerequisites": [
"tuples",
"mutation",
"assocs",
"higher-order-sequences",
"curry-compose-fry",
"locals"
],
"difficulty": 4
},
{
"slug": "kindergarten-garden",
"name": "Kindergarten Garden",
Expand Down Expand Up @@ -1273,6 +1303,20 @@
],
"difficulty": 4
},
{
"slug": "roman-numerals",
"name": "Roman Numerals",
"uuid": "31e438b9-e2c9-4d35-9b3f-dc8a97dcb787",
"practices": [],
"prerequisites": [
"numbers",
"tabulation",
"higher-order-sequences",
"arrays",
"locals"
],
"difficulty": 4
},
{
"slug": "sieve",
"name": "Sieve",
Expand Down Expand Up @@ -1498,6 +1542,18 @@
],
"difficulty": 5
},
{
"slug": "robot-name",
"name": "Robot Name",
"uuid": "1f3cded8-c357-448d-9640-63e8e6ea8efe",
"practices": [],
"prerequisites": [
"dynamic-variables",
"randomness",
"hash-sets"
],
"difficulty": 5
},
{
"slug": "run-length-encoding",
"name": "Run-Length Encoding",
Expand Down Expand Up @@ -1629,6 +1685,19 @@
],
"difficulty": 6
},
{
"slug": "flower-field",
"name": "Flower Field",
"uuid": "d635beb6-bc14-4846-909c-b6216c3f4d41",
"practices": [],
"prerequisites": [
"strings",
"tabulation",
"higher-order-sequences",
"locals"
],
"difficulty": 6
},
{
"slug": "food-chain",
"name": "Food Chain",
Expand All @@ -1643,6 +1712,23 @@
],
"difficulty": 6
},
{
"slug": "intergalactic-transmission",
"name": "Intergalactic Transmission",
"uuid": "e2ce391c-7d7e-4442-aea6-71f310206ace",
"practices": [],
"prerequisites": [
"bitwise-operations",
"arrays",
"windows",
"reductions",
"higher-order-sequences",
"combinators",
"strings",
"errors"
],
"difficulty": 6
},
{
"slug": "ocr-numbers",
"name": "OCR Numbers",
Expand Down Expand Up @@ -1672,6 +1758,22 @@
],
"difficulty": 6
},
{
"slug": "piecing-it-together",
"name": "Piecing It Together",
"uuid": "46be0bec-ed8e-4d32-9640-556acdbb5221",
"practices": [],
"prerequisites": [
"assocs",
"combinators",
"arrays",
"higher-order-sequences",
"booleans",
"locals",
"errors"
],
"difficulty": 6
},
{
"slug": "rail-fence-cipher",
"name": "Rail Fence Cipher",
Expand Down
4 changes: 2 additions & 2 deletions exercises/concept/boardwalk-games/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ USING: random random.mersenne-twister ;

Everything inside the quotation — `random`, `randomize`, `sample` —
draws from the seeded generator, so the same seed always reproduces the
same outcome. Marking a word that wraps `with-random` as `inline` lets
the quotation return values to the caller.
same outcome. A word that wraps `with-random` should be marked `inline`
so the quotation's result can flow back to the caller.

[random]: https://docs.factorcode.org/content/vocab-random.html
[mt]: https://docs.factorcode.org/content/vocab-random.mersenne-twister.html
Expand Down
24 changes: 20 additions & 4 deletions exercises/concept/pursers-pantry/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,27 @@ that on every iteration `each` only needs to supply the key.
`keep` runs the quotation while preserving the hashtable for the
final `.`.

## Converting back to a sequence
## Keys, values, and pairs

`>alist` (in [`assocs`][assocs]) returns a sequence of `{ key value }`
pairs. `sort-keys` (in [`sorting`][sorting]) returns the same
sequence sorted by key.
`keys` and `values` (in [`assocs`][assocs]) return just the keys or
just the values; `>alist` returns the `{ key value }` pairs.

```
keys ( assoc -- keys )
values ( assoc -- values )
>alist ( assoc -- alist )
```

```factor
H{ { "wood" 11 } { "coal" 7 } } keys . ! the keys (order not guaranteed)
H{ { "wood" 11 } { "coal" 7 } } values . ! the matching values
```

`keys` and `values` line up: the value at a given position belongs to
the key at the same position.

`sort-keys` (in [`sorting`][sorting]) returns the `{ key value }` pairs
sorted by key:

```factor
H{ { "wood" 11 } { "coal" 7 } } sort-keys .
Expand Down
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": [
"keiravillekode"
],
"files": {
"solution": [
"diamond/diamond.factor"
],
"test": [
"diamond/diamond-tests.factor"
],
"example": [
".meta/example.factor"
]
},
"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/"
}
19 changes: 19 additions & 0 deletions exercises/practice/diamond/.meta/example.factor
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
USING: kernel math sequences strings ;
IN: diamond

<PRIVATE

:: diamond-row ( n i -- str )
i CHAR: A + :> ch
i zero?
[ ch 1string ]
[ ch 1string i 2 * CHAR: space pad-tail ch suffix ] if
n i + 1 + CHAR: space pad-head
n 2 * 1 + CHAR: space pad-tail ;

PRIVATE>

:: rows ( letter -- rows )
letter CHAR: A - :> n
n 1 + <iota> [ n swap diamond-row ] map
dup but-last reverse append ;
9 changes: 9 additions & 0 deletions exercises/practice/diamond/.meta/generator.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Diamond

function gen_test_case(case)
letter = case["input"]["letter"]
expected = format_string_array(case["expected"])
return "{ $(expected) }\n[ CHAR: $(letter) rows ] unit-test"
end

end
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"
24 changes: 24 additions & 0 deletions exercises/practice/diamond/diamond/diamond-tests.factor
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
USING: diamond exercism-tools io kernel tools.test unicode ;
IN: diamond.tests

"Degenerate case with a single 'A' row" description
{ { "A" } }
[ CHAR: A rows ] unit-test

STOP-HERE

"Degenerate case with no row containing 3 distinct groups of spaces" description
{ { " A " "B B" " A " } }
[ CHAR: B rows ] unit-test

"Smallest non-degenerate case with odd diamond side length" description
{ { " A " " B B " "C C" " B B " " A " } }
[ CHAR: C rows ] unit-test

"Smallest non-degenerate case with even diamond side length" description
{ { " A " " B B " " C C " "D D" " C C " " B B " " A " } }
[ CHAR: D rows ] unit-test

"Largest possible diamond" description
{ { " 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 " } }
[ CHAR: Z rows ] unit-test
Loading