-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.hs
53 lines (45 loc) · 1.07 KB
/
11.hs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import System.IO
import Data.List.Split (splitOn)
import Control.Monad (forM)
numDigits :: Int -> Int
numDigits n
| n == 0 = 1
| n < 0 = numDigits(-n)
| otherwise = length (show n)
splitNum :: Int -> [Int]
splitNum n
| n < 10 = [n, 0]
| otherwise =
let str = show n
len = length str
(h1, h2) = splitAt (len `div` 2) str
in [read h1, read h2]
transform1 :: [Int] -> [Int]
transform1 nums = concatMap modfiy nums
where
modfiy n
| n == 0 = [1]
| even (numDigits n) = splitNum n
| otherwise = [n * 2024]
run :: [Int] -> Int -> IO [Int]
run nums 0 = return nums
run nums n = do
let newacc = transform1 nums
putStr (show n)
putStr " "
print (length newacc)
run newacc (n - 1)
main :: IO ()
main = do
-- Read file into nums
contents <- readFile "input"
let nums = map (read::String->Int) (words contents)
print (nums)
-- Loop 25 times
print "Loop 25"
result <- run nums 25
print (length result)
-- Loop 75 times
print "Loop 75"
result2 <- run nums 75
print (length result2)