Skip to content

Commit 3a041dc

Browse files
committed
refacto(2024/Day11)
1 parent be96e83 commit 3a041dc

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

2024/Day11/Day11.hs

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
module Main where
22

33
import Control.Parallel.Strategies
4-
import Data.List.Split
54
import Debug.Trace
65
import System.Environment
76

8-
-- TODO: Cleanup imports after day done
9-
107
type Input = [Int]
118

129
type Output = Int
1310

1411
parseInput :: String -> Input
15-
parseInput = map read . splitOn " " . head . lines
12+
parseInput = map read . words . head . lines
1613

1714
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)
2418

2519
splitNumber :: Int -> Int -> [Int]
2620
splitNumber n lengthn = [firstHalf, secondHalf]
2721
where
28-
-- lengthn = digitCount n
2922
powered10 = {-# SCC powered10 #-} (10 ^ (div lengthn 2))
3023
firstHalf = {-# SCC firstHalf #-} div n powered10
3124
secondHalf = {-# SCC secondHalf #-} n - (firstHalf * powered10)
@@ -48,7 +41,7 @@ part1 :: Input -> Output
4841
part1 = solve 25
4942

5043
part2 :: Input -> Output
51-
part2 = solve 35
44+
part2 = solve 40
5245

5346
main :: IO ()
5447
main = do
@@ -59,4 +52,4 @@ main = do
5952
print input
6053

6154
print $ part1 input
62-
print $ part2 input
55+
print $ (== 11965325) $ part2 input

2024/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,5 @@ Tried to multithread it (in the `iterateStones` change `map` to `parMap rseq`) b
145145
- r0 : 11.7
146146
- rdeepseq: 9.6
147147
- rpar : 12.7
148+
149+
Might try looking for loops and similar things

0 commit comments

Comments
 (0)