Compare commits

...

41 Commits
day2 ... main

Author SHA1 Message Date
EEva (JPotier)
e0ea0a26c8 Day 15, part 1 and 2: slow solution 2020-12-29 14:32:41 +02:00
EEva (JPotier)
400d1cdc57 Initial commit 2020-12-29 10:47:28 +02:00
6aba6f131e
Day 13
Cleaned up
2020-12-21 15:34:56 +02:00
f8d0b6c0da
Day 13 (dirty) 2020-12-21 15:27:51 +02:00
6ee8b3fafa
A bit faster with Parallel, but still too slow 2020-12-18 16:23:47 +02:00
7c8cb639cb
Still too slow 2020-12-18 14:36:58 +02:00
f41863a68b
Best effort 2020-12-17 15:54:32 +02:00
EEva (JPotier)
2240fd1325 In progress 2020-12-15 08:27:32 +02:00
0e498f3caa
Part 1 2020-12-14 14:53:53 +02:00
EEva (JPotier)
47bafe66dc In progress 2020-12-13 18:50:00 +02:00
EEva (JPotier)
538fba7063 Part 2
With some approximation
2020-12-13 17:33:04 +02:00
EEva (JPotier)
c15d4ee29d Part 1 2020-12-13 16:28:56 +02:00
EEva (JPotier)
3997886348 Day 12 in progress 2020-12-13 15:15:04 +02:00
d720534eaf
Day 10 - part 2
yeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah
2020-12-11 09:30:17 +02:00
Martin Potier
a1a4a6fb52 Almost there 2020-12-11 00:18:39 +02:00
fec46e87e0
Day 10 - Part 1 2020-12-10 16:10:39 +02:00
8d16541413
Day 9 - Part 2
Hope you have a fast machine. This is long to compute :)
2020-12-10 15:25:15 +02:00
0305b145a7
Part 1 done 2020-12-10 14:26:48 +02:00
fa87faaa02
Initial commit for day9 2020-12-10 13:30:34 +02:00
09ca90be06
Bad Haskell, Debug.Trace ftw! 2020-12-10 12:49:39 +02:00
Martin Potier
4faaf34bf8 Day 8 - still in progress 2020-12-09 23:30:18 +02:00
Martin Potier
f0c7f30103 Part 1 2020-12-09 19:59:35 +02:00
2ee9fa16c4
tmp 2020-12-09 14:05:30 +02:00
54ddd70f1d
Day 8 in progress 2020-12-09 14:04:43 +02:00
Martin Potier
a0ec7f0b63 Init day8 2020-12-08 22:26:09 +02:00
Martin Potier
f173da9ec7 Day7 Part 2 2020-12-08 22:21:45 +02:00
e387598fd1
Fun with Sum 2020-12-08 17:22:20 +02:00
207769dccc
Part 1 down 2020-12-08 17:17:47 +02:00
Martin Potier
b68ac986af Add exampleData 2020-12-07 22:07:42 +02:00
Martin Potier
629e9767c5 Day7 input 2020-12-07 20:35:03 +02:00
Martin Potier
97f5bd536f Finished day 6 2020-12-07 20:32:40 +02:00
b344686716
wip 2020-12-07 16:54:34 +02:00
f7d651ff92
Day 6, input 2020-12-07 12:13:02 +02:00
19975730a5
Day 5 - Part 2 2020-12-07 12:11:12 +02:00
640efa334b
Day 5 - Part 1 2020-12-07 11:57:34 +02:00
Martin Potier
e6a2e7f74b Finally, day4 is done 2020-12-06 19:50:22 +02:00
Martin Potier
4ed06fab49 Fixed with a complete hack (but it works) 2020-12-03 22:23:26 +02:00
Martin Potier
fff23228a4 Done, but buggy 2020-12-03 22:11:19 +02:00
40858ab68e
In progress 2020-12-03 17:36:12 +02:00
0ffb151a7c
Add input and skeleton file 2020-12-03 14:57:18 +02:00
Martin Potier
8325c6e224 Minor cleanup (removing explicit fold) 2020-12-02 21:10:58 +02:00
23 changed files with 8818 additions and 8 deletions

95
day10/input Normal file
View 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

92
day10/main.hs Executable file
View File

@ -0,0 +1,92 @@
#! /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 -Wno-type-defaults #-}
{-# LANGUAGE OverloadedStrings #-}
import Data.List
import Data.Monoid
import Debug.Trace (trace)
import Text.Pretty.Simple
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 ++ [l+3])
where
l = last sorted
sorted = sort xs
finally (x,y) = length x * length y
--------------------------------------------------------------------------------
-- 1 -> 1 possibility
-- 1 1 -> 2 possibilities
-- 1 1 1 -> 4 possibilities
-- 1 1 1 1 -> 7 (!) possibilities
-- 1 1 1 1 1 -> ? possibilities
--
--------------------------------------------------------------------------------
cleanup :: [[Int]] -> [[Int]]
cleanup = filter (\v -> (any (/= 3) v) && (length v > 1))
-- That is the actual problem right here:
-- ··· -> 2^3 - 1 = 7
-- ···· -> 2^4 - 1 - 2 = 13
-- ····· -> 2^5 - 1 - 2 - 3 = 26
combinations :: [Int] -> Int
combinations v =
(2 ^ n) -- All the ways to take any on/off combination in n
- (sum [1..(n-2)]) -- All the ways to take n+ consecutive in n (illegal),
-- *except* for n=1 and n=2 which are legal
where
n = (length v) - 1
estimatePermutations :: [Int] -> Int
estimatePermutations = getProduct
. foldMap Product
. map combinations
. cleanup
. group
distanceMap :: [Int] -> [Int]
distanceMap xs = map (\(x,y) -> y - x) $ zip (0:sorted) (sorted ++ [(last sorted)+3])
where
sorted = sort xs
solvePart2 :: [Int] -> Int
solvePart2 = estimatePermutations . distanceMap
where
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
putStrLn ":: Tests"
putStrLn ":: Day 10 - Part 2"
print $ distanceMap smallExample
print $ solvePart2 smallExample
print $ distanceMap biggerExample
print $ (map combinations . cleanup . group) $ distanceMap biggerExample
print $ solvePart2 biggerExample
print $ solvePart2 input

786
day12/input Normal file
View File

@ -0,0 +1,786 @@
N3
F18
L180
F40
N3
R90
S5
R90
N4
F24
R90
E5
F36
R180
W3
W4
F63
N4
W1
N1
E1
L90
W1
N2
E2
S2
F39
W4
S3
F93
N1
F83
S1
R90
W3
R90
W4
L90
F53
S4
F4
L90
W3
F83
L180
W2
L90
W2
L90
W1
N3
F63
R90
N2
N3
E4
F10
S3
E4
R90
F11
L90
R90
S2
W2
F100
W5
R270
F40
S5
L90
E2
L90
E2
L180
N5
F81
N4
E4
L180
F38
W2
F22
W5
N5
E1
N2
W4
N2
F68
N1
F2
S1
F47
W5
F80
N3
E3
S2
L180
F87
L180
E4
L90
E2
S3
L180
E2
L90
W2
N4
F21
S4
W5
F70
F4
N2
F14
E2
S3
R90
W3
N2
E3
S1
F85
R90
E1
F80
L90
F100
R90
W1
R180
S4
F58
L90
N3
R90
E1
F42
E3
F93
S3
R90
W2
N3
L90
W3
W2
N2
W1
S4
R180
N5
R180
F52
N5
F20
L180
E5
R90
W2
S4
E1
S3
F75
R90
F49
L180
N3
F31
S3
E3
S5
L180
N3
E2
R270
W5
N3
W5
N3
L270
F54
R90
W5
F73
S3
W2
R90
N2
R90
S5
R90
W4
S2
L90
F3
S2
R90
F76
S3
F56
L90
F5
N1
R180
E3
N2
F20
E2
L180
F38
R180
W4
R90
S3
N5
E5
F26
S2
L180
E4
R90
F52
N3
L90
N5
E4
F63
L90
F48
W5
F29
N1
E3
L90
N5
L90
S3
F8
N2
R90
E4
S2
E2
F10
W2
L90
N2
R90
F2
E2
N4
R90
F74
W3
W5
S2
R90
N3
L90
E3
F58
N4
E5
S4
E3
F72
L180
E3
S2
L90
W4
S1
F14
W1
N1
E3
W4
L90
N1
F97
R90
N4
E3
F95
F95
L90
S4
F55
R90
W2
N1
R90
F16
L90
S5
F4
R90
F24
S4
E2
R90
W5
E1
L270
F12
L90
F100
W1
S5
W2
S3
F95
L90
F44
N5
F79
S4
R180
E2
S1
F40
R90
W2
R90
F67
S5
F15
L90
N4
L90
S5
E1
R90
N3
W5
N4
L270
F61
L90
E1
L90
E1
F38
E2
F19
W2
L90
S4
R180
W4
F59
N1
F26
N1
W5
F7
N4
F72
E2
R90
F59
N1
F58
N5
F13
N2
F2
S2
W1
F85
R270
S2
F17
R90
F96
S2
L90
E1
N4
F9
R270
F58
N1
L90
W2
S2
F73
W1
S2
F20
E2
S4
F94
L180
F27
S2
F48
N1
L270
S2
F77
E3
F10
W3
L270
S4
F53
F66
E5
S2
F33
S5
L90
W3
S3
E3
R90
E1
F62
S1
L90
S3
E3
N1
S1
E5
S2
F66
N4
N1
W4
F84
R180
F23
F20
E1
S3
R90
E2
F48
F89
L90
F97
R180
N3
F62
L90
N5
F28
W5
N4
L180
N4
W1
N3
L90
F95
N1
W5
R180
N5
F34
S1
W2
N4
F3
S2
E1
R90
E2
F36
S4
E5
F42
W1
L180
S1
F74
F38
N4
R270
N3
W2
S4
L180
F26
S4
F51
R90
F83
R90
F9
S2
W1
F99
S4
W1
F84
W1
R180
F59
W5
R90
F75
S1
F34
E4
N3
L90
F43
W5
N1
R90
F59
W1
N3
W4
S2
F36
N5
W4
E2
F96
R180
F44
R90
F12
E5
F24
W3
F39
S2
L180
W3
W4
F70
N4
E4
F36
E2
N1
F30
L90
S2
F81
R270
R90
F66
W1
L90
W2
F98
S1
E1
L90
E3
N2
F100
W3
N3
R90
F88
E4
L180
F52
L90
E4
F76
W2
L90
E3
F72
S3
L180
F12
F34
E5
F90
S5
W5
E1
N5
L180
E5
F84
E5
E3
L90
E3
F14
L90
W3
L90
S1
L90
W2
F54
R90
S2
F73
S4
E1
S1
F55
E5
N4
R180
L180
N4
R90
F91
L180
F5
E2
N1
W2
F27
W2
S5
R90
S3
F39
S3
W2
F59
F83
W3
E3
E4
L90
S1
R90
E4
F81
E4
R90
W5
F74
W3
E3
F30
L180
S2
E3
F33
S3
R90
F22
S5
F97
S1
E2
F50
E2
F19
E3
L90
L90
S5
W3
F80
F33
E1
R90
N3
L90
F70
L180
W4
N2
R180
S2
F38
S3
F7
R90
E1
N5
F86
W4
F49
W4
F51
S4
F47
R90
W3
R180
R180
W1
F98
S1
W3
S4
L90
F76
E1
F76
R180
S4
R180
W3
F26
N5
F35
S2
F94
F24
N2
F45
E1
L90
F32
S1
R180
F78
F84
L90
N2
F42
R90
F72
S1
E3
N2
W1
F23
E2
F69
L90
F29
R90
S5
W5
L90
W1
S2
E1
F96
S5
R180
F26
S5
W1
S3
F38
S1
E2
S5
W2
S5
F52
L90
F11
E3
R90
E4
F6
L90
R90
W1
R90
E3
F1
E4
N3
E5
R90
N2
R180
W2
N5
F46
N3
E5
F83
R90
F42
S3
R90
N5
F10

130
day12/main.hs Executable file
View File

@ -0,0 +1,130 @@
#! /usr/bin/env -S"ANSWER=42" nix-shell
#! nix-shell -p ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [pretty-simple linear])"
#! nix-shell -i "ghcid -c 'ghci' -T main"
{-# OPTIONS_GHC -Wall -Wincomplete-uni-patterns #-}
{-# OPTIONS_GHC -Wno-unused-top-binds -Wno-unused-imports -Wno-type-defaults #-}
{-# OPTIONS_GHC -Wno-unused-matches #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveAnyClass #-}
import Debug.Trace (trace, traceShowId, traceShow)
import Text.Pretty.Simple
import Control.Monad
import Linear.V2
import Data.Monoid
exampleData :: [ String ]
exampleData =
[ "F10"
, "N3"
, "F7"
, "R90"
, "F11"
]
data Ship = Ship { position :: V2 Double, orientation :: V2 Double }
deriving (Show, Eq, Ord)
-- At first, ship is at (0,0) facing East
ship0 :: Ship
ship0 = Ship (pure 0) (V2 1 0)
-- At first, ship is at (0,0) facing East
ship1 :: Ship
ship1 = Ship (pure 0) (V2 10 1)
-- instance Semigroup Ship
-- where
-- (<>) s1 s2 = Ship (getSum <$> ((Sum <$> (position s1)) <> (Sum <$> (position s2))))
-- (getSum <$> ((Sum <$> (orientation s1)) <> (Sum <$> (orientation s2))))
--
-- instance Monoid Ship
-- where
-- mempty = Ship (pure 0) (pure 0)
data Instruction = InsMoveForward !Double
| InsMoveNorth !Double
| InsMoveSouth !Double
| InsMoveEast !Double
| InsMoveWest !Double
| InsTurnL !Double
| InsTurnR !Double
deriving (Show, Eq, Ord)
parseIns :: String -> Instruction
-- Action N means to move north by the given value.
parseIns ('N':x) = InsMoveNorth (read x)
-- Action S means to move south by the given value.
parseIns ('S':x) = InsMoveSouth (read x)
-- Action E means to move east by the given value.
parseIns ('E':x) = InsMoveEast (read x)
-- Action W means to move west by the given value.
parseIns ('W':x) = InsMoveWest (read x)
-- Action L means to turn left the given number of degrees.
parseIns ('L':x) = InsTurnL (read x)
-- Action R means to turn right the given number of degrees.
parseIns ('R':x) = InsTurnR (read x)
-- Action F means to move forward by the given value in the direction the ship is currently facing.
parseIns ('F':x) = InsMoveForward (read x)
parseIns e = trace ("Unknown instruction: "<>show e) undefined
-- 2*PI rad = 360 deg
-- 1 rad = 180/PI deg
-- PI/180 rad = 1 deg
runIns1 :: Ship -> Instruction -> Ship
runIns1 s (InsMoveForward n) = s { position = (position s) + (pure n) * (orientation s) }
runIns1 s (InsMoveNorth n) = s { position = (position s) + (pure n) * V2 0 1 }
runIns1 s (InsMoveSouth n) = s { position = (position s) + (pure n) * V2 0 (-1) }
runIns1 s (InsMoveEast n) = s { position = (position s) + (pure n) * V2 1 0 }
runIns1 s (InsMoveWest n) = s { position = (position s) + (pure n) * V2 (-1) 0 }
runIns1 s (InsTurnL n) = s { orientation = angle ((unangle (orientation s)) + n * pi / 180) }
runIns1 s (InsTurnR n) = s { orientation = angle ((unangle (orientation s)) - n * pi / 180) }
manhattanV2 :: (Num a) => V2 a -> a
manhattanV2 (V2 x y) = (abs x) + (abs y)
solvePart1 :: [String] -> Double
solvePart1 = manhattanV2 . position . foldl runIns1 ship0 . map parseIns
--------------------------------------------------------------------------------
runIns2 :: Ship -> Instruction -> Ship
runIns2 s (InsMoveForward n) = s { position = (position s) + (pure n) * (orientation s) }
runIns2 s (InsMoveNorth n) = s { orientation = (orientation s) + V2 0 n }
runIns2 s (InsMoveSouth n) = s { orientation = (orientation s) + V2 0 (-n) }
runIns2 s (InsMoveEast n) = s { orientation = (orientation s) + V2 n 0 }
runIns2 s (InsMoveWest n) = s { orientation = (orientation s) + V2 (-n) 0 }
runIns2 s (InsTurnL n) = s { orientation = rotV2By (orientation s) n }
runIns2 s (InsTurnR n) = s { orientation = rotV2By (orientation s) (-n) }
rotV2By :: (Num a, Floating a) => V2 a -> a -> V2 a
rotV2By (V2 x1 y1) n = V2 x y
where
x = cos a * x1 - sin a * y1
y = sin a * x1 + cos a * y1
a = n * pi / 180
solvePart2 :: [String] -> Double
solvePart2 = manhattanV2 . position . foldl runIns2 ship1 . map parseIns
main :: IO ()
main = do
input <- lines <$> readFile "day12/input"
putStrLn ":: Tests"
pPrint exampleData
pPrint $ map parseIns exampleData
pPrint $ angle (90 * pi / 180)
putStrLn ":: Day 12 - Part 1"
pPrint $ solvePart1 exampleData
pPrint $ solvePart1 input
putStrLn ":: Day 12 - Part 2"
pPrint $ solvePart2 exampleData
pPrint $ solvePart2 input

2
day13/input Normal file
View File

@ -0,0 +1,2 @@
1000507
29,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,37,x,x,x,x,x,631,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,13,19,x,x,x,23,x,x,x,x,x,x,x,383,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,17

129
day13/main.hs Executable file
View File

@ -0,0 +1,129 @@
#! /usr/bin/env -S"GHCRTS=-N4" nix-shell
#! nix-shell -p ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [pretty-simple attoparsec arithmoi])"
#! nix-shell -i "ghcid -c 'ghci' -T main"
{-# OPTIONS_GHC -Wall -Wincomplete-uni-patterns #-}
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import Control.Monad (foldM)
import Data.Attoparsec.Text (Parser)
import Data.Euclidean (gcdExt)
import Data.List (find,sortOn)
import Data.Maybe (fromMaybe,catMaybes)
import Text.Pretty.Simple
import qualified Data.Attoparsec.Text as A
import qualified Data.Text as T
exampleData :: String
exampleData = "939\n7,13,x,x,59,x,31,19"
numOrXParser :: Parser (Maybe Int)
numOrXParser = (Just <$> A.decimal) <|> ("x" *> pure Nothing)
inputParser :: Parser (Int,[Int])
inputParser = do
n <- A.decimal
A.skipSpace
xs <- numOrXParser `A.sepBy` ","
pure (n,catMaybes $ xs)
parseInput :: String -> Either String (Int,[Int])
parseInput = (A.parseOnly inputParser) . T.pack
solvePart1 :: String -> Either String Int
solvePart1 str = do
(n,xs) <- parseInput str
let (bus, time) = head
$ sortOn (snd)
$ map (\x -> (x,fromMaybe (-1) $ find (> n) [0,x..])) xs
pure $ bus * (time - n)
inputParser2 :: Parser (Int,[Maybe Int])
inputParser2 = do
n <- A.decimal
A.skipSpace
xs <- numOrXParser `A.sepBy` ","
pure (n,xs)
parseInput2 :: String -> Either String (Int,[Maybe Int])
parseInput2 = (A.parseOnly inputParser2) . T.pack
-- -------------------------------------------------------------------------- --
-- Here I sneak around a bit, and realize the problem is well defined --
-- (and solved!) already: it's called the Chinese Remainder Theorem --
-- https://en.wikipedia.org/wiki/Chinese_remainder_theorem --
-- -------------------------------------------------------------------------- --
-- Apllying the theorem allows to reduce a system of equation on x: --
-- --
-- x ≡ a1 (mod n1) --
-- · --
-- · --
-- · --
-- x ≡ ak (mod nk) --
-- --
-- to a single equation: --
-- --
-- x ≡ as (mod ns) --
-- --
-- It relates to the buses schedules in the following way: t is x, the bus --
-- number is the modulo factor (since a bus comes *every* ni) and subsequent --
-- additions to t (for other buses) is (-ai), so, for a but coming at --
-- t+ai, one would write x ≡ -ai (mod ni) --
-- --
-- I chose to encode ai and ni as a tuple (ai,ni), named startAndIds --
-- --
-- Basically, we're creating a “chinese” function: --
-- --
-- chinese :: (Int,Int) -> (Int,Int) -> (Int,Int) --
-- --
-- Then, given a list [(Int, Int)] we can fold over it to obtain the solution --
-- --
chinese :: (Integer,Integer) -> (Integer,Integer) -> Maybe (Integer,Integer)
chinese (0,n1) (0,n2) = chinese (n1,n1) (n2,n2)
chinese v (0,n2) = chinese v (n2,n2)
chinese (0,n1) v = chinese (n1,n1) v
chinese (a1,n1) (a2,n2) = do
-- Computes a solution such that: n1×c1 + n2×c2 = g, for some c2
-- n1×c1 - g = - n2×c2, for some c2
-- 1/n2 (n1×c1 - g) = - c2, for some c2 (n2 is > 0)
-- - 1/n2 (n1×c1 - g) = c2, for some c2 (n2 is > 0)
-- n1 and n2 must be coprimes for this to work (g must be 1), fail otherwise
(m1,m2) <- case gcdExt n1 n2 of
(1,c1) -> Just ( c1, negate ((n1 * c1) - 1) `div` n2 )
_ -> Nothing
let x = a1 * m2 * n2 + a2 * m1 * n1
let a12 = x `mod` (n1 * n2)
pure $ (a12, n1 * n2)
e2m :: Either e a -> Maybe a
e2m (Right v) = Just v
e2m _ = Nothing
solvePart2 :: String -> Maybe (Integer,Integer)
solvePart2 str = do
(_,xs) <- e2m $ parseInput2 str
let startAndIds = catMaybes $ sequence <$> zip [0..] (map (fmap fromIntegral) xs)
let chineseEqs = fmap (\(a,n) -> ((-a) `mod` n, n)) startAndIds
foldM chinese (1,1) chineseEqs
main :: IO ()
main = do
putStrLn ":: Test"
pPrint $ A.parseOnly inputParser $ T.pack exampleData
pPrint $ take 3 ((\n -> [1,(n::Integer)..]) 59)
putStrLn ":: Day 13 - Part 1"
input <- readFile "day13/input"
pPrint $ solvePart1 exampleData
pPrint $ solvePart1 input
putStrLn ":: Test 2"
print $ solvePart2 exampleData
print $ solvePart2 "1\n17,x,13,19"
print $ solvePart2 "1\n67,7,59,61"
print $ solvePart2 "1\n67,x,7,59,61"
print $ solvePart2 "1\n67,7,x,59,61"
print $ solvePart2 "1\n1789,37,47,1889"
putStrLn ":: Day 13 - Part 2"
print $ solvePart2 input

73
day15/main.hs Executable file
View File

@ -0,0 +1,73 @@
#! /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 #-}
{-# OPTIONS_GHC -Wno-unused-matches #-}
{-# LANGUAGE OverloadedStrings #-}
import Debug.Trace (trace)
import Text.Pretty.Simple
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as I
import Data.Maybe (fromMaybe)
import Data.List (iterate')
exampleInput1 :: [Int]
exampleInput1 = [0,3,6]
exampleInput2 :: [Int]
exampleInput2 = [1,3,2]
exampleInput3 :: [Int]
exampleInput3 = [3,1,2]
input :: [Int]
input = [0,3,1,6,7,5]
type Turn = Int
type Number = Int
-- Each Number is attached to the last Turn it was seen
-- The current Turn is recorded too
-- Last spoken Number is recorded too
data Game = Game { unMem :: (IntMap Turn)
, unTurn :: Turn
, unNumber :: Number
}
deriving Show
initGame :: [Int] -> Game
initGame keys = Game mem ((length keys) + 1) 0
where
mem = I.fromList (zip keys [1..])
next :: Game -> Game
next (Game mem turn n) = fromMaybe (Game (I.insert n turn mem) (turn+1) 0) $ do
lastTurn <- I.lookup n mem
pure $ Game (I.insert n turn mem) (turn+1) (turn - lastTurn)
main :: IO ()
main = do
putStrLn ":: Day 15 - Tests 1"
print exampleInput1
putStrLn $ "turn 04: " <> (show $ initGame exampleInput1)
putStrLn $ "turn 05: " <> (show $ next $ initGame exampleInput1)
putStrLn $ "turn 06: " <> (show $ next $ next $ initGame exampleInput1)
putStrLn $ "turn 07: " <> (show $ next $ next $ next $ initGame exampleInput1)
putStrLn $ "turn 08: " <> (show $ next $ next $ next $ next $ initGame exampleInput1)
putStrLn $ "turn 09: " <> (show $ next $ next $ next $ next $ next $ initGame exampleInput1)
putStrLn $ "turn 10: " <> (show $ next $ next $ next $ next $ next $ next $ initGame exampleInput1)
print $ last $ take 2017 $ map unNumber $ iterate next $ initGame exampleInput1
print $ last $ take 2017 $ map unNumber $ iterate next $ initGame exampleInput2
print $ last $ take 2017 $ map unNumber $ iterate next $ initGame exampleInput3
putStrLn ":: Day 15 - Part 1"
print $ last $ take (2020 - 6) $ map unNumber $ iterate next $ initGame input
putStrLn ":: Day 15 - Part 2"
-- print $ last $ take (30000000 - 3) $ map unNumber $ iterate' next $ initGame exampleInput1
print $ last $ take (30000000 - 6) $ map unNumber $ iterate' next $ initGame input

View File

@ -42,17 +42,13 @@ eitherToMaybe :: Either a b -> Maybe b
eitherToMaybe (Right e) = Just e
eitherToMaybe (Left _) = Nothing
match' :: Char -> Char -> Int
match' c1 c2 | c1 == c2 = 1
match' _ _ = 0
-- How many passwords are valid according to their policies?
validatePassword1 :: Input -> Bool
validatePassword1 (Input min' max' char' pass) =
c >= min' && c <= max'
where
c = foldl (\acc c' -> acc + match' char' c') 0 pass
c = (length . filter (== char')) pass
-- How many passwords are valid according to the new interpretation of the
-- policies?

323
day3/input Normal file
View File

@ -0,0 +1,323 @@
.#.#....##.......#..........#..
...#...........##...#..#.......
#.####......##.#...#......#.#..
##.....#.#.#..#.#............#.
##.....#....#.........#...##...
###..#.....#....#..............
..........#..#.#..#.#....#.....
##.....#....#.#...#.##.........
#...#......#....##....#..#.#...
.##.##...#....##..#.#.....#...#
.....#.#..........##.#........#
.##..................#..#..##.#
#.#..........##....#.####......
.#......#.#......#.........#...
#....#..##.##..##........#.#...
##..#.##..#...#..####.#..#.....
###....#.###.##...........##..#
.....#.##.....##.#..#####....##
....#.###....#..##....##...#...
..###.#...##.....#.##..#..#.#..
#...#..#..#.........#..#.......
##..#.#.....#.#.#.......#...#.#
...#...##.#........#...#.......
..#..#.#..#...#...#...........#
........#.....#......#...##....
#........##.##.#.#...#...#.....
####.......#.##.###.#....#.....
...#...........#...#......#...#
##...#...#............#.......#
....#...........##.......#.....
###......#.....#....#...#.#...#
.....##..........#.......#.#...
##.##.##...#......#....#.......
##..#.#..#......#...#..#.......
....#....##.##............####.
..#.###..#.##.###..#.##.......#
#.##..#.#.....#..#.....##......
..##..#.....##.#.##........#...
.#..#.#......#..#............#.
.....#..#.#...#....#.##.#......
.#...##.#..#.#...##...##..##...
###............#.#..#..#...#...
..#..##.####.#.....#.....##.###
#....#.##..##....#..#...#.##.#.
.....#.##.........##...##......
.........####.#....#.#......#.#
.........#.#..#...#.#..#.#....#
.#.....#..##.##..##....#.......
..........##......#.##.###....#
.##...###..##.#...#........##..
..............#.#....#.#.###.##
..##.##.......#.#......##...#..
.#.....#..##..#.###...#..#.##.#
#.....#.#..#...#........#...#..
.#......#....#.#.....###...#..#
..##.#....#..##......#.....#...
..#.#.##..#.....#.####..###....
.........#......#..#...........
..#........#.##.#.....##.##..#.
.......#.........#....#...#.#..
.##.....#.#....#.#.......#.....
..........#.##........##...##..
###..###.#.#..#..#####.##.#.##.
..##..##.#.#...#..#.#.#......#.
#..#..#..#..##..#.....#......#.
..#....#.##..#......##.........
..#.##......#...##.#......#....
.......#..#.##.#.....#.........
.......#.#.#.###...##......#...
.....#.#..........#..#...#.....
....##..........#..........##..
..#......#.....#.##.#..#...#.#.
....#.....#..#...#..#.#.##..###
.####....#........#...#........
...##.#.##.#..#...##...#.##....
....#...#...#.#.#.#...#..#.....
.....#...#.#.....#.#........##.
..#.#.......###.#.....##.......
......#.........##....#....#..#
.............##.....##.........
.........##...##.......#.....#.
##.........#..........#.###..##
...#.....#......#....#..##.....
##..#...#...##.#.....#.#......#
..#...##.#.......#.#......#.##.
......#.......#.#...........#..
..........#.....##............#
#........#...#..#.......###.##.
.##...........#.#........#.#.#.
...#..##...#.#....#####.#......
.....##...###...#..#.##...####.
...#....#.....#..#.......#.....
#....#....#...#..#..#.######..#
#.###...........#......#...#..#
.#.#.#.#..#....#....#...##.#...
.#..#.........#.#....###...#...
......#..##.##..........#....##
.....#......##....##.....#...#.
.#...#.#.#....##....#..#....#.#
..................#..###.#..##.
..#.........#......#....#..###.
#.#.....#..#..#....###..###....
..##..##.#..##........##...##..
##..#........##..###..#.....#.#
..#..###..#......#....#...#...#
#..#.#..............##.#..#.#..
.....####....#...####.....#.#..
.....#....##.#......###........
##.##...#.#.#.#.......#....##..
.#......#...#.#....#..##.#.##.#
#.#.##.#.#......#..##........##
...##.....#.....#...#..###...#.
........###.....#.....#...##..#
.....#.##.##......#.#....#...#.
.#....##.......#..#.####.......
.#..#....#..........#......#.#.
.#.##.##.....###.#.#...........
.........#......#..##..........
....#...##.#.#.#..#.#.........#
..#.....#.##...#..#..#.###....#
...#.##......#.....##....#.....
###............#.#....#...#....
.......#.....#..#.#.#....#..#.#
...#......#.#..##..#....#...#.#
............##........##..##...
..#..#.##..#......###..#.......
........#.........#............
..#...#.#########.#...##..###..
#....#......#.......#.#.....#..
#.#..#....###.###....#...#.#...
#...###.#.#.......#.##......#..
.................#...#.#.#.....
##....#...#........#....#.#..#.
......#.....#...#..........#.#.
##..........#...#..........#.##
..#.#.##.#....#.#......#...##..
.....#.......#..#.....#........
#.##.#..##..#.......##.........
....#......#..#..#.#...#.......
...#....#................###...
.##.....#.#....#.#..........##.
...#..#....#.##.##......#......
..#.#....#.......#.#..##.......
....#.....#..........##.#.#####
#.....................##..#..#.
.###..#.##.......##.#...#..#...
...###.......#..#...#......#..#
#..#...#.#..#.#..#..#.##.......
#...##.......#..#..#.##..###...
......#....#.#.#........#.##..#
..##..#....#....#..#.#..#......
..##.#...#.#######..#...#.....#
..#....#..#.........#..##......
...#....#.#......#..#..#.#.....
#..#....#........#.#..##....###
#....#..##......##.##.....#.###
...#.#..........#..#.#.#.#.##..
......##..#.#..#.#....#....#...
##....#....#..#..#.##......#...
....#.#..##.#.#...###....##.#..
...#.......##..#.......#...#...
......##.......#..##.....#...#.
...#.#...#...........#...#.....
.#....#...#......##.##..###..#.
.#..........#...#...#...##.##..
.....###..#.....#..##....#.####
..#.###..#..##..##.....#.#.....
.............#.###...##.#.....#
....###.......###.#.....#..#.#.
........##.#.........#.....###.
.....###.#..#.....#...#..#.....
.#....#..##.#..#.#....#.......#
........#......#.#..#.#..#...##
...#.##.##......#..............
.#.....##.#.....#..#......##...
#..#..#.....#.....#.....###....
.##...........#..#.##.....#....
..#.#......#.#...#.##.#..#...##
...#..........#.....#..........
#.#.#.#.#...#....#...#.....##..
#......##...#...#..........#.#.
....##........#.#..............
#..#.#.#..#........##......#.##
........####...##.#.....#......
....#........#.#..#..##..#.#...
.#.....#..###...#..#.....#..#..
#......###.#..#....#..#.#......
....#.....##.##..#...#.#..##.#.
..##..#...#.#......#....#...#.#
#..##...##..#...###...#..#.....
.......#.....#...........##....
#..##....#........#....##..#.#.
.#........#..##...###.#..#.....
.#.#....#..##...#...##.#..###..
#.........#.......#.....#.#....
#..#.....#.#.###.#..#......#...
....#..#.#....#..##..###....###
###.##.#.#..#...........#.#.#..
..##.#.......#......#..##....#.
.....#.#.#.......##.......#...#
...........#.##....##.##....#.#
...#.......#..#.##..#......#..#
#.#.#...#......##.#...........#
##........#...........###.#..#.
..........#.#.#....#.#..##.#.#.
...#.#.#....#..........#..#....
#.#....###.#.#..#.......###...#
.#....#......#.#.#..#..#.......
......##.............#....#.#.#
.#..........#.........#.##.....
##....#....##....#..#.......#..
#.##.##.#..#..#.....#..#.##.#..
.#..#.......##..#.....##.##....
.......#..........#.#.##..#.##.
....#.....#.#...##....##.......
.......#.........#...##....##.#
#.....#......#..........#...#..
...#.#.......#.#..#....###..#..
.....#.#.#.........#...........
.#..###.#.#........#.#.........
.........#..#......##...##....#
...###..#.....##.....#.###....#
.##...#...#........###.#..#....
.##........#..#.###.######.##.#
##.#...#.#....#..##.#....##....
.......##.....##.#..###.#......
..##...##........#.......#....#
#..##...#.####...###......#...#
.##.....#.##.#.#.....###.#..##.
..###....#.#.###.#....#........
....#..###..#...#....#..#..#.#.
#.#.##....##...##.......#......
.........#...#....#..#.........
.............#...#..##.#.......
...#.##.......#...#.#..##.##...
.####.#.##..#.#......#.##...#.#
.#..#.#.....#.................#
..#.##..###....#...#......####.
..##..##...........#....#...#..
....#...#...#...#.......#....#.
#.#...###...#...#.#...#....##.#
......#...#.#.......#.....#...#
....##...#.#.#....#....#.#....#
.....#.....#...##..#...#....##.
#.....#....#......##.##....#...
...#.#....#...#....#.#....##..#
...#.#..#...##....###..#.......
...##......###...###.#...#..#..
##.......#.......###.......#..#
..##.##..###.#............#...#
#.....##..#..##....##..#.......
......#.#...#......#.....#.....
#...........#....#..##.##.#....
.......#..#......#...#....#...#
.#...##...........#......#...#.
#........#....##...###.#....#..
.....#.......##.........#.##...
.#.###..#....#..##.#..#.#..#...
#.......#.##.#.#....#.#..#....#
###.....#.#.......#..#......#.#
#..#.#.......#.#..##..##.#.#...
#..#.#.#.###........#.....#...#
#.#.#..#..##.....#...........#.
..#.#..#.....#...#...#...##....
...#.##......#...##.#...#.#.#.#
#..#.#.#.#.......####..........
..#......#.#......##.###.....##
..#...##..#.........##....#.##.
##.##.##.#.#.....#..........##.
.#.....###.#..#....#..#.###...#
#...##.......###....#.#..#.....
..#....##.........##.........##
......#....#.##.......#........
..#.#.#..#...#...#...##.#...#..
......#..##.#.#.#...##...#.#.##
#..#...##.#.....#...#.##.......
..#..#.........##.#...#.##...##
##.##.#....#.......#.##..#.....
.....##...##.##...##.........##
#......#...#.......#...#...#...
...##...........#...#..#.......
.#.##.#..#........#....#.......
#.#...#..#......##...#.#.##....
##........####..#.#...#.#.##.##
#..#.#.##......##.#.#..#.......
.....#.........#..#.####....#..
......##..#....#...#.#....#....
#...##........#.........#.....#
.#.#...#.#.#..#............##.#
.#..#....#....#.....#...#.....#
..###...#..#.....#.##.###...#.#
.#.###..#..#...#.#...#.#......#
#...#####......###........##...
.....#.....#..#.#....#..##.....
....##...#.#.##.#####...#....#.
.#.#.........##.#.......#..##..
.#...#.#...#...#....#.#...##.#.
.##...#..#.#..#......#.#.#..##.
..#.....#..#.....##.....#......
..#........#..##...#.......###.
.#....#.......#....#....#..#...
....#......#.#.#.........#.....
..##...#.#.#...#.#........#....
.#.....####...##.#..#...##.....
...#.....#...#...#....#....#...
.........#..#.#.....#..#.#..#..
.........##...........#.......#
......#..#.....##...#.##.#.....
.#......##........##...#.#.##..
.....#.#..##...........#..#..#.
...#.......#...#.#..#.##..#.##.
...#.......#.....#.#...#.##.#..
#.....#.............##.#..####.
.#...#......#...##.#....#.#....
.##..##.##....#.#.....#.......#
...#...#....#....##.#..#....##.
..............##....#.......#.#
.#.#.#...##..#..#...###.#..#...
.#.#...#.#..#.#..#...######..#.
........#......#.#..#.#....#...
..###.....###.#.##....#...##...
.##.#.....#.......##.......#...
..#..##...#..........#.#....#.#

121
day3/main.hs Executable file
View File

@ -0,0 +1,121 @@
#! /usr/bin/env -S"ANSWER=42" nix-shell
#! nix-shell -p ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [])"
#! nix-shell -i "ghcid -c 'ghci -Wall' -T main"
{-# LANGUAGE OverloadedStrings #-}
import Data.List (intersperse)
testData :: [String]
testData = [ "..##......."
, "#...#...#.."
, ".#....#..#."
, "..#.#...#.#"
, ".#...##..#."
, "..#.##....."
, ".#.#.#....#"
, ".#........#"
, "#.##...#..."
, "#...##....#"
, ".#..#...#.#"
]
data Position = Position { x_::Int, y_::Int }
instance Show (Position)
where
show p = "("<>show (x_ p)<>","<>show (y_ p)<>")"
-- Returns a half-line starting on (0,0) and following the (x*a,x*b) eq:
line :: Int -> Int -> [Position]
line a b = Position 0 0 : [ Position (x*a) (x*b) | x <- [1..] ]
-- Starting at the top-left corner of your map and following a slope of right 3
-- and down 1, how many trees would you encounter?
-- Requirements for this first task:
-- - datastructure supporting random-access (or similar) interface (lists would work)
-- - function generating a list of (x,y) coordinate to check
-- - must have 2D datastructure, since it's infinite on 1D (x axis)
-- - in this version at least, there's no need to modify the datastructure, so
-- it can be read-only, or even just a function taking a position and returning
-- SquareSortEmpty or SquareSortTree
data SquareSort = SquareSortTree | SquareSortEmpty
deriving Eq
instance Show SquareSort
where
show SquareSortTree = "#"
show SquareSortEmpty = "_"
char2ss :: Char -> Maybe SquareSort
char2ss '#' = Just SquareSortTree
char2ss '.' = Just SquareSortEmpty
char2ss _ = Nothing
str2sss :: String -> Maybe [SquareSort]
str2sss = sequence . (map char2ss)
newtype Grid = Grid [[SquareSort]]
instance Show (Grid)
where
show (Grid x) = concat $ intersperse "\n" $ map show x
parseInput :: [String] -> Maybe Grid
parseInput x = Grid <$> sequence ( (map str2sss) x )
getSquareSortAtPosition :: Grid -> Position -> SquareSort
getSquareSortAtPosition (Grid grid) (Position x y) =
grid !! y !! (x `mod` n)
where
n = length (grid !! 0)
solveDay3Part1 :: Grid -> (Int,Int) -> Int
solveDay3Part1 grid@(Grid lx) (x',y')=
length $ filter (== SquareSortTree) $ map (getSquareSortAtPosition grid) px
where
px = take n' $ line x' y'
n' = if y' > 1 then n + 1 else n
n = (length lx) `div` y'
-- Determine the number of trees you would encounter if, for each of the
-- following slopes, you start at the top-left corner and traverse the map all
-- the way to the bottom:
--
-- - Right 1, down 1.
-- - Right 3, down 1. (This is the slope you already checked.)
-- - Right 5, down 1.
-- - Right 7, down 1.
-- - Right 1, down 2.
--
-- What do you get if you multiply together the number of trees encountered on
-- each of the listed slopes?
solveDay3Part2 :: Grid -> Int
solveDay3Part2 grid =
foldl (*) 1 [ solveDay3Part1 grid (1,1)
, solveDay3Part1 grid (3,1)
, solveDay3Part1 grid (5,1)
, solveDay3Part1 grid (7,1)
, solveDay3Part1 grid (1,2)
]
main :: IO ()
main = do
putStrLn "Day 3 - Part 1"
inputData <- readFile "day3/input"
print $ take 5 $ line 3 1
print $ take 6 $ line 1 2
let (Just parsedTestData) = parseInput testData
print parsedTestData
print $ getSquareSortAtPosition parsedTestData (Position 5 10)
let (Just parsedInputData) = parseInput (lines inputData)
putStrLn "Part 1:"
print $ solveDay3Part1 parsedTestData (3,1)
print $ solveDay3Part1 parsedInputData (3,1)
putStrLn "Part 2:"
print $ solveDay3Part2 parsedTestData
print $ solveDay3Part2 parsedInputData

989
day4/input Normal file
View File

@ -0,0 +1,989 @@
hgt:176cm
iyr:2013
hcl:#fffffd ecl:amb
byr:2000
eyr:2034
cid:89 pid:934693255
hcl:#b5c3db ecl:grn hgt:155cm pid:#baec97 iyr:2017
byr:1939
eyr:2020
pid:526669252 eyr:1972
hgt:152cm ecl:dne byr:1960 hcl:z iyr:2023
eyr:2028 hcl:#c0946f hgt:73in byr:1926 ecl:#473aaf iyr:2016 pid:565318180
pid:472686027 ecl:oth iyr:2019
cid:277 byr:1940
eyr:2030 hgt:170cm
hcl:#62e117
ecl:oth
iyr:2017
pid:938461813 hcl:#733820 byr:1959 hgt:159cm eyr:2022
iyr:2011 eyr:2021 hcl:z
ecl:hzl byr:2002 pid:17324328 cid:140
hgt:186cm
byr:2022 pid:3164234967 iyr:1984
hgt:76cm hcl:6b3837
ecl:#fa362b
eyr:2037
hcl:z eyr:1945
pid:9247286687 hgt:75cm
iyr:1934 cid:326 ecl:zzz
byr:2005
byr:2005
ecl:lzr
eyr:2021 pid:152cm
cid:254 iyr:2020 hcl:z hgt:157cm
iyr:2020 eyr:2020 hcl:#18171d ecl:gry pid:914128753 hgt:168cm
byr:2002
hcl:#7d3b0c hgt:160cm eyr:2020 iyr:2015
pid:054067854 ecl:brn byr:2023
hcl:#cfa07d hgt:157cm
byr:1994 eyr:2027 pid:344443856
iyr:2016
pid:762423097
iyr:2014 hcl:#a97842 ecl:brn hgt:180cm byr:1927 eyr:2021
pid:6645616064 hcl:#ceb3a1 byr:2030
eyr:2032 hgt:158cm iyr:2012
ecl:#e9619e
eyr:2022
ecl:brn
byr:1986
hgt:161cm cid:99 pid:288726584 hcl:#6b5442 iyr:2019
cid:75
pid:117771843
hgt:184cm byr:1937 ecl:brn
hcl:#d88fd9
iyr:2015 eyr:2027
iyr:2016 hcl:#fffffd hgt:170cm eyr:2022 ecl:oth pid:629454113
byr:1952
hcl:#c0946f iyr:2018 hgt:189cm
byr:1971 ecl:oth eyr:2029
pid:800207810
eyr:2022 hcl:#7d3b0c pid:969986413
byr:1978 iyr:2020 hgt:186cm
ecl:gry
hgt:171cm byr:1949 hcl:#341e13
ecl:amb eyr:2030 pid:359107274 iyr:2013
pid:839751525 eyr:2024 byr:1921
iyr:2012 ecl:amb hcl:#b0ed6f hgt:154cm
pid:32592758
byr:2009
hgt:107 iyr:2019 hcl:#866857
eyr:2036 ecl:amb
eyr:2040 hcl:#733820 cid:199
byr:2027
pid:7791792988 ecl:blu iyr:2026
hgt:63cm
iyr:2011 cid:119 pid:344693475
ecl:grn hgt:160cm eyr:2029 hcl:#346973 byr:1996
hgt:161in byr:2025 cid:167 iyr:2024 eyr:2040 pid:034804648
hcl:#efcc98 ecl:oth
ecl:#ba14f0 iyr:1935
hgt:60cm
byr:2003 eyr:1987
hcl:8e509b pid:161cm
iyr:2018 pid:620508652 ecl:amb eyr:2023 hgt:183cm hcl:#a97842
byr:1967 cid:117
eyr:2022 ecl:amb
pid:476049089 iyr:2012
hgt:165cm
byr:1955 hcl:#602927
byr:2014 hcl:z iyr:2029 cid:279 pid:28914607 hgt:75cm ecl:xry
hgt:156cm eyr:2023 iyr:2011 ecl:oth hcl:#7d3b0c pid:561313217 byr:1952
iyr:2011 byr:1935
hcl:#cfa07d ecl:oth pid:830614209
eyr:2028 hgt:173cm
iyr:2012 cid:210 eyr:2022
pid:652810130 hcl:#18171d ecl:grn byr:1960 hgt:152cm
eyr:2026 pid:815848563 hgt:75in iyr:2019 ecl:gry byr:1947
hcl:#cfa07d
cid:181 iyr:2012
eyr:2024 byr:1934 hcl:#c0946f
hgt:165cm ecl:oth pid:232944581
cid:135 iyr:2020
byr:1971 hcl:#733820 pid:531877857 hgt:179cm eyr:2027 ecl:amb
byr:1987 hcl:936807 eyr:2032 ecl:#4bec4a pid:605628619 cid:180 hgt:150in
iyr:2015
hcl:b62ef0 ecl:#092141
pid:876635399 byr:1944 hgt:158cm iyr:2017 eyr:1924
iyr:2016 pid:7039815301 byr:2014 hgt:150 eyr:2032 ecl:blu hcl:z
byr:1979 eyr:2030 iyr:1978 hgt:63 pid:1554613758 hcl:z ecl:amb
hgt:70cm hcl:e45897 iyr:2020 eyr:1977 ecl:dne pid:2878189427 byr:1973
iyr:2003
hcl:#cfa07d
pid:260517078
byr:2030 hgt:175cm eyr:2020
ecl:brn
pid:460604681 eyr:2022
cid:138 iyr:2016 hgt:163cm
byr:1922
hcl:#ceb3a1 ecl:oth
hgt:167cm byr:2009 eyr:1975 cid:295 pid:174cm iyr:2029
hcl:z
hgt:67in ecl:grn
eyr:2023
cid:122 pid:281246917 byr:1990 iyr:2011 hcl:#866857
ecl:#ed7ddc byr:1922 cid:234 hcl:e61b1e iyr:1932 eyr:1996 pid:31344005 hgt:62cm
byr:1949
cid:275 iyr:2017 ecl:grn
hgt:164cm eyr:2027 hcl:#18171d
pid:751342937
ecl:blu hgt:162cm
pid:432600613 byr:1923 eyr:2029 iyr:2011 hcl:#623a2f cid:315
iyr:2020
hcl:#b2bb11 pid:055891584 ecl:grn
hgt:67in
eyr:2029 byr:1937
iyr:2012
hcl:#a97842 pid:325640714 ecl:blu hgt:185cm eyr:2024 byr:1971
hcl:#b6652a pid:485327267
ecl:brn hgt:155cm eyr:2028
iyr:2019
pid:902164867 hgt:77 cid:283 eyr:2027
iyr:2020 ecl:hzl byr:1935 hcl:#efcc98
ecl:grn
hcl:#ceb3a1 byr:1977 hgt:165cm
pid:850700221 eyr:2030
iyr:2012
byr:1989 ecl:brn eyr:2026 pid:919138357 iyr:2016
hcl:#623a2f cid:319 hgt:161cm
iyr:2017
byr:1973 pid:293382118 hcl:#341e13 cid:143 ecl:hzl
hgt:166cm eyr:2022
pid:517102798
hcl:f9d9dd
eyr:1933 iyr:2019 hgt:164cm
byr:2017 ecl:utc
eyr:2023 pid:757868802 hcl:#18171d cid:244
hgt:156cm
ecl:blu iyr:2015 byr:1926
eyr:2022
iyr:2020
hgt:158cm ecl:grn
byr:1988
pid:979194751 hcl:#888785
eyr:2039
pid:3867868142 byr:1936 ecl:dne iyr:2022 hcl:4b43b8
hgt:115 cid:241
iyr:2015 eyr:2026
hcl:#ceb3a1 pid:539099924
cid:234
ecl:brn
byr:1920 hgt:163cm
cid:259 iyr:2020
pid:949453818 eyr:2022 hgt:181cm
byr:1997 ecl:blu hcl:#18171d
byr:2016
iyr:2012
ecl:utc
hgt:68in eyr:1993
pid:1542134802 hcl:486699
cid:239
iyr:2018
hgt:154cm ecl:brn byr:1970
eyr:2021 pid:581775861 hcl:#888785
iyr:2012
eyr:2027 hgt:67cm hcl:#efcc98 ecl:zzz pid:312104916 byr:2020
hcl:#b6652a ecl:hzl eyr:2023 iyr:2012 pid:513268492
hgt:159cm
hgt:162in hcl:z
byr:2029
eyr:2023 ecl:#e2e7ab iyr:2016 pid:65979982
cid:84 hgt:71in ecl:blu pid:982719716
eyr:2020 iyr:2014
eyr:2028 hgt:181cm
ecl:hzl pid:255796693 hcl:#341e13 byr:1994 iyr:2011 cid:218
ecl:blu
byr:2029 iyr:2017 pid:468504566 eyr:2020 hcl:z hgt:163cm
hgt:158cm
eyr:2025 ecl:hzl cid:295 pid:601339484
hcl:#7d3b0c byr:1991 iyr:2013
eyr:2028
iyr:2018 pid:2236240873
hgt:172cm
ecl:#0e337e hcl:#b6652a cid:108 byr:1930
ecl:gry hcl:#888785
eyr:2020 pid:442479017 iyr:2016
iyr:2014 ecl:grn
cid:313 eyr:2023
hgt:183cm
byr:1976
pid:499580308 hcl:#53efe6
eyr:2034
cid:235 hcl:8f3cf5
byr:2027
hgt:161in pid:3259965094 ecl:xry iyr:2026
eyr:1978 byr:1925 iyr:2018 hgt:170cm ecl:#0c94e8
pid:562699017 hcl:#816949
eyr:2023 hcl:#866857 hgt:179cm
pid:785862442 iyr:2014 cid:165 ecl:amb byr:1939
hgt:187cm
pid:64469711 ecl:gry eyr:2023 cid:225 hcl:#341e13 iyr:2011 byr:1958
hgt:162cm byr:2028 ecl:#37e345
eyr:2037 hcl:19fb3d
iyr:2021
pid:#87921a
eyr:2027 hcl:#18171d
byr:2002 ecl:gry iyr:2014
pid:561506850 hgt:177cm
hgt:64cm pid:#a92686
eyr:2029 cid:122
byr:2026
iyr:2017 hcl:z ecl:grn
eyr:2028 byr:2007 hgt:155cm ecl:#86fa1b hcl:#733820 pid:562889497
iyr:2019
pid:880698787
byr:1992
hcl:#7d3b0c hgt:163cm ecl:hzl
iyr:2011 eyr:2021
eyr:2020 byr:1994 iyr:2011 hgt:186cm pid:841855425 hcl:#cfa07d ecl:gry
byr:1923 iyr:2015 ecl:amb pid:414655744
hcl:#b6652a
hgt:159cm
eyr:2026
hgt:171cm ecl:amb pid:363065723 iyr:2020
cid:66 hcl:#b6652a eyr:2021
byr:1960
eyr:2002
hcl:2627b2 ecl:#1bf21d pid:168cm byr:2024 iyr:2020
hgt:186in
iyr:2011 byr:1924 eyr:2024
hcl:#b6652a ecl:brn
pid:794477411 hgt:162in
hcl:z hgt:67cm
byr:2025
pid:582569979
iyr:2013
ecl:oth eyr:2025
cid:50 hcl:931e2c
hgt:172in eyr:1994 iyr:2023
ecl:#cd2204
byr:2015
pid:157cm
hgt:173cm eyr:2028
ecl:amb pid:569607283
byr:1942
iyr:2019
cid:228
hcl:#866857
cid:109
ecl:oth eyr:1933 byr:1982 pid:173cm hcl:#b6652a hgt:174cm
iyr:2023
cid:69 hcl:#9ad05b pid:341135641
byr:1968 ecl:brn
iyr:2012 hgt:156cm
eyr:2020
hgt:176cm
byr:1954 ecl:blu
eyr:2020
pid:478462637 iyr:2019
hcl:#888785
iyr:2026 hgt:193in
byr:2018 pid:162cm hcl:605e7f eyr:1948 ecl:utc
byr:1962
eyr:2022 pid:445346117 iyr:2019 hgt:158cm hcl:#623a2f ecl:hzl
cid:278 hgt:187cm eyr:2024 iyr:2016 byr:1964
ecl:grn pid:450739552 hcl:#733820
ecl:grn byr:2000 eyr:2023
pid:344489911 hcl:#7d3b0c iyr:2011 hgt:177cm
iyr:2015 hgt:180cm cid:190 hcl:#a97842 pid:359774842 eyr:2029 byr:2002 ecl:amb
eyr:2027 iyr:2015 ecl:hzl
pid:082733109
byr:1975 hgt:191cm cid:251 hcl:#888785
hcl:#c0946f iyr:2015
hgt:167cm byr:1990 ecl:amb pid:168cm eyr:2023
ecl:gry eyr:2028
byr:1934 iyr:2013 hcl:#6b5442
pid:424412120 hgt:173cm
pid:273352568
eyr:2024
iyr:2013 byr:1926 hcl:#602927
ecl:brn hgt:180cm
hcl:#7d3b0c hgt:70in ecl:amb iyr:2019
byr:1937
eyr:2030 pid:309011548
ecl:grn
hgt:64in pid:796889811 hcl:#18171d
byr:1929 eyr:2027
ecl:amb hcl:#888785
pid:412449028 cid:316 byr:1982
iyr:2019 eyr:2030 hgt:193cm
eyr:1927
hcl:z hgt:158cm byr:1930
ecl:lzr iyr:2018
cid:197
pid:0906120002
ecl:grn byr:1970 hgt:181cm
pid:376212702 eyr:2030 iyr:2017 cid:266 hcl:#f8b0f5
iyr:2018 hgt:73in pid:652356158 hcl:#c0946f
ecl:grn byr:1973
cid:170 hcl:#b6652a byr:2011
ecl:gry iyr:2025 pid:#b6e567 hgt:67cm eyr:2016
hgt:192cm ecl:amb eyr:2026 pid:201824712 hcl:#888785 byr:1966 iyr:2019
iyr:2013 byr:1995 eyr:2028 hcl:#b6652a ecl:brn cid:53 pid:705606447 hgt:176cm
hcl:#341e13 byr:1951
hgt:161cm pid:231973770 iyr:2015 ecl:hzl
eyr:2030
cid:210 ecl:brn iyr:2017 eyr:2030
hgt:176cm hcl:#efcc98
byr:1965
eyr:2020 hcl:#7d3b0c
pid:872088079 ecl:oth iyr:2017 byr:1920
hgt:180cm
hcl:#0b540c iyr:2019
byr:1938
hgt:153cm ecl:gry pid:236785988
eyr:2020
eyr:2020 hgt:184cm iyr:2019
pid:673186642 ecl:oth byr:1977 hcl:#866857
eyr:2025
ecl:gry hcl:#341e13 byr:1970 iyr:2010 pid:972122542 hgt:184cm
ecl:grn byr:1992 hgt:71in
iyr:2014 cid:254 hcl:#fffffd pid:749733013
eyr:2026
cid:98 ecl:amb eyr:2022
hgt:169cm pid:022677680
byr:1937 iyr:2014 hcl:#e62c71
hgt:192cm
iyr:2015
eyr:2028 ecl:oth pid:6000619833 hcl:#c0946f
byr:1930
byr:1938 hcl:#efcc98 hgt:178cm iyr:1953 eyr:2038
ecl:brn pid:#cdc55a
hgt:66in byr:1951 iyr:2016 hcl:#18171d
eyr:2027
ecl:lzr pid:834188980
iyr:2012 eyr:2025
hcl:#7d3b0c pid:330325803 cid:166 hgt:186cm byr:1938
ecl:amb
iyr:2015 hcl:#602927 cid:268 eyr:2021
ecl:amb hgt:186cm pid:318676962
hcl:#3d6f3c iyr:2014 pid:665730784 cid:191 hgt:150cm byr:1981 ecl:oth eyr:2024
ecl:grn hcl:#733820
eyr:2028 iyr:2010
hgt:162cm byr:1944 pid:872962499
eyr:2028 byr:1974
ecl:brn
iyr:2010 hcl:#18171d hgt:160cm
hcl:#602927
byr:1959 eyr:2027 iyr:2016 ecl:brn hgt:169cm pid:078503025
hcl:#623a2f pid:326300051 hgt:153cm
byr:1973 iyr:2012
ecl:gry eyr:2026
hgt:151cm
byr:1966 eyr:2029 pid:026952622 hcl:#18171d ecl:gry iyr:2010
hcl:#7d3b0c byr:1974 pid:444713591 iyr:2017 eyr:2030
hgt:165cm ecl:oth
iyr:2026 pid:184cm
ecl:gmt hcl:z hgt:71cm
eyr:2029
cid:310 hcl:#fffffd byr:1998
pid:450705840 iyr:2015
ecl:grn eyr:2021 hgt:165cm
byr:1939 hcl:#623a2f ecl:gry hgt:69in pid:539812641 eyr:2027 iyr:2013
pid:207645014
iyr:2015
cid:314 ecl:oth
byr:1942
eyr:2027 hgt:186cm hcl:#fffffd
ecl:#fb7e3d eyr:2031 iyr:1956
hgt:188 pid:160cm hcl:z byr:2027
byr:1972 iyr:2020 eyr:2026 hcl:#b6652a pid:289088329 hgt:65in ecl:gry
eyr:2027
hgt:59cm
byr:2022
pid:938063769 ecl:zzz iyr:2028 hcl:23c762
byr:2004 hgt:74 iyr:2017
eyr:2040 ecl:blu pid:4611117799 cid:73 hcl:z
ecl:brn byr:1962 cid:321
iyr:2019 eyr:2026
hgt:159cm
hcl:#667310 pid:439864945
iyr:2026 eyr:2039 pid:633263851 cid:321 ecl:lzr hgt:166cm
byr:2023 hcl:fc3c63
byr:1961 iyr:2010 ecl:blu
eyr:2023 pid:245858010
hgt:193cm pid:821303249 eyr:2020 hcl:#6b5442 cid:130 byr:1946
eyr:2026 ecl:brn
hcl:#733820 byr:1983 hgt:182cm pid:727380954 cid:188 iyr:2015
hgt:152cm cid:206 iyr:2012 byr:1947 hcl:#888785 ecl:gry
pid:720312394 eyr:2023
hgt:150cm ecl:gry pid:863712648
iyr:2019 cid:349 byr:1976 hcl:#602927 eyr:2022
hgt:164in pid:953500867
eyr:2021
iyr:2014
hcl:z cid:343 ecl:amb
byr:1981 pid:529710230 iyr:2013 eyr:2023
hcl:#c0946f ecl:amb
hgt:151cm
pid:706204190 hgt:154cm cid:317
hcl:#602927 byr:1949 ecl:blu iyr:2010 eyr:2028
iyr:2019 hcl:#0219e6
pid:850093151 ecl:gry
eyr:2030
byr:1938 hgt:177cm
ecl:brn hcl:#efcc98 eyr:2029 byr:1963
hgt:185cm pid:611279647 iyr:2011
ecl:blu eyr:2022 byr:1941 hgt:167cm
iyr:2012 hcl:#7d3b0c pid:415739564
cid:193
eyr:2027 ecl:blu byr:1968 pid:479994566
hcl:#733820 hgt:151cm
iyr:2011
pid:263729839 hgt:189cm eyr:2030 ecl:gry byr:2001 hcl:#602927
byr:1985
ecl:amb pid:672663977 cid:139
hgt:159cm hcl:#733820 iyr:2018 eyr:2020
byr:1998
hcl:#cfa07d eyr:2023 pid:255046063 iyr:2011 ecl:blu hgt:177cm
ecl:oth
byr:1980 pid:253747166 eyr:2029
hcl:#6b5442 hgt:186cm
eyr:2030 hcl:#866857
hgt:165cm
ecl:amb
iyr:2017 pid:241240220 cid:164 byr:2001
byr:1994 hcl:#b6652a iyr:2015
pid:753831241
hgt:175cm
eyr:2027 ecl:blu
hcl:#b6652a pid:471594512
byr:1961 ecl:hzl hgt:175cm
iyr:2020 eyr:2025
byr:1987 pid:112366159
eyr:2028 hcl:22b2d7
hgt:64in cid:222
ecl:#b40dca iyr:2019
iyr:2015 hcl:e1ed55 hgt:160in ecl:utc byr:2015 eyr:2036
byr:1935
hcl:#7d3b0c hgt:152cm ecl:gry
pid:160090332 iyr:2020 eyr:2020
pid:552779024 byr:1998 hgt:185cm ecl:gry eyr:2026 iyr:2013 hcl:#d46cd6
ecl:oth pid:311860969
cid:57
hgt:60in
eyr:2026
hcl:#ceb3a1
byr:1961 iyr:2011
eyr:2021 hgt:162cm cid:240
pid:259997995
hcl:#efcc98
ecl:gry byr:1962 iyr:2017
hcl:#866857
iyr:2016
eyr:2029
ecl:blu byr:1927 cid:249 pid:665324615 hgt:65in
byr:1931
cid:331
hgt:66in
ecl:grn iyr:2020 hcl:#efcc98 eyr:2025 pid:175780921
hgt:98
eyr:2040 ecl:blu byr:2029
iyr:1967 hcl:0d76e9
pid:#c9053a cid:296
pid:370918950
hcl:#602927
byr:1938
hgt:178cm iyr:2018 eyr:2030
ecl:oth
hgt:185cm
eyr:1984 ecl:oth pid:851080398
hcl:z byr:2027 iyr:2017
pid:095078224 byr:1957 hcl:#45bcf4 ecl:#f643f9 hgt:63cm eyr:2036 iyr:1978
hcl:z
eyr:2023 ecl:oth hgt:162cm
iyr:2016 byr:1938 pid:#fdcddf
hcl:#341e13 iyr:2013 hgt:189cm
pid:982271041 ecl:brn
byr:1930 eyr:2030
eyr:2026
iyr:2012 hcl:#cfa07d cid:59 pid:105862717 ecl:blu
hgt:159cm byr:1943
ecl:hzl
pid:604172804 iyr:2016 hgt:174cm cid:79 eyr:2025
hcl:#733820 byr:1994
iyr:2011 pid:452628771 ecl:gry hgt:182cm hcl:#623a2f
eyr:2023
byr:1986
hcl:#341e13 iyr:2010 byr:1946 eyr:2021
cid:350 pid:049684494 hgt:180cm
ecl:grn
iyr:2020
hgt:173cm pid:384503937
byr:1986
hcl:#341e13
cid:113
eyr:2025 ecl:amb
hgt:180cm byr:1949
hcl:#733820 iyr:2010 eyr:2030
cid:123 pid:065609606 ecl:oth
iyr:2010 eyr:2028
pid:231750173
hgt:63in ecl:brn
byr:1948 hcl:#18171d
iyr:2020 hcl:#623a2f
ecl:gry
byr:1922 pid:961213634 eyr:2022 hgt:177cm
hcl:#18171d eyr:2020 iyr:2014 byr:1983
pid:183568344 hgt:72in
ecl:gry
eyr:2023 pid:102781246 ecl:brn
hcl:#888785 byr:1929 hgt:167cm iyr:2010
pid:362873066 byr:1994 hcl:#de545f iyr:2018 hgt:177cm ecl:blu cid:86
eyr:2024
hcl:842f2d iyr:1983
byr:1954 eyr:2037
ecl:lzr pid:3915492573 hgt:166cm
ecl:grn
hcl:#fffffd iyr:2014
hgt:173cm
byr:1939
pid:930650489
eyr:2025
eyr:2028 ecl:brn hcl:#7d3b0c hgt:166cm byr:1938 pid:992958531 iyr:2011
pid:101149939 eyr:2024 iyr:2018 hgt:165cm
ecl:hzl
hcl:#ceb3a1 cid:176
cid:62
pid:651390352 hcl:#efcc98
iyr:2018
eyr:2027
ecl:brn
hgt:66in byr:1953
hcl:#623a2f byr:1978
iyr:2013
hgt:180cm eyr:2027 ecl:amb pid:836425641
pid:557464096 hgt:155cm ecl:blu cid:142 byr:1936 iyr:2010
hcl:#cfa07d eyr:2027
ecl:gry iyr:2024 hcl:#341e13 pid:442593279 cid:314 hgt:186cm byr:1960
eyr:2022
cid:123 iyr:2014
byr:2000
pid:878733390 eyr:2021 ecl:hzl hgt:162cm
byr:1959 cid:259
pid:722895016
ecl:brn iyr:2018 eyr:2027 hgt:185cm
pid:163697814 ecl:hzl
iyr:2013 byr:1932
hgt:68in cid:286 eyr:2025 hcl:#efcc98
byr:1927
hgt:72cm ecl:oth
eyr:2021 hcl:#99e959
pid:669724466 iyr:2010
byr:1943 iyr:2011 eyr:2024 pid:384419879 ecl:hzl hcl:#7d3b0c hgt:170cm
pid:137944386 ecl:gry
byr:1953 hcl:#733820 iyr:2013 eyr:2025 hgt:184cm
iyr:2017 eyr:2023 pid:288078785
hgt:179cm
byr:1993 hcl:#602927 ecl:hzl
ecl:brn
hgt:187cm eyr:2024 byr:1971 iyr:2020 hcl:#b6652a pid:622975646
cid:290
pid:371817422 ecl:blu byr:1964
iyr:2018
eyr:2021 cid:176
hgt:153cm hcl:#888785
byr:2002
cid:256 iyr:2014 eyr:2024 ecl:blu hcl:#18171d hgt:187cm
pid:050022911
hgt:178cm pid:211144001 eyr:2027 iyr:2013
byr:1947
hcl:#7d3b0c ecl:grn
eyr:2025 ecl:blu pid:046417901 byr:1950
iyr:2015 hgt:165cm
hcl:#7d3b0c cid:128
ecl:hzl eyr:2029
iyr:2015
hgt:171cm hcl:#341e13
pid:561680375 byr:1997
byr:1948 iyr:2023 pid:17288381 hcl:6a34a3 ecl:#671ece eyr:2001
cid:152
eyr:2036 hgt:141 iyr:1957 byr:1987 hcl:z
pid:86986187 ecl:utc
eyr:2024 hcl:#b6652a iyr:2017 ecl:blu byr:1988 cid:348 hgt:152cm pid:068684272
iyr:2011 pid:989825275
cid:78 hcl:#341e13 byr:1983 ecl:blu hgt:158cm eyr:2020
ecl:grn hgt:187cm eyr:2027 iyr:2015
hcl:#866857 pid:240650427
byr:1940
cid:91
hcl:#888785 cid:185 byr:1925
hgt:155cm iyr:2015 ecl:blu eyr:2027 pid:851697441
iyr:2016 ecl:oth pid:056439470 byr:1985 eyr:2026
hgt:154cm hcl:#282539
ecl:hzl hcl:#a97842
iyr:1944
pid:118846711 eyr:2026 byr:1922 hgt:185cm
iyr:2020 hcl:#733820
pid:854531642 hgt:165cm
ecl:hzl eyr:2022
iyr:2014
byr:1957 hcl:#7fa674 hgt:189cm
eyr:2023 pid:740871941 ecl:brn
ecl:amb cid:349 hgt:170cm
byr:1952 hcl:#ceb3a1 iyr:2020
eyr:2026
pid:730499325
eyr:2027 ecl:amb
byr:1975 pid:985687961
hcl:z hgt:157cm
iyr:2013
cid:133
ecl:blu
hgt:193cm iyr:2015 hcl:#10f2ba byr:1989 pid:939704495 eyr:2021
ecl:oth eyr:2025 hgt:69in iyr:2014 cid:258 pid:477970733 byr:1984 hcl:#b6652a
hcl:z byr:2013
ecl:zzz
pid:1904741884 hgt:180 cid:138 eyr:1985 iyr:1935
eyr:2025
iyr:2026 hgt:190in pid:#43ca33
ecl:#3e1ef1 hcl:#7d3b0c byr:2030
eyr:2029 hgt:191cm
byr:1986 hcl:#ceb3a1 cid:327 pid:795060714 iyr:2012 ecl:hzl
eyr:2025 iyr:2017 ecl:grn
hcl:z
pid:8886398 hgt:174cm byr:2016
hcl:#a97842
eyr:2021 ecl:grn iyr:2013 pid:565234133 byr:1998
hgt:161cm
eyr:2029 hgt:163cm byr:1933 cid:86 iyr:2011
ecl:grn
hcl:#fffffd
pid:818769307
hgt:190cm eyr:2030 hcl:#af5b5d iyr:2011 ecl:brn pid:359524299 byr:1969
ecl:amb iyr:2011 eyr:2022
cid:141
byr:1978 hgt:69in hcl:#fffffd pid:013006109
ecl:blu hgt:164cm iyr:2019 eyr:2027 pid:899103430 hcl:#cfa07d
byr:1976
eyr:1938
ecl:#a03c41 pid:708735698
iyr:2030
hgt:184cm hcl:#b6652a byr:2013
ecl:hzl byr:1997 hcl:#a97842 cid:60 pid:172cm
eyr:2023 hgt:161in iyr:1936
ecl:hzl
byr:1938 pid:094889181
hgt:162cm iyr:2020
eyr:2028
hcl:#623a2f
hgt:162cm cid:86
hcl:#623a2f pid:738174580 ecl:brn byr:1980 eyr:2028 iyr:2014
byr:2007 hgt:150in hcl:z
eyr:2032
ecl:#114f3b
iyr:2030 pid:5129772
ecl:hzl iyr:2017
hcl:#18171d
pid:696283412 byr:1976 hgt:168cm
eyr:2028
eyr:1922 ecl:#84b0d4 byr:2013 hcl:#ceb3a1 pid:150cm iyr:2030
hgt:71cm
hgt:164cm byr:1949 ecl:gry eyr:2026
hcl:#623a2f
ecl:oth
iyr:2013 hgt:166cm hcl:#50e385
pid:478852286
eyr:2030 byr:1930
cid:129
iyr:2020 byr:1978 pid:907580992 eyr:1955
hcl:#602927
ecl:grn hgt:165cm
ecl:blu iyr:2018 byr:1953
hgt:177cm pid:126681706 eyr:2025 hcl:#c0946f
byr:1984 pid:275799917
ecl:oth hcl:#623a2f cid:348 iyr:2020
hgt:189cm eyr:2024
iyr:2016
ecl:hzl byr:1954
hcl:#623a2f pid:810508839 eyr:2026
hgt:185cm
byr:1967
eyr:2021 hcl:#ceb3a1
pid:406634908 hgt:158cm iyr:2018 ecl:hzl
iyr:2019 eyr:2030 pid:995681076 hcl:#341e13
cid:101 hgt:162cm ecl:blu byr:1925
eyr:2026 pid:272513479 hcl:#b6652a byr:1973 iyr:2016 ecl:amb hgt:182cm
pid:298704871 eyr:2024 hcl:#efcc98 byr:1959
iyr:2014 hgt:191cm ecl:grn
hgt:193cm pid:750729809 ecl:oth
cid:324
iyr:2011 hcl:#efcc98 byr:1954 eyr:2020
byr:1966 iyr:2019 eyr:2025 ecl:#2df4b6
hgt:184cm pid:#fc17f4 cid:161 hcl:#602927
byr:1955 hcl:299464 ecl:amb
hgt:157cm iyr:2017 eyr:2021
pid:239450987
hgt:172cm
ecl:hzl
pid:839804598
hcl:#341e13 eyr:2030 byr:1964 iyr:2013
iyr:2018 hgt:152cm byr:1948 hcl:#623a2f pid:400121515
ecl:blu
eyr:2020
cid:296
ecl:grn
byr:1960 iyr:2028 pid:#1f4b95 eyr:2033 hcl:#602927
hgt:66cm
iyr:1933 ecl:#232e20 pid:#d03ca7
eyr:2030 hcl:598ed6 hgt:154in byr:2011
cid:247 ecl:grn iyr:2014
hgt:178cm
byr:1992 hcl:#602927 eyr:2021
pid:678964478
iyr:2010 pid:623705680
ecl:hzl hgt:181cm byr:1980 hcl:#341e13 eyr:2028

200
day4/main.hs Executable file
View File

@ -0,0 +1,200 @@
#! /usr/bin/env -S"ANSWER=42" nix-shell
#! nix-shell -p ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [attoparsec])"
#! nix-shell -i "ghcid -c 'ghci -Wall' -T main"
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import Data.Attoparsec.Text (Parser, parseOnly)
import Data.Char (isSpace)
import Data.Map.Strict (Map)
import Data.Maybe (catMaybes)
import qualified Data.Attoparsec.Text as A
import qualified Data.Map.Strict as M
import qualified Data.Text as T
-- The expected fields are as follows:
--
-- - byr (Birth Year)
-- - iyr (Issue Year)
-- - eyr (Expiration Year)
-- - hgt (Height)
-- - hcl (Hair Color)
-- - ecl (Eye Color)
-- - pid (Passport ID)
-- - cid (Country ID)
-- Count the number of valid passports - those that have all required fields.
-- Treat cid as optional. In your batch file, how many passports are valid?
data Field = BYR | IYR | EYR | HGT | HCL | ECL | PID | CID
deriving (Show, Ord, Eq)
data PassportSpec = PassportSpec { birthYear :: !String
, issueYear :: !String
, expirationYear :: !String
, height :: !String
, hairColor :: !String
, eyeColor :: !String
, passportID :: !String
, countryID :: !(Maybe String)
}
deriving Show
fieldParser :: Parser (Map Field String)
fieldParser = ("byr:" *> A.takeTill isSpace >>= pure . (M.singleton BYR) . T.unpack)
<|> ("iyr:" *> A.takeTill isSpace >>= pure . (M.singleton IYR) . T.unpack)
<|> ("eyr:" *> A.takeTill isSpace >>= pure . (M.singleton EYR) . T.unpack)
<|> ("hgt:" *> A.takeTill isSpace >>= pure . (M.singleton HGT) . T.unpack)
<|> ("hcl:" *> A.takeTill isSpace >>= pure . (M.singleton HCL) . T.unpack)
<|> ("ecl:" *> A.takeTill isSpace >>= pure . (M.singleton ECL) . T.unpack)
<|> ("pid:" *> A.takeTill isSpace >>= pure . (M.singleton PID) . T.unpack)
<|> ("cid:" *> A.takeTill isSpace >>= pure . (M.singleton CID) . T.unpack)
fieldsParser :: Parser (Map Field String)
fieldsParser = mconcat <$> fieldParser `A.sepBy` (A.space)
batchFileParser :: Parser [Map Field String]
batchFileParser = fieldsParser `A.sepBy` (A.string "\n\n")
parseFields :: String -> Either String [Map Field String]
parseFields str = parseOnly batchFileParser (T.pack str)
mkPassport1 :: Map Field String -> Maybe PassportSpec
mkPassport1 m = do
byr <- M.lookup BYR m
iyr <- M.lookup IYR m
eyr <- M.lookup EYR m
hgt <- M.lookup HGT m
hcl <- M.lookup HCL m
ecl <- M.lookup ECL m
pid <- M.lookup PID m
cid <- Just $ M.lookup CID m
pure $ PassportSpec byr iyr eyr hgt hcl ecl pid cid
testData :: [String]
testData = [ "ecl:gry pid:860033327 eyr:2020 hcl:#fffffd"
, "byr:1937 iyr:2017 cid:147 hgt:183cm"
, ""
, "iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884"
, "hcl:#cfa07d byr:1929"
, ""
, "hcl:#ae17e1 iyr:2013"
, "eyr:2024"
, "ecl:brn pid:760753108 byr:1931"
, "hgt:179cm"
, ""
, "hcl:#cfa07d eyr:2025 pid:166559648"
, "iyr:2011 ecl:brn hgt:59in"
]
testData2 :: [String]
testData2 =
[ "eyr:1972 cid:100"
, "hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926"
, ""
, "iyr:2019"
, "hcl:#602927 eyr:1967 hgt:170cm"
, "ecl:grn pid:012533040 byr:1946"
, ""
, "hcl:dab227 iyr:2012"
, "ecl:brn hgt:182cm pid:021572410 eyr:2020 byr:1992 cid:277"
, ""
, "hgt:59cm ecl:zzz"
, "eyr:2038 hcl:74454a iyr:2023"
, "pid:3556412378 byr:2007"
, ""
, "pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980"
, "hcl:#623a2f"
, ""
, "eyr:2029 ecl:blu cid:129 byr:1989"
, "iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm"
, ""
, "hcl:#888785"
, "hgt:164cm byr:2001 iyr:2015 cid:88"
, "pid:545766238 ecl:hzl"
, "eyr:2022"
, ""
, "iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719"
]
solveDay4Part1 :: String -> Either String Int
solveDay4Part1 s =
length . catMaybes . map mkPassport1 <$> parseFields s
eitherToMaybe :: Either a b -> Maybe b
eitherToMaybe (Right x) = Just x
eitherToMaybe (Left _) = Nothing
nothingIfFalse :: Bool -> Maybe Bool
nothingIfFalse False = Nothing
nothingIfFalse True = Just True
mkPassport2 :: Map Field String -> Maybe PassportSpec
mkPassport2 m = do
byr <- M.lookup BYR m
iyr <- M.lookup IYR m
eyr <- M.lookup EYR m
hgt <- M.lookup HGT m
hcl <- M.lookup HCL m
ecl <- M.lookup ECL m
pid <- M.lookup PID m
cid <- Just $ M.lookup CID m
_ <- nothingIfFalse (checkByr byr)
_ <- nothingIfFalse (checkIyr iyr)
_ <- nothingIfFalse (checkEyr eyr)
_ <- (checkHgt hgt)
_ <- (checkHcl hcl)
_ <- (checkEcl ecl)
_ <- (checkPid pid)
pure $ PassportSpec byr iyr eyr hgt hcl ecl pid cid
where
checkByr s = (\n -> n >= 1920 && n <= 2002) $ (read s :: Int)
checkIyr s = (\n -> n >= 2010 && n <= 2020) $ (read s :: Int)
checkEyr s = (\n -> n >= 2020 && n <= 2030) $ (read s :: Int)
checkHcl = eitherToMaybe . parseOnly (
A.char '#' *> (A.hexadecimal :: Parser Int) *> pure True) . T.pack
checkEcl = eitherToMaybe . parseOnly (
( A.string "amb"
<|> A.string "blu"
<|> A.string "brn"
<|> A.string "gry"
<|> A.string "grn"
<|> A.string "hzl"
<|> A.string "oth"
) *> pure True) . T.pack
checkPid = eitherToMaybe . parseOnly (A.count 9 A.digit *> A.endOfInput *> pure True) . T.pack
checkHgt :: String -> Maybe Bool
checkHgt = eitherToMaybe . parseOnly hgtParser . T.pack
hgtParser :: Parser Bool
hgtParser = (decimalIn <* A.string "in") <|> (decimalCm <* A.string "cm")
decimalIn :: Parser Bool
decimalIn = do
d <- A.decimal
unless (d >= (59::Int) && d <= (76::Int)) (fail "")
pure $ True
decimalCm :: Parser Bool
decimalCm = do
d <- A.decimal
unless (d >= (150::Int) && d <= (193::Int)) (fail "")
pure $ True
solveDay4Part2 :: String -> Either String Int
solveDay4Part2 s =
length . catMaybes . map mkPassport2 <$> parseFields s
main :: IO ()
main = do
putStrLn "Day 4 - Part 1"
print $ unlines testData
print $ solveDay4Part1 (unlines testData)
input <- readFile "day4/input"
print $ solveDay4Part1 input
print $ solveDay4Part2 (unlines testData2)
print $ solveDay4Part2 input

965
day5/input Normal file
View File

@ -0,0 +1,965 @@
FBFBBBFRLR
FBBFBBBLLR
FFFFFBBRRL
BBBFFFBRRL
BFFBFBFLRL
FBFFBFFLLR
FBFBBBBRLR
FBFBFBFRLL
BFFBFFBRLR
FBBFFFBLRR
FBFBBBFRRR
BFFBBFBRLR
BFFBFBFRRL
FFFFBBBLRL
FBBFBFFRLL
BBFBBFBRLR
BFFFFBBLLR
FBFFFFFRRR
BFBFFBFLRR
BBFBFFBLLL
BFBFFFFLLR
FBBFBBBRLL
BBBBFFFRRL
FFBBBFFRLR
FFFBFFFRRL
FFFBBBBLRL
BFBBFBFRRL
BFFBBFBLLL
FBFBBFFLRL
BFFBBBBLRL
FFBBBFFLRL
FFBFBFFRRL
BBBFBFBRLR
FBFBBBBRLL
FBBBFBBRRR
FBFBFBFLLL
BBFFFFFLLR
FBFFFBBLRR
FFBFFFBLRR
BBBFBFFRLR
FFFFFFBRRL
BFBBFFFRRR
FBFFBFBRRR
BFFFBBFLRL
BBFBFFFRRR
BBFFFBBLRL
FFBBFFFLLL
FFFFFBBRLR
BFBFFFFRRL
FFBBFBBLRR
BFBBFBBLLR
FFBBBBFRRL
BBBFFFFLRL
BFBFFBFLRL
BFFFFBBLRL
BBBFBBBRLL
BFBBFBBLRR
BFBFFBBRRL
BBFBFFFLLL
FFFFBFFRRL
FFFFBBBRRR
FBBFBBFLRL
FBFFBFBRLR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LL
FBFBFFBRLL
BBBFBBBLLR
FFBFBFFRRR
FBFBBFFRLR
BBBFBFBRLL
BFBBBFFLLR
BBFBFBFRRR
FBFBBFFRRL
FFBBBFFLLL
BBFFFBBRLL
FBBBFBFLRR
FBFFBFBLLL
FFBFBFBLRL
FFFBFBBRRR
FBBBBBFRRR
BFFFBFFLLL
FFBBBBBRRR
FFFFFBFRRL
FBBBFBBRLL
FBBFBBFLLR
FBBFFFFRRR
FFBBBFBRRL
BFFBFFFLRL
BFFFFBFRRR
BFFFFBBLLL
FBBBBBFLRR
BFFBBFFRRR
BFBFBBFLLR
FFBBBFFRRR
FFBBFFBRRL
BFBFFBBLRL
BFFBFFBLRL
FFBBBBFLRL
FFBBFFBRLL
FBFFBFFLRL
FFBBBFBLLL
BBFBBFFRLR
BBBFBBBLRR
FFFBBBBRRR
BFFFFBBLRR
FFBFFFFLRL
BFBBBBBLRL
BBBFBBFRLL
FBFFFFFRLR
BBFFFFFRLL
FBFBFFFLRL
FFFBFBBRLR
FBBFBBFRRR
FBFBBFBRRR
BBFFFBFRRR
FFFFBBFRRR
FFFFBFBLLR
BFBBFBFLLR
BBFFBBBRRL
FFBBFBFRLL
FBFBFFFLLR
BFFBBBFRLL
FBBBBBBRRR
FBFFBBBRRL
FFBFBBFLRR
BFFFBFFRLR
BFBBBBFLLL
FFBBFFFRLR
FFBFBFFLRL

47
day5/main.hs Executable file
View File

@ -0,0 +1,47 @@
#! /usr/bin/env -S"ANSWER=42" nix-shell
#! nix-shell -p ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [])"
#! nix-shell -i "ghcid -c 'ghci -Wall' -T main"
{-# LANGUAGE OverloadedStrings #-}
-- import Debug.Trace (trace)
import Data.List (sort)
binaryPartitionWalker :: String -> Int -> Int -> (String, Int, Int)
binaryPartitionWalker ('F':s) begin end =
binaryPartitionWalker s begin (((end - begin) `div` 2) + begin)
binaryPartitionWalker ('B':s) begin end =
binaryPartitionWalker s (((end - begin) `div` 2) + begin + 1) end
binaryPartitionWalker ('L':s) begin end =
binaryPartitionWalker ('F':s) begin end
binaryPartitionWalker ('R':s) begin end =
binaryPartitionWalker ('B':s) begin end
binaryPartitionWalker "" b e = ("",b,e)
binaryPartitionWalker _ _ _ = undefined
seatID :: String -> Int
seatID str = row * 8 + seat
where
(rowStr, seatStr) = splitAt 7 str
(_,row,_) = binaryPartitionWalker rowStr 0 127
(_,seat,_) = binaryPartitionWalker seatStr 0 7
solvePart1 :: [String] -> Int
solvePart1 = maximum . (map seatID)
solvePart2 :: [String] -> Int
solvePart2 = fst . head . (filter (\(x,y) -> x /= y)) . (zip [13..]) . sort . (map seatID)
main :: IO ()
main = do
putStrLn "Day 5 - Part 1"
print $ seatID "FBFBBFFRLR"
print $ seatID "BFFFBBFRRR"
print $ seatID "FFFBBBFRRR"
print $ seatID "BBFFBBFRLL"
input <- lines <$> readFile "day5/input"
putStrLn $ "Solution of part 1"
print $ solvePart1 input
putStrLn $ "Solution of part 2"
print $ solvePart2 input

2178
day6/input Normal file

File diff suppressed because it is too large Load Diff

72
day6/main.hs Executable file
View File

@ -0,0 +1,72 @@
#! /usr/bin/env -S"ANSWER=42" nix-shell
#! nix-shell -p ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [shower])"
#! nix-shell -i "ghcid -c 'ghci -Wall' -T main"
{-# LANGUAGE OverloadedStrings #-}
-- import Debug.Trace (trace)
import Data.List (nub)
exampleData :: [String]
exampleData =
[ "abc"
, ""
, "a"
, "b"
, "c"
, ""
, "ab"
, "ac"
, ""
, "a"
, "a"
, "a"
, "a"
, ""
, "b"
]
-- Count how many different chars per paragraph and sum them
countUniqueAnswers :: [String] -> Int
countUniqueAnswers = length . nub . concat
paragraphs :: [String] -> [[String]]
paragraphs strs = go (strs, [])
where
go :: ([String], [[String]]) -> [[String]]
go ([], ys) = ys
go (x:xs, []) = go (xs, [x] : [])
go ("":xs, ys) = go (xs, [] : ys)
go (x:xs, y:ys) = go (xs, (x:y) : ys)
solvePart1 :: [String] -> Int
solvePart1 = sum . (map countUniqueAnswers) . paragraphs
allAnsweredX :: Char -> [[String]] -> [Bool]
allAnsweredX c = map (all (any (== c)))
solvePart2 :: [String] -> Int
solvePart2 strs = length . (filter (== True)) $ concat $ map (\x -> (allAnsweredX x . paragraphs) strs) ['a'..'z']
main :: IO ()
main = do
putStrLn "Day 6 - Part 1"
print $ exampleData
print $ countUniqueAnswers [""]
print $ countUniqueAnswers ["abc"]
print $ countUniqueAnswers ["a", "b", "c"]
print $ countUniqueAnswers ["ab", "ac"]
putStrLn "Day 6 - Part 1 : solving test"
print $ solvePart1 exampleData
putStrLn "Day 6 - Part 1 : solving input"
input <- lines <$> readFile "day6/input"
print $ solvePart1 input
putStrLn "Day 6 - Part 2 : solving test"
print $ paragraphs exampleData
print $ solvePart2 exampleData
putStrLn "Day 6 - Part 2 : solving input"
print $ solvePart2 input

594
day7/input Normal file
View File

@ -0,0 +1,594 @@
vibrant aqua bags contain 1 shiny magenta bag, 2 muted teal bags, 1 dim magenta bag, 1 muted chartreuse bag.
vibrant violet bags contain 4 pale maroon bags.
dark indigo bags contain 1 light maroon bag, 3 pale red bags, 1 drab brown bag, 4 dim magenta bags.
dark coral bags contain 5 dull aqua bags, 5 plaid green bags, 2 posh bronze bags.
dim lavender bags contain 2 muted violet bags, 5 wavy gold bags, 3 vibrant plum bags, 5 bright teal bags.
mirrored turquoise bags contain 5 muted olive bags, 5 bright gold bags, 2 vibrant violet bags.
faded brown bags contain 5 faded tomato bags.
muted orange bags contain 5 dull aqua bags, 2 light salmon bags, 1 striped black bag, 1 pale gray bag.
posh black bags contain 4 faded silver bags.
muted coral bags contain 3 mirrored turquoise bags.
clear silver bags contain 5 dark cyan bags.
clear crimson bags contain 2 dim blue bags, 4 bright indigo bags.
clear salmon bags contain 4 striped cyan bags, 1 muted maroon bag, 1 light bronze bag, 1 vibrant tan bag.
light olive bags contain 1 faded white bag, 2 dull chartreuse bags, 5 faded gray bags.
muted maroon bags contain 5 dark fuchsia bags, 5 drab violet bags.
posh plum bags contain 2 striped gray bags, 5 dim violet bags.
light orange bags contain 1 light purple bag.
drab white bags contain 4 plaid lime bags, 1 drab gold bag.
plaid indigo bags contain 5 clear lime bags, 1 dark fuchsia bag.
muted red bags contain 1 dull bronze bag.
mirrored magenta bags contain 5 plaid white bags, 1 faded plum bag, 5 wavy purple bags.
dotted lavender bags contain 5 shiny olive bags, 3 plaid blue bags, 1 shiny gold bag.
drab bronze bags contain 3 wavy silver bags, 4 light turquoise bags, 1 vibrant lavender bag, 5 light magenta bags.
plaid maroon bags contain 2 dim salmon bags, 5 muted violet bags.
dull salmon bags contain 5 striped beige bags, 2 muted plum bags, 1 posh teal bag.
dotted turquoise bags contain 5 striped orange bags.
bright yellow bags contain 2 shiny olive bags, 3 wavy teal bags, 1 pale plum bag, 3 mirrored coral bags.
dark black bags contain 5 pale gray bags.
shiny yellow bags contain 4 dark aqua bags, 2 drab lime bags, 2 bright gold bags, 4 dark cyan bags.
shiny red bags contain 2 posh blue bags.
posh olive bags contain 3 dim aqua bags.
muted chartreuse bags contain 4 posh brown bags, 5 shiny magenta bags.
mirrored orange bags contain 5 dotted salmon bags, 1 posh green bag.
muted plum bags contain 1 dull red bag, 4 posh green bags.
light green bags contain 2 wavy plum bags.
light cyan bags contain 2 dotted crimson bags, 4 faded salmon bags, 3 muted coral bags, 3 plaid blue bags.
dull lavender bags contain 3 drab gold bags, 5 plaid crimson bags.
posh red bags contain 3 dotted salmon bags, 2 pale beige bags, 2 mirrored coral bags, 5 muted teal bags.
vibrant beige bags contain 2 faded lime bags.
plaid blue bags contain 5 dull red bags, 3 light maroon bags, 4 muted gold bags, 2 drab orange bags.
dotted white bags contain 3 muted white bags.
drab fuchsia bags contain 2 shiny fuchsia bags.
drab crimson bags contain 1 posh beige bag, 4 drab violet bags.
drab beige bags contain 3 mirrored orange bags, 1 wavy silver bag, 2 pale magenta bags, 1 drab lime bag.
posh teal bags contain 2 clear brown bags.
mirrored brown bags contain 2 faded tan bags.
clear coral bags contain 1 muted chartreuse bag, 2 muted violet bags, 2 faded purple bags.
pale lime bags contain 5 vibrant aqua bags, 3 wavy purple bags, 1 drab violet bag.
vibrant red bags contain 5 shiny gold bags.
shiny fuchsia bags contain 1 dark salmon bag, 1 posh white bag.
bright gray bags contain 2 dim red bags.
drab lavender bags contain 2 clear tomato bags, 1 faded red bag, 1 pale chartreuse bag.
clear red bags contain 3 light salmon bags, 1 bright red bag, 5 dark indigo bags.
bright aqua bags contain 3 faded brown bags, 1 shiny yellow bag.
faded red bags contain 3 posh turquoise bags, 5 dark fuchsia bags.
faded turquoise bags contain 3 drab fuchsia bags.
dim aqua bags contain 1 faded white bag, 5 faded violet bags.
muted white bags contain 5 pale red bags, 4 dull red bags, 3 dotted maroon bags.
dull gold bags contain 3 posh green bags, 2 mirrored yellow bags, 2 dull olive bags, 2 bright purple bags.
faded blue bags contain 3 wavy crimson bags, 1 plaid beige bag, 3 dotted orange bags, 1 vibrant purple bag.
faded gray bags contain 1 bright gold bag.
dim bronze bags contain 2 bright gold bags, 4 light brown bags, 5 muted chartreuse bags.
light teal bags contain 5 striped tomato bags, 5 drab teal bags, 5 shiny lavender bags.
striped white bags contain 1 plaid silver bag, 2 wavy plum bags, 3 dull maroon bags, 2 muted green bags.
vibrant salmon bags contain 2 shiny violet bags, 4 light salmon bags.
dim plum bags contain 1 dull blue bag, 5 vibrant bronze bags.
dotted fuchsia bags contain 4 plaid green bags.
plaid crimson bags contain 3 clear teal bags, 5 dark gray bags, 2 mirrored tan bags, 5 shiny fuchsia bags.
pale white bags contain 2 muted silver bags, 1 muted lime bag.
bright violet bags contain 2 clear chartreuse bags, 2 dull gray bags, 2 muted cyan bags.
drab red bags contain 1 dotted white bag, 1 light plum bag, 5 muted indigo bags, 1 dull lime bag.
muted indigo bags contain 3 mirrored blue bags, 5 light fuchsia bags.
vibrant cyan bags contain 2 pale blue bags, 3 mirrored chartreuse bags.
mirrored gray bags contain 1 shiny red bag, 2 pale blue bags, 4 dotted lime bags, 1 faded violet bag.
posh lavender bags contain 3 vibrant aqua bags, 5 mirrored chartreuse bags.
dotted silver bags contain 3 dark beige bags, 5 dotted teal bags, 3 mirrored indigo bags, 2 dim yellow bags.
wavy magenta bags contain 4 wavy beige bags.
faded tomato bags contain 3 plaid black bags, 5 bright orange bags, 2 vibrant blue bags.
mirrored maroon bags contain 3 plaid gray bags.
pale bronze bags contain 4 vibrant violet bags, 2 muted white bags.
plaid turquoise bags contain 2 dotted lime bags, 3 striped beige bags, 1 pale crimson bag, 2 pale purple bags.
posh turquoise bags contain 5 clear yellow bags, 1 dotted turquoise bag, 3 dim cyan bags, 5 pale maroon bags.
wavy white bags contain 2 mirrored gray bags, 3 pale yellow bags.
vibrant tan bags contain 1 wavy lavender bag.
pale turquoise bags contain 2 dark gray bags, 4 faded green bags, 1 light maroon bag, 5 posh white bags.
faded beige bags contain 1 striped brown bag, 1 dull gray bag, 5 mirrored blue bags.
bright maroon bags contain 1 light blue bag, 5 dim bronze bags, 4 dotted beige bags.
shiny lavender bags contain 3 dim gray bags, 4 pale gray bags.
dull beige bags contain 3 dark crimson bags.
striped coral bags contain 3 dark lavender bags, 2 mirrored turquoise bags, 5 posh maroon bags, 1 striped yellow bag.
shiny magenta bags contain 1 plaid black bag.
muted magenta bags contain 2 plaid beige bags.
light salmon bags contain 5 striped black bags, 1 pale lavender bag.
shiny white bags contain 2 bright gold bags, 3 mirrored olive bags.
dark tomato bags contain 2 dark gold bags, 2 clear teal bags, 5 dull fuchsia bags, 4 dotted gold bags.
dotted violet bags contain 3 plaid teal bags, 5 mirrored aqua bags.
plaid purple bags contain 4 mirrored olive bags.
drab lime bags contain 5 bright beige bags, 4 mirrored tan bags, 5 striped black bags, 4 faded green bags.
dull blue bags contain 4 light red bags, 2 pale turquoise bags, 1 posh maroon bag.
muted tan bags contain 1 pale magenta bag, 3 mirrored turquoise bags, 3 shiny blue bags, 4 dotted salmon bags.
dim teal bags contain 1 posh turquoise bag, 3 dull red bags.
muted fuchsia bags contain 4 pale salmon bags, 1 pale silver bag, 3 pale maroon bags, 2 bright purple bags.
bright gold bags contain 2 shiny magenta bags, 4 pale red bags, 4 posh brown bags.
faded lime bags contain 5 vibrant bronze bags, 2 pale violet bags, 2 plaid coral bags.
posh tan bags contain 3 bright lavender bags, 2 striped blue bags, 5 shiny gold bags.
posh bronze bags contain 3 plaid olive bags, 3 dotted salmon bags.
shiny lime bags contain 1 bright salmon bag, 3 faded green bags, 2 wavy aqua bags.
faded lavender bags contain 2 bright silver bags.
muted black bags contain 5 mirrored coral bags.
plaid chartreuse bags contain 3 dull coral bags, 2 light tomato bags.
mirrored aqua bags contain 2 dark cyan bags, 2 dark indigo bags.
dark yellow bags contain 5 dotted lime bags, 1 dim cyan bag.
bright plum bags contain 5 dim salmon bags.
striped gray bags contain 3 plaid black bags, 1 wavy crimson bag, 5 bright orange bags.
faded salmon bags contain 3 clear lime bags, 4 drab purple bags.
pale olive bags contain 2 light magenta bags, 4 dim salmon bags, 5 light olive bags, 2 pale salmon bags.
faded crimson bags contain 2 wavy beige bags, 4 dim aqua bags, 5 light lavender bags.
posh chartreuse bags contain 5 pale lavender bags, 5 mirrored turquoise bags, 2 dark maroon bags.
posh aqua bags contain 5 faded crimson bags, 2 mirrored tan bags.
faded coral bags contain 2 dotted lime bags, 2 faded white bags.
striped bronze bags contain 4 plaid blue bags, 1 plaid coral bag.
wavy orange bags contain 5 pale tomato bags.
dim crimson bags contain 4 posh tan bags, 1 muted gold bag.
clear gray bags contain 3 striped lime bags, 4 vibrant fuchsia bags.
light gold bags contain 4 bright tan bags, 5 faded lime bags, 4 faded plum bags, 5 clear brown bags.
wavy red bags contain 4 pale red bags, 4 dotted maroon bags, 4 mirrored violet bags.
dull silver bags contain 1 striped turquoise bag, 2 striped orange bags, 1 dotted plum bag, 3 muted coral bags.
striped magenta bags contain 1 mirrored tan bag.
plaid plum bags contain 4 wavy tan bags, 5 wavy brown bags, 5 shiny olive bags, 5 clear yellow bags.
faded chartreuse bags contain 1 shiny teal bag.
clear chartreuse bags contain 2 drab tan bags, 3 plaid maroon bags, 2 drab orange bags, 2 plaid salmon bags.
wavy olive bags contain 5 dark lavender bags.
dull orange bags contain 1 dull gray bag, 2 light magenta bags.
wavy gold bags contain 5 vibrant yellow bags, 4 pale black bags, 2 light olive bags.
muted salmon bags contain 5 dotted turquoise bags, 5 dotted violet bags.
wavy tan bags contain 2 plaid green bags.
dotted cyan bags contain 4 drab gold bags, 1 dark crimson bag, 3 pale lavender bags.
wavy coral bags contain 3 mirrored blue bags, 5 wavy white bags, 1 striped indigo bag.
clear olive bags contain 4 wavy silver bags, 2 pale orange bags, 2 bright tan bags.
light indigo bags contain 1 pale purple bag, 4 clear teal bags, 1 plaid indigo bag, 4 dim blue bags.
dotted tomato bags contain 4 dim cyan bags.
pale indigo bags contain 2 muted chartreuse bags, 4 faded salmon bags, 3 dull brown bags.
bright magenta bags contain 1 vibrant salmon bag, 1 pale teal bag, 4 faded orange bags.
faded gold bags contain 4 striped cyan bags.
shiny orange bags contain 5 vibrant turquoise bags, 3 pale purple bags.
posh salmon bags contain 1 dotted crimson bag, 3 dark maroon bags.
dull violet bags contain 2 clear indigo bags.
posh gray bags contain 1 shiny fuchsia bag, 1 faded plum bag, 5 pale turquoise bags.
dull chartreuse bags contain 4 dull red bags, 1 striped black bag, 3 dark tan bags, 3 muted maroon bags.
dotted chartreuse bags contain 5 striped aqua bags.
dim magenta bags contain no other bags.
light lime bags contain 2 shiny magenta bags, 3 striped black bags.
drab maroon bags contain 2 vibrant bronze bags, 1 clear white bag, 2 dim gray bags.
drab salmon bags contain 2 wavy crimson bags, 3 dim gold bags, 5 drab chartreuse bags.
dotted crimson bags contain 4 pale purple bags, 3 plaid coral bags.
dull red bags contain 3 dark indigo bags, 2 posh white bags, 4 light maroon bags.
drab turquoise bags contain 2 striped tomato bags, 1 bright gold bag, 5 mirrored tan bags, 1 drab chartreuse bag.
shiny teal bags contain 4 bright lime bags, 2 pale red bags.
dark purple bags contain 5 mirrored beige bags, 1 posh purple bag, 5 dotted beige bags.
drab aqua bags contain 4 plaid blue bags, 3 dark salmon bags, 4 striped lime bags, 4 striped blue bags.
dull magenta bags contain 2 clear white bags, 5 muted bronze bags.
pale tan bags contain 1 pale lime bag.
dark fuchsia bags contain 3 dim coral bags, 1 muted white bag, 2 plaid blue bags.
mirrored beige bags contain 5 dotted magenta bags, 1 wavy olive bag, 1 dark tan bag.
drab tomato bags contain 4 dim cyan bags.
shiny tomato bags contain 2 shiny maroon bags, 2 dark lavender bags, 1 posh red bag, 3 vibrant green bags.
dim turquoise bags contain 4 muted salmon bags, 2 bright purple bags, 4 plaid maroon bags, 3 bright beige bags.
mirrored salmon bags contain 2 drab violet bags, 3 faded red bags.
pale crimson bags contain 3 bright white bags, 5 plaid beige bags.
shiny cyan bags contain 4 light blue bags.
clear lavender bags contain 5 bright turquoise bags.
vibrant purple bags contain 5 pale turquoise bags, 2 posh orange bags.
striped purple bags contain 5 muted orange bags, 5 dark aqua bags.
pale gray bags contain 5 dark indigo bags, 1 vibrant violet bag, 3 pale maroon bags, 4 bright gold bags.
posh brown bags contain 3 drab brown bags, 4 pale red bags, 2 posh white bags, 4 muted gold bags.
muted bronze bags contain 2 clear magenta bags, 5 shiny green bags, 2 mirrored tan bags, 4 posh gray bags.
pale brown bags contain 5 muted white bags, 3 plaid beige bags, 3 wavy lavender bags, 3 clear indigo bags.
dull yellow bags contain 5 clear lime bags, 4 plaid blue bags, 4 dotted lime bags.
light tan bags contain 5 dull blue bags, 2 drab yellow bags, 5 mirrored red bags.
posh gold bags contain 4 dull chartreuse bags, 2 dim magenta bags.
pale silver bags contain 4 dull aqua bags, 4 bright gold bags.
light beige bags contain 3 posh orange bags, 3 mirrored gray bags, 2 bright red bags.
striped turquoise bags contain 2 posh blue bags, 1 striped orange bag, 2 shiny tan bags, 5 vibrant aqua bags.
vibrant plum bags contain 4 pale gray bags.
dotted teal bags contain 2 dim magenta bags.
dull purple bags contain 5 drab brown bags, 4 dotted maroon bags, 1 muted white bag.
mirrored fuchsia bags contain 2 dark tomato bags, 4 faded tan bags, 2 faded white bags, 4 dotted orange bags.
dotted plum bags contain 2 dull aqua bags, 4 faded green bags.
bright fuchsia bags contain 2 wavy blue bags, 5 clear brown bags.
dim beige bags contain 2 pale orange bags.
dotted orange bags contain 2 faded brown bags, 1 clear tomato bag, 1 clear indigo bag.
plaid gold bags contain 1 striped turquoise bag, 3 vibrant magenta bags, 5 shiny gray bags, 5 shiny red bags.
clear plum bags contain 3 dim turquoise bags, 3 faded magenta bags, 2 dull coral bags.
muted green bags contain 3 dim crimson bags.
bright black bags contain 3 pale purple bags, 3 plaid white bags, 1 clear teal bag, 3 pale magenta bags.
dim gray bags contain 3 dull coral bags, 1 pale turquoise bag, 5 wavy cyan bags, 5 striped lime bags.
dotted beige bags contain 5 dull aqua bags, 3 dark fuchsia bags, 1 pale violet bag, 4 dim gold bags.
mirrored lime bags contain 4 plaid tomato bags, 1 pale lavender bag, 5 shiny blue bags, 1 light gray bag.
bright chartreuse bags contain 1 dotted teal bag, 3 shiny lavender bags.
vibrant tomato bags contain 1 vibrant coral bag.
mirrored purple bags contain 4 dark tan bags, 4 faded coral bags.
pale tomato bags contain 1 dull maroon bag, 2 striped tan bags, 5 muted cyan bags, 2 dark maroon bags.
vibrant brown bags contain 1 vibrant bronze bag, 2 pale yellow bags, 4 wavy coral bags.
dim green bags contain 2 striped coral bags.
muted lavender bags contain 3 clear purple bags, 4 dark red bags, 1 light silver bag, 1 dull blue bag.
wavy crimson bags contain 5 muted teal bags, 1 drab brown bag, 3 posh brown bags.
wavy tomato bags contain 4 striped blue bags, 3 mirrored lime bags, 1 shiny gray bag, 1 dark plum bag.
muted aqua bags contain 3 clear silver bags, 3 bright chartreuse bags, 4 striped teal bags, 2 clear indigo bags.
posh blue bags contain 2 posh teal bags, 4 dark maroon bags, 2 drab brown bags, 5 faded coral bags.
vibrant silver bags contain 5 drab yellow bags, 3 faded silver bags, 2 bright silver bags.
dim chartreuse bags contain 4 pale beige bags.
shiny gray bags contain 3 dotted magenta bags, 4 plaid crimson bags.
dim salmon bags contain 4 clear lime bags, 3 muted tomato bags, 2 shiny olive bags.
clear orange bags contain 4 posh beige bags, 5 dotted gray bags, 5 dotted turquoise bags.
plaid salmon bags contain 4 bright indigo bags.
posh beige bags contain 3 pale red bags.
clear lime bags contain 1 bright gold bag.
faded magenta bags contain 5 dim salmon bags, 3 dull aqua bags, 5 drab crimson bags.
drab blue bags contain 5 dark maroon bags, 4 wavy plum bags.
plaid aqua bags contain 5 mirrored orange bags, 3 dull violet bags, 3 bright salmon bags.
muted teal bags contain 4 dull red bags, 1 light maroon bag, 4 dark cyan bags.
posh green bags contain 1 mirrored chartreuse bag, 4 muted chartreuse bags, 5 plaid olive bags, 4 dark salmon bags.
posh fuchsia bags contain 3 bright cyan bags, 1 bright salmon bag, 4 dim salmon bags, 1 light black bag.
muted yellow bags contain 2 muted teal bags, 5 pale orange bags.
clear cyan bags contain 3 clear teal bags, 5 drab aqua bags, 2 drab brown bags.
wavy salmon bags contain 5 dark fuchsia bags, 2 dull gray bags, 4 pale tan bags.
dull crimson bags contain 5 faded indigo bags, 2 plaid black bags.
mirrored white bags contain 2 dotted plum bags, 2 dark coral bags, 3 faded gray bags.
striped violet bags contain 4 mirrored tan bags.
striped tan bags contain 2 posh coral bags.
striped tomato bags contain 1 muted teal bag, 1 faded tan bag.
faded aqua bags contain 5 faded red bags, 2 mirrored coral bags, 5 light red bags, 2 mirrored purple bags.
drab olive bags contain 2 drab gold bags.
bright lavender bags contain 1 dark salmon bag, 1 striped olive bag.
plaid green bags contain 2 bright gold bags.
dim purple bags contain 1 plaid yellow bag, 3 muted plum bags, 2 vibrant magenta bags.
faded violet bags contain 3 mirrored violet bags.
posh tomato bags contain 1 dark indigo bag, 2 pale yellow bags, 5 dull orange bags.
dim silver bags contain 1 dotted white bag, 5 faded white bags.
dotted red bags contain 2 dull yellow bags, 4 dim lavender bags, 1 light gold bag.
bright indigo bags contain 5 pale gray bags, 3 posh white bags.
faded fuchsia bags contain 4 muted green bags, 3 posh magenta bags.
wavy silver bags contain 1 dotted violet bag, 3 drab tomato bags, 4 dark fuchsia bags.
dim white bags contain 2 bright magenta bags.
pale beige bags contain 5 dim orange bags, 5 vibrant red bags.
vibrant orange bags contain 4 dull violet bags, 2 mirrored salmon bags, 1 drab lavender bag.
clear fuchsia bags contain 1 mirrored olive bag, 4 mirrored chartreuse bags, 1 posh beige bag.
vibrant indigo bags contain 5 dim lavender bags, 4 drab blue bags, 1 muted beige bag.
dim brown bags contain 2 posh brown bags.
plaid beige bags contain 1 dark tan bag, 5 clear teal bags, 2 light gray bags, 4 wavy lime bags.
bright crimson bags contain 4 drab chartreuse bags, 4 vibrant blue bags, 5 mirrored lime bags, 2 muted plum bags.
shiny purple bags contain 1 muted crimson bag.
wavy bronze bags contain 1 dim brown bag, 3 light salmon bags, 1 muted teal bag, 3 plaid olive bags.
faded bronze bags contain 2 striped blue bags, 2 posh white bags, 2 posh orange bags.
dark orange bags contain 2 vibrant aqua bags, 5 dark maroon bags, 1 mirrored aqua bag.
drab green bags contain 2 faded aqua bags, 5 posh crimson bags.
clear white bags contain 3 plaid black bags, 2 posh white bags, 5 posh lavender bags, 1 dull purple bag.
wavy black bags contain 4 bright magenta bags.
posh crimson bags contain 3 dark yellow bags, 1 mirrored purple bag, 2 dark maroon bags, 5 shiny olive bags.
dotted gray bags contain 4 posh maroon bags, 2 mirrored chartreuse bags, 5 wavy fuchsia bags.
vibrant lavender bags contain 2 plaid coral bags, 4 posh brown bags, 4 dim tan bags.
drab violet bags contain 4 muted gold bags.
striped maroon bags contain 4 dotted lavender bags, 2 dark fuchsia bags, 3 bright olive bags.
plaid white bags contain 2 wavy olive bags, 2 pale blue bags, 4 pale aqua bags.
pale gold bags contain 4 bright teal bags, 2 posh bronze bags, 3 shiny maroon bags, 1 pale brown bag.
vibrant olive bags contain 3 plaid green bags, 2 light maroon bags, 3 dotted salmon bags, 4 faded tomato bags.
dotted maroon bags contain no other bags.
light blue bags contain 2 dim violet bags, 1 vibrant beige bag.
mirrored tan bags contain 4 drab brown bags, 1 striped orange bag, 5 light maroon bags, 2 dotted maroon bags.
dark beige bags contain 1 drab maroon bag.
light silver bags contain 1 shiny chartreuse bag, 2 dim turquoise bags.
dull green bags contain 2 striped chartreuse bags, 2 mirrored gold bags, 4 dim fuchsia bags.
faded silver bags contain 3 drab violet bags.
bright beige bags contain 5 bright teal bags, 5 mirrored violet bags.
striped gold bags contain 2 wavy beige bags, 4 dim black bags.
wavy fuchsia bags contain 4 posh green bags.
shiny blue bags contain 3 posh maroon bags.
mirrored indigo bags contain 3 striped cyan bags, 2 vibrant blue bags, 5 wavy violet bags.
dim tomato bags contain 4 dull orange bags, 5 shiny green bags, 1 plaid olive bag.
plaid violet bags contain 1 dull violet bag, 4 plaid fuchsia bags.
dark white bags contain 3 drab orange bags.
drab indigo bags contain 3 dark red bags, 2 plaid tomato bags, 5 clear white bags.
shiny beige bags contain 2 posh tomato bags.
striped indigo bags contain 5 clear lavender bags, 5 dotted indigo bags, 1 muted cyan bag, 5 dark olive bags.
drab cyan bags contain 1 drab orange bag, 4 posh gold bags.
light red bags contain 4 dark indigo bags, 1 vibrant violet bag, 4 shiny magenta bags.
muted gold bags contain 3 light maroon bags, 1 striped orange bag, 4 pale maroon bags.
clear indigo bags contain 4 faded green bags, 3 clear crimson bags, 2 vibrant cyan bags.
faded tan bags contain 5 bright gold bags.
shiny salmon bags contain 1 bright lavender bag, 1 posh blue bag, 4 shiny coral bags.
dull turquoise bags contain 5 drab yellow bags, 5 dotted plum bags, 5 plaid magenta bags.
posh lime bags contain 4 wavy tan bags, 4 shiny tomato bags, 4 dim violet bags, 5 bright tan bags.
pale green bags contain 1 wavy gray bag, 2 faded lavender bags, 1 vibrant yellow bag.
mirrored gold bags contain 2 light gray bags, 5 wavy tan bags.
mirrored green bags contain 1 faded violet bag.
dark red bags contain 3 faded bronze bags, 4 dark green bags, 4 wavy crimson bags.
bright tomato bags contain 4 faded bronze bags.
mirrored crimson bags contain 5 faded red bags, 1 drab crimson bag.
faded orange bags contain 2 muted teal bags, 5 pale maroon bags, 1 dark yellow bag.
striped silver bags contain 4 mirrored lime bags, 1 dull tan bag, 1 pale fuchsia bag, 1 wavy purple bag.
wavy aqua bags contain 4 vibrant aqua bags, 4 shiny fuchsia bags, 4 dotted turquoise bags, 4 striped olive bags.
striped lavender bags contain 5 shiny lavender bags, 3 pale lime bags.
vibrant white bags contain 2 dim bronze bags, 2 light red bags, 5 shiny gold bags.
vibrant yellow bags contain 1 shiny turquoise bag, 5 dull beige bags, 4 dark gold bags, 5 dull tomato bags.
striped green bags contain 5 striped tomato bags.
muted silver bags contain 5 striped maroon bags, 5 light salmon bags, 4 clear maroon bags.
light plum bags contain 5 mirrored blue bags, 2 vibrant coral bags, 5 dim brown bags, 2 striped yellow bags.
posh yellow bags contain 1 mirrored salmon bag, 5 light plum bags.
plaid magenta bags contain 3 dull plum bags, 2 mirrored tan bags.
plaid tan bags contain 4 light turquoise bags, 4 faded purple bags, 3 mirrored crimson bags.
shiny black bags contain 3 striped violet bags, 1 dim cyan bag, 2 dim white bags.
wavy brown bags contain 2 plaid lavender bags.
vibrant gold bags contain 1 clear tomato bag, 1 wavy olive bag, 2 faded magenta bags.
clear brown bags contain 2 dim blue bags.
dim fuchsia bags contain 2 bright gold bags, 5 wavy purple bags, 3 posh orange bags.
muted turquoise bags contain 1 light turquoise bag, 3 vibrant plum bags, 5 posh maroon bags, 1 muted maroon bag.
shiny coral bags contain 3 striped yellow bags.
dotted coral bags contain 1 dark orange bag, 4 striped violet bags.
shiny bronze bags contain 5 mirrored yellow bags, 4 light violet bags, 4 light crimson bags.
dull cyan bags contain 2 dim cyan bags, 5 pale red bags.
bright tan bags contain 4 pale gray bags, 4 posh brown bags, 3 shiny fuchsia bags.
pale purple bags contain 5 wavy cyan bags, 5 dark salmon bags, 2 dark indigo bags, 1 plaid black bag.
shiny gold bags contain 2 pale maroon bags, 5 pale purple bags, 4 posh brown bags, 1 dotted turquoise bag.
dim tan bags contain 4 dark violet bags, 3 shiny blue bags.
wavy green bags contain 3 plaid gray bags.
pale orange bags contain 3 dim lime bags, 2 dark coral bags.
faded maroon bags contain 5 clear black bags, 3 light lavender bags, 3 light black bags, 2 muted orange bags.
drab teal bags contain 2 dotted crimson bags, 3 dim teal bags, 5 pale turquoise bags, 4 dark plum bags.
bright orange bags contain 3 pale maroon bags, 1 pale bronze bag, 3 dotted maroon bags.
posh coral bags contain 3 dim gold bags, 1 bright indigo bag, 3 clear black bags.
mirrored bronze bags contain 5 dull violet bags, 3 vibrant red bags.
pale lavender bags contain 2 pale purple bags, 1 pale red bag, 4 vibrant blue bags, 3 muted chartreuse bags.
wavy lavender bags contain 3 drab chartreuse bags, 1 posh teal bag.
pale blue bags contain 1 dark tan bag, 4 faded violet bags, 3 dim coral bags.
striped yellow bags contain 2 pale red bags.
shiny aqua bags contain 3 pale magenta bags.
faded olive bags contain 1 vibrant white bag, 4 muted cyan bags.
dark chartreuse bags contain 3 dim magenta bags, 3 dull plum bags, 2 pale lime bags.
dim lime bags contain 3 muted white bags, 4 striped blue bags.
wavy cyan bags contain 4 light maroon bags.
light bronze bags contain 1 dull lime bag.
muted beige bags contain 4 wavy blue bags, 2 dotted violet bags, 4 shiny orange bags.
dim coral bags contain 4 wavy crimson bags, 3 mirrored tan bags, 2 wavy cyan bags, 5 light maroon bags.
dark green bags contain 2 striped gray bags, 3 pale lavender bags, 1 striped lime bag.
pale cyan bags contain 2 vibrant green bags, 1 mirrored lime bag, 5 vibrant chartreuse bags, 1 shiny lime bag.
shiny crimson bags contain 4 dull aqua bags, 1 pale turquoise bag.
pale black bags contain 3 vibrant olive bags, 2 dull aqua bags, 1 drab turquoise bag.
striped crimson bags contain 4 dotted lavender bags, 2 clear orange bags.
clear maroon bags contain 2 muted bronze bags, 3 vibrant olive bags, 1 striped lavender bag.
dim olive bags contain 1 wavy lavender bag, 1 dotted salmon bag, 1 pale silver bag, 5 vibrant coral bags.
dotted indigo bags contain 3 dark salmon bags, 2 shiny turquoise bags, 4 plaid coral bags.
plaid orange bags contain 2 mirrored plum bags, 5 faded lime bags, 4 dotted brown bags, 2 pale tan bags.
light maroon bags contain no other bags.
light violet bags contain 5 clear yellow bags, 4 muted chartreuse bags.
light lavender bags contain 3 striped olive bags, 1 posh black bag.
muted lime bags contain 2 muted turquoise bags, 3 mirrored yellow bags, 5 clear gray bags.
faded black bags contain 1 bright crimson bag, 1 dotted beige bag, 2 shiny magenta bags.
wavy blue bags contain 5 vibrant plum bags, 5 shiny fuchsia bags, 2 posh orange bags, 1 wavy purple bag.
dark turquoise bags contain 5 shiny tan bags, 2 dull silver bags, 2 muted lime bags, 2 mirrored tan bags.
mirrored teal bags contain 4 pale brown bags, 5 drab lime bags, 5 striped beige bags.
vibrant gray bags contain 5 bright yellow bags, 1 vibrant teal bag.
clear purple bags contain 5 bright silver bags, 1 bright teal bag, 1 wavy lime bag, 4 striped blue bags.
striped lime bags contain 1 mirrored violet bag, 3 dim cyan bags, 3 vibrant turquoise bags, 2 muted white bags.
mirrored lavender bags contain 2 faded yellow bags.
posh maroon bags contain 1 dotted salmon bag, 5 drab violet bags, 5 striped lime bags, 3 dotted olive bags.
faded yellow bags contain 1 dull plum bag, 5 dim fuchsia bags.
dull aqua bags contain 2 pale maroon bags.
dark tan bags contain 4 dark salmon bags.
dim maroon bags contain 4 posh aqua bags, 3 striped yellow bags.
faded purple bags contain 5 clear teal bags, 2 dark olive bags.
clear tomato bags contain 2 pale maroon bags.
dull gray bags contain 5 light brown bags, 3 bright gold bags, 4 faded white bags, 3 vibrant coral bags.
dull maroon bags contain 4 clear indigo bags, 5 shiny magenta bags, 3 drab tomato bags, 4 dim violet bags.
pale coral bags contain 2 pale bronze bags, 2 wavy salmon bags.
drab silver bags contain 3 dark coral bags, 5 shiny violet bags, 5 faded indigo bags.
plaid black bags contain 1 dull red bag.
plaid silver bags contain 4 clear cyan bags.
dotted blue bags contain 2 plaid beige bags, 4 posh cyan bags, 4 shiny gray bags.
dotted magenta bags contain 1 drab orange bag, 5 wavy aqua bags, 2 wavy lavender bags.
clear aqua bags contain 4 striped magenta bags, 4 muted chartreuse bags.
pale red bags contain no other bags.
bright turquoise bags contain 1 wavy purple bag, 3 vibrant turquoise bags, 2 dark brown bags.
vibrant magenta bags contain 5 drab brown bags, 2 striped olive bags, 5 light plum bags.
dull brown bags contain 4 drab teal bags, 4 bright gold bags, 4 dim blue bags, 3 dotted teal bags.
dotted olive bags contain 5 striped orange bags, 1 wavy cyan bag, 3 wavy crimson bags.
bright teal bags contain 3 dim coral bags, 1 dark cyan bag, 4 bright indigo bags.
shiny chartreuse bags contain 1 drab brown bag.
bright lime bags contain 2 pale silver bags.
vibrant crimson bags contain 4 shiny white bags, 4 pale black bags, 5 clear cyan bags, 1 bright tan bag.
muted brown bags contain 5 drab purple bags.
dotted aqua bags contain 1 dim gray bag, 1 dark indigo bag, 3 posh tan bags, 5 dim lime bags.
muted tomato bags contain 1 faded orange bag, 3 vibrant aqua bags.
bright cyan bags contain 4 dotted coral bags, 2 dull lime bags, 5 clear maroon bags.
posh violet bags contain 1 light magenta bag, 4 pale maroon bags, 1 dark teal bag.
wavy turquoise bags contain 1 shiny gray bag, 4 drab tan bags, 3 pale lavender bags.
dark magenta bags contain 2 dull bronze bags.
drab gray bags contain 4 dotted turquoise bags, 5 light aqua bags.
dull coral bags contain 2 plaid black bags, 2 striped cyan bags, 3 faded bronze bags, 5 plaid crimson bags.
vibrant chartreuse bags contain 5 pale turquoise bags.
bright purple bags contain 5 vibrant salmon bags, 1 posh green bag, 4 vibrant beige bags.
mirrored tomato bags contain 4 wavy beige bags, 5 striped tan bags, 2 pale aqua bags.
shiny violet bags contain 3 shiny tan bags, 3 faded brown bags, 4 shiny green bags, 3 shiny orange bags.
plaid lavender bags contain 1 light maroon bag.
faded green bags contain 5 dark cyan bags, 2 clear teal bags, 5 muted olive bags.
dotted salmon bags contain 3 dotted olive bags, 1 dark cyan bag.
faded white bags contain 3 drab brown bags.
striped black bags contain 2 dark green bags, 5 pale bronze bags, 2 plaid olive bags.
dotted brown bags contain 1 drab salmon bag.
dark crimson bags contain 1 vibrant teal bag, 2 dim gray bags, 1 posh orange bag, 3 faded tan bags.
pale teal bags contain 5 dim violet bags.
striped cyan bags contain 3 pale purple bags, 4 dull red bags, 1 dark indigo bag, 3 dark yellow bags.
mirrored coral bags contain 2 shiny olive bags.
shiny maroon bags contain 5 vibrant coral bags, 3 plaid maroon bags, 1 striped turquoise bag, 2 wavy violet bags.
dull indigo bags contain 2 plaid magenta bags, 1 bright chartreuse bag.
drab magenta bags contain 4 striped olive bags, 3 posh white bags.
clear tan bags contain 4 light gold bags, 4 muted gold bags.
dark gray bags contain 4 plaid blue bags, 5 drab brown bags, 3 pale gray bags, 3 mirrored violet bags.
wavy teal bags contain 4 drab aqua bags, 3 pale salmon bags.
dotted tan bags contain 2 pale bronze bags, 3 faded orange bags.
bright brown bags contain 3 bright blue bags.
clear blue bags contain 5 shiny crimson bags, 1 dark cyan bag.
clear yellow bags contain 1 muted gold bag, 1 posh orange bag, 1 dull purple bag, 4 dark indigo bags.
pale aqua bags contain 3 dim coral bags, 2 mirrored aqua bags.
dull olive bags contain 1 dull yellow bag.
muted violet bags contain 3 shiny tan bags.
striped aqua bags contain 2 vibrant green bags, 2 faded coral bags, 2 dark cyan bags, 4 wavy beige bags.
pale fuchsia bags contain 5 dull green bags, 2 dotted aqua bags.
shiny brown bags contain 4 dim black bags.
plaid coral bags contain 3 faded bronze bags, 2 pale lavender bags, 3 dotted tan bags, 2 wavy lavender bags.
posh magenta bags contain 2 clear red bags, 4 dim brown bags.
wavy purple bags contain 4 dim magenta bags.
plaid fuchsia bags contain 2 striped olive bags, 3 light gray bags.
dim violet bags contain 3 dark brown bags, 4 muted plum bags.
light turquoise bags contain 5 clear brown bags, 5 muted chartreuse bags.
dull white bags contain 4 wavy salmon bags, 3 dotted crimson bags, 1 dark coral bag, 1 pale chartreuse bag.
light brown bags contain 2 plaid black bags, 3 light red bags.
dotted purple bags contain 1 posh crimson bag, 4 vibrant red bags, 2 wavy beige bags.
striped orange bags contain no other bags.
clear green bags contain 3 light plum bags, 1 wavy lavender bag, 1 shiny olive bag.
bright red bags contain 5 dotted turquoise bags, 3 dim aqua bags, 2 posh orange bags.
dark bronze bags contain 2 pale yellow bags, 1 striped brown bag, 3 striped chartreuse bags.
muted cyan bags contain 3 muted olive bags, 2 shiny red bags, 1 vibrant lavender bag, 5 drab gold bags.
light coral bags contain 3 shiny gray bags, 5 dull bronze bags, 5 muted fuchsia bags, 5 clear magenta bags.
shiny olive bags contain 4 dull cyan bags, 5 dark gray bags.
drab orange bags contain no other bags.
striped salmon bags contain 5 drab salmon bags, 5 pale plum bags.
plaid cyan bags contain 2 bright blue bags, 1 mirrored gray bag, 5 faded violet bags.
plaid teal bags contain 3 pale maroon bags, 1 clear teal bag.
faded cyan bags contain 1 dim bronze bag, 3 light olive bags, 1 muted beige bag, 1 wavy teal bag.
clear magenta bags contain 5 striped orange bags.
dull black bags contain 1 shiny purple bag, 1 mirrored red bag, 4 dotted fuchsia bags, 3 vibrant crimson bags.
mirrored blue bags contain 3 light brown bags.
mirrored black bags contain 3 dim coral bags, 3 plaid purple bags.
dim black bags contain 4 dim blue bags.
pale plum bags contain 4 muted coral bags, 2 light purple bags.
dark salmon bags contain 2 plaid blue bags, 4 vibrant turquoise bags, 3 posh white bags.
striped red bags contain 1 dim plum bag.
striped beige bags contain 1 dark tomato bag.
clear beige bags contain 2 posh orange bags, 4 muted coral bags.
bright blue bags contain 4 faded gold bags, 4 faded indigo bags.
light purple bags contain 4 muted violet bags, 1 pale red bag.
dim indigo bags contain 3 dim silver bags, 2 faded violet bags.
dotted green bags contain 5 dotted chartreuse bags, 1 pale black bag.
pale yellow bags contain 3 plaid tomato bags.
drab tan bags contain 3 dim plum bags, 2 dark fuchsia bags.
bright white bags contain 3 muted bronze bags.
shiny turquoise bags contain 4 drab brown bags.
pale maroon bags contain no other bags.
faded indigo bags contain 1 faded tomato bag, 2 light red bags, 5 vibrant bronze bags.
dotted black bags contain 1 clear brown bag, 5 mirrored olive bags, 4 dim brown bags, 2 drab red bags.
light chartreuse bags contain 5 muted black bags.
posh orange bags contain 4 light maroon bags, 1 muted white bag.
vibrant turquoise bags contain 1 dark maroon bag, 1 shiny magenta bag, 2 dotted maroon bags.
striped fuchsia bags contain 5 clear blue bags, 5 pale black bags, 1 mirrored maroon bag, 2 dotted maroon bags.
dark violet bags contain 5 clear white bags.
pale salmon bags contain 1 vibrant violet bag, 3 plaid olive bags.
pale violet bags contain 4 shiny chartreuse bags, 5 dark salmon bags, 3 bright indigo bags, 4 dark orange bags.
faded teal bags contain 2 dark gray bags, 2 posh black bags, 3 plaid maroon bags.
drab yellow bags contain 4 mirrored blue bags, 4 mirrored violet bags, 3 dim salmon bags, 1 clear yellow bag.
wavy indigo bags contain 2 shiny olive bags, 5 plaid aqua bags.
shiny tan bags contain 2 wavy purple bags, 1 dotted aqua bag, 1 light violet bag.
dull lime bags contain 1 dull coral bag.
clear turquoise bags contain 1 vibrant fuchsia bag, 5 dull beige bags.
dark blue bags contain 2 dark violet bags, 2 dotted maroon bags, 4 bright aqua bags, 4 clear black bags.
drab black bags contain 2 dim gold bags, 1 plaid crimson bag.
dotted bronze bags contain 5 dim bronze bags.
mirrored cyan bags contain 3 muted salmon bags.
light gray bags contain 1 faded gold bag, 4 faded coral bags, 4 faded silver bags, 2 faded tomato bags.
vibrant blue bags contain 2 muted gold bags.
dark maroon bags contain 3 mirrored violet bags, 3 muted gold bags, 3 drab brown bags, 4 plaid black bags.
pale chartreuse bags contain 5 dotted teal bags, 4 bright gold bags.
mirrored yellow bags contain 4 dim cyan bags.
shiny plum bags contain 3 dull green bags, 3 vibrant olive bags, 3 dim tan bags.
mirrored chartreuse bags contain 1 dark tan bag, 5 drab aqua bags.
dark gold bags contain 4 drab yellow bags, 4 pale bronze bags.
vibrant lime bags contain 3 dull salmon bags.
dim blue bags contain 2 dull cyan bags, 2 dull purple bags, 1 dark indigo bag.
dark brown bags contain 5 dull chartreuse bags.
light tomato bags contain 5 posh teal bags, 3 wavy yellow bags, 5 bright olive bags, 4 pale brown bags.
bright green bags contain 2 bright teal bags.
shiny silver bags contain 2 mirrored indigo bags, 4 faded silver bags, 2 dark lavender bags.
bright olive bags contain 5 drab turquoise bags.
striped teal bags contain 1 vibrant tan bag.
dotted yellow bags contain 1 clear tomato bag, 5 muted orange bags, 3 striped turquoise bags, 3 dim lime bags.
posh white bags contain no other bags.
plaid red bags contain 3 dotted teal bags, 2 light brown bags, 4 vibrant teal bags.
drab purple bags contain 5 pale purple bags, 1 shiny blue bag, 2 shiny orange bags.
vibrant maroon bags contain 3 shiny cyan bags, 5 striped lavender bags.
striped brown bags contain 5 faded salmon bags, 4 clear violet bags, 1 plaid salmon bag, 5 dotted tomato bags.
muted blue bags contain 1 drab chartreuse bag.
striped blue bags contain 4 dark cyan bags.
striped plum bags contain 2 wavy violet bags.
clear violet bags contain 2 dotted crimson bags, 3 plaid magenta bags.
clear teal bags contain 2 bright gold bags, 4 plaid black bags.
dim gold bags contain 5 pale gray bags, 3 drab orange bags, 3 plaid black bags.
wavy violet bags contain 3 dull beige bags.
wavy lime bags contain 2 bright lavender bags.
muted purple bags contain 3 wavy brown bags, 4 muted blue bags.
shiny indigo bags contain 1 shiny aqua bag, 4 bright aqua bags, 2 clear turquoise bags.
dim orange bags contain 5 striped lime bags.
clear bronze bags contain 4 pale black bags, 4 bright olive bags.
wavy gray bags contain 3 dotted teal bags, 2 striped lavender bags, 2 wavy aqua bags.
dull tan bags contain 5 vibrant violet bags, 2 muted maroon bags, 5 vibrant plum bags, 3 shiny red bags.
drab chartreuse bags contain 4 striped gray bags, 4 pale bronze bags, 5 dim aqua bags.
plaid gray bags contain 1 shiny blue bag, 4 clear brown bags, 4 shiny tan bags, 4 plaid beige bags.
drab plum bags contain 5 vibrant cyan bags, 3 vibrant aqua bags, 5 dim coral bags, 1 dull orange bag.
clear gold bags contain 1 drab olive bag, 5 drab orange bags, 4 shiny tan bags.
dull tomato bags contain 3 bright teal bags, 1 muted chartreuse bag.
bright silver bags contain 1 dull chartreuse bag, 5 bright gold bags, 4 faded silver bags.
clear black bags contain 5 dull orange bags, 3 dim black bags, 1 posh beige bag.
striped olive bags contain 2 pale maroon bags.
light fuchsia bags contain 5 pale silver bags, 4 dark olive bags, 1 clear magenta bag.
posh indigo bags contain 2 wavy purple bags, 3 striped beige bags, 4 vibrant white bags.
dark aqua bags contain 5 drab tomato bags, 4 faded red bags, 4 light magenta bags, 4 striped tomato bags.
plaid olive bags contain 2 posh brown bags.
wavy plum bags contain 3 shiny blue bags, 4 dark lavender bags, 5 pale violet bags.
vibrant teal bags contain 4 dull purple bags, 4 dull plum bags.
dotted gold bags contain 3 wavy maroon bags.
drab brown bags contain no other bags.
dull teal bags contain 5 wavy beige bags, 1 muted tomato bag, 1 drab aqua bag.
mirrored plum bags contain 4 muted chartreuse bags, 5 dull orange bags, 3 clear black bags.
wavy beige bags contain 4 pale violet bags, 5 dim tan bags, 3 pale fuchsia bags, 2 wavy tan bags.
plaid lime bags contain 3 pale crimson bags.
plaid brown bags contain 2 dull green bags.
light black bags contain 1 faded gold bag, 1 bright tan bag.
dim cyan bags contain 2 clear yellow bags, 3 plaid blue bags, 1 dull purple bag.
drab coral bags contain 1 bright gray bag, 1 muted magenta bag, 5 mirrored lime bags, 1 mirrored olive bag.
bright coral bags contain 3 plaid blue bags.
mirrored silver bags contain 5 clear white bags.
plaid tomato bags contain 5 dull red bags, 3 shiny green bags, 5 drab fuchsia bags, 3 dull tomato bags.
faded plum bags contain 5 dark violet bags, 3 dim brown bags.
light white bags contain 5 dotted teal bags, 2 dim tan bags.
dull bronze bags contain 3 vibrant turquoise bags.
vibrant coral bags contain 3 faded bronze bags.
posh silver bags contain 5 wavy olive bags, 3 dotted red bags, 3 faded violet bags.
dim yellow bags contain 4 pale tomato bags, 4 dim tan bags, 3 vibrant gold bags, 2 bright gold bags.
bright salmon bags contain 5 shiny orange bags, 2 dark yellow bags, 5 muted gold bags, 4 dark fuchsia bags.
light yellow bags contain 3 clear cyan bags.
dim red bags contain 3 clear lavender bags, 1 muted bronze bag, 4 vibrant salmon bags.
dark silver bags contain 1 dull brown bag, 1 wavy lavender bag, 2 shiny crimson bags, 1 clear tan bag.
dull fuchsia bags contain 5 striped cyan bags, 4 mirrored violet bags.
drab gold bags contain 5 posh lavender bags, 4 mirrored olive bags, 2 dark tan bags, 3 dotted olive bags.
muted gray bags contain 1 striped magenta bag, 2 dull tomato bags, 5 plaid olive bags, 1 faded gray bag.
bright bronze bags contain 1 clear silver bag, 4 dim lime bags.
dark cyan bags contain 5 dark maroon bags, 3 dull red bags, 1 bright gold bag.
dark plum bags contain 1 vibrant turquoise bag.
wavy maroon bags contain 5 shiny gold bags, 1 drab black bag.
light crimson bags contain 2 light plum bags, 3 plaid purple bags.
wavy chartreuse bags contain 2 pale gray bags, 5 dim purple bags, 2 drab turquoise bags.
plaid yellow bags contain 5 muted tan bags, 2 wavy cyan bags, 3 light gold bags, 1 dim gold bag.
mirrored violet bags contain no other bags.
wavy yellow bags contain 2 dim aqua bags, 1 dark fuchsia bag, 5 faded coral bags, 1 faded silver bag.
plaid bronze bags contain 1 striped bronze bag.
vibrant green bags contain 3 striped chartreuse bags, 3 pale lavender bags, 4 dotted lime bags, 4 plaid lavender bags.
muted crimson bags contain 3 dim blue bags, 1 dull lime bag, 3 plaid indigo bags, 1 pale plum bag.
posh cyan bags contain 5 drab brown bags, 5 faded blue bags.
vibrant black bags contain 3 pale silver bags.
light aqua bags contain 2 faded crimson bags, 3 dark bronze bags, 1 dim orange bag.
mirrored red bags contain 3 light violet bags.
dark lime bags contain 1 striped turquoise bag.
mirrored olive bags contain 1 faded bronze bag, 1 drab aqua bag, 1 dark indigo bag, 3 posh white bags.
striped chartreuse bags contain 2 mirrored gold bags.
dotted lime bags contain 1 vibrant turquoise bag, 2 dotted turquoise bags, 5 dull red bags.
vibrant bronze bags contain 1 posh green bag, 3 posh tan bags, 5 light salmon bags.
dark teal bags contain 4 shiny lavender bags, 5 dull orange bags.
shiny green bags contain 2 bright lavender bags, 3 shiny olive bags, 4 mirrored violet bags, 5 posh white bags.
light magenta bags contain 2 pale maroon bags.
pale magenta bags contain 5 dull aqua bags.
dull plum bags contain 2 vibrant violet bags, 5 pale red bags, 2 wavy fuchsia bags.
muted olive bags contain 5 bright teal bags.
vibrant fuchsia bags contain 3 posh brown bags.
dark olive bags contain 5 dim coral bags, 4 pale red bags, 5 drab aqua bags.
posh purple bags contain 2 bright red bags, 4 pale coral bags, 1 dotted bronze bag.
dark lavender bags contain 2 striped blue bags, 5 posh blue bags, 2 plaid green bags.

154
day7/main.hs Executable file
View File

@ -0,0 +1,154 @@
#! /usr/bin/env -S"ANSWER=42" nix-shell
#! nix-shell -p ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [attoparsec multiset containers pretty-simple])"
#! nix-shell -i "ghcid -c 'ghci -Wall' -T main"
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import Control.Monad.Zip
import Data.Attoparsec.Text (Parser, parseOnly)
import Data.Bool (bool)
import Data.Map (Map)
import Data.Monoid (Sum(..))
import Data.MultiSet (MultiSet)
import Data.Tree (Tree)
import Text.Pretty.Simple
-- import Debug.Trace (trace)
import qualified Data.Attoparsec.Text as A
import qualified Data.Map.Strict as M
import qualified Data.MultiSet as B
import qualified Data.Text as Text
import qualified Data.Tree as T
exampleData :: [String]
exampleData =
[ "light red bags contain 1 bright white bag, 2 muted yellow bags."
, "dark orange bags contain 3 bright white bags, 4 muted yellow bags."
, "bright white bags contain 1 shiny gold bag."
, "muted yellow bags contain 2 shiny gold bags, 9 faded blue bags."
, "shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags."
, "dark olive bags contain 3 faded blue bags, 4 dotted black bags."
, "vibrant plum bags contain 5 faded blue bags, 6 dotted black bags."
, "faded blue bags contain no other bags."
, "dotted black bags contain no other bags."
]
exampleData2 :: [String]
exampleData2 =
[ "shiny gold bags contain 2 dark red bags."
, "dark red bags contain 2 dark orange bags."
, "dark orange bags contain 2 dark yellow bags."
, "dark yellow bags contain 2 dark green bags."
, "dark green bags contain 2 dark blue bags."
, "dark blue bags contain 2 dark violet bags."
, "dark violet bags contain no other bags."
]
data Color = Color String String
deriving (Show, Ord, Eq)
-- An efficient implementation of multisets, also sometimes called bags.
type Bag = MultiSet Color
parseFullColor :: Parser Color
parseFullColor = do
adjective <- A.many' A.letter
A.skipSpace
colorName <- A.many' A.letter
A.skipSpace
_ <- ("bags" <|> "bag")
pure $ Color adjective colorName
parseBag' :: Parser Bag
parseBag' = do
i <- A.decimal
A.skipSpace
c <- parseFullColor
pure $ B.insertMany c i B.empty
parseNoBag :: Parser Bag
parseNoBag = do
_ <- "no other bags"
pure $ B.empty
parseBag :: Parser Bag
parseBag = parseNoBag <|> parseBag'
type Rules = Map Color Bag
parseRule :: Parser Rules
parseRule = do
k <- parseFullColor
A.skipSpace
_ <- "contain"
A.skipSpace
vx <- parseBag `A.sepBy` (", ")
_ <- "."
let v = B.unions vx
pure $ M.insert k v M.empty
eitherToMaybe :: Either b a -> Maybe a
eitherToMaybe (Right v) = Just v
eitherToMaybe (Left _) = Nothing
parseStrs :: [String] -> Maybe Rules
parseStrs s = M.unions <$> parse s
where
parse = eitherToMaybe
. sequence
. map (parseOnly (parseRule <* A.endOfInput) . Text.pack)
mkTree :: (Color,Int) -> Rules -> Tree (Color, Int)
mkTree color rules = T.unfoldTree mkNode color
where
mkNode :: (Color, Int) -> ((Color, Int), [(Color, Int)])
mkNode n@(c,_) = (n, concat $ B.toOccurList <$> M.lookup c rules)
mkSimpleTree :: Color -> Rules -> Tree Color
mkSimpleTree color rules = T.unfoldTree mkNode color
where
mkNode :: Color -> (Color, [Color])
mkNode c = (c, fmap fst <$> concat $ B.toOccurList <$> M.lookup c rules)
solvePart1 :: Color -> [String] -> Maybe Int
solvePart1 color strs = do
rules <- parseStrs strs
let trees = map (\c -> mkSimpleTree c rules) (filter (/= color) $ M.keys rules)
let containColor = map (elem color) trees
pure $ getSum $ foldMap (Sum . bool 0 1) containColor
-- ^^ complicated exp for: pure $ length $ filter (== True) containColor
updateTree :: Tree Int -> Tree Int
updateTree t@(T.Node _ []) = t
updateTree (T.Node v vx) = T.Node v (fmap ((fmap ((*) v)) . updateTree) vx)
solvePart2 :: Color -> [String] -> Maybe ( Sum Int )
solvePart2 color strs = do
rules <- parseStrs strs
let tree = mkTree (color,1) rules
pure $ foldMap Sum $ (updateTree . snd . munzip) tree
main :: IO ()
main = do
input <- lines <$> readFile "day7/input"
putStrLn ":: Day 7 - Part 1"
print $ exampleData
putStrLn ":: Tests"
print $ parseOnly (parseFullColor <* A.endOfInput) "light red bag"
print $ parseOnly (parseBag <* A.endOfInput) "2 muted blue bags"
print $ parseOnly (parseBag <* A.endOfInput) "3 muted red bages"
print $ parseOnly (parseRule <* A.endOfInput) "dark orange bags contain 3 bright white bags, 4 muted yellow bags."
putStrLn ":: Parsing test data"
print $ parseStrs exampleData
putStrLn ":: Building tree"
pPrint $ mkTree (Color "shiny" "gold", 1) <$> (parseStrs exampleData)
putStrLn ":: Solving Part 1"
print $ solvePart1 (Color "shiny" "gold") exampleData
print $ solvePart1 (Color "shiny" "gold") input
putStrLn ":: Solving Part 2"
print $ solvePart2 (Color "shiny" "gold") exampleData
print $ solvePart2 (Color "shiny" "gold") exampleData2
print $ solvePart2 (Color "shiny" "gold") input

643
day8/input Normal file
View File

@ -0,0 +1,643 @@
acc -15
jmp +164
nop +157
acc -12
acc -19
acc +41
jmp +177
acc +36
acc +37
nop +471
jmp +433
acc +24
acc +13
acc -12
jmp +556
jmp +1
acc -15
acc +33
jmp +299
jmp +344
acc -3
jmp +124
acc +10
nop +562
acc +45
jmp +386
acc -3
jmp +206
acc -19
acc +12
jmp +424
acc -18
acc +23
acc +12
acc +0
jmp +311
nop +327
jmp +301
acc +20
nop +375
jmp +25
acc -13
acc +49
acc +23
acc -3
jmp +346
acc +2
acc +3
jmp +123
acc -7
nop +183
jmp +165
acc +47
acc +34
jmp +1
jmp +359
acc +12
acc +16
acc -3
acc +0
jmp +556
acc +14
acc -3
jmp +559
jmp +192
jmp +495
nop +264
acc +3
acc +47
jmp +187
acc -18
jmp +1
acc -12
jmp -58
acc +49
nop +288
jmp +145
acc +46
jmp +294
acc +38
nop +400
jmp +373
acc +7
acc +31
jmp +492
acc +40
acc +5
acc +11
jmp +263
acc +29
acc +10
acc +21
acc +14
jmp +450
nop +458
acc +38
nop +432
acc +42
jmp +191
jmp +279
nop +71
acc -17
jmp -64
acc +17
jmp +1
acc +29
jmp +506
jmp +354
acc +42
acc +32
jmp -40
jmp +184
acc +41
acc -7
acc +10
acc +38
jmp +100
jmp +104
jmp +245
jmp +335
jmp +20
acc +3
jmp +490
jmp -62
acc +34
acc +34
acc -1
jmp +6
acc +5
acc -9
acc -19
jmp +397
jmp +253
acc +9
jmp +270
acc +8
acc -16
acc +32
acc +48
jmp +258
acc +4
acc +37
nop +319
jmp +318
jmp -4
acc -5
jmp +32
nop -86
jmp +306
acc -13
acc +50
acc -16
jmp -53
acc +31
jmp +52
acc -11
jmp +89
acc +21
jmp +126
acc +44
acc +49
nop +177
jmp +44
acc +8
jmp +166
acc +20
acc -8
acc +38
acc +10
jmp +311
jmp +21
acc -10
nop +84
acc -7
acc +13
jmp +78
jmp +1
jmp +366
acc -6
acc -12
jmp -142
nop +223
jmp +42
acc -6
nop +227
nop +193
acc +23
jmp +83
acc -10
acc +12
jmp +1
acc -8
acc +3
nop +28
jmp +301
acc +23
jmp -170
nop -79
acc +21
acc +37
jmp +138
acc +37
acc +24
nop +413
acc -9
jmp -179
acc -1
acc -10
nop +261
acc -19
jmp +168
acc -16
acc +19
acc +17
acc +21
jmp -9
jmp +46
acc +4
nop +398
acc +28
jmp +396
acc +11
jmp +384
jmp +375
acc +25
acc +30
acc -11
jmp +371
jmp +249
acc -10
acc -15
jmp -7
jmp +38
acc +29
acc +15
acc +46
jmp -77
acc +43
jmp -83
jmp -42
acc +30
acc +44
acc +33
acc +14
jmp +326
acc -3
nop +49
acc +12
jmp +63
acc -13
acc -19
acc -17
jmp +126
jmp +293
acc +16
jmp -185
acc -12
jmp -92
acc -13
acc +19
acc -1
jmp -138
acc +28
nop -243
nop +352
acc +43
jmp +249
acc -5
acc +36
jmp -217
nop +197
nop -106
acc +30
jmp +194
acc +7
acc -16
nop +128
jmp -239
jmp -258
acc +11
nop -74
acc +42
acc +40
jmp +72
jmp -207
nop +337
nop -240
nop -169
jmp -55
nop +165
acc +27
acc +4
jmp -169
acc -2
jmp +69
acc +0
jmp -250
acc +11
acc +45
acc +31
jmp +195
acc -10
acc -8
nop -283
acc -2
jmp +63
acc +17
acc +12
acc +0
nop +243
jmp +190
acc +17
acc -18
jmp +78
acc +7
acc +33
jmp +244
nop +29
acc +20
nop +150
acc +29
jmp -43
acc +45
nop -132
acc +16
acc +14
jmp -237
jmp -199
acc -4
jmp +179
acc +13
acc +15
acc +6
acc +46
jmp -222
acc -8
acc +15
jmp -26
acc +38
jmp +1
nop +266
jmp +44
acc -13
nop +209
acc +21
jmp +201
acc +8
acc +18
jmp +190
acc +35
jmp -238
jmp +69
acc -11
nop -182
jmp -221
acc -16
acc -5
acc +7
jmp +39
acc +26
acc +43
acc +20
jmp +92
acc +22
jmp +81
acc +32
acc -13
jmp +30
acc +1
jmp +201
acc +4
jmp -165
acc -17
jmp -84
acc -16
acc +2
acc +47
jmp +54
jmp -195
acc +33
acc -17
jmp -18
jmp +256
acc +1
jmp -244
acc +28
acc +35
jmp +189
nop +32
acc +9
jmp +24
acc +21
acc +14
acc +17
jmp -67
acc +21
jmp -297
acc +36
acc +14
acc -13
jmp +115
acc -2
acc -13
jmp -182
nop +119
acc -4
acc +44
acc -14
jmp +61
acc +41
jmp -13
nop -116
jmp -294
jmp +7
jmp +17
acc -14
acc +42
acc -6
acc +24
jmp +151
nop -374
nop -375
acc +4
jmp -268
nop -27
acc +16
acc +2
jmp -206
jmp -320
nop -196
jmp +168
nop +36
acc +34
jmp -402
acc +36
acc +38
acc -11
nop +17
jmp -182
acc +15
jmp -145
acc +43
jmp -79
jmp -391
jmp -155
nop -94
acc +0
acc +9
jmp -441
acc +3
acc +6
acc +50
nop -334
jmp +163
acc +18
acc -11
jmp +21
acc +10
acc +4
nop +132
jmp -348
acc +18
nop -1
acc -4
nop +148
jmp +165
jmp +146
jmp -460
jmp -14
acc +26
nop -388
nop -353
jmp +119
acc +26
acc -1
acc +9
jmp -285
acc +37
jmp -345
jmp -178
acc +7
acc +13
jmp -39
acc +29
nop -200
acc +50
acc +24
jmp -160
acc +18
jmp +63
acc -11
acc +1
acc -6
acc +33
jmp -90
acc -3
acc +11
acc +45
jmp -197
jmp -169
acc +7
acc -4
jmp -281
acc +48
nop +19
nop -25
nop +9
jmp -274
nop -126
acc +22
acc -4
jmp -408
acc +1
acc +0
jmp +98
acc +25
acc +12
acc -19
jmp -90
acc +44
acc +20
acc +21
jmp -192
acc -12
jmp -70
nop +3
acc +17
jmp -349
acc +20
acc -7
acc +6
nop -43
jmp +53
acc +34
acc +48
acc -4
acc +8
jmp -126
acc +23
acc +25
jmp -349
acc -4
jmp -272
jmp -129
nop -366
jmp -292
acc +29
nop -269
acc +50
nop -254
jmp -321
jmp -23
acc +11
nop -425
nop -150
acc -9
jmp -467
acc +18
acc +27
jmp -338
jmp +1
acc +21
acc +27
acc -11
jmp -160
acc +27
acc +15
acc +0
acc +41
jmp -386
acc -10
acc +14
jmp -217
nop -484
acc +47
jmp -529
acc -10
acc +48
acc +0
jmp -430
acc +45
acc -8
acc +3
nop -103
jmp -387
acc -16
acc +39
jmp +1
acc +17
jmp -350
jmp -328
acc +30
acc +28
jmp -309
nop -361
acc +1
nop -468
jmp -212
acc +29
acc -4
jmp -249
acc +45
acc +30
acc +40
acc -17
jmp -579
acc +25
jmp -525
nop -217
acc +17
acc +3
jmp -142
nop +18
jmp -493
jmp +1
jmp -495
jmp -360
acc +7
acc +30
acc -3
nop -449
jmp -326
acc -10
acc -8
jmp -371
acc +22
acc +48
acc +6
acc +18
jmp -59
acc +17
acc +14
jmp -250
acc +19
acc +25
acc -14
acc -17
jmp -517
acc +29
acc -4
acc +9
acc +17
jmp +1

140
day8/main.hs Executable file
View File

@ -0,0 +1,140 @@
#! /usr/bin/env -S"ANSWER=42" nix-shell
#! nix-shell -p ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [pretty-simple vector containers])"
#! nix-shell -i "ghcid -c 'ghci' -T main"
{-# OPTIONS_GHC -Wall -Wincomplete-uni-patterns #-}
{-# OPTIONS_GHC -Wno-unused-top-binds -Wno-unused-local-binds #-}
{-# LANGUAGE OverloadedStrings #-}
import Text.Pretty.Simple
-- import Data.List.NonEmpty (NonEmpty(..))
-- import qualified Data.List.NonEmpty as NE
import Data.Vector (Vector)
import Debug.Trace (trace)
import Data.List (unfoldr, zip4, unzip4)
import Data.IntMap.Strict (IntMap)
import qualified Data.Vector as V
import qualified Data.IntMap.Strict as M
data Op = OpNop !Int
| OpJmp !Int
| OpAcc !Int
deriving (Show, Ord, Eq)
data VMState = VMRun | VMHalt
deriving (Show, Ord, Eq)
data VirtualMachine = VM
{ pgmCounter :: !Int
, pgmAccumulator :: !Int
, pgmInstructions :: Vector Op
, vmState :: VMState
}
deriving (Show, Ord, Eq)
initialVM :: Vector Op -> VirtualMachine
initialVM ins = VM 1 0 ins VMRun
stepVM :: VirtualMachine -> Maybe (VirtualMachine, VirtualMachine)
stepVM current@(VM c a ins VMRun) = Just (current, checkHalt next)
where
next = go (ins V.! (c-1))
go (OpNop _) = VM (c+1) a ins VMRun
go (OpJmp n) = VM (c+n) a ins VMRun
go (OpAcc n) = VM (c+1) (a+n) ins VMRun
checkHalt vm0@(VM c0 a0 _ _) | c0 == lastCount + 1 =
trace ("halted, acc="<>show a0) $ vm0 { vmState = VMHalt }
checkHalt vm0@(VM _ _ _ _) | otherwise =
vm0
lastCount = V.length ins
stepVM (VM _ _ _ VMHalt) = Nothing
exampleData :: [String]
exampleData =
[ "nop +0"
, "acc +1"
, "jmp +4"
, "acc +3"
, "jmp -3"
, "acc -99"
, "acc +1"
, "jmp -4"
, "acc +6"
]
vmFromInput :: [String] -> VirtualMachine
vmFromInput input = initialVM (ins input)
where
ins = V.fromList . map parseOp
parseOp :: String -> Op
parseOp = go . (\(x,y)-> (x,tail y)) . break (== ' ')
where
go ("nop",'+':s) = OpNop (read s :: Int)
go ("acc",'+':s) = OpAcc (read s :: Int)
go ("jmp",'+':s) = OpJmp (read s :: Int)
go ("nop",s) = OpNop (read s :: Int)
go ("acc",s) = OpAcc (read s :: Int)
go ("jmp",s) = OpJmp (read s :: Int)
go s@_ = trace (show s) $ undefined
-- Find smallest looping prefix in list of Int, returns associated pgmAccumulator
solvePart1 :: VirtualMachine -> Int
solvePart1 vm0 =
snd . last $ shortestCycleOn $ (\vm -> (pgmCounter vm, pgmAccumulator vm)) <$> unfoldr stepVM vm0
-- Shortest cycle in [Int]
shortestCycle :: [Int] -> [Int]
shortestCycle ix = reverse $ go M.empty ix []
where
go :: (IntMap ()) -> [Int] -> [Int] -> [Int]
go mem (x:_ ) ys | (mem M.!? x) /= Nothing = ys
go mem (x:xs) ys | otherwise = go (M.insert x () mem) xs (x:ys)
go _ [] ys = ys
shortestCycleOn :: [(Int,Int)] -> [(Int,Int)]
shortestCycleOn tx = zip (shortestCycle cx) ax
where
(cx, ax) = unzip tx
shortestCycleVm :: [VirtualMachine] -> [VirtualMachine]
shortestCycleVm vx = (\(a,b,c,d) -> VM a b c d) <$> zip4 (shortestCycle cx) ax ins state
where
(cx, ax, ins, state) = unzip4 $ (\(VM a b c d) -> (a,b,c,d)) <$> vx
-- Try lots of permutations of OpNop -> OpJmp, or OpJmp -> OpNop
-- until the VirtualMachine halts, and read the value of the accumulator
solvePart2 :: Vector Op -> Vector VMState
solvePart2 = fmap (vmState . last . shortestCycleVm . unfoldr stepVM . initialVM) . swapInstructions
swapInstructions :: Vector Op -> Vector (Vector Op)
swapInstructions ins = V.imap swap ins
where
swap i (OpNop v) = ins V.// [(i,OpJmp v)]
swap i (OpJmp v) = ins V.// [(i,OpNop v)]
swap _ (OpAcc _) = ins
main :: IO ()
main = do
putStrLn "Day 8 - Part 1"
putStrLn ":: Tests"
print exampleData
print $ parseOp <$> exampleData
putStrLn ":: Solving part 1"
pPrint $ solvePart1 (vmFromInput exampleData)
input <- lines <$> readFile "day8/input"
pPrint $ solvePart1 (vmFromInput input)
putStrLn ":: Tests"
let miniIns = V.fromList [OpJmp 2, OpNop 0, OpAcc (-8)]
pPrint $ length $ swapInstructions $ miniIns
let miniVM = initialVM $ V.fromList [ OpNop 0 ]
pPrint $ miniVM { vmState = VMHalt }
pPrint $ (unfoldr stepVM) $ miniVM
putStrLn ":: Solving part 2"
pPrint $ solvePart2 $ V.fromList $ parseOp <$> exampleData
pPrint $ solvePart2 $ V.fromList $ parseOp <$> input

1000
day9/input Normal file

File diff suppressed because it is too large Load Diff

75
day9/main.hs Executable file
View File

@ -0,0 +1,75 @@
#! /usr/bin/env -S"ANSWER=42" nix-shell
#! nix-shell -p ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [pretty-simple containers])"
#! 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 Data.IntMap.Strict (IntMap)
import Data.IntSet (IntSet)
import Data.List (inits, tails, sortOn)
import Data.Monoid
import Debug.Trace (trace)
import Text.Pretty.Simple
import qualified Data.IntMap.Strict as M
import qualified Data.IntSet as S
exampleData :: [Int]
exampleData = [ 35,20,15,25,47,40,62,55,65,95,102,117,150
, 182,127,219,299,277,309,576 ];
pairSums :: [Int] -> IntSet
pairSums xs = S.fromList $ do
i1 <- xs
i2 <- xs
pure (i1 + i2)
isSumOfPreamble :: Int -> [Int] -> Bool
isSumOfPreamble size xs = go tx
where
go (x:_) = x `S.member` (pairSums preamble)
go ([]) = False
(preamble, tx) = splitAt size xs
solvePart1 :: Int -> [Int] -> (Int,Bool)
solvePart1 size message =
head $ dropWhile (snd) $
map go ( takeWhile ((> size) . length) $ tails message )
where
go xs = (head $ drop size xs,isSumOfPreamble size xs)
--------------------------------------------------------------------------------
sortedContiguousSubLists :: [Int] -> [[Int]]
sortedContiguousSubLists =
dropWhile (== []) . sortOn length . concat . fmap inits . tails
listSums :: [[Int]] -> IntMap [Int]
listSums xss = M.fromList $ do
xs <- xss
pure $ (getSum $ foldMap Sum xs, xs)
solvePart2 :: Int -> [Int] -> Int
solvePart2 target message = (\x -> minimum x + maximum x) $ bigMap M.! target
where
bigMap = listSums $ sortedContiguousSubLists message
main :: IO ()
main = do
putStrLn "Test"
print exampleData
print $ 1 `S.member` (pairSums [])
print $ pairSums exampleData
putStrLn "Day 9 - Part 1"
print $ solvePart1 5 exampleData
input <- lines <$> readFile "day9/input"
print $ solvePart1 25 $ map read input
putStrLn "Test"
print $ take 10 $ drop 20 $ sortedContiguousSubLists exampleData
putStrLn "Day 9 - Part 2"
print $ solvePart2 127 exampleData
print $ solvePart2 3199139634 $ map read input

View File

@ -1,10 +1,16 @@
#! /usr/bin/env -S"ANSWER=42" nix-shell
#! nix-shell -p ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [shower])"
#! nix-shell -i "ghcid -c 'ghci -Wall' -T main"
#! 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 #-}
{-# OPTIONS_GHC -Wno-unused-matches #-}
{-# LANGUAGE OverloadedStrings #-}
import Debug.Trace (trace)
import Text.Pretty.Simple
main :: IO ()
main = do
putStrLn "Day 1 - Part 1"
putStrLn ":: Day x - Part 1"