From 9c3befc0c8f9d37584f7168330e0fcf4bb45ab46 Mon Sep 17 00:00:00 2001 From: Steph Date: Thu, 8 Dec 2022 22:09:56 +0100 Subject: [PATCH] Day 6! --- 2022/aoc2022.cabal | 14 ++------------ 2022/app/Day4/Main.hs | 2 +- 2022/app/Day5/Main.hs | 2 +- 2022/app/Day6/Main.hs | 35 +++++++++++++++++++++++++++++++++++ 2022/app/Day6/input | 1 + 2022/app/Main.hs | 2 ++ 2022/default.nix | 2 +- 7 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 2022/app/Day6/Main.hs create mode 100644 2022/app/Day6/input diff --git a/2022/aoc2022.cabal b/2022/aoc2022.cabal index 28b8bbe..2a85faf 100644 --- a/2022/aoc2022.cabal +++ b/2022/aoc2022.cabal @@ -1,22 +1,12 @@ cabal-version: 2.4 name: aoc2022 version: 0.1.0.0 - --- A short (one-line) description of the package. --- synopsis: - --- A longer description of the package. --- description: - --- A URL where users can report bugs. --- bug-reports: - author: Steph maintainer: noreply+steph@code.steph.tools executable aoc2022 main-is: Main.hs - build-depends: base ^>=4.16.3.0, split ^>=0.2.3.5, regex-tdfa ^>=1.3.2, containers ^>=0.6.6 + build-depends: base ^>=4.16.2.0, split ^>=0.2.3.5, regex-tdfa ^>=1.3.2, containers ^>=0.6.6 hs-source-dirs: app default-language: Haskell2010 - other-modules: Day1.Main Day2.Main Day3.Main Day4.Main Day5.Main + other-modules: Day1.Main Day2.Main Day3.Main Day4.Main Day5.Main Day6.Main diff --git a/2022/app/Day4/Main.hs b/2022/app/Day4/Main.hs index 183376d..3dd83d9 100644 --- a/2022/app/Day4/Main.hs +++ b/2022/app/Day4/Main.hs @@ -1,4 +1,4 @@ -module Day4.Main where +module Day4.Main (main) where import System.IO import Data.List.Split diff --git a/2022/app/Day5/Main.hs b/2022/app/Day5/Main.hs index e868b1e..cadc946 100644 --- a/2022/app/Day5/Main.hs +++ b/2022/app/Day5/Main.hs @@ -1,4 +1,4 @@ -module Day5.Main where +module Day5.Main (main) where import System.IO import Data.List diff --git a/2022/app/Day6/Main.hs b/2022/app/Day6/Main.hs new file mode 100644 index 0000000..340ee10 --- /dev/null +++ b/2022/app/Day6/Main.hs @@ -0,0 +1,35 @@ +module Day6.Main (main) where + +import System.IO +import Data.List + +main :: IO () +main = do + putStrLn "Day 6" + + handle <- openFile "app/Day6/input" ReadMode + contents <- hGetContents handle + + let r1 = part1 contents + putStrLn $ "part 1: " ++ show r1 + + let r2 = part2 contents + putStrLn $ "part 2: " ++ show r2 + +distinct xs = length (nub xs) == length xs + +part1 :: String -> Int +part1 contents = go contents 0 + where + go [] _ = 0 + go (a:b:c:d:es) n | distinct [a,b,c,d] = n + 4 + go (a:es) n = go es (n + 1) + +part2 :: String -> Int +part2 contents = go contents 0 + where + go [] _ = 0 + go (e:es) n = if distinct (e : take 13 es) + then n + 14 + else go es (n + 1) + diff --git a/2022/app/Day6/input b/2022/app/Day6/input new file mode 100644 index 0000000..dc16ab4 --- /dev/null +++ b/2022/app/Day6/input @@ -0,0 +1 @@ +dvgdvvbpbtbhbdhbhmmmcctmcmccggtrgghnhmnnqffpcprrqssnhsnhnshhsrsqqhchcdcfcqqcncrrzpppmzpzzhjzzzvrvnnpbpzzswzwswnngjgjgcjcfcllhffjbfjfhhppvnppfmfcmmcnnmnfnzfnzffphpnnnsvswvvnwnfntftjftfvvztzqzhzddttjpjbpphhlnnwgnwggdmmczclczzqddlcdldrlrccfflwwgqwwrjwrwzrrsdrrfssddcmmvrvlvhvfhfzhzbhbzzdmdvvsppwswmwdwjjzmzhhvghgthghvvtcthcttgsttpqpbbhthppzznntpnttshtshthhwrrgbbjzbjblblzbllcblcblbvvqfqqnjqqhfhftftwfftvvmddgzzmdzmdmtttttqmqmnqmqpmqpqqjlldpllfvlffjdfjjvlvjjjjbsjbjnnhmnhnrrwtrrfvvtppwmmpnnjbnjjcncjcttrcrjjlqjljccpzccvqvzzscctgccsmmnznhzhnnjggmjgmgjgtgtlgglhhrlhhrvhvrvtvvlvvwmmrjjzqqbzqqtgtzgttmgggwpgwgbwggwwprwwvswszznczncnccjnccjdjdjssqmmgcmcjmmhwhswhwdwrddtccmzmjmsmrmrddhrhhqbbspbsppqvqmvqmmclcddzjzvvslsffdhhqgqrqjrqjqjrrmpmrppcjpjffwhfwwppqvvzjzqqtftgfghgpglgnglldlvvwzwmmfzzhzmzhhswhhnvhvphpmphphrrwwfccmgmqgmmzgmgngznnzbzttjwttgngzzdndffwhfwhhlmllwqlwwgfgfpfnnldnldndbdcdddmbdmbbdpbpwbpptrrpggtrtrnttsmmcrmmlhltlgttblttbhttjzzvnnsbsqbqwbbtwtmtbbcjcljjslscswwglgqlgqgmmcpctcrttprpjjfvjfjqqljlvjljnnfhhfzhzmhmghhjnhjjbppmqqwlwswwgbbzszspzsppcscvvnhndhdwdmdrdssqrqdqsddnbnpplqppjbjdbdqdcccffsnntzntnmnlnbbrzzzvgvvqttbbzpbzpzdpdvppjmjpjbbdrbbgwgffzpzzjddmldlwwjdwwscwcfccnznmmfttvvmpmvpmvmcvmmjmwjwbbwqwjjzqjzjbbjqbjqqqthhsssmrsshvvprvvwccjlcctwwmgwgpwgpgcpptrppjppltlhthctttfptppwgpwprpbbqzbzznssfcsffbnnndffqmmqwmmpvvpvdppjqqttfpttjccbnbddvtdvddlsstjtccphchsswbbrqqgtqgqpqjqnjjvccwscwssjwjttqvtvmtmjjghghccpnpsplslmmfjfjtffgtgrtrftfhttpsttzzmhmllwqwhhnffdpffwbwnnbrrfbrrnjrjlljqqnjqnqqwlqqbbbtvvwgvgbgddpwdwvdwvdvvwzvwwtzwttppnttqccjtjrttqbbprpsrpssfjsffmdfmfbmbggjhggcjgcgvvjqqbhbllhrlhlclzzplpqqdtddrhhfssdvsvrrscsjjnwjjfpjfffcbfcfmmlpmphhhlpltptcpttppfssppgwppjgjnnblbhbtbrbgbpplnlvlsvlvwvwpptmtsswzswsnscsfcsfsfggzhghvvgbbfddgbbrmrtrqtthvhzhzthtbtjjcljjlcllzglzzdszdzjzjfzzzblbslbljjdnndvvnwnqnwqqscscmczcwwvrrlclttbtdtvddbrddvllnppvpmvmbbvfvttfcttggwgffrfwwwpwcpchppcrrgprgprgrjgjdgdgvddzndzdbzzswsvvtgtccrrnggbwggpjpnnsjjwfjjqfqvffrrhdrrsfrfjjfzfdzzqfqwbztszjqtttfdqvzmznzjlsjnwdthtwdtfslgdmgfpwsqcsqdhnsnsmghttfvlzqgspzdtlstdmthzftwmnqrznldpmwqbtthggjwcgjjmbpqgrnwspggjvrlcmtvpchmqhlwwtswqgpdjpbznqnssqhdjzgbjnfmgssrvnmmcvvhgmcvqbfdhgrhnqqzdmttmdzwgtprzqhplwnhhmlrvcbwpllqprtltdvqrwhvwzvlqsvfqsfjwmrnzlqpdgfpmtfdczqdnfjjbjmrdnffcmtwlzcmvnwmlpmqhvggdhptnzlvzwzwjbcszsnzgpwncfgvzfgbzwclvrbmllzpltzwjrftmppsfwhvvvhvqjtstnnczgtdbmpjjsscbdwplftgcgmtrnrnzplzhghrqgdtjwntwfstjwqjjrlhtwhnfqwfqgsjptjfpsrbnvvlgsltnvtfvscttwvrfzblzmfmnfrlrnzrrzhclggtntpjbbcphdvrfhnrtzvdmwbwgbftgzwlcqztghdhdmzwlmjbgptfnnzbmwsnzlzcpprqzmbbdsplmhpgmzthqcsfjcnfbfvsdsqzfvfcnpgqsvpgwsdbgjmsglrwmfjfpddczwvgdppfmrtszbtfdwbmlmzhqvvwmvlzvjfpffjnhwwhssfjnbzlqwqvjbjbhfntmhgswntdpbzlwwfbdbhrfhzfjsjbtlrqhlnrpfbwtpmrfvbhlmmsgtvcmrqmdpwvhqfqpgmfgnfrbvprhprtnpzjcnltndfsvjgndwblhwphtpsmnczgbtpwdvjsrctjbvbfslvslzlwbtstqvgcrqmfphwztpjqdmvcjpjqmjbdndfpzwsfwplchsmqwwbggptjdtztszmpfwgfwnqpdwfcpgrrhmfglsctjllflfltbcfvcpfcnqbwrvzmcmjpwptgsrlbrdchngwsdstfmcbrqvdsvvbnppdmnfwcgvpjjzqwcpvqfncvqlsfnjzprvhpgqscshqwsttdrsmqjfwlhcwlvnzvgvclqfjdgctvsrbwzflcldmrwlfhbgdtstqsqlblndnpgqlfbjzslcpcwvdwdffshhrzvhqwdsdmwtmtvcnrhmstvrnscppmbpmjbfjhljmsjnbjlhjhmnmcvvfgbdrblwbzrcctrjwjjwjtgnfjhhqbsmdjvdrdjtjbscfrsljnvqjlgjwqrvfmdttsvqjwdbswdtcfqsrpbvzrbsdqlqfjlrgcwzbqtqrpsrfcmbzcvjngcsmvqlbnghllcqcztbtvdrfcmpgfdprghsmbjvzbdnrdqnjdzslclgdsqglvpvcjpzqfwztlssljtmcdfcqdnqzwcttvpqfdpvzlhjfvvsgphgqrmzppvnjznqmdzfnfztjppstjfwddftcpcjnssznqbrvlvrzfhbvsjrwghttwlwfrptsvsrwfnvjtthwrppbngbgqvbsdgcrjcwjjljcwptrvgmbjpjtdbmhmzcfhzbsbrmzhdsrjbbmnwbsntpffdrrlgcrcgbcfwvlpmrzvsmvpjthtdjdvcspdsdvshlrwzcqnjmcnrgzbqzhfzbmtrvzzmjwbnjggtrtgcsnrmzbtjzgdmffdntspdhgnvgrmpbtnsspcqhsrvppjbrmdbggjbftnnbrgdsmdscqthdzflldfnplqccthpwccsfsnstttwztqnmnfshntqngmcndbsbftmgnhhwjvhchdfqzzgpdnfgvnjzjzfdzvsvtdqqcftrvmdcszcwpfrbcsmlqqfprrjgncwcvcngmrnwntcvzzlnwrhrznnldslhqdscbgsrqnvnmdtqvlttwqljmvbpbfldtbgzhvwzghnhwrwdqphhhgjpnmtlcmvfbdffnsvcswtmffzsrvczbntfpdsmwbqphvvcflpwgsrmjhrljlvzdgrcwpfphmvtwqwhjmrvmjzjlzlbflhzrdrzcdwhblpqwjljbvprddtvnccmchgctncwbpnmlqppfmhwchvjvpmblqhccfhlprdrczdfhmnsqhddbqlppgsnvhhfrwhqhfdpvsfcvzbqhgswtmnpmzrwsvnmztnqwdrhllssmgtzbztsprpsj diff --git a/2022/app/Main.hs b/2022/app/Main.hs index 8b36507..ef9b8e0 100644 --- a/2022/app/Main.hs +++ b/2022/app/Main.hs @@ -5,6 +5,7 @@ import qualified Day2.Main as Day2 import qualified Day3.Main as Day3 import qualified Day4.Main as Day4 import qualified Day5.Main as Day5 +import qualified Day6.Main as Day6 main :: IO () main = do @@ -13,3 +14,4 @@ main = do Day3.main Day4.main Day5.main + Day6.main diff --git a/2022/default.nix b/2022/default.nix index 631233a..9bf2a65 100644 --- a/2022/default.nix +++ b/2022/default.nix @@ -1,6 +1,6 @@ { pkgs ? import {}, - hc ? "ghc924" + hc ? "ghc923" }: pkgs.stdenv.mkDerivation rec {