tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,18 @@
def step(state, rule) {
var result := state(0, 1) # fixed left cell
for i in 1..(state.size() - 2) {
# Rule function receives the substring which is the neighborhood
result += E.toString(rule(state(i-1, i+2)))
}
result += state(state.size() - 1) # fixed right cell
return result
}
def play(var state, rule, count, out) {
out.print(`0 | $state$\n`)
for i in 1..count {
state := step(state, rosettaRule)
out.print(`$i | $state$\n`)
}
return state
}

View file

@ -0,0 +1,23 @@
def rosettaRule := [
" " => " ",
" #" => " ",
" # " => " ",
" ##" => "#",
"# " => " ",
"# #" => "#",
"## " => "#",
"###" => " ",
].get
? play(" ### ## # # # # # ", rosettaRule, 9, stdout)
0 | ### ## # # # # #
1 | # ##### # # #
2 | ## ## # #
3 | ## ### #
4 | ## # ##
5 | ## ###
6 | ## # #
7 | ## #
8 | ##
9 | ##
# value: " ## "