day 6
parent
8b15b5f2c6
commit
6fe209eac9
@ -0,0 +1 @@
|
||||
mjqjpqmgbljsphdztnvjfqwrcgsmlb
|
@ -0,0 +1 @@
|
||||
bvwbjplbgvbhsrlpgdmjqwftvncz
|
@ -0,0 +1 @@
|
||||
nppdvjthqldpwncqszvftbrmjlhg
|
@ -0,0 +1 @@
|
||||
nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg
|
@ -0,0 +1 @@
|
||||
zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw
|
@ -0,0 +1 @@
|
||||
lrdrgrcggjrgrddfqfqrqppptrtssnqqqlzqqslspppsddfnnwgnnwhhjttnsnswnnbqbrrcqrqdqcdddlnddwwlmmlmtmwmggjgjmmmrppqhhswhwhmhchtchhsttvbtvvpspjjqrrgqrqmqvmvzmvzzrnnqlnlwlttjstjtjvjddrzzrnrmrbmbwwzppnqpqmmjnnvqnvvdzdpdvvmhvhhmshmsssvnnqppclcqlcqctqtfffvrfvrffptfftppncncwnntfntftdftfhfzzfwzzcddngdndccrttjmmcddrvrwwnntggghccjbjvbvjvlvjlvlgljlnjjtvjjfddmwwhnnqnrnccwllpmprmmspsvsrsslstsllpmllfzlflqltlssdbbdsdqsdqqgfgfjjtzjzmmsnsmnnzssgfgzgjgwwqfqtfthhhczzpwprwwqttqcqctcpcrrvwrvrggfvfqvvbqqhnnczcjjjfbfhbhjhssnwwfswszwwgbgzgczcbbvmvrrdgrddfwdffvsvtstztftfvfssgffnrnnzzqddltdtbdttnnfrnnfrfddpmpqqplqqbdbzbnnnrttjfttprtrllqhhwjhjghjjcrcqqznztzllldjjhqqspsfpfprrsfspsrrzbbjmjssnjnsjnjllbttgrtrnnqhhvjhvvrrplrprtrtprtrdtdfttwdttqtttwvtvtmtntnnfvfsfnndsnnnfqfmmcdmdppsmpmnnwhhlwwrvwrwvwlwnwhwjwvwbvwvnnqtnnttcgtccbggzgwzwczcpzcpzpzgzngnzzhfhdhzzzsggtssddgtdtndtdllpbpjpgjjsllvqvmmvjmvjvbbfzzbdzzghhzjzvvnffwsshqhqhjhmmtgmgpmgmpmzzzhtzzbzsbzsbzszvsvgsvspvsstwtgwgqgjggsfsmffhlhmhdmhmgmrmffjcjggqgsghgttjffprpmmscsggswssgzzsqzqjqwqjwqwswjjqpjpllwrwffvfbfpbffjsswgsshjsjqssqrrvcrrnvvdnnwndnffpdffjlffrjrlrqrmmlzlttpccgchggdjjhwwvqvvrprdrttlvvtlvtlvvvhqhwhmmpmrrjsrrzbzfzdzhdzzwgwwqllmmthmmvpprqprrzmrrfrmfrrmfmjmwwhtwhttnbbhbnnhbnnmhmgmjgmgfmmhpplwplwlswwjjbpbhpbbzmmgjmmggbzbssppjtttfmfwwcwmmbmrmbrblbmmszzvgvzgvgvdggjgsjgsjgghfgfngffsnfssdpdgpgrgnrggrlggdwgdgddfwddjdrrppnnqbnntmmrmlmrrgvvqjjwzzgnzzdtzzbccnbcbttbzzcqqrcqqpspbphbphhnpnccggczcgcpgcpctppqwpwccsgsttgtbttvftfcfbfvfppfpnpffmjmljmmrtrsrttnhhcvctclttrffhzhrzzdpzzwvwddcggpbptbpbzpzdpzddbjjdvvwmmfvfcfmfmmvrmvrmmcdmdqqhjqhqmmstmmdnnvssmbsmmnhmnmlmttlthtvhvvgbvgvbvqbvbvnbvvpwwhwsszpszppjljsllzhzcchmhdhphvvtpvvfssvmvcmmrjmmgfmfwmfmsspbbpnnsbsgbbzzllzzsqqswqqsbqqlvqlqzzbrzzqsqdqjqzqlqccqbqlblpprrthrttjzzfvzzpvpbppqjpjjtllmrmzzwnnrggpfpllwhhnmnpmmdppwnnwpnnzlzggvpvgpprdrzddlmddjndjjrljlsjshhqbbhhmhvhqhzqqlbqlqnqqmhmwmhwwgbwbpbhpbblnnshnshslllrcrncctnthtllmglmlmnmfnfllrbrmdqsncjfbjnghmvpctfzttqwsfptwhfhmdhzgbmrpqvsbbwdwdnqgclrgvdbqvtnzvlzmdjzgbhbtqjhrgqqjgwcvpqhhwsmmflgsjsvbnjcjcqwqqfcbvfrllbpphfglptjfczmnfnrmqdgrhbvrddwvhnbffsnzntvldrwmgqmqdbmmpdjhpdqfsbzsfbtdzlfjwtwfpfrhzcwwrcfpdjzjzqvcnhvdvlbdbjfrnmchdjprbfpzdtmjhdjtrwfrsghngbswhfzdfvhdmnqwnpspdjgsfcjjhrlnpncfdhzfzglgvrjlzdcncbfjhpnrvwnqbzhtdfcnpnpddsnjcbgdvzlsmpnlbftgjfsjsslljppjhtjfddmwbtrvmhvshnvhhfdsqhpmgzfrcqtpdmfcwglnbjzmtmzshzsrnbzlwlzdjzzsqfmjzbnprjdzswwcgjjwslhnfhbflvcpdfzwhzzjmfvpfhzbrcdvtlmbvrqvvtlpbdnshtsvlcnlwqzcnfhzndfjbhgwpvspdvhfptnfvwznscmgthspwpjfwlbbcrzgthrhnvscvfvwrwvtzpjqmwdbjjslvzlmqstzwqtsdsqqjpqthgnshpjncwgvppngvvfrjpztftgjbbmgdddrcgjggwpfrvfqbnzvwtscftbwfssmrgrbchjmvqcdgbdmmsswvplnvnjrnqzhttbzhlthzjslgtgrnqpghtbjnbftpdttvqhrljhnfqllrhfmzcnnwrljmchsvdbgvwmrpfzjsbngpffpgntrgflntbjnjwqbdhvhssvptdvvqvtrgqhhzrcfnnmbtzqrcghggcqhndggqzzgswflhqqrgmnggbrvpwqgtlptgmzdvgztgfqdzwnbrvvqhpnmcmptqljmqqmsslfcmgpnmnjmrsngrtbsffqbwlhsrwbzdcqvpbptpjphcjnwsmrjdbbrwftsnrgfhpjvsjcwpmpvfjtjvfnnwdjdttsjrqrgsznzqwjmsvscdtpptmdhqvwngtldtsnstjmwwrwwzdzvtndrrhgsgshzlpdrmlsgvplvbfrffvgvhmncbjdlqspbpdpcdsffrjzptltsznwwqbvnrwfdtrlbbvsmzjrhhvscqfwsqtmwnpjfgnjcttwphtqqhnvgjmzvczcrlmjjgwgnprcmmprltfrgrjlhvggdwvpnrqrtfwhpsfnjfvmvgzpmhrqmggldmsvztwcwzgblfbvbfvnshrdppzcvjwbjmsncwnbnjwbmwqjjwtjmwzpdvpwrfdtrqhnltgntvglgspvnbcsvnpppwmgphhsdqtpmrzmbdqlghsgjnnbhflzwghzzhdfsvjjcjfcssmvrmfqbgzcfwmhpvjqqrrhpsffczwgbjgwqlvzrvnhvzrqnfllqtrcjhmpdjfpqnlzhdnsctbfhsbpgwqdjdjhfbqzvzpsgmqwfjsffdjcqfmjgzqzvfsbhhvnwlfjfmdnphggdbnmpznlrzbnlbvhvplhjbzdmspnnlbctgzphghpngppdpdfbcdcpfntqlrwclsvnpljdbwcbhwzzdhbhsmslvvtjsmqmtpnhmmqnhfggnlpfthdhpwmrhzgfpwsffnrdqszcttrjsqzjqgspltfzzjnzwdfzvnmncwnphmjvcwlgrzcvpzcbndvhtjnfsgjtjdqfmgcgtgppsrcqwdjcqfddlhhnlfjrnsnssqblmnjjvmfbghtwwgcpgzfddvzsrsghqfrpvdtqmjfrzpvclmsnpmrqngdwvznlhdpbrzqtswfhnblnnbwjcwwbwfrgcdgrpphnslgnwbtfcgcmvvllwgvrcrdfcfwvwmdhhzmmnzmjgmgrgpdhngjgmhlqwtgzlngrbbfwfjrpwbqjnvdggrcfdgphfctvbmjnwfbpwrvbdbjrbhtnhfvhwvrptptsdrnzmnlwgbrwcswrccwdftgvjnvhffghdvhltjwhppfwfnmmtwclzzftzwvmhpmgvdsqzrfwqsmcgswnzjcnrvdgjlqdjrczphsvldlfzwdwmpncpvgqsvgpfpsfbgbmdhnfqbhdqwwwfdgqtmjlfbztsrwjrtqnrfpfqgplznpftrnjzhzcrnngqpwbrpbhlbfsgrpwfflrpbqdrqdplgcn
|
@ -0,0 +1,29 @@
|
||||
module Day6Lib
|
||||
( --
|
||||
processInput1,
|
||||
processInput2,
|
||||
)
|
||||
where
|
||||
|
||||
import Data.List (sort)
|
||||
-- import Debug.Trace
|
||||
|
||||
createTiles :: Int -> [a] -> [[a]]
|
||||
createTiles size list
|
||||
| length list >= size = take size list : createTiles size (tail list)
|
||||
| otherwise = []
|
||||
|
||||
allUnique :: Ord a => [a] -> Bool
|
||||
allUnique = allUnique' . sort
|
||||
|
||||
allUnique' [] = True
|
||||
allUnique' [e] = True
|
||||
allUnique' (e1 : e2 : l) = e1 /= e2 && allUnique' (e2 : l)
|
||||
|
||||
-- ####################
|
||||
|
||||
processInput1 :: String -> Int
|
||||
processInput1 = (+ 4) . length . (takeWhile not) . map allUnique . createTiles 4
|
||||
|
||||
processInput2 :: String -> Int
|
||||
processInput2 = (+ 14) . length . (takeWhile not) . map allUnique . createTiles 14
|
@ -0,0 +1,49 @@
|
||||
import Day6Lib (processInput1, processInput2)
|
||||
import System.IO
|
||||
import Test.HUnit
|
||||
|
||||
testCases1 =
|
||||
[ ("data/input0601.txt", 7),
|
||||
("data/input0602.txt", 5),
|
||||
("data/input0603.txt", 6),
|
||||
("data/input0604.txt", 10),
|
||||
("data/input0605.txt", 11),
|
||||
("data/input061.txt", 1920)
|
||||
]
|
||||
|
||||
testCase1 (file, result) = do
|
||||
withFile
|
||||
file
|
||||
ReadMode
|
||||
( \handle -> do
|
||||
contents <- hGetContents handle
|
||||
assertEqual "input test" result $ processInput1 contents
|
||||
)
|
||||
|
||||
testCases2 =
|
||||
[ ("data/input0601.txt", 19),
|
||||
("data/input0602.txt", 23),
|
||||
("data/input0603.txt", 23),
|
||||
("data/input0604.txt", 29),
|
||||
("data/input0605.txt", 26),
|
||||
("data/input061.txt", 2334)
|
||||
]
|
||||
|
||||
testCase2 (file, result) = do
|
||||
withFile
|
||||
file
|
||||
ReadMode
|
||||
( \handle -> do
|
||||
contents <- hGetContents handle
|
||||
assertEqual ("input test: " ++ file) result $ processInput2 contents
|
||||
)
|
||||
|
||||
tests =
|
||||
TestList $
|
||||
[TestCase (testCase1 c) | c <- testCases1]
|
||||
++ [TestCase (testCase2 c) | c <- testCases2]
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
runTestTT tests
|
||||
return ()
|
@ -0,0 +1,30 @@
|
||||
import Day6Lib
|
||||
import Test.HUnit
|
||||
import Text.Parsec
|
||||
|
||||
|
||||
-- tCommand2 =
|
||||
-- TestCase $
|
||||
-- assertEqual
|
||||
-- "command"
|
||||
-- (Right Command {cnt = 1, from = 0, to = 1})
|
||||
-- (parse command " " "move 1 from 1 to 2")
|
||||
|
||||
|
||||
tests =
|
||||
TestList $
|
||||
[ tParseCrate,
|
||||
tParseCrateOrNothing1,
|
||||
tParseCrateOrNothing2,
|
||||
tCrateRow,
|
||||
tNumberRow,
|
||||
tCommand1,
|
||||
tCommand2,
|
||||
tStackBuild1,
|
||||
tStackBuild2
|
||||
]
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
runTestTT tests
|
||||
return ()
|
Loading…
Reference in New Issue