Skip to content

Commit

Permalink
Improvements for food-chain
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Oct 15, 2024
1 parent f1ae0a8 commit 07d67ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
39 changes: 15 additions & 24 deletions exercises/practice/food-chain/.meta/food-chain.ys
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,21 @@ barn =::
- horse: She's dead, of course!

defn recite(start-verse end-verse):
drop-last:
reduce: add-verse [] (start-verse.-- .. end-verse.--)
reduce(add-verse [] (start-verse.-- .. end-verse.--)):drop-last

defn add-verse(lines verse):
animal =: barn.$verse.first().0
lines =:
conj lines:
-"I know an old lady who swallowed a $animal."
barn.$verse.first().1
lines =:
if 0 < verse < barn.#.--:
conj _ barn.0:first.1:
reduce _ lines (verse .. 1):
fn(lines verse):
lines =:
animal1 animal2 =:
L(barn.$verse.first().0
barn.nth(verse.--):first.0)
line =: "She swallowed the $animal1 to catch the $animal2."
line =:
if animal2 == 'spider':
replace(line /\./ replace(barn.1:first.1 /It/ ' that'))
line
conj lines: line
=>: lines
=>: lines
conj lines: ''
lines .=: conj("I know an old lady who swallowed a $animal.")
lines .=: conj(barn.$verse.first().1)
conj _ '':
or _ lines:
when 0 < verse < barn.#.--:
conj _ barn.0:first.1:
reduce _ lines (verse .. 1):
fn(lines verse):
conj lines:
animal1 =: barn.$verse.first().0
animal2 =: barn.nth(verse.--):first.0
S("She swallowed the $animal1 to catch the $animal2."):
.call(fn([s] if((animal2 != 'spider') s
replace(s /\./ replace(barn.1:first.1 /It/ ' that'))))_)
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
!yamlscript/v0


colors =:
zipmap _ range():
qw(black brown red orange yellow
Expand Down

0 comments on commit 07d67ae

Please sign in to comment.