-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommons.hs
More file actions
38 lines (27 loc) · 709 Bytes
/
commons.hs
File metadata and controls
38 lines (27 loc) · 709 Bytes
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
getMultipleLines :: Int -> IO [String]
getMultipleLines n
| n <= 0 = return []
| otherwise = do
x <- getLine
xs <- getMultipleLines (n-1)
return (x:xs)
parseInt :: IO Int
parseInt = do
n <- getLine
return (toInt n)
toInt :: String -> Int
toInt xs = read xs :: Int
parseIntArray :: IO [Int]
parseIntArray = do
xs <- getLine
return $ map toInt (words xs)
format :: [Int] -> String
format xs = unwords (map show xs)
-- Strings
incrementChar :: Char -> Char
incrementChar 'z' = 'a'
incrementChar c = chr (1 + ord c)
increment :: String -> String
increment (x:xs)
| x == 'z' = 'a' : increment xs
| otherwise = incrementChar x : xs