-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsimpleplus.tel
More file actions
23 lines (18 loc) · 893 Bytes
/
simpleplus.tel
File metadata and controls
23 lines (18 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import Prelude
validDigit = \x -> and ($47 left x) (not ($57 left x))
validInput = \x -> assert (and (validDigit (left x))
(and (validDigit (left (right (right x))))
(not ($3 right x))))
"invalid input"
toI = \x -> $48 left x
doAdd = \x y -> c2d (plus (d2c (toI x)) (d2c (toI y)))
main = \input -> let inString : validInput = left input
x = left inString
y = left (right (right inString))
r = doAdd x y
dr = if dMinus r 9
then concat ["1", $49 succ (dMinus r 10)]
else $49 succ r
in if not input
then ("enter two digits separated by a space", 1)
else (concat [succ x, " plus ", succ y, " is ", dr], 0)