src/answer.bend
snap@1.4.0.0 · 44 lines · 5 definitions
1
2
3import Base
4
5
6
7def code.at(nl: Bool, +ch: Char, rest: Unit -> String) -> String:
8 match nl:
9 case True{}:
10 SNil{}
11 case False{}:
12 SCon{ch, rest(Unit{})}
13
14
15
16def code(out: String) -> String:
17 match out:
18 case SNil{}:
19 SNil{}
20 case SCon{+ch, tail}:
21 code.at(Char.is_eq(ch, '\n'), ch, _u => code(tail))
22
23
24
25def text.at(nl: Bool, +tail: String, rest: Unit -> String) -> String:
26 match nl:
27 case True{}:
28 tail
29 case False{}:
30 rest(Unit{})
31
32
33
34
35def text(out: String) -> String:
36 match out:
37 case SNil{}:
38 SNil{}
39 case SCon{ch, +tail}:
40 text.at(Char.is_eq(ch, '\n'), tail, _u => text(tail))
41
42
43def ok(+out: String) -> Bool:
44 String.eq(code(out), "0")