Skip to content

Instantly share code, notes, and snippets.

@toomasv
Last active June 25, 2022 19:20
Show Gist options
  • Save toomasv/4b1fea69cfae802930f57cf022ba02cb to your computer and use it in GitHub Desktop.
Save toomasv/4b1fea69cfae802930f57cf022ba02cb to your computer and use it in GitHub Desktop.
Golovolomka
Red [
Description: "Puzzle"
See: "[June 22, 2022 9:56 PM](https://gitter.im/red/rethink?at=62b365e276cd751a2f507697)"
]
#include %to-num-word.red ;See next gist
prepare: func [puz] [
count: 0
total: length? reduce puzzle
clear res: []
op: func [op /local f x][
f: func [a b] bind compose [
x: a (op) b
count: count + 1
append res case [
total = 1 ['Just]
count = 1 ['First]
count = 2 ['then]
count = total [[and finally]]
'else [[and then]]
]
append res to-num-word x
if count = total [append res to-word append form take/last res dot append res random/only [Ta-da! Done! Bye-bye!]]
] system/words
make op! :f
]
ops: object [+: op '+ *: op '* -: op '-]
bind puz ops
]()
comment [
prepare puzzle: [1 + 3 2 - 5 6 + 2 5 - 5 12 - 3 -3 + 4]()
do puzzle
;== [First Four then Minus Three and then Eight and then Zero and then Nine and finally One. Ta-da!]
reduce load mold puzzle
;== [4 -3 8 0 9 1]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment