Added Haskell Implementations and changed directory structure

This commit is contained in:
Julia Lange 2021-12-08 15:34:05 -08:00
parent 9f40c27eb9
commit cb9dee889b
Signed by: Julia
SSH key fingerprint: SHA256:KI8YxpkPRbnDRkXPgCuQCVz181++Vy7NAvmQj8alOhM
14 changed files with 392 additions and 0 deletions

19
Haskell/2020/02/day2.hs Normal file
View file

@ -0,0 +1,19 @@
-- parseInput :: String -> (Int, Int, Char)
-- parseInput st = (ord (head st), read (tail (take 3 st)), tail (take 5 st))
parseMinimum :: String -> String -> Int
parseMinimum st out
| h == '-' = read (reverse out)
| h `elem` ['0'..'9'] = parseMinimum (tail st) (h:out)
| otherwise = error "Unexpected input"
where h = head st
parseMax :: String -> String -> Int
parseMax st out
| h == ' ' = read (reverse out)
| h == '-' = parseMax (tail st) ""
| out == "!" = parseMax (tail st) "!"
| h `elem` ['0'..'9'] = parseMax (tail st) (h:out)
| otherwise = error "Unexpected input"
where h = head st