This commit is contained in:
Orangerot 2024-05-17 15:41:55 +02:00
parent a1895fe157
commit 347d2f1fbc
32 changed files with 3324 additions and 0 deletions

9
.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
# Ignore all files without an extension
*
# Don't ignore files with extensions
!*.*
# Don't ignore directories
!*/
*.o

23
2023/.gitignore vendored Normal file
View file

@ -0,0 +1,23 @@
dist
dist-*
cabal-dev
*.o
*.hi
*.hie
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*

34
2023/day01/Main.hs Normal file
View file

@ -0,0 +1,34 @@
import Data.List
import Data.Char
-- isDigit :: Char -> Bool
-- isDigit c = c >= '0' && c <= '9'
wordDict = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
findFirst :: String -> [String] -> Int
findFirst [] _ = 0
findFirst s@(x:xs) wordDict
| isDigit x = read [x]
| Just y <- elemIndex (take 3 s) wordDict = y
| Just y <- elemIndex (take 4 s) wordDict = y
| Just y <- elemIndex (take 5 s) wordDict = y
| otherwise = findFirst xs wordDict
rev [] = []
rev (x:xs) = rev xs ++ [x]
main :: IO ()
main = do
inputLines <- lines <$> getContents
let filterLines = map (filter isDigit) inputLines
let outerChars = map (\x -> [head x, last x]) filterLines
mapM_ putStrLn outerChars
let intList = map read outerChars :: [Int]
-- let intList = map (\x -> findFirst x wordDict * 10 + findFirst (rev x) (map rev wordDict)) inputLines
let result = sum intList
putStrLn $ show result

25
2023/day01/Main_clean.hs Normal file
View file

@ -0,0 +1,25 @@
import Data.List
import Data.Char
wordDict = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
findFirst :: String -> [String] -> Int
findFirst [] _ = 0
findFirst s@(x:xs) wordDict
| isDigit x = read [x]
| Just y <- elemIndex (take 3 s) wordDict = y -- not needed for exercise 1
| Just y <- elemIndex (take 4 s) wordDict = y -- not needed for exercise 1
| Just y <- elemIndex (take 5 s) wordDict = y -- not needed for exercise 1
| otherwise = findFirst xs wordDict
findLast s wordDict = findFirst (reverse s) (map reverse wordDict)
main :: IO ()
main = do
inputLines <- lines <$> getContents
let intList = map (\x -> findFirst x wordDict * 10 + findLast x wordDict) inputLines
let result = sum intList
print result

1000
2023/day01/daniel.txt Normal file

File diff suppressed because it is too large Load diff

4
2023/day01/example.txt Normal file
View file

@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

7
2023/day01/example2.txt Normal file
View file

@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

1000
2023/day01/input.txt Normal file

File diff suppressed because it is too large Load diff

26
2023/day02/Main.hs Normal file
View file

@ -0,0 +1,26 @@
import Data.Char
import Data.List
type Parser a = String -> [(a, String)]
char :: Parser Char
char [] = []
char (x:xs) = [(x, xs)]
failure :: Parser a
failure = (\a -> [])
return :: Parser a
return v inp = [(v, inp)]
parse :: Parser a -> String -> [(a, String)]
parse p inp = p inp
main :: IO ()
main = do
inputLines <- lines <$> getContents
-- let arePossible = filter isPossible lines
mapM_ putStrLn inputLines

41
2023/day02/MySplit.hs Normal file
View file

@ -0,0 +1,41 @@
import Data.List.Split (splitOn)
game :: String -> [String]
game = splitOn [';']
reveal :: String -> [String]
reveal x = concat ( map (splitOn [',']) (game x) )
colors :: String -> [(Int, String)]
colors x = map (\x -> color (splitOn [' '] x)) (reveal x)
color :: [String] -> (Int, String)
color [_, i, s] = (read i, s)
validColor :: (Int, String) -> Bool
validColor (i, s) = case s of
"red" -> i <= 12
"green" -> i <= 13
"blue" -> i <= 14
_ -> False
getColors :: String -> String
getColors s = tail (dropWhile (/= ':') s)
isGameValid :: String -> Bool
isGameValid s = all validColor (colors (getColors s))
isValid :: [String] -> Bool
isValid s = all isGameValid s
main :: IO ()
main = do
inputLines <- lines <$> getContents
-- let arePossible = filter isPossible lines
-- myColors <- isValid inputLines
print (sum (map (\(_,n) -> n) (filter (\(b,_) -> b) (zip (map isGameValid inputLines) [1..]))))
-- mapM_ putStrLn myColors
-- mapM_ putStrLn inputLines

50
2023/day02/MySplit2.hs Normal file
View file

@ -0,0 +1,50 @@
import Data.List.Split (splitOn)
game :: String -> [String]
game = splitOn [';']
reveal :: String -> [String]
reveal x = concat ( map (splitOn [',']) (game x) )
colors :: String -> [(Int, String)]
colors x = map (\x -> color (splitOn [' '] x)) (reveal x)
color :: [String] -> (Int, String)
color [_, i, s] = (read i, s)
validColor :: (Int, String) -> Bool
validColor (i, s) = case s of
"red" -> i <= 12
"green" -> i <= 13
"blue" -> i <= 14
_ -> False
getColors :: String -> String
getColors s = tail (dropWhile (/= ':') s)
isGameValid :: String -> Bool
isGameValid s = all validColor (colors (getColors s))
isValid :: [String] -> Bool
isValid s = all isGameValid s
getMyColor :: String -> [(Int, String)]
getMyColor s = colors (getColors s)
myFilter :: String -> [(Int, String)] -> Int
myFilter color s = maximum (map (\(i,_) -> i) (filter (\(_,c) -> c == color) s))
main :: IO ()
main = do
inputLines <- lines <$> getContents
-- let arePossible = filter isPossible lines
-- myColors <- isValid inputLines
-- print (sum (map (\(_,n) -> n) (filter (\(b,_) -> b) (zip (map isGameValid inputLines) [1..]))))
let myColors = map (\x -> getMyColor x) inputLines
let myResult = map (\c -> myFilter "red" c * myFilter "green" c * myFilter "blue" c) myColors
print (sum myResult)
-- mapM_ putStrLn myColors
-- mapM_ putStrLn inputLines

122
2023/day02/Parsing.hs Normal file
View file

@ -0,0 +1,122 @@
-- Functional parsing library from chapter 13 of Programming in Haskell,
-- Graham Hutton, Cambridge University Press, 2016.
module Parsing (module Parsing, module Control.Applicative) where
import Control.Applicative
import Data.Char
-- Basic definitions
newtype Parser a = P (String -> [(a,String)])
parse :: Parser a -> String -> [(a,String)]
parse (P p) inp = p inp
item :: Parser Char
item = P (\inp -> case inp of
[] -> []
(x:xs) -> [(x,xs)])
-- Sequencing parsers
instance Functor Parser where
-- fmap :: (a -> b) -> Parser a -> Parser b
fmap g p = P (\inp -> case parse p inp of
[] -> []
[(v,out)] -> [(g v, out)])
instance Applicative Parser where
-- pure :: a -> Parser a
pure v = P (\inp -> [(v,inp)])
-- <*> :: Parser (a -> b) -> Parser a -> Parser b
pg <*> px = P (\inp -> case parse pg inp of
[] -> []
[(g,out)] -> parse (fmap g px) out)
instance Monad Parser where
-- (>>=) :: Parser a -> (a -> Parser b) -> Parser b
p >>= f = P (\inp -> case parse p inp of
[] -> []
[(v,out)] -> parse (f v) out)
-- Making choices
instance Alternative Parser where
-- empty :: Parser a
empty = P (\inp -> [])
-- (<|>) :: Parser a -> Parser a -> Parser a
p <|> q = P (\inp -> case parse p inp of
[] -> parse q inp
[(v,out)] -> [(v,out)])
-- Derived primitives
sat :: (Char -> Bool) -> Parser Char
sat p = do x <- item
if p x then return x else empty
digit :: Parser Char
digit = sat isDigit
lower :: Parser Char
lower = sat isLower
upper :: Parser Char
upper = sat isUpper
letter :: Parser Char
letter = sat isAlpha
alphanum :: Parser Char
alphanum = sat isAlphaNum
char :: Char -> Parser Char
char x = sat (== x)
string :: String -> Parser String
string [] = return []
string (x:xs) = do char x
string xs
return (x:xs)
ident :: Parser String
ident = do x <- lower
xs <- many alphanum
return (x:xs)
nat :: Parser Int
nat = do xs <- some digit
return (read xs)
int :: Parser Int
int = do char '-'
n <- nat
return (-n)
<|> nat
-- Handling spacing
space :: Parser ()
space = do many (sat isSpace)
return ()
token :: Parser a -> Parser a
token p = do space
v <- p
space
return v
identifier :: Parser String
identifier = token ident
natural :: Parser Int
natural = token nat
integer :: Parser Int
integer = token int
symbol :: String -> Parser String
symbol xs = token (string xs)

43
2023/day02/Test.hs Normal file
View file

@ -0,0 +1,43 @@
import Data.Char (isDigit, isSpace)
data Color = Red | Green | Blue deriving (Show, Eq)
-- Parse a single digit
digit :: Char -> Maybe Int
digit c
| isDigit c = Just (read [c])
| otherwise = Nothing
-- Parse an integer
-- Parse an integer
parseInt :: String -> Maybe Int
parseInt str = case reads str of
[(num, "")] -> Just num
_ -> Nothing
-- Parse color
parseColor :: String -> Maybe Color
parseColor "red" = Just Red
parseColor "green" = Just Green
parseColor "blue" = Just Blue
parseColor _ = Nothing
-- Parse the entire input string
parseInput :: String -> Maybe Bool
parseInput input = do
let (numStr, rest) = span (\c -> isDigit c ) input
num <- parseInt numStr
let colorStr = dropWhile isSpace rest
color <- parseColor colorStr
case color of
Red -> pure (num < 12)
Green -> pure (num < 13)
Blue -> pure (num < 14)
main :: IO ()
main = do
putStrLn "Enter input (e.g., '10 red'):"
input <- getLine
case parseInput input of
Just result -> putStrLn $ "Result: " ++ show result
Nothing -> putStrLn "Invalid input."

5
2023/day02/example.txt Normal file
View file

@ -0,0 +1,5 @@
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green

100
2023/day02/input.txt Normal file
View file

@ -0,0 +1,100 @@
Game 1: 12 blue; 2 green, 13 blue, 19 red; 13 red, 3 green, 14 blue
Game 2: 12 blue, 1 red, 1 green; 1 red, 12 blue, 3 green; 5 green, 1 red, 9 blue; 1 red, 7 blue, 4 green
Game 3: 1 red; 12 blue, 15 red; 1 green, 10 red, 2 blue; 1 green, 3 red, 9 blue
Game 4: 6 blue, 5 green; 2 blue, 6 green, 6 red; 11 blue, 5 red; 6 green, 11 red, 7 blue; 4 green, 10 red; 1 green, 7 red, 13 blue
Game 5: 10 green, 1 red, 2 blue; 3 red, 4 green, 4 blue; 5 green, 5 red
Game 6: 1 green, 6 blue, 14 red; 9 blue, 5 red; 14 red, 12 blue
Game 7: 1 green, 9 red, 8 blue; 9 blue, 1 green, 6 red; 1 green, 15 blue, 19 red
Game 8: 9 red, 7 green, 2 blue; 6 red, 17 green; 18 red, 16 green, 2 blue; 10 red, 14 green
Game 9: 1 blue, 11 red, 9 green; 8 red, 1 blue, 9 green; 4 blue, 16 red, 9 green; 8 green, 3 blue, 6 red; 8 green, 11 red, 3 blue; 11 red, 2 blue
Game 10: 8 green, 14 blue; 1 red, 6 blue, 9 green; 6 blue, 4 green, 1 red; 16 green, 9 blue
Game 11: 6 green, 11 blue, 1 red; 10 green, 1 red; 7 blue, 2 green, 1 red
Game 12: 3 green, 5 blue, 2 red; 14 blue, 16 green, 4 red; 8 green, 14 blue, 4 red
Game 13: 5 red, 12 blue, 2 green; 2 green, 1 red, 9 blue; 1 red, 2 blue, 3 green; 3 green, 3 red, 7 blue; 2 red, 13 blue; 1 red, 10 blue, 2 green
Game 14: 5 blue, 1 red, 2 green; 8 blue, 1 green, 1 red; 1 blue, 2 green
Game 15: 14 blue, 9 green, 1 red; 2 red, 15 blue, 12 green; 1 blue, 2 green, 1 red; 1 red, 16 green, 15 blue; 1 red, 12 green, 8 blue; 1 red, 17 blue
Game 16: 7 red, 1 green, 18 blue; 7 blue, 5 green, 17 red; 14 blue, 8 red, 6 green
Game 17: 4 green, 5 blue; 5 green, 1 red, 7 blue; 3 green, 6 blue, 4 red; 2 green, 5 blue; 9 green, 6 red, 6 blue
Game 18: 8 red, 6 blue; 4 blue, 19 red; 4 blue, 9 red; 9 blue, 10 red; 2 green, 9 blue, 13 red; 3 blue, 7 red
Game 19: 8 green, 2 red, 17 blue; 11 blue, 4 red, 5 green; 8 blue, 8 green, 10 red; 9 green, 4 blue, 2 red; 4 green, 10 red, 6 blue
Game 20: 9 green, 3 blue, 1 red; 5 blue, 16 green, 3 red; 3 green, 3 red; 2 blue, 1 red, 5 green
Game 21: 7 green, 1 red, 10 blue; 7 green, 5 blue, 7 red; 7 green, 9 blue
Game 22: 5 red, 2 blue, 9 green; 6 red, 11 green; 6 green, 6 red
Game 23: 14 red, 2 blue, 9 green; 9 green, 1 blue, 4 red; 9 red, 1 green, 1 blue; 6 green; 3 blue, 1 green, 9 red; 1 blue, 2 red
Game 24: 3 red, 7 green, 6 blue; 1 green, 5 blue; 6 blue, 1 red, 2 green; 5 red, 1 blue, 4 green; 6 red, 2 blue, 11 green; 2 green, 2 red, 1 blue
Game 25: 5 green, 1 red, 3 blue; 3 blue, 6 green, 3 red; 3 red, 4 green, 1 blue; 6 green, 1 blue, 9 red; 2 blue, 2 red, 1 green
Game 26: 3 green, 4 red, 12 blue; 2 red, 1 green, 15 blue; 7 red, 16 green, 4 blue; 11 blue, 11 green, 3 red; 8 green, 15 blue, 10 red
Game 27: 9 red; 10 red, 2 blue; 3 red; 8 red, 1 green, 2 blue; 1 red, 2 blue; 1 blue, 4 red
Game 28: 5 blue, 8 red, 5 green; 10 blue, 4 red, 5 green; 8 red, 14 blue, 10 green; 10 blue, 4 red, 1 green; 5 red, 17 green, 4 blue
Game 29: 16 green, 11 red, 5 blue; 11 red, 14 blue, 13 green; 13 blue, 8 green; 3 red, 18 green, 15 blue
Game 30: 2 red, 4 blue, 8 green; 6 green, 2 red, 2 blue; 6 green, 6 blue, 2 red
Game 31: 2 red, 1 blue, 16 green; 10 green, 1 blue, 7 red; 1 blue, 14 green, 7 red; 2 blue, 1 green, 1 red; 6 red, 13 green; 2 blue, 6 red, 10 green
Game 32: 4 green, 4 blue; 1 green, 5 red; 6 green, 1 red; 3 green, 5 red, 2 blue; 4 red, 1 blue, 4 green; 6 green, 2 blue, 6 red
Game 33: 5 blue, 2 red, 1 green; 5 blue; 1 blue, 1 green, 10 red; 8 red, 3 blue, 1 green
Game 34: 15 blue, 7 green; 12 green, 17 blue; 10 blue, 11 green; 1 red, 5 blue, 9 green; 2 red, 10 blue, 11 green
Game 35: 2 red, 6 blue; 2 red, 5 blue, 4 green; 2 red, 8 green, 10 blue
Game 36: 4 red, 9 green, 3 blue; 4 red, 6 green; 6 red; 11 red, 4 green
Game 37: 3 blue, 12 green, 14 red; 3 red, 5 green, 7 blue; 2 blue, 2 green, 16 red
Game 38: 17 blue, 16 red, 8 green; 4 green, 17 blue, 4 red; 8 red, 7 blue, 6 green; 2 blue, 9 green, 17 red; 10 blue, 8 green, 11 red
Game 39: 10 blue, 1 red, 4 green; 4 green, 4 red, 6 blue; 11 blue
Game 40: 5 green, 17 blue; 11 blue, 4 green, 7 red; 2 green, 6 red, 13 blue; 7 blue, 12 green, 16 red; 15 red, 3 green, 8 blue; 12 green, 3 blue, 12 red
Game 41: 13 blue, 3 red, 1 green; 2 green, 10 red; 1 blue, 5 red, 3 green; 5 green, 16 blue; 9 blue, 2 green; 14 blue, 4 green, 5 red
Game 42: 2 blue, 15 green, 3 red; 3 red, 17 green; 6 red, 1 blue, 8 green
Game 43: 8 green, 9 red, 3 blue; 1 blue, 13 red; 5 red, 1 blue, 6 green; 2 red, 2 blue; 17 red, 2 blue, 6 green
Game 44: 10 red, 3 blue; 10 blue, 5 green; 4 red, 4 blue, 1 green; 16 blue, 6 red, 7 green; 3 green, 12 blue
Game 45: 12 blue, 2 red; 2 blue, 3 red, 2 green; 8 blue, 3 green; 4 green, 8 blue, 5 red; 3 red, 2 blue, 1 green; 1 red, 2 blue, 7 green
Game 46: 1 blue, 11 red, 6 green; 2 blue, 11 red, 6 green; 8 red, 5 green
Game 47: 2 blue, 9 red; 1 green, 5 blue; 10 red, 2 blue, 2 green; 10 red, 3 green, 3 blue; 3 red, 6 blue, 2 green; 1 red, 1 green, 5 blue
Game 48: 1 red, 7 green; 1 blue, 10 green, 5 red; 4 red, 8 green; 10 red, 10 green; 2 red, 16 green; 11 red, 14 green, 1 blue
Game 49: 1 red, 1 blue, 5 green; 6 green, 5 red; 3 blue, 4 red, 3 green; 3 red, 5 green, 2 blue; 3 blue, 3 red
Game 50: 17 red, 1 green, 7 blue; 4 blue, 1 red, 5 green; 10 red, 13 blue; 17 red
Game 51: 2 red, 1 green; 1 green, 10 blue, 2 red; 5 red, 1 green, 7 blue; 7 blue, 1 red; 9 blue, 5 red, 2 green
Game 52: 8 green, 1 blue; 14 green, 1 red; 10 green, 1 red
Game 53: 17 green, 6 blue; 17 blue, 9 green; 1 red, 12 blue
Game 54: 4 blue, 7 red, 9 green; 7 red, 2 green; 14 green, 10 red, 3 blue; 9 green, 6 blue, 5 red; 2 blue, 3 green, 11 red
Game 55: 11 green, 4 red; 14 green; 3 red, 3 green; 3 green, 4 red, 1 blue; 15 green, 6 red, 2 blue; 4 red, 3 blue, 15 green
Game 56: 8 blue, 5 red, 9 green; 11 green, 5 blue, 6 red; 1 green, 1 blue, 7 red; 7 green, 4 red, 1 blue; 9 blue, 5 red, 1 green; 5 red, 2 blue
Game 57: 11 green, 19 blue, 5 red; 15 green, 5 red, 18 blue; 16 green, 5 red, 10 blue; 19 blue, 3 red; 9 green, 8 blue
Game 58: 4 blue, 12 green; 11 green, 4 blue; 6 blue, 6 green; 1 red, 2 green; 11 green, 3 blue; 13 blue, 6 green
Game 59: 10 blue, 1 red; 1 green, 4 blue; 4 blue
Game 60: 7 red, 2 green, 6 blue; 1 green, 13 red, 12 blue; 9 blue, 9 green, 8 red
Game 61: 7 green, 3 red, 2 blue; 1 red, 1 blue; 5 green, 3 blue; 4 blue, 1 red, 4 green
Game 62: 1 green, 8 blue, 6 red; 7 blue, 3 red, 12 green; 2 blue, 7 red, 6 green
Game 63: 3 red, 2 green; 3 green, 4 blue, 9 red; 3 blue, 3 green, 16 red; 4 red, 1 blue
Game 64: 10 red, 2 green, 15 blue; 4 red, 14 green; 6 red, 14 green, 2 blue
Game 65: 11 red, 14 green, 5 blue; 7 blue, 14 green, 15 red; 1 blue, 14 green; 4 green, 4 blue, 7 red
Game 66: 6 blue, 9 green, 6 red; 6 blue, 2 red, 4 green; 3 blue; 8 blue, 5 green, 8 red; 17 blue, 11 green; 12 green, 11 blue, 4 red
Game 67: 8 red, 4 blue, 6 green; 4 blue, 8 red, 2 green; 1 green, 6 red, 2 blue; 10 red, 1 green, 2 blue; 1 blue, 5 red; 2 red, 1 green, 2 blue
Game 68: 10 green, 9 red, 13 blue; 2 blue, 2 green, 4 red; 11 red, 13 blue; 4 green, 2 red, 8 blue
Game 69: 16 red; 12 red, 1 green, 4 blue; 1 green, 14 red, 9 blue; 12 blue, 2 green, 13 red; 14 red, 2 green, 10 blue; 11 blue
Game 70: 1 red, 19 green; 4 blue, 6 green; 12 green, 2 red
Game 71: 9 green, 2 blue, 3 red; 5 red; 1 red, 1 blue, 5 green
Game 72: 1 green, 19 red; 12 red, 1 green, 1 blue; 16 red, 6 blue; 14 red, 7 blue; 11 blue, 1 green, 13 red; 16 blue, 4 red
Game 73: 1 green, 1 red, 2 blue; 8 green, 2 red, 4 blue; 7 blue, 7 green, 7 red
Game 74: 1 blue, 1 green; 1 red; 1 red, 5 blue, 4 green; 2 blue, 1 red; 1 blue
Game 75: 8 green, 1 red; 3 blue, 1 red, 5 green; 12 green
Game 76: 8 green, 6 red, 2 blue; 7 red, 1 blue; 2 blue, 9 green, 1 red; 8 red, 13 green; 12 green, 2 red; 7 green, 5 red
Game 77: 3 blue, 1 green, 10 red; 13 red; 1 blue, 13 red, 1 green
Game 78: 2 red, 3 green, 14 blue; 3 red, 16 blue, 6 green; 3 blue, 3 red, 9 green; 4 blue, 11 green; 6 green, 2 blue; 2 red, 10 green, 11 blue
Game 79: 5 green, 10 blue, 2 red; 16 green, 15 blue, 1 red; 1 red, 11 green; 1 red, 11 blue, 16 green; 7 blue, 18 green
Game 80: 9 blue, 10 green; 13 green, 9 blue; 1 red, 5 green, 5 blue; 13 green, 5 blue, 1 red
Game 81: 9 green, 15 red, 11 blue; 11 blue, 9 red, 5 green; 2 green, 11 blue, 19 red; 14 green, 15 red, 5 blue
Game 82: 4 green, 6 red, 13 blue; 5 blue, 5 red, 4 green; 2 green, 7 blue
Game 83: 12 blue, 8 red; 6 red, 1 blue, 1 green; 7 red, 1 green, 1 blue; 6 red, 1 green, 9 blue; 10 blue, 3 red; 1 red, 5 blue
Game 84: 9 blue, 13 red; 8 blue, 1 green; 9 blue, 1 green; 3 blue, 5 red, 1 green
Game 85: 14 green, 5 blue, 8 red; 1 blue, 5 green, 1 red; 10 red, 7 blue, 17 green; 3 blue, 6 green; 6 red, 5 blue, 4 green; 5 blue, 4 green, 6 red
Game 86: 14 red; 20 red, 3 blue; 1 green, 12 blue, 15 red; 16 red, 13 blue; 13 red, 12 blue; 2 blue, 20 red
Game 87: 2 blue, 2 red, 10 green; 8 green, 9 red, 1 blue; 11 red, 1 green, 4 blue; 13 red, 1 blue; 11 green, 16 red, 3 blue
Game 88: 5 green, 4 red, 1 blue; 3 blue, 8 red, 10 green; 11 green, 7 red, 4 blue; 11 green, 5 blue, 4 red; 9 red, 9 green; 4 blue, 6 green, 9 red
Game 89: 2 blue, 2 red, 5 green; 2 red, 2 blue, 3 green; 2 red, 1 blue, 7 green; 6 green, 1 red, 2 blue
Game 90: 4 green, 1 blue, 5 red; 2 blue, 2 red, 10 green; 2 green, 8 red, 1 blue; 10 green, 5 red; 2 red, 3 green, 2 blue
Game 91: 16 blue, 5 red, 15 green; 4 green, 7 red, 3 blue; 4 red, 8 green, 12 blue; 4 green, 8 red, 17 blue
Game 92: 13 red, 2 blue, 12 green; 19 green, 7 red; 17 green, 2 blue, 3 red; 6 blue, 11 red, 10 green; 6 red, 15 green, 3 blue; 6 blue, 20 green, 11 red
Game 93: 2 blue, 3 green; 1 blue, 4 red; 1 red
Game 94: 3 red, 5 green, 6 blue; 7 blue, 5 green, 6 red; 9 blue, 1 green, 2 red; 4 blue, 1 green, 4 red
Game 95: 8 green, 9 red, 2 blue; 7 green, 7 red; 2 green, 4 blue, 6 red; 6 blue, 2 red, 2 green
Game 96: 11 blue, 4 red; 1 green, 3 red, 14 blue; 2 green, 3 red, 8 blue; 7 red, 1 green, 3 blue; 8 blue, 6 red, 2 green; 9 blue, 3 red, 3 green
Game 97: 5 green, 13 red, 7 blue; 2 blue, 12 red, 6 green; 10 blue, 11 red, 3 green; 4 green, 11 blue, 15 red; 8 green, 16 blue, 1 red; 15 blue, 4 red, 5 green
Game 98: 3 blue, 1 red; 4 blue; 2 green, 1 blue; 2 green, 1 red, 5 blue
Game 99: 4 green, 3 blue, 9 red; 6 blue, 5 red, 3 green; 2 green, 4 blue, 7 red; 8 red, 4 blue; 2 green, 15 red; 4 red, 5 blue, 3 green
Game 100: 8 red, 4 blue, 4 green; 10 blue, 3 red, 4 green; 10 green, 4 red; 18 red, 9 blue, 2 green; 12 red, 4 green, 2 blue

28
2023/day03/Main.hs Normal file
View file

@ -0,0 +1,28 @@
import Data.Char
import Data.List
-- findBegin :: ((Int, Int), Char) -> [((Int, Int), Char)] -> ((Int, Int), Char)
findBegin s@((x,y), c) dict = case filter (\(p,_) -> p == (x,y-1)) dict of
[] -> s
n:xs -> findBegin n dict
main :: IO ()
main = do
inputLines <- lines <$> getContents
let distances = concat (map (\x -> (map (\y -> (x,y)) [-1..1])) [-1..1])
let numInputLines = zip [0..] (map (zip [0..]) inputLines)
let charCoords = concat (map (\(x, l) -> (map (\(y, c) -> ((x,y),c)) l)) numInputLines)
let symbols = map (\(p, c) -> p) (filter (\(_,c) -> not (c == '.' || isDigit c)) charCoords)
let digits = filter (\(_,c) -> isDigit c) charCoords
let serialChars = filter (\((x,y),_) -> any (\x -> elem x symbols) (map (\(x1,y2) -> (x + x1, y + y2)) distances)) digits
let serialBegins = nub $ map (\x -> findBegin x digits) serialChars
let serialNumbers = map (\((x,y), c) -> read (takeWhile isDigit (drop y (inputLines!!x))) :: Integer) serialBegins
-- print charCoords
-- print symbols
print (sum serialNumbers)
-- convert input to [((x,y), Char)]
-- mapM_ putStrLn inputLines

30
2023/day03/Main2.hs Normal file
View file

@ -0,0 +1,30 @@
import Data.Char
import Data.List (nub, sort)
findBegin s@((x,y), c) dict = case filter (\(p,_) -> p == (x,y-1)) dict of
[] -> s
n:xs -> findBegin n dict
uniqueLists :: [[((Int, Int), Char)]] -> [[((Int, Int), Char)]]
uniqueLists = nub . map sort
getNumber :: ((Int, Int), Char) -> [String] -> Int
getNumber ((x,y),c) dict = read (takeWhile isDigit (drop y (dict!!x))) :: Int
main :: IO ()
main = do
inputLines <- lines <$> getContents
let distances = concat (map (\x -> (map (\y -> (x,y)) [-1..1])) [-1..1])
let numInputLines = zip [0..] (map (zip [0..]) inputLines)
let charCoords = concat (map (\(x, l) -> (map (\(y, c) -> ((x,y),c)) l)) numInputLines)
let gears = map (\(p, c) -> p) (filter (\(_,c) -> c == '*') charCoords)
let digits = filter (\(_,c) -> isDigit c) charCoords
let gearsChars = map (\(x,y) -> (filter (\(p,xd) -> (elem p (map (\(x1,y1) -> (x+x1,y+y1)) distances))) digits)) gears
let gearsBegins = uniqueLists $ map (\gearChars -> (nub (map (\x -> (findBegin x digits)) gearChars))) gearsChars
let twoGears = filter (\x -> length x == 2) gearsBegins
let serialNumbers = map (\gs -> product $ map (\g -> getNumber g inputLines) gs) twoGears
print (sum serialNumbers)

10
2023/day03/example.txt Normal file
View file

@ -0,0 +1,10 @@
467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598..

140
2023/day03/input.txt Normal file
View file

@ -0,0 +1,140 @@
.......262....300...................507.....961..............668.....................189.906...........................624..................
..148.................805..130..880*...........*684.............*......*..............*..-......%.................$........17...65....91*...
......272.....464.....=......*.........................208*.....260.967.38.......692*.........676............@247..652.585.#......@......74.
.................*734........772......171.........728$.....52........................747.=866............350...........*....................
..328....21...........941......../.....*...243................429@......567$...623.................654..#.....*815....360......812%.........
..........$.....%....@....6....583.....598...&.114@...618......................+...............156.........817...../.................340....
.....883........359.....*.*..........................*............@............................./...920............302.712...........*......
........*.....*......100..192.160........791......843...680*643.252.................322...354..........*.....+.........*............556.....
.........958.580.................*.............................................879.....-..$............633...63......561.....289............
..............................745.......221..504-................356..............*827........355...............................*46.........
...................206..382...........$...........142@.105...534........./.......................*..........535.....................515.....
..201.....336.......-..*.....268..121..775...-...........%..............791.............129...449.....450..*.........790...........*........
............%.559*......7.....+..*..........865......895............930.....427..242......#...............414.830............37..809........
..................85.............466..550-..........+....................44...*...*.........361..215..........*......808.220*...............
................*......709....................577......430...&..148........*.696.988....801.*.....*..........202..25..*.....................
.....636......14...........372.............64...*...........586.%...15..241.............&....387..447...............*..811....146...........
.....-...........892*226....*....161.........%.623..................*...........$...............................................&.....657...
........987.................147.=....+.254..........887........773...321.....221....415.971..................74.......702..212..............
......@............182............335.....*...........*..77.......#......................./.....29..........%...........&..*.......872......
......643............*...................756.........677.*..........251......521..620......................................685.206.......132
............274*...........929.................871........686.542..%........*......*.......................882....756.............*859..*...
................516.........*.....................*..............*...289...10.....890..985...258...963...............*.................526..
.............................610...............857........210..818......*.......@.........#..=......*.....968.........42..........732.......
.............../..*453.................467..........376......$..........429..218.....................955..%..............357................
.......841....493..............830#.......*342.........*........*................./....562....945................224.......*..435...........
..................843.803......................2........56...248.560.............281.....*.......*.........-........*5....728..*......156...
...822*288....352.*...+..............$.........$........................@..............794......539..-814..528.81.......+.......687.....*...
................*.783..../454.859....809..742........................663...267/..................................*.....847..............167.
....&371.296.484..............*..........=...........516.......925...............................#................441...............224.....
.........#............594..417....458............112*.....65.....#.....337...357....#..369*277.825....386..................212..............
................651..#...........*.....$..................*............*.....*...125...................*......497.........*..............509
......320..........*......-...883..989..733.....668.905...997.......454.....353...........946....18.....340...&......515...774........*.....
......-.....880....476...955.......=................*...........58.....................23....*69.+..102..............*.............933.687..
........931....*..............................757....602.983......-..822..............*.............*.......732.....15......................
....../....*....463.............183$..961........*.......*....#...........572......618.............52..........@........205......*....&429..
...204......550............-.........%.........628.....240..588............*................................/..........*......167.776.......
................360....*....69..........*..........534..................%..340.....................885*912..52......949.....................
.........483......*..46.754......-....607.346.....*..............851.302..................@....................-........330.-201............
.........@...274.811..............819...........56......326......................496....650...........382......168.420...*.........452......
..............#........325.449........581...........112*........................+............163.......*.................407.......*...460..
......595.........*......*...................226+.................268..153.........#123........*.....$..877..........#..........361...*.....
......*........280.287.427...........755...........................%.........................722...323................307...................
..132.553...............................*.......117......450.109...............849.....749.................................105..537#..741...
...*.................................788.......*....691...%...$............148.....960..*....512.728#..544.624.....$......*.................
.523..97...186..907....508....................739......*................*.....*856.&....15..................$.....911.......&..877..632.....
..............*.*.........*.........161*....+........381.............453.376..........................30..................806.......*.......
............560.877...773...............168..446..............465..............435@..24..622...%.................................=..347.....
...*165................-.......................................*......@816..............*....313..421......269....539.49.530..113...........
768......*626.926....=.....676...981=............703.........682.&141....................444......=........@.........*......*......539......
......159.......$..362......../.......254.....14..=...............................219.................383.........*......182.............733
.324........879.....................*.=...............316.....*480......*............*............439*.........621.961.......*481...........
....*...208*...........188.......763.....553...........*...957.......771.944........445......4...........375..............174.....903.665...
.................651........851.......37*...........303.................................446......61......*......346................@...*....
......160....412*......../.....=.220.........354.........-.....838...........473..........#........$.870.......*............*........391....
.....*....................218.....*.............*.....739..320*.........358....*...521......383.........*.....27...........107..............
...969...718..................+....200.534.237+..........................=..889....*..........@........396.......................103..243...
........&..................841...-......&........./748...655..325.................430............813.................618.....687...#..@.....
..........825...761............800......................*....&...........496............652...$..*...............206..*.....................
...................+....&584.........35..663*590.....677...................*........741*....908...293..918............570....$......%.......
...........794.......................&...................852*...........361...............-.................................502.769.82......
..535.......$............523*522................-..............847..........593..........267.....................................*..........
....*...........73...............................299..262..941*..................813..............682..........877........494...411.........
..528................*997....*...477........464.....................521........@....*315......#...=..............*..........................
............669...909.......342..*...........*..........444@...@.....-..611.911..............864......114....555..628..890..................
............*.....................444.....921................783.......*.......................................*........=...414.............
..........622..................................422..-...............404......&906..381............438..........605.........@.....389.352@...
....77.........519...282........720.....159=..*....87......225.605......125...........+.............*..860-......................=..........
...$...556.......-.....*..........#..........479............&....*.........*967...343..............400...........*883..................*881.
......*............207.653....113...359............227............357............*..........771...........426.905..............313..563.....
...74..233....959../.........*.........&............*...#.................543..64..*....179................*........@.............*.........
.....*..........*.......707.341..........&489.....206..132..407..........*........224..*................310........255./.........136........
...251.......770........................................................475.............694....514.....................236..................
........944........-379...............403.....934......47........................................*..............694........359..............
732.............14..........*..........*.........*.................720....325..............375.483.............*.....356&..............686..
.......160..672*.........250.125....791.....&76...1.....&963...422..#........../....191......*................925..........771...405&.-.....
...205....%......402................................117........*.........887....509..........44.....417.................=.-.................
...................*............=..145......746.......*........861..804....*.........313...............*....*.........761.......638.........
..852..767.....#67.835......$.359..*..................789.@................675.938.............957..........459.652..............*...949....
........*.................977.....779.......348...627.....136.........+623..........964.............948+..........*.................=.......
........882......+............................./...#...............................*......311...152.......186......233.......374.......989..
..148.........125.....931......706%....#...379.........................181.......227..........*..........*..............581..*..............
.....*..179..............*.............970.../.......605...........736*......................700......970.................*.........+.487...
....209...*..............810....790..............787*......................#...+....-...824......587......709*.....899.....283....324..*....
...........50...750............./.......633...............................364..66..593./......................115......-..............561...
...................#......989..............*217.......................620...........................................740.....*361....+.......
..........266.........647*....$..992....*...........318...345...........*..............-........252..797.................354........8...110.
.............................375.....344.334.......*.......*..........460......558.....364.......#..$...........@....%..........3...........
...$14...314...652...............................626............%...................%.....................778....868..215...................
...........&....*.......$........241.................*796....552..738..#234...@....358............993....*..................................
................594..230..-..647*.....&............56.............*............479.....921..............519................426......713.....
.....944*................404........53..349....$........459......986..+......=..............-666..............237...897#..*........&....755.
.........176........280......714..........*..876.268...*.............946.492.113..........*..............................855................
.....................*........*...936..................973.................*............736.......844.659....652.@............266...547.....
...677......@........426.....89........./...................185..........630.285............196...../....*...*....349....102....*....*......
........765..677................*..46....85.901.....*...440...................../..........*.............304..952............1........507...
...........=.........669......847....*........*..821......*.301.......880.................829.951.460....................876................
.................466*......*.........69.....207.........419...*...................442............*...........-.....898.....=.667............
....421.56=................318....................................178...............+...............896*855...522..&..........%....151*405..
....*.......481-...70*401..............550...................*.......*296...91........998.566..112..........................................
...235.472..............................*......962....963.935...921.........+.....................-...........168.....=516.304...416*699....
........#...*10.................240=.....687..*...................*.475..-...........697.......................*..............*.............
..261.....47.......750....954.........=......274........-...203.570....*..71...........*...484..*.....%61...397..854...#.......523.....931..
..............34............$....%.....500........216.647............271.......908....906.......488...............*..92..634................
..........83*....................994.......511.55*........991...16.........417*....*......96...................697.................&........
.............582.450=.....................................=.....*...............654.411........313..................29.........32.849.......
.......563..............239.........&.............405............193......+.411.........%......*...&.....623.........$....+748..=.....840...
..........&......#.......-....761....639.275+.......*...................69..$....../.233..@..88.....226...*.....366................../......
.............248.16............/...............+...556...........306............354......308..............682.../......894...#..............
..697.......*.........@..........959...125....297.......................*337...................72....108...............*......991.344....781
...*.......715...49.392.........*.......*................652/........#.......55*.......................-.844......./..344..........-........
...591....................334.701.......838.......................397....501....759.....-.........................946.......442.............
..................557*421...@.....749........500..........#170..........%............941..373....425..818.......................828.....237.
..793*144...........................$.302....*.....938*..................................*..........*....%.378........66..63...*............
............474...............893............267.......810................585..........558.......694......../.................340.701.......
..............#..798......332*.....855.....................592.589........&.....833=.........199......730.......+......177..................
.................*..................*.........................*........................#.......*......*.....154.589...*.....................
.....64*809........../............@.139............228..374....../.......771.........534........281...........*......506.......=............
..............427.750......546...98............707..=......&..381..877..*..........*........6.........%......489.........../.795............
...895.805*.....*.....................*694....=........848...............616.....69.86.....*..460......895.......544.....651.......14.886...
...........390...850..777.534..138..52..........570....@.........812.$71................795.......557............-.....................*....
..46*41...............*...........*................@.........613*.................584.......=........*...............106*....627.602....829.
........217*380.............721..928.873...........................593..353...............341..430..989..923.............695......-...%.....
..................586.......$.........*...207.......585&......485..*...*..........................*......*..........................929.....
............#.154*.....60.............95.......................*..138.764..........................425.275......%.331*664..854..........887.
908.917..359........../........659........125..785...........499..........991....358..........102*...........903..........*.....409....-....
...*.........963*.../......408.............%........830*871...............*......*...828..........764.671................293...*............
....................559....=..........81............................391...969.513....*.......991........&..518.....208*.......75............
.....461.560*......................../........950.........320%.....*................97........................#..........+675.....352...339.
......*......439.%101.709...302.870......838....@.....594........953.......514*862........339....................................*..........
...247...................@......*.................312....#.................................-...271..800...@..818.850....333*722...330..951..
........922.................184.666.............../..........................356...105.........#...*.....353./........................*.....
832.....-.......758...800....$......................337.......419...........=.......*...258........926.........................../592..186..
...................+...........220.287...117....783......646..#.........451........750..........27.....$.......*750......890................
........719............982....%.......*..*.........*144.*..................*...........*764./.....*373..368.201..........@..................
......../..........388....*........115...432.............594............345..658$...442......833.................408.........=..........542.
..........27.#498..*.....286..+490...............................966.....................262.......................#..542.237...............
72....251..#.......667.....................282..556..260...........%.$......................*....107..................*.....................
.......*.......*..............................*..-...*...............64..#...=.....402..@....790.@.....................295.766...484..969...
......85....882.80.......184$................117........................454..583......*..351...............266....................&....*....
.......................................................48...........................436........275...................869............258.....

20
2023/day04/Main.hs Normal file
View file

@ -0,0 +1,20 @@
import Data.List.Split (splitOn)
getGame :: String -> String
getGame s = tail $ dropWhile (/= ':') s
splitGame :: String -> [[String]]
splitGame s = map (\x -> filter (/= "") (splitOn [' '] x)) (splitOn ['|'] s)
calcPoints :: [String] -> Int
calcPoints w = round $ 2^^(length w - 1)
main :: IO ()
main = do
inputLines <- lines <$> getContents
let games = map (\x -> splitGame (getGame x)) inputLines
let wins = map (\[w, cards] -> filter (\card -> elem card w) cards) games
let points = map calcPoints wins
print (sum points)

26
2023/day04/Main2.hs Normal file
View file

@ -0,0 +1,26 @@
import Data.List.Split (splitOn)
getGame :: String -> String
getGame s = tail $ dropWhile (/= ':') s
splitGame :: String -> [[String]]
splitGame s = map (\x -> filter (/= "") (splitOn [' '] x)) (splitOn ['|'] s)
calcPoints :: [(Int, Int)] -> (Int, [(Int, Int)]) -> (Int, [(Int, Int)])
calcPoints dict (num_cards, []) = (num_cards, [])
calcPoints dict (num_cards, this) =
let new_wins = map (\(i, w) -> take w (drop i dict)) this
in calcPoints dict (num_cards + length new_wins, concat new_wins)
main :: IO ()
main = do
inputLines <- lines <$> getContents
let games = map (\x -> splitGame (getGame x)) inputLines
let wins = zip [1..] (map (\[w, cards] -> length (filter (\card -> elem card w) cards)) games) :: [(Int, Int)]
-- let points = map calcPoints wins
print (calcPoints wins (0, wins))
-- print (wins)

6
2023/day04/example.txt Normal file
View file

@ -0,0 +1,6 @@
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11

208
2023/day04/input.txt Normal file
View file

@ -0,0 +1,208 @@
Card 1: 57 76 72 11 8 28 15 38 54 46 | 77 87 71 98 40 7 84 43 61 64 5 50 19 83 79 99 36 47 4 95 30 44 37 55 26
Card 2: 44 69 14 83 54 48 21 6 20 26 | 80 26 86 3 9 4 62 34 15 87 60 88 90 29 65 46 92 73 24 12 40 10 99 37 74
Card 3: 15 60 63 84 20 93 36 39 17 19 | 68 80 17 91 20 84 69 72 15 39 5 61 74 99 60 85 19 45 24 79 53 36 7 63 93
Card 4: 22 74 83 58 88 46 7 52 84 5 | 75 20 95 8 37 56 31 42 73 43 40 48 4 28 99 45 90 63 81 93 68 50 46 30 7
Card 5: 4 97 41 50 32 26 68 84 5 11 | 91 70 87 4 88 13 48 51 32 34 38 82 86 11 1 50 40 43 28 5 61 89 84 41 37
Card 6: 79 97 39 26 57 69 38 87 60 44 | 22 92 80 38 27 66 54 2 9 62 3 4 71 99 24 97 14 7 93 28 53 50 77 68 73
Card 7: 73 91 51 23 90 67 19 81 50 12 | 4 76 97 64 19 85 31 3 74 12 23 60 20 68 52 39 43 65 37 63 40 59 99 80 6
Card 8: 23 64 38 82 68 79 49 56 5 76 | 68 25 64 30 40 52 16 53 95 96 85 9 4 7 26 80 62 67 73 35 32 44 90 69 93
Card 9: 75 87 69 31 8 11 89 49 95 24 | 35 26 68 69 42 66 37 77 25 45 75 72 38 50 27 24 32 46 11 10 14 95 62 7 86
Card 10: 37 25 47 36 57 81 44 6 79 98 | 67 34 86 70 39 97 80 69 27 17 7 50 99 84 45 32 49 53 15 95 19 18 47 37 41
Card 11: 87 98 16 76 21 53 8 42 40 75 | 21 7 89 85 65 30 32 19 68 22 64 82 48 62 39 46 4 57 77 18 55 24 34 29 67
Card 12: 60 11 44 35 9 56 93 91 15 32 | 31 45 37 63 26 12 15 14 48 92 81 1 97 65 29 95 57 77 99 93 27 25 58 66 61
Card 13: 25 75 5 60 47 83 8 37 2 43 | 52 30 68 13 1 92 89 63 78 57 87 75 28 82 59 46 33 3 65 41 47 69 21 2 96
Card 14: 64 44 89 88 1 38 20 99 9 81 | 71 68 91 21 92 75 49 22 27 12 9 26 57 13 66 45 40 37 16 4 44 90 98 85 61
Card 15: 16 56 91 62 12 83 25 3 70 61 | 81 55 73 96 13 7 67 99 88 90 87 48 83 35 19 97 9 31 20 49 38 44 41 45 5
Card 16: 78 68 81 18 76 41 88 45 24 87 | 59 84 67 36 33 57 42 32 11 74 65 31 54 46 72 39 98 40 16 49 79 19 3 44 22
Card 17: 84 11 48 66 54 86 28 4 45 23 | 4 54 42 62 81 8 92 45 47 66 84 48 18 72 28 86 23 34 3 24 73 82 96 11 59
Card 18: 46 40 41 22 75 92 68 10 52 3 | 84 73 9 22 7 19 3 65 32 6 99 77 97 63 62 59 57 17 8 68 91 28 39 4 41
Card 19: 19 57 22 85 75 69 50 62 65 61 | 35 24 50 47 74 97 61 27 66 57 77 75 22 30 70 41 62 69 85 58 81 65 19 91 63
Card 20: 18 13 96 41 20 44 62 97 57 52 | 18 59 96 40 23 58 20 57 41 97 44 62 75 54 85 78 94 52 64 34 37 45 84 13 53
Card 21: 34 3 13 85 81 19 37 97 29 91 | 9 97 52 3 35 48 24 34 17 50 21 71 57 36 94 82 19 4 14 83 98 37 80 91 59
Card 22: 18 14 95 74 23 71 31 83 51 57 | 94 14 63 18 16 73 57 31 5 23 51 69 85 45 70 35 74 49 79 27 40 95 83 13 71
Card 23: 54 12 52 31 58 93 9 45 27 64 | 48 54 93 12 44 64 56 83 35 94 33 4 58 89 8 45 27 1 86 90 52 31 19 57 9
Card 24: 56 75 17 67 59 37 76 94 25 36 | 24 14 56 53 82 35 92 96 17 34 25 1 16 86 41 95 64 45 38 63 31 18 80 33 66
Card 25: 32 22 47 24 80 92 96 67 5 26 | 22 81 87 47 26 96 92 60 57 64 66 16 5 83 67 49 32 39 71 80 40 63 99 75 53
Card 26: 62 36 66 9 3 71 75 67 29 61 | 9 31 66 82 29 41 67 71 38 36 28 76 14 75 69 61 99 57 62 88 70 95 63 10 59
Card 27: 46 38 59 90 1 65 16 80 76 34 | 70 15 49 31 27 71 54 46 76 1 8 77 93 2 90 39 14 67 62 16 78 56 68 9 58
Card 28: 47 85 54 21 37 14 44 73 12 51 | 78 70 14 77 98 88 25 49 9 79 58 23 52 2 43 17 12 84 59 51 56 89 47 48 6
Card 29: 74 37 60 11 56 21 87 44 33 46 | 80 61 34 54 9 3 45 7 55 13 98 84 10 19 14 8 90 81 50 69 31 12 38 29 78
Card 30: 29 20 44 62 79 34 52 15 49 48 | 17 84 34 1 33 9 23 55 94 10 95 69 42 79 78 44 51 82 20 25 81 29 15 13 32
Card 31: 88 41 38 98 34 40 92 36 25 50 | 33 54 18 53 46 69 8 22 25 36 51 34 42 92 85 45 40 60 84 27 97 39 10 70 41
Card 32: 5 28 85 29 95 37 60 34 24 16 | 74 8 48 73 34 65 66 56 64 85 78 17 39 67 92 30 75 22 95 12 29 24 6 2 51
Card 33: 71 31 99 53 62 80 65 32 13 23 | 87 20 55 24 42 19 67 77 37 89 32 83 44 9 60 46 47 36 49 35 92 10 82 2 81
Card 34: 78 61 12 81 96 82 7 30 80 32 | 62 8 56 89 11 12 39 31 17 18 79 51 30 92 48 5 45 78 41 44 77 98 71 67 73
Card 35: 59 35 63 76 51 8 53 70 24 97 | 20 36 31 17 77 26 34 15 41 39 61 24 35 46 80 74 2 71 5 91 16 11 55 87 4
Card 36: 46 51 79 66 57 52 21 11 75 33 | 88 64 74 99 22 39 42 11 14 65 1 56 86 8 26 16 72 13 55 20 60 40 19 85 58
Card 37: 83 88 1 19 95 30 38 43 14 51 | 98 20 22 55 13 58 93 21 68 11 76 70 71 35 44 90 52 53 75 17 96 27 49 31 26
Card 38: 87 49 43 19 16 34 88 66 67 9 | 70 46 63 58 7 53 96 1 59 35 91 85 18 21 93 68 90 73 11 92 60 61 98 38 15
Card 39: 24 68 25 61 54 63 30 37 21 73 | 50 84 48 10 81 5 62 28 92 66 96 6 20 83 78 88 31 89 12 71 60 8 34 70 90
Card 40: 18 72 44 15 3 19 69 63 73 57 | 14 3 52 76 71 12 50 13 86 21 55 31 27 29 43 47 90 75 9 97 6 32 96 37 18
Card 41: 81 66 49 20 86 80 4 55 93 44 | 87 81 7 47 25 85 80 51 76 27 78 10 16 50 33 66 13 64 35 18 44 63 29 92 48
Card 42: 27 21 14 28 69 89 94 9 19 46 | 92 13 27 99 96 19 43 54 4 14 45 16 44 83 24 61 2 28 5 90 49 51 63 64 73
Card 43: 34 49 58 85 23 88 84 78 89 55 | 72 45 73 23 75 52 84 78 46 55 58 71 98 5 56 91 49 39 88 70 42 59 89 85 34
Card 44: 18 69 46 58 73 59 56 23 12 40 | 71 23 87 93 21 84 10 79 47 92 91 13 52 1 32 78 59 95 72 55 97 56 43 61 75
Card 45: 33 47 58 69 57 1 82 6 61 48 | 48 97 4 1 67 66 82 12 6 29 21 96 90 33 57 28 47 69 74 27 2 32 58 61 9
Card 46: 42 54 98 50 36 86 27 66 29 60 | 32 23 40 62 38 91 43 98 29 85 18 30 66 28 81 35 68 61 11 27 50 22 41 46 42
Card 47: 1 31 87 71 53 17 5 93 84 56 | 48 26 14 47 34 44 18 93 17 88 61 8 95 74 53 50 56 80 62 84 99 49 87 52 1
Card 48: 40 75 79 29 64 57 33 49 95 68 | 7 39 63 79 89 10 23 40 22 86 92 13 57 29 9 19 90 87 58 12 77 16 75 4 91
Card 49: 4 45 87 47 71 35 9 2 81 77 | 93 33 49 75 11 34 62 39 83 40 55 17 84 43 80 60 46 7 18 56 48 66 95 57 74
Card 50: 88 42 2 30 24 89 15 93 16 45 | 93 45 72 68 30 28 17 82 64 91 29 98 14 24 88 70 55 48 58 10 42 83 66 2 77
Card 51: 91 96 87 48 6 73 95 55 71 89 | 94 49 84 33 82 9 21 32 25 46 65 15 86 83 66 11 37 1 14 61 92 36 35 45 27
Card 52: 48 3 94 56 41 13 34 8 96 25 | 40 88 46 14 68 25 75 66 87 55 64 78 92 43 19 97 53 90 83 59 69 31 84 95 13
Card 53: 13 45 61 92 91 32 49 58 43 36 | 44 70 55 28 2 6 35 79 24 54 82 95 52 73 75 84 34 57 21 23 33 22 80 88 1
Card 54: 61 52 20 8 73 54 83 60 29 6 | 74 40 27 46 81 75 3 42 47 69 22 59 58 49 90 63 57 50 79 70 82 5 53 91 39
Card 55: 41 51 64 55 57 44 26 70 62 34 | 24 82 49 39 56 84 31 27 86 77 22 6 73 72 99 47 60 18 53 68 42 19 66 9 50
Card 56: 30 89 82 17 72 46 98 5 54 58 | 4 86 18 15 84 41 16 63 44 91 12 31 66 96 94 87 49 59 67 64 80 33 5 11 40
Card 57: 39 80 17 47 15 96 69 50 46 24 | 5 83 16 52 57 27 98 43 78 1 66 90 19 6 58 3 49 94 85 62 44 54 75 14 9
Card 58: 42 77 37 13 74 40 31 92 36 46 | 16 74 80 59 51 31 95 85 40 93 23 15 32 18 46 97 36 13 79 10 37 99 77 25 92
Card 59: 39 1 78 7 57 46 91 26 12 94 | 46 13 26 83 21 1 67 78 50 94 8 12 39 61 86 91 35 29 32 72 30 97 57 16 7
Card 60: 62 32 18 51 40 96 93 36 80 84 | 42 93 65 8 2 52 84 70 11 1 92 21 80 99 18 14 17 47 56 90 49 67 19 48 97
Card 61: 6 83 74 89 44 73 39 42 47 88 | 72 74 42 21 88 77 18 6 83 85 49 73 5 39 78 44 64 10 47 14 89 53 98 13 92
Card 62: 91 86 35 23 30 28 77 88 56 41 | 54 26 90 20 96 78 14 5 47 98 31 55 74 83 33 15 67 92 19 40 73 72 52 81 94
Card 63: 87 91 78 92 33 71 80 47 13 65 | 32 33 56 55 2 4 61 71 91 97 93 78 83 74 3 13 47 70 54 80 65 60 49 26 96
Card 64: 70 61 63 52 32 35 85 46 54 4 | 42 54 32 84 56 46 29 61 63 78 4 36 80 86 26 17 3 87 48 21 85 52 35 70 22
Card 65: 83 95 45 97 49 67 13 92 1 90 | 68 75 20 96 6 33 73 1 50 14 17 66 34 78 54 84 92 9 64 61 85 88 72 42 12
Card 66: 1 7 99 75 17 21 48 70 30 13 | 70 80 45 89 75 7 21 99 20 54 42 46 67 85 61 17 1 16 30 92 77 48 13 68 90
Card 67: 69 55 20 91 47 31 33 75 56 39 | 69 31 62 20 58 1 93 48 35 55 47 13 56 60 50 75 25 37 91 81 10 39 32 33 54
Card 68: 14 97 54 28 73 64 81 32 47 17 | 86 48 88 25 47 65 22 81 28 95 41 14 27 26 46 64 79 61 45 96 32 9 21 54 53
Card 69: 6 21 89 82 75 48 46 56 68 47 | 48 32 74 30 13 56 93 90 68 33 41 58 21 47 8 17 65 6 89 97 75 82 46 26 59
Card 70: 35 48 78 92 64 30 88 77 76 10 | 76 33 48 67 78 64 24 69 36 14 77 85 30 73 53 91 3 35 96 88 43 84 10 95 92
Card 71: 59 78 57 66 15 18 41 83 70 35 | 7 62 19 30 48 97 89 71 40 27 11 63 60 47 23 86 10 84 4 75 80 69 61 67 25
Card 72: 80 82 46 70 10 14 55 49 62 9 | 31 76 62 17 8 49 19 50 85 72 77 75 42 48 33 60 54 45 12 91 20 92 15 3 25
Card 73: 38 83 96 47 42 99 13 82 36 85 | 74 86 59 16 49 45 81 61 44 39 3 91 9 26 35 25 55 21 19 41 90 70 10 29 4
Card 74: 92 36 96 65 24 6 98 13 33 86 | 17 83 30 5 46 51 54 81 44 99 33 56 45 14 57 34 8 16 77 48 40 94 82 73 75
Card 75: 14 21 57 66 33 8 90 7 4 28 | 91 61 3 84 89 45 60 56 51 10 58 20 96 78 73 93 97 44 19 15 12 90 35 87 42
Card 76: 37 91 60 44 43 3 40 33 95 51 | 24 39 81 1 46 83 97 88 87 6 67 40 22 96 93 2 71 33 29 15 41 16 89 21 68
Card 77: 91 84 43 9 87 96 37 64 41 31 | 35 13 30 43 78 32 23 85 84 19 88 68 10 63 27 77 61 50 41 94 54 12 97 86 33
Card 78: 9 78 53 16 80 56 91 3 62 70 | 85 64 21 88 51 16 15 4 69 30 13 1 70 17 52 23 90 5 24 50 19 81 41 67 12
Card 79: 59 28 42 51 66 58 63 9 24 47 | 69 95 26 36 14 62 13 20 35 25 34 74 40 41 9 39 45 77 5 10 55 96 22 81 49
Card 80: 72 83 73 23 85 2 53 22 3 43 | 14 50 67 63 19 76 39 60 31 33 62 92 29 12 49 75 69 78 44 8 96 95 34 65 20
Card 81: 2 46 29 50 65 57 55 83 74 12 | 4 70 97 54 68 99 81 5 84 10 73 61 88 66 27 8 56 33 79 47 85 49 17 16 34
Card 82: 37 30 10 3 8 34 44 24 57 13 | 42 17 25 65 48 71 4 64 51 83 75 27 72 96 45 18 11 15 70 53 91 14 12 87 59
Card 83: 82 81 15 4 54 96 74 72 37 70 | 37 78 72 25 4 66 81 97 6 83 43 96 61 44 15 71 40 54 27 70 82 98 74 93 7
Card 84: 97 52 96 23 80 53 57 83 16 62 | 5 31 89 91 84 33 52 83 76 23 64 67 10 97 29 63 96 58 74 53 62 57 80 81 92
Card 85: 53 33 76 24 81 68 51 47 40 89 | 70 38 51 50 85 57 89 40 30 61 1 24 54 75 32 33 96 19 14 53 76 20 7 99 47
Card 86: 19 96 52 18 15 53 82 16 86 13 | 69 27 32 85 87 30 33 83 11 47 3 21 68 70 42 61 46 2 64 65 44 1 97 48 74
Card 87: 18 40 55 62 39 95 60 11 76 46 | 82 81 22 46 92 80 62 91 12 40 76 60 69 78 17 18 11 93 56 39 37 88 3 64 95
Card 88: 72 65 91 61 57 4 49 24 45 31 | 28 49 91 31 19 59 65 36 34 87 72 24 60 89 17 12 57 30 75 32 63 8 21 4 25
Card 89: 18 24 64 43 33 56 6 67 8 16 | 40 21 27 52 3 23 65 89 16 7 96 31 48 73 33 37 18 99 12 50 74 26 71 84 8
Card 90: 75 3 92 35 12 26 49 59 60 55 | 65 58 39 73 3 56 11 44 4 47 68 24 86 10 61 6 72 13 82 42 29 93 97 77 8
Card 91: 78 40 49 75 60 15 59 7 31 93 | 71 9 48 10 69 29 65 40 21 57 68 87 12 35 81 70 30 94 36 97 51 43 8 82 5
Card 92: 3 53 23 43 15 4 98 11 67 29 | 35 3 93 87 83 60 5 92 1 90 67 23 78 98 20 37 81 71 31 82 95 47 53 75 21
Card 93: 20 61 6 36 52 77 59 16 18 81 | 66 29 4 87 61 92 78 30 68 69 67 57 88 83 71 54 24 21 13 56 84 35 60 86 53
Card 94: 25 52 87 17 94 41 23 30 72 53 | 93 62 38 77 31 24 21 36 75 64 45 83 56 39 90 29 55 43 71 54 42 98 76 74 28
Card 95: 84 66 91 8 26 82 85 96 31 36 | 93 51 40 98 69 74 53 67 86 23 77 41 62 89 64 34 5 26 50 73 42 43 13 19 91
Card 96: 7 6 90 39 14 73 66 81 33 67 | 63 26 1 58 29 10 3 13 94 9 85 68 69 19 53 96 90 36 49 99 31 74 54 45 77
Card 97: 66 64 77 7 88 18 40 24 10 63 | 28 22 62 41 30 21 19 12 50 43 46 42 56 6 60 36 95 82 97 2 73 55 38 53 8
Card 98: 48 10 16 15 93 40 37 72 57 88 | 10 59 38 19 97 23 51 40 35 31 56 54 21 27 28 81 15 67 12 57 37 65 9 22 74
Card 99: 45 57 7 23 86 82 15 14 75 35 | 55 19 84 37 82 39 15 77 42 52 44 18 75 45 7 69 67 23 86 6 89 14 43 57 35
Card 100: 68 85 29 69 17 44 19 56 92 8 | 8 4 20 98 36 39 78 79 72 81 51 22 13 47 2 77 30 28 64 41 89 57 50 34 16
Card 101: 6 91 90 43 85 1 19 2 28 9 | 63 25 2 9 83 85 87 43 91 6 62 64 74 28 19 82 92 29 36 1 71 90 60 99 84
Card 102: 20 72 12 52 58 28 30 76 42 55 | 30 47 59 29 20 93 90 33 76 58 78 28 52 83 48 72 54 42 67 17 55 12 36 2 37
Card 103: 58 18 40 8 73 69 22 74 26 63 | 61 40 63 41 82 87 22 8 34 6 73 95 69 44 45 85 62 74 27 28 26 4 96 58 15
Card 104: 42 71 57 39 22 79 43 80 90 37 | 43 37 76 94 40 67 4 55 74 21 7 42 3 39 28 12 80 57 32 61 95 58 64 90 13
Card 105: 60 9 50 14 56 11 54 33 77 84 | 77 81 17 99 11 84 70 60 5 43 83 19 80 13 54 33 50 30 87 31 9 4 37 56 14
Card 106: 79 87 86 96 1 8 63 43 39 91 | 6 2 75 63 67 38 11 96 90 91 87 97 86 9 21 77 43 36 79 8 40 85 39 1 13
Card 107: 97 83 21 39 74 64 79 70 77 14 | 85 32 55 18 24 14 79 57 51 12 4 21 23 70 26 83 39 66 63 1 64 73 30 8 77
Card 108: 18 41 11 62 88 38 73 4 47 36 | 82 53 41 92 65 15 42 47 85 96 26 43 58 62 11 3 54 55 89 63 30 17 20 93 2
Card 109: 28 34 55 39 22 99 98 89 86 54 | 58 76 46 70 91 43 2 79 16 25 89 42 78 52 12 56 44 69 80 85 84 99 62 19 15
Card 110: 32 38 50 41 8 97 84 60 92 40 | 43 7 51 76 69 38 92 34 41 71 8 49 95 79 32 45 42 58 60 40 4 3 98 31 20
Card 111: 61 7 67 98 74 21 79 4 85 68 | 90 80 4 8 46 55 40 28 30 38 64 86 73 51 42 66 69 15 29 6 52 78 82 49 41
Card 112: 13 92 98 37 72 52 1 30 42 36 | 17 65 49 6 5 33 40 10 57 72 12 53 7 15 44 18 90 46 81 99 26 16 23 52 66
Card 113: 39 30 46 62 55 42 32 77 9 37 | 37 21 50 40 63 97 28 11 51 26 75 86 80 32 16 69 77 60 6 99 9 72 22 55 79
Card 114: 54 6 72 17 56 76 23 78 7 38 | 15 76 40 56 8 50 51 97 94 64 13 3 69 24 54 66 14 25 82 1 71 41 47 74 92
Card 115: 50 66 30 89 46 20 35 59 22 88 | 96 72 32 97 61 64 25 70 4 11 88 34 46 6 10 73 71 79 45 33 66 50 24 13 42
Card 116: 83 33 99 22 90 32 11 28 47 85 | 80 58 57 7 15 1 23 59 86 54 67 36 83 38 34 18 37 35 19 90 45 24 46 4 84
Card 117: 95 23 58 8 76 82 60 1 15 80 | 75 77 10 85 36 52 91 54 44 96 97 89 25 67 16 31 99 51 68 83 55 29 3 20 33
Card 118: 53 7 99 97 39 37 80 52 18 77 | 76 78 83 34 75 69 39 14 27 44 89 56 23 30 43 48 57 61 29 82 87 93 67 62 12
Card 119: 19 22 6 97 71 68 59 95 67 75 | 91 40 20 74 87 46 4 85 63 64 50 88 14 1 54 39 3 62 58 10 28 55 27 86 60
Card 120: 37 76 87 74 15 84 14 11 99 60 | 24 15 92 60 25 3 86 1 33 5 62 65 79 6 91 45 11 14 10 2 43 4 68 85 54
Card 121: 74 43 96 14 67 85 19 51 80 95 | 27 53 14 15 72 99 85 30 33 20 13 58 12 25 36 18 45 67 34 79 32 76 96 95 55
Card 122: 93 51 95 32 2 18 40 72 31 45 | 8 98 70 17 62 22 63 72 69 73 3 26 42 25 1 41 28 13 77 92 32 60 56 2 65
Card 123: 9 82 93 20 35 69 87 40 30 67 | 87 10 67 63 76 23 45 35 54 5 75 79 66 40 1 89 71 20 77 43 90 65 9 82 37
Card 124: 93 48 59 54 75 8 83 35 4 64 | 71 59 41 35 4 65 49 5 98 91 54 45 76 64 93 75 8 83 48 87 94 32 16 89 82
Card 125: 24 14 40 22 2 57 67 35 36 98 | 36 82 19 88 23 55 15 97 78 35 94 24 67 52 14 30 40 56 38 57 2 31 22 98 71
Card 126: 22 7 97 12 95 66 69 51 59 88 | 94 88 59 58 70 64 95 29 7 93 68 21 16 19 36 39 41 66 10 76 78 82 63 34 56
Card 127: 46 9 32 85 22 20 14 68 98 61 | 69 25 4 70 64 57 14 89 41 98 22 53 27 77 20 56 84 42 85 40 90 6 61 71 60
Card 128: 53 84 81 45 23 13 93 34 42 80 | 80 74 39 50 75 49 7 61 43 5 1 51 36 54 57 97 26 32 82 98 68 45 93 37 86
Card 129: 40 29 85 88 86 7 49 67 91 92 | 86 38 79 31 57 34 78 17 52 53 22 36 62 75 21 70 88 7 3 49 28 6 85 14 4
Card 130: 63 20 36 62 43 98 99 12 46 57 | 14 32 99 22 17 70 5 91 57 95 49 15 28 46 84 89 78 79 43 98 45 50 88 16 23
Card 131: 7 16 87 36 73 82 11 40 14 69 | 25 31 82 24 50 38 2 28 4 23 72 6 51 79 86 46 55 97 42 90 84 1 39 32 27
Card 132: 67 56 15 63 40 9 59 23 94 27 | 26 65 80 40 46 23 37 78 27 12 34 98 41 59 94 16 50 79 90 15 4 7 6 62 17
Card 133: 18 91 27 52 4 34 12 32 65 41 | 45 55 7 3 84 79 54 91 75 80 17 49 42 9 18 48 59 6 8 22 94 10 93 53 57
Card 134: 78 75 48 26 14 8 91 41 34 68 | 18 29 57 5 17 22 56 97 74 34 13 50 40 33 62 20 10 71 58 1 21 88 87 8 25
Card 135: 5 97 16 92 74 51 61 65 3 14 | 15 50 86 24 99 90 59 32 45 81 97 75 6 25 29 80 9 89 46 70 40 57 42 63 60
Card 136: 81 35 23 70 51 14 31 50 67 7 | 32 28 40 58 4 99 18 95 11 90 86 13 84 74 61 5 44 47 24 38 21 1 77 48 78
Card 137: 74 99 57 81 5 1 90 9 69 30 | 88 23 97 7 25 68 78 91 53 15 55 81 92 90 12 18 50 71 61 75 8 76 36 19 34
Card 138: 37 2 84 13 78 51 29 15 42 71 | 49 30 16 88 79 67 76 75 38 80 91 6 28 83 14 26 1 19 40 18 32 98 74 17 44
Card 139: 49 75 16 61 39 4 51 55 17 97 | 11 45 56 47 81 78 67 21 57 42 84 58 8 13 10 91 7 19 46 14 90 87 26 1 18
Card 140: 39 19 41 45 17 30 29 66 61 25 | 61 53 29 41 37 30 95 93 45 17 8 21 66 10 14 78 65 18 39 5 52 91 19 25 4
Card 141: 7 66 29 40 9 14 34 64 4 31 | 98 63 65 6 92 56 81 67 48 88 49 18 38 61 13 95 28 85 20 17 21 30 58 52 89
Card 142: 32 88 54 27 21 86 49 87 44 45 | 15 44 67 75 87 79 21 10 34 70 54 49 88 3 28 32 65 27 43 98 53 64 45 86 9
Card 143: 14 7 67 53 37 73 45 18 62 34 | 87 68 3 22 40 86 26 85 70 4 61 78 1 29 48 12 37 10 77 54 99 36 94 79 15
Card 144: 92 35 52 27 19 16 58 4 22 85 | 47 37 30 51 96 28 58 81 85 9 19 10 46 22 27 7 35 52 16 60 4 92 53 13 84
Card 145: 71 32 62 83 43 20 97 57 78 24 | 88 34 23 25 67 52 11 9 49 80 70 29 43 2 44 45 62 56 33 3 20 98 28 77 79
Card 146: 99 11 17 93 16 77 1 46 55 68 | 25 17 77 99 35 53 3 84 98 2 21 74 27 58 16 20 33 22 39 28 69 9 92 46 52
Card 147: 56 26 30 23 66 94 82 47 14 49 | 68 41 6 13 99 7 71 67 35 93 57 84 44 40 70 89 42 63 74 22 20 55 33 91 64
Card 148: 21 6 43 36 7 44 61 23 93 57 | 53 20 51 59 74 77 16 92 47 25 62 58 18 85 3 63 46 81 99 5 79 70 69 75 34
Card 149: 31 36 91 20 17 50 1 18 64 52 | 66 90 80 33 26 24 30 58 45 77 25 29 44 48 6 35 96 13 78 65 68 98 93 89 94
Card 150: 81 91 37 66 12 33 59 97 38 32 | 61 38 91 95 75 85 48 44 37 47 84 66 35 62 79 94 25 22 97 17 10 31 96 5 78
Card 151: 32 35 11 75 63 61 42 62 10 56 | 4 44 53 12 50 76 51 5 82 25 30 8 89 41 34 98 54 96 37 74 35 16 31 57 65
Card 152: 96 60 29 43 99 19 80 8 5 2 | 87 52 19 11 99 35 20 60 55 80 24 21 8 61 38 78 42 28 95 6 64 65 49 59 26
Card 153: 53 30 75 13 87 77 56 89 63 6 | 7 54 93 80 47 4 72 9 69 44 97 96 23 24 94 67 55 8 33 30 37 6 14 5 3
Card 154: 10 65 46 58 13 25 69 52 19 3 | 47 41 9 3 40 79 89 21 33 73 14 7 74 65 31 62 24 69 60 87 12 16 53 80 82
Card 155: 24 51 35 95 93 73 36 65 27 20 | 14 83 97 94 29 39 19 38 33 32 44 92 60 25 76 64 49 71 65 34 91 31 53 74 23
Card 156: 52 31 50 54 82 42 23 9 39 3 | 29 64 88 70 48 74 12 90 75 57 23 25 58 68 36 33 73 5 84 28 47 92 50 41 21
Card 157: 66 20 50 96 6 84 54 67 59 81 | 77 60 38 65 37 44 15 73 23 83 18 71 89 53 90 36 40 32 2 39 78 63 8 51 19
Card 158: 38 46 85 81 87 86 98 90 37 34 | 41 71 35 26 12 19 51 93 39 20 76 24 7 80 50 56 49 2 57 84 68 92 54 1 75
Card 159: 61 36 84 47 4 22 49 17 31 75 | 77 83 49 55 84 80 18 44 31 47 22 67 4 68 69 35 75 5 59 13 61 39 36 54 17
Card 160: 90 70 62 65 87 95 15 77 76 35 | 70 94 97 10 90 80 35 27 84 87 42 62 54 26 95 57 82 63 1 18 92 25 49 64 21
Card 161: 44 6 28 50 79 16 15 83 45 53 | 79 72 12 45 50 35 67 6 89 28 15 61 16 7 46 36 44 55 27 92 1 59 83 53 94
Card 162: 29 51 46 64 4 75 37 78 81 71 | 83 71 37 39 74 66 32 1 51 93 43 46 20 3 15 50 81 64 75 73 78 29 33 4 22
Card 163: 1 52 37 97 88 47 94 10 98 5 | 85 31 33 46 15 1 16 61 98 59 64 94 83 68 35 11 44 80 38 36 84 72 86 40 29
Card 164: 60 40 94 62 18 71 92 25 21 64 | 64 18 58 76 38 55 40 45 71 92 73 75 25 62 12 94 68 79 23 91 21 60 72 39 7
Card 165: 63 88 91 22 85 18 39 55 33 84 | 95 88 37 5 39 46 33 61 32 45 74 20 27 35 76 85 84 18 54 86 91 75 22 55 63
Card 166: 72 11 31 50 53 82 41 74 62 87 | 42 34 50 11 96 3 77 7 37 22 44 38 62 1 87 68 12 54 74 53 47 82 69 89 85
Card 167: 79 26 70 95 25 16 18 37 75 61 | 39 11 68 61 44 53 42 94 37 45 75 78 62 18 95 26 79 92 38 13 16 64 21 91 57
Card 168: 94 86 69 88 31 15 62 44 19 14 | 3 24 29 8 44 61 89 7 75 15 91 36 45 70 66 4 35 6 71 22 25 39 55 33 18
Card 169: 86 68 72 15 42 99 9 35 2 74 | 42 84 59 86 6 15 53 89 85 79 20 68 62 61 10 2 9 51 99 54 33 35 13 48 93
Card 170: 83 6 15 80 93 63 79 50 69 5 | 15 25 6 93 69 50 83 68 16 40 66 58 63 79 52 7 80 34 61 95 5 33 78 91 32
Card 171: 33 85 4 12 72 62 49 67 17 53 | 4 17 53 72 47 6 49 56 82 48 12 26 30 85 61 15 36 70 64 25 2 33 67 46 62
Card 172: 98 63 26 82 12 61 56 95 27 99 | 76 30 14 95 26 97 71 19 57 67 73 48 63 54 82 18 98 27 61 5 12 44 1 56 74
Card 173: 7 32 34 4 22 79 27 10 78 65 | 3 81 65 36 91 62 94 54 41 32 12 28 39 34 18 61 78 79 80 66 9 63 43 72 97
Card 174: 14 78 60 32 26 31 15 80 11 72 | 1 31 33 35 73 83 97 36 21 3 26 9 91 23 51 84 82 70 22 20 34 90 98 87 69
Card 175: 73 14 7 11 20 64 30 90 62 23 | 60 53 15 73 63 19 71 92 48 89 80 44 78 79 2 76 45 64 42 35 81 27 10 21 26
Card 176: 32 30 39 10 1 3 67 66 94 62 | 86 95 56 54 58 35 90 19 74 43 5 48 17 2 46 65 97 71 36 31 69 8 47 94 42
Card 177: 24 90 40 47 51 75 63 29 57 10 | 49 68 61 43 30 26 84 59 99 75 44 41 17 24 12 38 90 37 36 35 91 9 89 46 8
Card 178: 73 74 31 76 10 21 70 3 30 41 | 39 14 30 70 79 75 97 44 87 20 92 12 86 56 18 46 8 90 23 98 2 59 28 53 3
Card 179: 78 44 89 84 50 97 55 90 77 99 | 79 1 88 65 2 50 72 68 7 15 85 41 64 93 37 16 53 44 42 48 89 97 59 60 8
Card 180: 55 98 13 45 33 91 88 4 49 37 | 18 44 64 83 56 79 81 26 78 54 72 75 11 70 66 57 73 61 62 34 19 95 93 94 76
Card 181: 94 47 65 55 8 45 1 67 71 25 | 99 34 43 64 36 50 6 51 27 59 37 40 3 98 72 78 38 74 82 46 85 90 48 32 84
Card 182: 78 75 63 31 30 70 84 50 28 19 | 61 18 58 87 77 48 71 50 91 92 60 86 73 94 85 57 97 15 1 25 74 67 11 68 47
Card 183: 94 27 68 41 8 72 48 85 97 49 | 81 35 90 69 76 18 53 1 59 25 88 31 4 93 84 32 9 55 66 50 22 62 43 60 17
Card 184: 40 31 56 54 59 98 93 81 24 44 | 62 42 93 56 99 10 81 59 37 6 41 66 44 72 31 30 20 54 51 24 27 83 40 73 98
Card 185: 38 73 79 48 3 46 99 93 50 24 | 65 34 40 2 20 92 10 32 67 57 22 47 96 11 7 31 87 6 28 95 77 25 58 29 27
Card 186: 47 65 99 98 90 68 13 49 51 10 | 90 82 27 68 84 83 57 50 18 5 49 65 85 10 46 13 21 81 73 51 71 47 98 88 99
Card 187: 25 56 18 15 59 47 20 86 50 83 | 25 57 83 36 56 87 50 34 9 70 4 64 77 45 92 13 20 47 48 15 97 18 86 28 59
Card 188: 99 16 44 2 85 17 71 45 49 11 | 94 13 45 36 77 89 26 6 39 27 84 1 80 21 73 41 33 90 46 72 65 96 34 71 83
Card 189: 34 24 76 68 47 19 85 15 50 46 | 43 67 4 44 14 34 19 61 47 68 50 46 99 94 16 76 15 28 36 27 52 85 88 24 89
Card 190: 56 20 43 86 2 88 87 30 14 4 | 43 14 19 92 3 23 87 74 50 97 2 88 18 80 20 86 36 41 95 27 57 98 49 30 26
Card 191: 47 2 18 84 91 66 24 6 42 56 | 12 93 7 50 42 45 2 91 66 4 32 47 19 56 49 18 15 24 44 84 97 6 16 31 25
Card 192: 42 88 68 56 93 48 9 52 20 70 | 30 93 42 4 68 70 36 56 9 15 88 98 64 67 33 91 20 61 50 27 13 94 52 48 85
Card 193: 46 57 19 40 9 7 47 33 86 11 | 65 54 38 43 82 55 79 51 77 73 74 97 75 96 6 47 62 88 92 18 84 48 41 29 52
Card 194: 58 23 35 79 82 72 44 93 12 43 | 43 60 2 24 77 48 61 25 44 75 35 12 93 51 36 72 6 31 29 50 37 80 19 14 87
Card 195: 15 77 78 50 36 83 68 52 86 26 | 16 72 67 88 14 81 34 24 71 32 91 77 90 1 98 95 7 28 49 84 86 20 44 73 56
Card 196: 25 3 32 15 1 56 27 51 82 81 | 87 79 15 11 98 54 56 88 18 92 69 25 66 27 60 58 44 1 51 3 32 81 12 72 41
Card 197: 3 99 81 8 93 28 76 7 27 48 | 78 98 85 5 93 77 72 62 69 82 50 9 35 74 18 10 33 67 90 31 79 84 58 29 17
Card 198: 26 81 19 24 59 82 8 95 86 17 | 13 22 10 96 19 20 88 3 90 78 24 9 50 34 6 94 7 60 44 76 31 81 26 33 43
Card 199: 77 91 58 16 47 94 23 30 88 5 | 38 66 12 25 95 67 72 89 36 45 63 15 54 98 74 57 32 39 59 28 7 62 82 13 26
Card 200: 82 47 52 12 83 4 26 93 33 9 | 31 30 91 2 6 27 28 1 81 8 75 92 56 57 41 24 72 85 53 74 59 11 66 32 54
Card 201: 4 13 26 57 84 17 63 10 98 56 | 72 85 68 47 44 60 54 34 38 16 8 11 23 84 32 18 69 13 26 35 9 73 43 15 89
Card 202: 11 9 1 42 71 78 97 89 8 10 | 33 17 81 48 60 96 69 37 12 46 73 4 76 54 86 91 28 5 51 98 99 84 13 85 32
Card 203: 37 80 7 87 79 60 6 49 16 12 | 23 34 15 46 38 20 27 45 33 97 37 14 68 83 49 79 43 70 57 60 11 63 24 35 73
Card 204: 84 24 48 76 7 18 77 37 69 5 | 88 39 92 94 34 37 11 40 85 35 2 81 73 58 42 66 83 9 56 12 14 51 62 20 7
Card 205: 5 84 4 6 95 77 59 67 74 35 | 58 47 29 34 79 86 35 89 71 96 27 64 90 48 37 78 1 39 46 21 98 91 43 8 56
Card 206: 56 21 34 13 1 17 99 11 76 60 | 36 24 83 31 50 19 82 32 61 9 98 71 79 39 97 37 29 13 27 10 52 22 41 40 59
Card 207: 62 7 22 90 51 96 12 13 36 52 | 48 37 70 24 73 51 83 3 5 77 29 87 23 18 26 76 19 97 20 86 84 14 63 33 21
Card 208: 40 42 5 91 29 59 70 49 23 94 | 82 81 30 61 64 65 19 9 67 75 92 16 26 52 73 43 55 35 17 93 39 90 74 53 51

24
2023/day05/Main.hs Normal file
View file

@ -0,0 +1,24 @@
import Data.List.Split
import Data.List
toMapFn :: [(Int, Int)] -> Int -> Int
toMapFn map seed
| Just (d,s) <- find (\(drs, srs) -> srs == seed) map = d
| otherwise = seed
main :: IO ()
main = do
lines <- lines <$> getContents
let sections = splitOn [""] lines
let seeds = map read $ tail $ splitOn [' '] (sections!!0!!0) :: [Int]
let maps = map (\(_:xs) -> (map (\l -> map (\i -> (read i) :: Int) (splitOn [' '] l)) xs)) (tail sections)
let myMaps = map (\m -> concat (map (\[drs, srs, r] -> zip [drs..(drs+r)] [srs..(srs+r)]) m)) maps
let myMapFns = map (toMapFn) myMaps
let myFn = foldr (.) id (reverse myMapFns)
print (minimum (map myFn seeds))
-- mapM_ putStrLn lines

52
2023/day05/Main2.hs Normal file
View file

@ -0,0 +1,52 @@
import Data.List.Split
import Data.List
import Data.Maybe
windows :: [a] -> [[a]]
windows = filter (\xs -> length xs == 2) . map (take 2) . tails
genBetweens :: [[Int]] -> [[Int]]
genBetweens section = map (\[[dl, sl, rl], [du, su, ru]] -> [sl + rl, sl + rl, su + ru - sl]) (windows section)
-- 79 14
--
-- 50 98 2
-- 52 50 48
sectionToRange :: [Int] -> [Int] -> [Int]
sectionToRange [d,s,r] [start,range]
| begin <= s + r - 1 && end >= s = [d + (begin - s), end - begin + 1]
| otherwise = [start, range]
where
begin = max start s
end = min (start+range -1) (s+r-1)
toMapFn :: [[Int]] -> [[Int]] -> [[Int]]
toMapFn section seedPairs = nub $ filter (/= []) $ concat $ map (\f -> (map (f) seedPairs)) (map (sectionToRange) section)
main :: IO ()
main = do
lines <- lines <$> getContents
let sections = splitOn [""] lines
let seeds = map read $ tail $ splitOn [' '] (sections!!0!!0) :: [Int]
let seedPairs = chunksOf 2 seeds
let maps = map (\(_:xs) -> (map (\l -> map (\i -> (read i) :: Int) (splitOn [' '] l)) xs)) (tail sections)
let mapsBetweens = map (\x -> [0, 0, (x!!0!!2 -1)] ++ mapBetweens map ++ maps ++ [(last x)!!1 + (last x)!!2, (last x)!!1 + (last x)!!2, (maxBound :: Int) - (last x)!!1 + (last x)!!2] ) maps
let myMapFns = map (toMapFn) maps
let myFn = foldr (.) id (reverse myMapFns)
let seedRanges = concat $ map (\seedPair -> myFn [seedPair]) seedPairs
print ((myMapFns!!0) [seedPairs!!0])
-- print ((myMapFns!!1) ((myMapFns!!0) [seedPairs!!0]))
-- print ((myFn) [seedPairs!!0])
-- print ((map (head) ((myFn) [seedPairs!!0])))
-- print ((map (head) ((myFn) [seedPairs!!0])))
-- print seedRanges
-- print ((map (\[start, range] -> start) seedRanges))
-- print (minimum (map (\[start, range] -> start) seedRanges))
-- mapM_ putStrLn lines

23
2023/day05/MainOpt.hs Normal file
View file

@ -0,0 +1,23 @@
import Data.List.Split
import Data.List
toMapFn :: [[Int]] -> Int -> Int
toMapFn map seed
| Just [d,s, r] <- find (\[drs, srs, r] -> (srs <= seed) && (seed <= srs + r)) map = d + (seed - s)
| otherwise = seed
main :: IO ()
main = do
lines <- lines <$> getContents
let sections = splitOn [""] lines
let seeds = map read $ tail $ splitOn [' '] (sections!!0!!0) :: [Int]
let maps = map (\(_:xs) -> (map (\l -> map (\i -> (read i) :: Int) (splitOn [' '] l)) xs)) (tail sections)
let myMapFns = map (toMapFn) maps
let myFn = foldr (.) id (reverse myMapFns)
print (minimum (map myFn seeds))
-- mapM_ putStrLn lines

33
2023/day05/example.txt Normal file
View file

@ -0,0 +1,33 @@
seeds: 79 14 55 13
seed-to-soil map:
50 98 2
52 50 48
soil-to-fertilizer map:
0 15 37
37 52 2
39 0 15
fertilizer-to-water map:
49 53 8
0 11 42
42 0 7
57 7 4
water-to-light map:
88 18 7
18 25 70
light-to-temperature map:
45 77 23
81 45 19
68 64 13
temperature-to-humidity map:
0 69 1
1 0 69
humidity-to-location map:
60 56 37
56 93 4

197
2023/day05/input.txt Normal file
View file

@ -0,0 +1,197 @@
seeds: 3082872446 316680412 2769223903 74043323 4131958457 99539464 109726392 353536902 619902767 648714498 3762874676 148318192 1545670780 343889780 4259893555 6139816 3980757676 20172062 2199623551 196958359
seed-to-soil map:
2211745924 1281207339 39747980
3648083739 2564129012 145170114
4171944574 2333022880 44675857
540694760 848661020 78793182
256996824 588160543 260500477
1870557289 1804847051 174857657
3877597859 2853012070 228980636
1634159465 2150723562 100770342
3793253853 2293912908 39109972
652571990 567856215 20304328
2480343183 3372556760 130573730
1831144195 528443121 39413094
0 1690920197 113926854
3145720856 3081992706 290564054
624623106 1979704708 27948884
3844601856 3751059243 32996003
1260492360 1175075910 106131429
1366623789 166330978 138490835
1175000149 927454202 85492211
696570061 1596389312 94530885
2647046837 3784055246 498674019
4216620431 2709299126 78346865
953230443 1450000160 146389152
791100946 1012946413 162129497
1734929807 427093569 96214388
672876318 403399826 23693743
113926854 2007653592 143069970
2045414946 0 166330978
1099619595 328019272 75380554
3832363825 4282729265 12238031
619487942 523307957 5135164
517497301 304821813 23197459
2293912908 2377698737 186430275
1505114624 1320955319 129044841
2610916913 3714929319 36129924
3436284910 3503130490 211798829
4106578495 2787645991 65366079
soil-to-fertilizer map:
2733576308 471599794 76965554
1171423854 1329782324 37554133
2640052871 928987130 93523437
2015828352 548565348 204028986
3562821857 3651707516 643259780
1208977987 2596877127 12575372
778871551 2204324824 392552303
1221553359 2609452499 201089363
3520687457 3069361301 42134400
4240454288 3542205804 54513008
2219857338 1367336457 420195533
3034988650 3111495701 430710103
307271757 0 471599794
1422642722 2082393746 121931078
3465698753 3596718812 54988704
0 1022510567 307271757
1544573800 1787531990 294861756
4206081637 3034988650 34372651
1839435556 752594334 176392796
fertilizer-to-water map:
1807260819 3957534991 337432305
774926879 2718324291 701236360
2351569884 1690420176 794087185
313174888 2484507361 233816930
3145657069 541109949 949949029
546991818 313174888 227935061
2144693124 3750658231 206876760
4095606098 1491058978 199361198
1476163239 3419560651 331097580
water-to-light map:
3834982820 3688486185 202897824
2016707141 372287565 116618935
3386838019 3412408553 81116937
1125723906 705568567 205087174
4037880644 1840142480 150018623
2359176858 4109550629 126312910
3328178239 4050890849 58659780
1801115923 3893484758 43944958
1516002989 1645262885 194879595
3501845456 488906500 216662067
1373868013 2223115169 142134976
3467954956 3641943956 33890500
1845060881 3937429716 113461133
3718507523 910655741 57371540
3315526510 3675834456 12651729
2936874590 2031117287 84929853
1710882584 3551710617 90233339
372287565 2365250145 753436341
2133326076 968027281 225850782
1330811080 1990161103 40956184
1958522014 3493525490 58185127
3021804443 3118686486 293722067
2485489768 1193878063 451384822
3775879063 4235863539 59103757
1371767264 3891384009 2100749
4187899267 2116047140 107068029
light-to-temperature map:
156743496 2059819668 37694357
4058204935 4136802755 38991573
2484168315 1803830764 54458297
2053264847 2531370441 7735546
586814267 2539105987 96956250
2538626612 2097514025 117228608
4097196508 3782742182 197770788
1246999413 607900903 25957627
1877009740 1752361784 30081637
683770517 3121708332 89729874
1835387899 343006762 41621841
1806332066 3242032508 29055833
2212907940 137512351 205494411
809588378 2954088675 69458905
1689902424 3271088341 436818
3306521233 894737794 308504080
3235066415 3050253514 71454818
1147299995 1960120250 99699418
2046683718 749851354 6581129
3782742182 4222506720 5456115
2061000393 756432483 138305311
792839631 591152156 16748747
1478425864 2742612115 211476560
2793367571 2636062237 73608402
2471831801 2214742633 12336514
194437853 1622309324 130052460
3901915150 3980512970 156289785
2655855220 0 137512351
324490313 1359985370 262323954
3855202758 4175794328 46712392
2445108285 1782443421 21387343
2467550357 3211438206 4281444
3788198297 4227962835 67004461
2199305704 2709670639 13602236
1272957040 385683332 205468824
1690339242 633858530 115992824
1907091377 2227079147 139592341
0 1203241874 156743496
2866975973 1858289061 24590288
1120987137 3215719650 26312858
2891566261 3271525159 343500154
2466495628 384628603 1054729
1043746236 1882879349 77240901
879047283 2366671488 164698953
773500391 2723272875 19339240
2418402351 3023547580 26705934
temperature-to-humidity map:
159374282 333555332 155635040
2263203984 507165487 202752561
1337996197 836383358 269347352
733930089 139752127 104367475
2840449774 3878218681 416748615
3373626730 3111757526 416998602
3943881399 2795875886 241056063
3790625332 2642619819 153256067
3298801153 3036931949 30341941
1671783850 1980182260 485774285
0 313933177 19622155
2642619819 3680388726 197829955
2157558135 1398186167 105645849
4283100212 3528756128 11867084
843670838 1503832016 347905328
1607343549 244119602 64440301
315009322 709918048 126465310
441474632 1105730710 292455457
3257198389 3540623212 41602764
838297564 308559903 5373274
1320021082 489190372 17975115
4184937462 3582225976 98162750
1191576166 1851737344 128444916
3329143094 3067273890 44483636
19622155 0 139752127
humidity-to-location map:
3728200417 3220538748 36833684
1907946842 1065499951 70751518
1978698360 2011387412 298481649
4048923771 3541262102 246043525
1314245652 402299218 396512619
577039234 798811837 266688114
3249926596 2795059130 273974120
1734859977 229212353 173086865
2718652009 3787305627 454867466
1710758271 1405898165 24101706
843727348 1510857580 66114574
3765034101 3257372432 283889670
1179488618 1876630378 134757034
909841922 1136251469 269646696
3675406214 4242173093 52794203
310070062 1576972154 266969172
229212353 1429999871 80857709
3523900716 3069033250 151505498
3173519475 2718652009 76407121
2277180009 1843941326 32689052

18
2023/day06/Main.hs Normal file
View file

@ -0,0 +1,18 @@
import Data.List.Split (splitOn)
winsFromTimeDist :: (Int, Int) -> Int
winsFromTimeDist (time, dist) = length $ filter (> dist) $ zipWith (*) [0..time] (reverse [0..time])
main :: IO ()
main = do
lines <- lines <$> getContents
-- let values = map (map (\y -> read y :: Int) . splitOn [' '] . drop 9) lines
let values = map (map read . filter (/= "") . splitOn [' '] . drop 9) lines :: [[Int]]
let time_dist = zip (values!!0) (values!!1)
let wins = map winsFromTimeDist time_dist
let result = product wins
print result

16
2023/day06/Main2.hs Normal file
View file

@ -0,0 +1,16 @@
import Data.List.Split (splitOn)
winsFromTimeDist :: (Int, Int) -> Int
winsFromTimeDist (time, dist) = length $ filter (> dist) $ zipWith (*) [0..time] (reverse [0..time])
main :: IO ()
main = do
lines <- lines <$> getContents
-- let values = map (map (\y -> read y :: Int) . splitOn [' '] . drop 9) lines
let values = map (read . filter (/= ' ') . drop 9) lines :: [Int]
let wins = winsFromTimeDist (values!!0, values!!1)
print wins

2
2023/day06/example.txt Normal file
View file

@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200

2
2023/day06/input.txt Normal file
View file

@ -0,0 +1,2 @@
Time: 38 94 79 70
Distance: 241 1549 1074 1091