File tree 2 files changed +8
-13
lines changed
2 files changed +8
-13
lines changed Original file line number Diff line number Diff line change 1
1
module Main where
2
2
3
3
import Control.Parallel.Strategies
4
- import Data.List.Split
5
4
import Debug.Trace
6
5
import System.Environment
7
6
8
- -- TODO: Cleanup imports after day done
9
-
10
7
type Input = [Int ]
11
8
12
9
type Output = Int
13
10
14
11
parseInput :: String -> Input
15
- parseInput = map read . splitOn " " . head . lines
12
+ parseInput = map read . words . head . lines
16
13
17
14
digitCount :: Int -> Int
18
- digitCount 0 = 1
19
- digitCount n = countThem n
20
- where
21
- countThem i
22
- | i < 10 = 1
23
- | otherwise = 1 + countThem (div i 10 )
15
+ digitCount i
16
+ | i < 10 = 1
17
+ | otherwise = 1 + digitCount (div i 10 )
24
18
25
19
splitNumber :: Int -> Int -> [Int ]
26
20
splitNumber n lengthn = [firstHalf, secondHalf]
27
21
where
28
- -- lengthn = digitCount n
29
22
powered10 = {-# SCC powered10 #-} (10 ^ (div lengthn 2 ))
30
23
firstHalf = {-# SCC firstHalf #-} div n powered10
31
24
secondHalf = {-# SCC secondHalf #-} n - (firstHalf * powered10)
@@ -48,7 +41,7 @@ part1 :: Input -> Output
48
41
part1 = solve 25
49
42
50
43
part2 :: Input -> Output
51
- part2 = solve 35
44
+ part2 = solve 40
52
45
53
46
main :: IO ()
54
47
main = do
@@ -59,4 +52,4 @@ main = do
59
52
print input
60
53
61
54
print $ part1 input
62
- print $ part2 input
55
+ print $ ( == 11965325 ) $ part2 input
Original file line number Diff line number Diff line change @@ -145,3 +145,5 @@ Tried to multithread it (in the `iterateStones` change `map` to `parMap rseq`) b
145
145
- r0 : 11.7
146
146
- rdeepseq: 9.6
147
147
- rpar : 12.7
148
+
149
+ Might try looking for loops and similar things
You can’t perform that action at this time.
0 commit comments