Day 2
This commit is contained in:
parent
7e9f1b8f47
commit
6eb6bd8d14
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,3 +1,8 @@
|
|||||||
|
# files without extensions
|
||||||
|
*
|
||||||
|
!*/
|
||||||
|
!*.*
|
||||||
|
|
||||||
## Ignore Visual Studio temporary files, build results, and
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
## files generated by popular Visual Studio add-ons.
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
|
||||||
@ -219,3 +224,8 @@ _Pvt_Extensions
|
|||||||
# ignore EVERYTHING
|
# ignore EVERYTHING
|
||||||
*.vcxproj*
|
*.vcxproj*
|
||||||
*.sln
|
*.sln
|
||||||
|
|
||||||
|
# Haskell
|
||||||
|
*.o
|
||||||
|
*.hi
|
||||||
|
*.out
|
||||||
|
250
aoc-2/inputs.txt
Normal file
250
aoc-2/inputs.txt
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
pnebjqralgdgckzfifvtxywomu
|
||||||
|
pnebjqsalrdgcqzfihotxhwomu
|
||||||
|
pneajqsalrdgckzfihytxywoml
|
||||||
|
pnepjqsalrwgckztihvtxywomu
|
||||||
|
pnhbjqsalrdgckzfimvtxywodu
|
||||||
|
pnwbjqsdlrdgckzfihvnxywomu
|
||||||
|
inebjqnalrdgckzfihvtxzwomu
|
||||||
|
pnebjssalhdgckzfihvtsywomu
|
||||||
|
pnebjqjalrdgckzfiavtxywoku
|
||||||
|
vnebjqsalrdgckzfihvbxmwomu
|
||||||
|
phebjksaurdgckzfihvtxywomu
|
||||||
|
pneojqealrdgckzhihvtxywomu
|
||||||
|
snebjqsalrdgckzqihvtxyzomu
|
||||||
|
pnebjqsalrtackzfihvtxswomu
|
||||||
|
bnebjqlalrdgckzfihvtxywhmu
|
||||||
|
pnebjqfalrdgckzfijvtxywomi
|
||||||
|
fnehjbsalrdgckzfihvtxywomu
|
||||||
|
pnebjasalrdgckzdihvtxqwomu
|
||||||
|
pnebjhsaljdgckzfihvtxywmmu
|
||||||
|
pnebjqsalrdgckzfihvsxykoau
|
||||||
|
pnebjqsalrdgckzbihvtdywomc
|
||||||
|
pnobjqsalrxgckzfihvtxywomh
|
||||||
|
pnebjqstlrdgchzfihvtxywnmu
|
||||||
|
pnebjquaxrdgckzfihvtxywolu
|
||||||
|
pqebjqsalrdgcdzfihvtcywomu
|
||||||
|
xnabjqsalrdgckzfihvtxywmmu
|
||||||
|
rnebjqsalrdgckzfihvtxmwouu
|
||||||
|
vaebjqsalrdgckcfihvtxywomu
|
||||||
|
pnebjqsalrpgcnzfihvbxywomu
|
||||||
|
pcvbjqsalrdjckzfihvtxywomu
|
||||||
|
pneyjqsafrdgckzfihdtxywomu
|
||||||
|
pxedjqsalrdgckzfihvtxyzomu
|
||||||
|
pnebjqsalrdgctzfihnyxywomu
|
||||||
|
pnebjqsalrdgckzfihvtnylsmu
|
||||||
|
pnebjqsalrdyckzfihvbxycomu
|
||||||
|
fnebjqsalrdgckzfihvtxtwomc
|
||||||
|
pnobjqsalrdgckdfihvtxywomh
|
||||||
|
pqebjqsalrdgcqzfihvtxywymu
|
||||||
|
pnebxqsalrdgckzficvtwywomu
|
||||||
|
pnebjqshlragczzfihvtxywomu
|
||||||
|
pnebqqsalrdackzfihttxywomu
|
||||||
|
pnebjqsalrdsckwfbhvtxywomu
|
||||||
|
pnehjqsalrdgcuzfxhvtxywomu
|
||||||
|
pnebjqsavrdgckzfihvexywomn
|
||||||
|
pnebunsalrdgckzfihvtxywomi
|
||||||
|
pnebjxsalrdgckzfmhvtpywomu
|
||||||
|
rnebjqsalrdghkzfihztxywomu
|
||||||
|
pnebjqsalrigcbzfihvfxywomu
|
||||||
|
pnebqqsalrggckzfihvtxyromu
|
||||||
|
pnebjqsalrdgchzfihvtxylmmu
|
||||||
|
pnebeqsalrdgckzdihvtxywoms
|
||||||
|
pnebjqsalrdgckzzihvfxywozu
|
||||||
|
pnzbjgsalrtgckzfihvtxywomu
|
||||||
|
pnebjqsaledgckzjihvtxzwomu
|
||||||
|
pnebjqsalydgckqfihvtxywouu
|
||||||
|
pnebjqsalrdgckufihvqxdwomu
|
||||||
|
pnebjqsylrdgckzfihvdxyjomu
|
||||||
|
pnemjqsalrdgckzeihvtxywoqu
|
||||||
|
plebjasalrdgckzfihvtxywomb
|
||||||
|
pnebjqsadrdgckufihvtxyfomu
|
||||||
|
pbebjqsaardgckzfihvtxmwomu
|
||||||
|
pnebjqsalrdgcmzfihotxywgmu
|
||||||
|
pnebjqsaprdgcizfihvtxywhmu
|
||||||
|
pnebjqsalrkgcuzfihvtlywomu
|
||||||
|
pnebjqsalrdnckzfihvtxysomg
|
||||||
|
pnebjqdafrdgckzfihctxywomu
|
||||||
|
pnebjqsalrdgckzfihutxkwomp
|
||||||
|
pnebvqsalrdgclzfimvtxywomu
|
||||||
|
pnebjqralrdgcktfihvtxiwomu
|
||||||
|
pneujqsalrdsckzfzhvtxywomu
|
||||||
|
pnebfqgalrdgckzfihvtxywjmu
|
||||||
|
pneyjqsalrkgckzfihctxywomu
|
||||||
|
pndbjqsalrdgckzfjhvtxywouu
|
||||||
|
pneljnsalrdgcozfihvtxywomu
|
||||||
|
phebjqsalrdgckzfihxtxdwomu
|
||||||
|
pnlbjqsalrhgckzfzhvtxywomu
|
||||||
|
pnebjqsalrsgckzfiovtxywwmu
|
||||||
|
pncbjqsalrdgfkzfivvtxywomu
|
||||||
|
nnebjqsalrdgckzfthvtxycomu
|
||||||
|
pnebjqwalsdgckzfixvtxywomu
|
||||||
|
pnebjtsalrdgcfzfimvtxywomu
|
||||||
|
pnebjqsvlrdgckzfihutxfwomu
|
||||||
|
pnebjmsalrdgckzkxhvtxywomu
|
||||||
|
pnekjqsllrdgckzfinvtxywomu
|
||||||
|
pneijqsxlrdgckzfihvtxywjmu
|
||||||
|
wnxbjqsafrdgckzfihvtxywomu
|
||||||
|
pnebjqskledgokzfihvtxywomu
|
||||||
|
pnebjqvalrdgckzfihvtxytoju
|
||||||
|
pneqjqsalrdgckzfilvthywomu
|
||||||
|
pnebjqsalrdgckzfihvokywomf
|
||||||
|
bnebjqsalrdgckufihvtxywimu
|
||||||
|
pnebjqsaurdgckzfihvtrywosu
|
||||||
|
pnebjmsaludgckzfihvtxywomn
|
||||||
|
pnebdqsalrdgcktfihvtxywodu
|
||||||
|
pnebjqjylzdgckzfihvtxywomu
|
||||||
|
piebjqsalrdgcrzfihstxywomu
|
||||||
|
pnebjqsaurdgckwfnhvtxywomu
|
||||||
|
pnebxqsajrdgcjzfihvtxywomu
|
||||||
|
pnebjqsalrdghsdfihvtxywomu
|
||||||
|
pnebcqsxlrdgckzfihvtxyaomu
|
||||||
|
pnefjqsalrdgckzfuhvtxyworu
|
||||||
|
pnebjqsalrdlcksfihvteywomu
|
||||||
|
pnebjqlalrgackzfihvtxywomu
|
||||||
|
pnebdqsalrdickzfihvtxdwomu
|
||||||
|
pneujksalrdgctzfihvtxywomu
|
||||||
|
pnebjqsalrduckzfihvsxywomf
|
||||||
|
pnebjqsalrdgckcfihotxywomd
|
||||||
|
envbjqsalsdgckzfihvtxywomu
|
||||||
|
pnebjqsalzdgcvzzihvtxywomu
|
||||||
|
pnebjqsalrdyckzflhvyxywomu
|
||||||
|
pnebjqsalrdglkzfihstxymomu
|
||||||
|
pnebmqsalrdgokzfihvtxywoml
|
||||||
|
pnebjqsylrdnckzfihatxywomu
|
||||||
|
pnebjqaflndgckzfihvtxywomu
|
||||||
|
pneboqsagragckzfihvtxywomu
|
||||||
|
peebjqstlndgckzfihvtxywomu
|
||||||
|
onebjqsklrdgckzfihvtxmwomu
|
||||||
|
pnebjqjnlrdgckrfihvtxywomu
|
||||||
|
pnebjqsalrhgckzfihvqxywomh
|
||||||
|
pnebjqsalrdgckzzihvtxowomw
|
||||||
|
pnebjgsalrdgckffihltxywomu
|
||||||
|
znebaqsalcdgckzfihvtxywomu
|
||||||
|
pnnbjqeasrdgckzfihvtxywomu
|
||||||
|
rnebjqaalrxgckzfihvtxywomu
|
||||||
|
pnebjqsalrdgckaxphvtxywomu
|
||||||
|
pnebjcnalrdgnkzfihvtxywomu
|
||||||
|
pnebjasalbdgckzmihvtxywomu
|
||||||
|
pnebjqsalrdgckefjhvtmywomu
|
||||||
|
pnebjqsalrdgmkzfihvtxyoomb
|
||||||
|
pnebjqsalrkgckogihvtxywomu
|
||||||
|
pnwbjqsalrdgckztihvtxywomt
|
||||||
|
pnebjqsalrdgckzfihotgnwomu
|
||||||
|
pnebjqsdlrrgckzfihvtxyaomu
|
||||||
|
pnebvasalrdgckzfihvtsywomu
|
||||||
|
pnebrqqalrvgckzfihvtxywomu
|
||||||
|
tnebjqsglrdgqkzfihvtxywomu
|
||||||
|
pnebjqsatrsgckifihvtxywomu
|
||||||
|
pneboqsalrdgckzfihvkxywomi
|
||||||
|
pnezaqsalrdgcktfihvtxywomu
|
||||||
|
pnebjqsnlrdgckzfihvfxqwomu
|
||||||
|
pneajqsaxrmgckzfihvtxywomu
|
||||||
|
pnebjosalodgckzfihvxxywomu
|
||||||
|
pnebjqsalndgckmfihvtfywomu
|
||||||
|
pneejqsalidgckzfihgtxywomu
|
||||||
|
pnecjqsalrdgckzfihptxiwomu
|
||||||
|
tnebjqsalrdgckznihvxxywomu
|
||||||
|
ptebjqsalrdgckzfimvtxywomm
|
||||||
|
wnebjqsalndgckzfihvtxywoju
|
||||||
|
fnebmqsplrdgckzfihvtxywomu
|
||||||
|
pnlbjqsalrdghkzficvtxywomu
|
||||||
|
pnebjqsesrdgckzdihvtxywomu
|
||||||
|
pnebjqsalregokzfirvtxywomu
|
||||||
|
pnebjtualrtgckzfihvtxywomu
|
||||||
|
pnebjwsdlrdgckzfihvtxywoml
|
||||||
|
pnlbjqsayrdgckzfqhvtxywomu
|
||||||
|
pnebjwsalpdgckzfihvtxywomc
|
||||||
|
pnqbjqsalcdgckzhihvtxywomu
|
||||||
|
pneujqsalrdgckzfhhvtxrwomu
|
||||||
|
pnebjqsalqdgcizfihvtxywimu
|
||||||
|
pnebjqsacldgckzfihvwxywomu
|
||||||
|
puebjqsalrdgckzfbhvtxyeomu
|
||||||
|
pnebjqsalrdgcyimihvtxywomu
|
||||||
|
pnebjlsalrdgckzfihvtxiwome
|
||||||
|
pnebfusalrdgckzfihvtxywodu
|
||||||
|
pnebjqsalrdgvazfirvtxywomu
|
||||||
|
pnebjqsalrdgckyfohvtxywomz
|
||||||
|
gnenjqsalrdgckzfihvtxynomu
|
||||||
|
mnebjqsalrdgckhfihvtxycomu
|
||||||
|
phebjqsalrdgckzfihvtxtworu
|
||||||
|
pnebjqsalrdgdkzfihvtxywfmj
|
||||||
|
pneveqsairdgckzfihvtxywomu
|
||||||
|
pnebjqsalcdlckzfihvtxywomg
|
||||||
|
pneajqsalrdgckzfihvtxygoxu
|
||||||
|
puebjqdclrdgckzfihvtxywomu
|
||||||
|
tuebjqsalrdgckzfihvtxywoou
|
||||||
|
pwenjqsalrdgckzfihvtxywomg
|
||||||
|
pnebjqsalrdgckzfihhltywomu
|
||||||
|
pnebjqsalrdgchzqievtxywomu
|
||||||
|
pnegjqsalrdgckzfiovtxywdmu
|
||||||
|
pnebjaralrqgckzfihvtxywomu
|
||||||
|
pnebjqsalrdrckzfimvtxywomm
|
||||||
|
pnebjqsalrdgckzfpgvtxewomu
|
||||||
|
pnebjqsalrdhcqzfihitxywomu
|
||||||
|
pnebjqsalrjgckefihmtxywomu
|
||||||
|
pnebjcsalrdgcksfikvtxywomu
|
||||||
|
pnebjqsalrdgckzfihvtxywdjc
|
||||||
|
pnebjqsazrjgckzjihvtxywomu
|
||||||
|
pnfbjqsclrdgckzfihvtxybomu
|
||||||
|
pnebjqsalrdgckuqihvtxyaomu
|
||||||
|
pfpbjzsalrdgckzfihvtxywomu
|
||||||
|
pnevjqsalrdgckwfihytxywomu
|
||||||
|
pnebjqsqlrkgckzfihvtvywomu
|
||||||
|
pneejqsalrdlckzfihvtxywopu
|
||||||
|
pnebjqsalcdgxkzfihvtxywomd
|
||||||
|
pneqjqsalrdgcvzzihvtxywomu
|
||||||
|
pnvbjqsalydgctzfihvtxywomu
|
||||||
|
pnebjqsalrdgckzzihvfxywomn
|
||||||
|
pnybjqsaerdgckzfihstxywomu
|
||||||
|
pnobjqsalrdkckzfihvtxywomv
|
||||||
|
pnebjqsalridckzfihvtxywfmu
|
||||||
|
pnhbjqsaludgckyfihvtxywomu
|
||||||
|
pnetjqsaprdgykzfihvtxywomu
|
||||||
|
wnebjqsalrdvcfzfihvtxywomu
|
||||||
|
pnetjqsalrdmckwfihvtxywomu
|
||||||
|
pnebjysalrdgcszfihvtxnwomu
|
||||||
|
pnebjqsrlrdgckzfihvtxywkhu
|
||||||
|
pnubjqsplrdgcjzfihvtxywomu
|
||||||
|
pnebjqsalrdzckzficjtxywomu
|
||||||
|
pnebjqsalregckzfinvtxywoku
|
||||||
|
pnebjqsalrcgckyfivvtxywomu
|
||||||
|
pyenjqsalrdgckzfihvnxywomu
|
||||||
|
prebjqsalrdnckzfihvtxysomg
|
||||||
|
pnebjnsalrdgchzfihvaxywomu
|
||||||
|
pnebjqsalrdgckzfihxagywomu
|
||||||
|
pnebjqsalrdgckzvihvtoywoml
|
||||||
|
pnebjqsilrdgckzfihvtfywgmu
|
||||||
|
pnebjqmalrdgckzfihvtvawomu
|
||||||
|
pnebqqsalrdgckzfiuvtfywomu
|
||||||
|
pneqjqsalrdgckzfihvqxywomi
|
||||||
|
pnebjesalrsgckzfihvtxywmmu
|
||||||
|
znebjqsblrdgckzfihvlxywomu
|
||||||
|
pnebjqsalrdgckzfuhvtlyworu
|
||||||
|
pnebjqsylrdgckzfihvqxpwomu
|
||||||
|
onebjqsalfdgckifihvtxywomu
|
||||||
|
pnebjusalrdgckzfihvtxywyml
|
||||||
|
pnebjssflrdgckzfigvtxywomu
|
||||||
|
pnebjfsdzrdgckzfihvtxywomu
|
||||||
|
pnebjqsalrdgcktfihvixywocu
|
||||||
|
gnebjqnaqrdgckzfihvtxywomu
|
||||||
|
pnebjqsaqrugckzfihhtxywomu
|
||||||
|
pnebjqsxlrdgckzfihvtxlwosu
|
||||||
|
pnebjzsalrdgckzmihvtxywovu
|
||||||
|
pnebgqsalrdgckzfizvtxyjomu
|
||||||
|
pnebjqsmlrdgckzfihvtxywsmi
|
||||||
|
pnebjqsakmdgckzjihvtxywomu
|
||||||
|
pnebjqdglrdgckvfihvtxywomu
|
||||||
|
pnebmhsalrdgckxfihvtxywomu
|
||||||
|
pneejqsalrdlckzfihvnxywomu
|
||||||
|
bnebjqsalmdgckzfihvfxywomu
|
||||||
|
bnebjnsalrdgcizfihvtxywomu
|
||||||
|
pnebjqsalhdgcdzfihvbxywomu
|
||||||
|
pnebjqsjlrdgckzfihvgiywomu
|
||||||
|
pnebjisalrdgckzfihvtxywqmi
|
||||||
|
pdebjqsalrdickzfihhtxywomu
|
||||||
|
pnebjqsalrdkckzfihvjeywomu
|
||||||
|
pneyjqsalrqgckzfihvtxywohu
|
||||||
|
pnebjqsalrdgckcfihvtxjlomu
|
||||||
|
plebqwsalrdgckzfihvtxywomu
|
||||||
|
pnebjqlalrdgckzfihetxynomu
|
||||||
|
sngbjqsalrdgckzfihvmxywomu
|
50
aoc-2/main.hs
Normal file
50
aoc-2/main.hs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import Data.Map (Map)
|
||||||
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
|
|
||||||
|
charCounts :: String -> Map Char Int
|
||||||
|
charCounts (x:xs) = Map.insertWith (+) x 1 (charCounts xs)
|
||||||
|
charCounts [] = Map.empty
|
||||||
|
|
||||||
|
processId :: [(Char, Int)] -> (Bool, Bool)
|
||||||
|
processId xs = foldr f (False, False) m
|
||||||
|
where m :: [(Bool, Bool)]
|
||||||
|
m = map (\(c, i) -> (i == 2, i == 3)) xs
|
||||||
|
|
||||||
|
f :: (Bool, Bool) -> (Bool, Bool) -> (Bool, Bool)
|
||||||
|
f (a1, a2) (b1, b2) = (a1 || b1, a2 || b2)
|
||||||
|
|
||||||
|
collect :: [(Bool, Bool)] -> (Int, Int)
|
||||||
|
collect xs = foldr f (0, 0) xs
|
||||||
|
where f :: (Bool, Bool) -> (Int, Int) -> (Int, Int)
|
||||||
|
f (a1, a2) (b1, b2)
|
||||||
|
| a1 && a2 = (b1 + 1, b2 + 1)
|
||||||
|
| a1 = (b1 + 1, b2)
|
||||||
|
| a2 = (b1, b2 + 1)
|
||||||
|
| otherwise = (b1, b2)
|
||||||
|
|
||||||
|
calculateChecksum :: [String] -> Int
|
||||||
|
calculateChecksum input = a * b
|
||||||
|
where (a, b) = collect [ (processId . Map.toList . charCounts) s | s <- input ]
|
||||||
|
|
||||||
|
sameChars :: String -> String -> Int
|
||||||
|
sameChars (x:xs) (y:ys)
|
||||||
|
| x == y = 1 + sameChars xs ys
|
||||||
|
| otherwise = sameChars xs ys
|
||||||
|
sameChars [] [] = 0
|
||||||
|
|
||||||
|
getCorrectBoxes :: [String] -> [String]
|
||||||
|
getCorrectBoxes xs = [ x | x <- xs, y <- xs, (length x - (sameChars x y)) == 1 ]
|
||||||
|
|
||||||
|
removeDiffChars :: [String] -> String
|
||||||
|
removeDiffChars xs = foldr f (last xs) xs
|
||||||
|
where f :: String -> String -> String
|
||||||
|
f (x:xs) (y:ys)
|
||||||
|
| x == y = x:(f xs ys)
|
||||||
|
| otherwise = f xs ys
|
||||||
|
f [] [] = []
|
||||||
|
|
||||||
|
main = do
|
||||||
|
input <- readFile "inputs.txt"
|
||||||
|
putStrLn ("[Part 1] Checksum: " ++ (show . calculateChecksum) (lines input))
|
||||||
|
putStrLn ("[Part 2] ID: " ++ (removeDiffChars . getCorrectBoxes) (lines input))
|
Loading…
Reference in New Issue
Block a user