-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsimpleplus2.tel
More file actions
39 lines (26 loc) · 1.01 KB
/
simpleplus2.tel
File metadata and controls
39 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
id = \x -> x
and2 = \a b -> if a then (if b then 1 else 0) else 0
not2 = \x -> if x then 0 else 1
succ2 = \x -> (x,0)
makeRecur = \n t r b -> n (\c i -> if t i then r c i else b i) b
d2c2 = \n f b -> { id
, \recur i -> f (recur (left i))
, \i -> b
} n
c2d2 = \c -> c succ2 0
assert2 = \t s -> if not t then (1, s) else 0
times2 = \m n f -> m (n f)
validDigit = \x -> and2 ($47 left x) (not2 ($57 left x))
-- validDigit = \x -> not2 ($57 left x)
validInput = \x -> assert2 (and2 (validDigit (left x))
(not2 ($3 right x)))
"invalid input"
toI = \x -> $48 left x
doAdd = \x -> c2d2 (times2 (d2c2 (toI x)) $9)
main = \input -> let inString : validInput = left input
x = left inString
r = doAdd x
dr = $49 succ2 r
in if not input
then ("enter two digits separated by a space", 1)
else (dr, 0)