Day 10 - Part 1
This commit is contained in:
parent
8d16541413
commit
fec46e87e0
2 changed files with 136 additions and 0 deletions
95
day10/input
Normal file
95
day10/input
Normal file
|
@ -0,0 +1,95 @@
|
|||
99
|
||||
3
|
||||
1
|
||||
11
|
||||
48
|
||||
113
|
||||
131
|
||||
43
|
||||
82
|
||||
19
|
||||
4
|
||||
153
|
||||
105
|
||||
52
|
||||
56
|
||||
109
|
||||
27
|
||||
119
|
||||
147
|
||||
31
|
||||
34
|
||||
13
|
||||
129
|
||||
17
|
||||
61
|
||||
10
|
||||
29
|
||||
24
|
||||
12
|
||||
104
|
||||
152
|
||||
103
|
||||
80
|
||||
116
|
||||
79
|
||||
73
|
||||
21
|
||||
133
|
||||
44
|
||||
18
|
||||
74
|
||||
112
|
||||
136
|
||||
30
|
||||
146
|
||||
100
|
||||
39
|
||||
130
|
||||
91
|
||||
124
|
||||
70
|
||||
115
|
||||
81
|
||||
28
|
||||
151
|
||||
2
|
||||
122
|
||||
87
|
||||
143
|
||||
62
|
||||
7
|
||||
126
|
||||
95
|
||||
75
|
||||
20
|
||||
123
|
||||
63
|
||||
125
|
||||
53
|
||||
45
|
||||
141
|
||||
14
|
||||
67
|
||||
69
|
||||
60
|
||||
114
|
||||
57
|
||||
142
|
||||
150
|
||||
42
|
||||
78
|
||||
132
|
||||
66
|
||||
88
|
||||
140
|
||||
139
|
||||
106
|
||||
38
|
||||
85
|
||||
37
|
||||
51
|
||||
94
|
||||
98
|
||||
86
|
||||
68
|
41
day10/main.hs
Executable file
41
day10/main.hs
Executable file
|
@ -0,0 +1,41 @@
|
|||
#! /usr/bin/env -S"ANSWER=42" nix-shell
|
||||
#! nix-shell -p ghcid
|
||||
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [pretty-simple])"
|
||||
#! nix-shell -i "ghcid -c 'ghci' -T main"
|
||||
|
||||
{-# OPTIONS_GHC -Wall -Wincomplete-uni-patterns #-}
|
||||
{-# OPTIONS_GHC -Wno-unused-top-binds -Wno-unused-imports #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
import Debug.Trace (trace)
|
||||
import Text.Pretty.Simple
|
||||
import Data.List
|
||||
|
||||
smallExample :: [Int]
|
||||
smallExample = [16,10,15,5,1,11,7,19,6,12,4]
|
||||
|
||||
biggerExample :: [Int]
|
||||
biggerExample = [28,33,18,42,31,14,46,20,48,47,24,23,49,45,19,38,39,11,1,32,25
|
||||
,35,8,17,7,9,4,2,34,10,3]
|
||||
|
||||
solvePart1 :: [Int] -> Int
|
||||
solvePart1 xs = finally
|
||||
$ span (== 1)
|
||||
$ sort
|
||||
$ map (\(x,y) -> y - x)
|
||||
$ zip (0:sorted) sorted
|
||||
where
|
||||
sorted = sort xs
|
||||
finally (x,y) = length x * ((length y)+1)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
input' <- lines <$> readFile "day10/input"
|
||||
let input = read <$> input'
|
||||
putStrLn "Tests"
|
||||
print $ smallExample
|
||||
print $ biggerExample
|
||||
putStrLn "Day 10 - Part 1"
|
||||
print $ solvePart1 smallExample
|
||||
print $ solvePart1 biggerExample
|
||||
print $ solvePart1 input
|
Loading…
Reference in a new issue