Skip to content

Commit 6f1e127

Browse files
add lyrics exercises (#236)
We add practice exercises - bottle-song - house - pig-latin - proverb - save-the-cow - twelve-days
1 parent c08e20d commit 6f1e127

53 files changed

Lines changed: 1564 additions & 8 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config.json

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,20 @@
11041104
],
11051105
"difficulty": 4
11061106
},
1107+
{
1108+
"slug": "bottle-song",
1109+
"name": "Bottle Song",
1110+
"uuid": "7457b271-28de-4d30-b429-3f0b6e05e395",
1111+
"practices": [],
1112+
"prerequisites": [
1113+
"locals",
1114+
"unicode",
1115+
"arrays",
1116+
"tabulation",
1117+
"higher-order-sequences"
1118+
],
1119+
"difficulty": 4
1120+
},
11071121
{
11081122
"slug": "complex-numbers",
11091123
"name": "Complex Numbers",
@@ -1198,6 +1212,19 @@
11981212
],
11991213
"difficulty": 4
12001214
},
1215+
{
1216+
"slug": "house",
1217+
"name": "House",
1218+
"uuid": "1284fba0-4dcf-43c6-bcf6-4975d9bd72f7",
1219+
"practices": [],
1220+
"prerequisites": [
1221+
"tabulation",
1222+
"arrays",
1223+
"higher-order-sequences",
1224+
"sequences"
1225+
],
1226+
"difficulty": 4
1227+
},
12011228
{
12021229
"slug": "kindergarten-garden",
12031230
"name": "Kindergarten Garden",
@@ -1277,6 +1304,19 @@
12771304
],
12781305
"difficulty": 4
12791306
},
1307+
{
1308+
"slug": "proverb",
1309+
"name": "Proverb",
1310+
"uuid": "a787b061-c960-44d8-828c-1c6b12b4f2a0",
1311+
"practices": [],
1312+
"prerequisites": [
1313+
"wire-format",
1314+
"higher-order-sequences",
1315+
"strings",
1316+
"conditionals"
1317+
],
1318+
"difficulty": 4
1319+
},
12801320
{
12811321
"slug": "rational-numbers",
12821322
"name": "Rational Numbers",
@@ -1373,6 +1413,20 @@
13731413
],
13741414
"difficulty": 4
13751415
},
1416+
{
1417+
"slug": "twelve-days",
1418+
"name": "Twelve Days",
1419+
"uuid": "ce0683ac-a581-4bb1-9c12-9fe2dd89aafc",
1420+
"practices": [],
1421+
"prerequisites": [
1422+
"tabulation",
1423+
"arrays",
1424+
"higher-order-sequences",
1425+
"combinators",
1426+
"conditionals"
1427+
],
1428+
"difficulty": 4
1429+
},
13761430
{
13771431
"slug": "word-count",
13781432
"name": "Word Count",
@@ -1549,6 +1603,20 @@
15491603
],
15501604
"difficulty": 5
15511605
},
1606+
{
1607+
"slug": "pig-latin",
1608+
"name": "Pig Latin",
1609+
"uuid": "26d75b43-0f97-4224-809d-7246fda13195",
1610+
"practices": [],
1611+
"prerequisites": [
1612+
"locals",
1613+
"wire-format",
1614+
"strings",
1615+
"higher-order-sequences",
1616+
"conditionals"
1617+
],
1618+
"difficulty": 5
1619+
},
15521620
{
15531621
"slug": "robot-name",
15541622
"name": "Robot Name",
@@ -1579,6 +1647,21 @@
15791647
],
15801648
"difficulty": 5
15811649
},
1650+
{
1651+
"slug": "save-the-cow",
1652+
"name": "Save the Cow",
1653+
"uuid": "b36844d7-f9f5-48e6-8e66-81f0cac8c14a",
1654+
"practices": [],
1655+
"prerequisites": [
1656+
"locals",
1657+
"errors",
1658+
"mutation",
1659+
"higher-order-sequences",
1660+
"conditionals",
1661+
"numbers"
1662+
],
1663+
"difficulty": 5
1664+
},
15821665
{
15831666
"slug": "square-root",
15841667
"name": "Square Root",

exercises/concept/mosaic-making/.docs/introduction.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ then look up or rearrange their contents.
88

99
## Building from the stack
1010

11-
`1array`, `2array`, and `3array` (in [`arrays`][arrays]) take
12-
1, 2, or 3 values off the top of the stack and bundle them:
11+
`1array`, `2array`, `3array`, and `4array` (in [`arrays`][arrays])
12+
take 1, 2, 3, or 4 values off the top of the stack and bundle them:
1313

1414
```
15-
1array ( a -- { a } )
16-
2array ( a b -- { a b } )
17-
3array ( a b c -- { a b c } )
15+
1array ( a -- { a } )
16+
2array ( a b -- { a b } )
17+
3array ( a b c -- { a b c } )
18+
4array ( a b c d -- { a b c d } )
1819
```
1920

2021
```factor
21-
42 1array . ! => { 42 }
22-
3 4 2array . ! => { 3 4 }
23-
"x" "y" "z" 3array . ! => { "x" "y" "z" }
22+
42 1array . ! => { 42 }
23+
3 4 2array . ! => { 3 4 }
24+
"x" "y" "z" 3array . ! => { "x" "y" "z" }
25+
1 2 3 4 4array . ! => { 1 2 3 4 }
2426
```
2527

2628
## Joining

exercises/concept/signalers-satchel/.docs/introduction.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,31 @@ code to a fixed width or to lay down a run of repeated markers;
8888
coerce with `>string` (or `>array`) only when a concrete
8989
sequence is actually needed.
9090

91+
## `<clumps>` — overlapping windows, virtually
92+
93+
[`<clumps>`][clumps] (in `grouping`) is a third non-copying
94+
virtual sequence — `( seq n -- clumps )` views `seq` as the
95+
series of *overlapping* length-`n` windows over it, each window a
96+
slice:
97+
98+
```factor
99+
USING: grouping math sequences ;
100+
101+
! each window is a slice; map >array to view them concretely
102+
{ 1 2 3 4 } 2 <clumps> [ >array ] map .
103+
! => { { 1 2 } { 2 3 } { 3 4 } }
104+
105+
! the usual move is to project straight from each window
106+
{ 1 2 3 4 } 2 <clumps> [ first2 + ] map .
107+
! => { 3 5 7 }
108+
```
109+
110+
A sequence of `length` n yields `length - n + 1` windows.
111+
Because each window is a slice, pairing successive readings costs
112+
no copying — `[ first2 ]` on each `2`-clump gives you every
113+
consecutive pair to project from. (The non-overlapping cousin,
114+
`<groups>`, chops the sequence into disjoint blocks instead.)
115+
91116
## Multi-input cleave — `2bi`, `3bi`, `2tri`, `3tri`
92117

93118
The plain cleave words `bi` and `tri` apply two or three
@@ -123,3 +148,4 @@ USING: combinators math ;
123148

124149
[unparse]: https://docs.factorcode.org/content/word-unparse%2Cprettyprint.html
125150
[repetition]: https://docs.factorcode.org/content/word-__lt__repetition__gt__%2Csequences.html
151+
[clumps]: https://docs.factorcode.org/content/word-__lt__clumps__gt__%2Cgrouping.html
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Instructions
2+
3+
Recite the lyrics to that popular children's repetitive song: Ten Green Bottles.
4+
5+
Note that not all verses are identical.
6+
7+
```text
8+
Ten green bottles hanging on the wall,
9+
Ten green bottles hanging on the wall,
10+
And if one green bottle should accidentally fall,
11+
There'll be nine green bottles hanging on the wall.
12+
13+
Nine green bottles hanging on the wall,
14+
Nine green bottles hanging on the wall,
15+
And if one green bottle should accidentally fall,
16+
There'll be eight green bottles hanging on the wall.
17+
18+
Eight green bottles hanging on the wall,
19+
Eight green bottles hanging on the wall,
20+
And if one green bottle should accidentally fall,
21+
There'll be seven green bottles hanging on the wall.
22+
23+
Seven green bottles hanging on the wall,
24+
Seven green bottles hanging on the wall,
25+
And if one green bottle should accidentally fall,
26+
There'll be six green bottles hanging on the wall.
27+
28+
Six green bottles hanging on the wall,
29+
Six green bottles hanging on the wall,
30+
And if one green bottle should accidentally fall,
31+
There'll be five green bottles hanging on the wall.
32+
33+
Five green bottles hanging on the wall,
34+
Five green bottles hanging on the wall,
35+
And if one green bottle should accidentally fall,
36+
There'll be four green bottles hanging on the wall.
37+
38+
Four green bottles hanging on the wall,
39+
Four green bottles hanging on the wall,
40+
And if one green bottle should accidentally fall,
41+
There'll be three green bottles hanging on the wall.
42+
43+
Three green bottles hanging on the wall,
44+
Three green bottles hanging on the wall,
45+
And if one green bottle should accidentally fall,
46+
There'll be two green bottles hanging on the wall.
47+
48+
Two green bottles hanging on the wall,
49+
Two green bottles hanging on the wall,
50+
And if one green bottle should accidentally fall,
51+
There'll be one green bottle hanging on the wall.
52+
53+
One green bottle hanging on the wall,
54+
One green bottle hanging on the wall,
55+
And if one green bottle should accidentally fall,
56+
There'll be no green bottles hanging on the wall.
57+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"keiravillekode"
4+
],
5+
"files": {
6+
"solution": [
7+
"bottle-song/bottle-song.factor"
8+
],
9+
"test": [
10+
"bottle-song/bottle-song-tests.factor"
11+
],
12+
"example": [
13+
".meta/example.factor"
14+
]
15+
},
16+
"blurb": "Produce the lyrics to the popular children's repetitive song: Ten Green Bottles.",
17+
"source": "Wikipedia",
18+
"source_url": "https://en.wikipedia.org/wiki/Ten_Green_Bottles"
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
USING: arrays kernel locals math ranges sequences unicode ;
2+
IN: bottle-song
3+
4+
CONSTANT: numbers {
5+
"no" "one" "two" "three" "four" "five" "six"
6+
"seven" "eight" "nine" "ten"
7+
}
8+
9+
: bottles ( n -- str )
10+
dup numbers nth " green bottle" append
11+
swap 1 = [ "s" append ] unless ;
12+
13+
: cap ( str -- str' )
14+
unclip ch>upper prefix ;
15+
16+
:: verse ( n -- lines )
17+
n bottles cap " hanging on the wall," append :> top
18+
"There'll be " n 1 - bottles append " hanging on the wall." append :> bottom
19+
top top "And if one green bottle should accidentally fall," bottom 4array ;
20+
21+
:: recite ( start take -- lines )
22+
start start take - 1 + [a..b] [ verse ] map { "" } join ;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module BottleSong
2+
3+
function gen_test_case(case)
4+
input = case["input"]
5+
start, take = input["startBottles"], input["takeDown"]
6+
lines = format_string_array(case["expected"])
7+
return "{ $(lines) }\n[ $(start) $(take) recite ] unit-test"
8+
end
9+
10+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[d4ccf8fc-01dc-48c0-a201-4fbeb30f2d03]
13+
description = "verse -> single verse -> first generic verse"
14+
15+
[0f0aded3-472a-4c64-b842-18d4f1f5f030]
16+
description = "verse -> single verse -> last generic verse"
17+
18+
[f61f3c97-131f-459e-b40a-7428f3ed99d9]
19+
description = "verse -> single verse -> verse with 2 bottles"
20+
21+
[05eadba9-5dbd-401e-a7e8-d17cc9baa8e0]
22+
description = "verse -> single verse -> verse with 1 bottle"
23+
24+
[a4a28170-83d6-4dc1-bd8b-319b6abb6a80]
25+
description = "lyrics -> multiple verses -> first two verses"
26+
27+
[3185d438-c5ac-4ce6-bcd3-02c9ff1ed8db]
28+
description = "lyrics -> multiple verses -> last three verses"
29+
30+
[28c1584a-0e51-4b65-9ae2-fbc0bf4bbb28]
31+
description = "lyrics -> multiple verses -> all verses"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
USING: bottle-song exercism-tools io kernel tools.test unicode ;
2+
IN: bottle-song.tests
3+
4+
"first generic verse" description
5+
{ { "Ten green bottles hanging on the wall," "Ten green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be nine green bottles hanging on the wall." } }
6+
[ 10 1 recite ] unit-test
7+
8+
STOP-HERE
9+
10+
"last generic verse" description
11+
{ { "Three green bottles hanging on the wall," "Three green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be two green bottles hanging on the wall." } }
12+
[ 3 1 recite ] unit-test
13+
14+
"verse with 2 bottles" description
15+
{ { "Two green bottles hanging on the wall," "Two green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be one green bottle hanging on the wall." } }
16+
[ 2 1 recite ] unit-test
17+
18+
"verse with 1 bottle" description
19+
{ { "One green bottle hanging on the wall," "One green bottle hanging on the wall," "And if one green bottle should accidentally fall," "There'll be no green bottles hanging on the wall." } }
20+
[ 1 1 recite ] unit-test
21+
22+
"first two verses" description
23+
{ { "Ten green bottles hanging on the wall," "Ten green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be nine green bottles hanging on the wall." "" "Nine green bottles hanging on the wall," "Nine green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be eight green bottles hanging on the wall." } }
24+
[ 10 2 recite ] unit-test
25+
26+
"last three verses" description
27+
{ { "Three green bottles hanging on the wall," "Three green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be two green bottles hanging on the wall." "" "Two green bottles hanging on the wall," "Two green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be one green bottle hanging on the wall." "" "One green bottle hanging on the wall," "One green bottle hanging on the wall," "And if one green bottle should accidentally fall," "There'll be no green bottles hanging on the wall." } }
28+
[ 3 3 recite ] unit-test
29+
30+
"all verses" description
31+
{ { "Ten green bottles hanging on the wall," "Ten green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be nine green bottles hanging on the wall." "" "Nine green bottles hanging on the wall," "Nine green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be eight green bottles hanging on the wall." "" "Eight green bottles hanging on the wall," "Eight green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be seven green bottles hanging on the wall." "" "Seven green bottles hanging on the wall," "Seven green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be six green bottles hanging on the wall." "" "Six green bottles hanging on the wall," "Six green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be five green bottles hanging on the wall." "" "Five green bottles hanging on the wall," "Five green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be four green bottles hanging on the wall." "" "Four green bottles hanging on the wall," "Four green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be three green bottles hanging on the wall." "" "Three green bottles hanging on the wall," "Three green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be two green bottles hanging on the wall." "" "Two green bottles hanging on the wall," "Two green bottles hanging on the wall," "And if one green bottle should accidentally fall," "There'll be one green bottle hanging on the wall." "" "One green bottle hanging on the wall," "One green bottle hanging on the wall," "And if one green bottle should accidentally fall," "There'll be no green bottles hanging on the wall." } }
32+
[ 10 10 recite ] unit-test
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
USING: kernel ;
2+
IN: bottle-song
3+
4+
: recite ( start take -- lines )
5+
"unimplemented" throw ;

0 commit comments

Comments
 (0)