fst: a, b -> a;;
snd: a, b -> b;;
next:
nil -> nil;
ch, nil -> 1, ch, nil;
ch, (sch, rest): ch = sch -> 2 + fst(count(ch, rest)), ch, next(snd(count(ch, rest)));
ch, rest -> 1, ch, next(rest);;
count:
ch, nil -> 0, nil;
ch, (sch, rest): ch = sch -> 1 + fst(count(ch, rest)), snd(count(ch, rest));
ch, (sch, rest) -> 0, sch, rest;;
iterate:
0, _ -> nil;
n, str -> println(str) then iterate(n - 1, next(str));;
main:
_ -> print("How many iterations? > ") then iterate(parse(readln(nil)), 1, nil);;
# [https://github.com/japi012/match/]
post a comment