Added Haskell Implementations and changed directory structure
This commit is contained in:
parent
9f40c27eb9
commit
cb9dee889b
14 changed files with 392 additions and 0 deletions
19
Haskell/2020/02/day2.hs
Normal file
19
Haskell/2020/02/day2.hs
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue