From 30f2ac165744b80139e28c783aa4d0f0ac122e87 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Wed, 1 Dec 2021 16:10:33 +0000 Subject: [PATCH] Initial commit --- .gitignore | 42 + CHANGELOG.md | 5 + Main.hs | 4 + README.md | 117 ++ Setup.hs | 2 + advent-of-code-21.sublime-project | 8 + advent-of-code21.cabal | 87 ++ advent01/Main.hs | 18 + data/advent01.txt | 2000 +++++++++++++++++++++++++++++ problems/day01.html | 181 +++ 10 files changed, 2464 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 Main.hs create mode 100644 README.md create mode 100644 Setup.hs create mode 100644 advent-of-code-21.sublime-project create mode 100644 advent-of-code21.cabal create mode 100644 advent01/Main.hs create mode 100644 data/advent01.txt create mode 100644 problems/day01.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a0ee39 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# Extensionless files +* +!/**/ +!*.* + +# Haskell bits +dist +dist-* +cabal-dev +*.o +*.hi +*.chi +*.chs.h +*.dyn_o +*.dyn_hi +.hpc +.hsenv +.cabal-sandbox/ +cabal.sandbox.config +*.prof +*.aux +*.hp +*.eventlog +cabal.project.local +.HTF/ + + +# IPython / IHaskell notebook checkpoints +.ipynb* + +# Sublime text +*.sublime-workspace + +# Logs +*.log + +# Profile exports +*.ps + +# KDE +.directory + diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c5f01f9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for advent-of-code21 + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/Main.hs b/Main.hs new file mode 100644 index 0000000..65ae4a0 --- /dev/null +++ b/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = putStrLn "Hello, Haskell!" diff --git a/README.md b/README.md new file mode 100644 index 0000000..935b938 --- /dev/null +++ b/README.md @@ -0,0 +1,117 @@ +--- +title: "Advent of Code 2020" +output: html_document +css: modest.css +--- +Code to solve the [Advent of Code](http://adventofcode.com/2020/) puzzles. This year, I'm using the puzzles to develop my skills in [Haskell](https://wiki.haskell.org/Haskell). I'm writing up a [commentary on these puzzles and my solutions](https://work.njae.me.uk/tag/advent-of-code/) on my blog. + +[Learn you a Haskell](http://learnyouahaskell.com/chapters), [Introduction to Haskell 98](https://www.haskell.org/tutorial/index.html), and [Hackage](https://hackage.haskell.org/) are good resources. + +The [Stack documentation](https://docs.haskellstack.org/en/stable/README/) and [How I Start: Haskell](http://howistart.org/posts/haskell/1/) are good sources of using the tools. + + +# Toolchain + +Install Ghcup following [the instructions](https://www.haskell.org/ghcup/install/#installation), making sure to load the updated environment with + +```bash +source /home/neil/.ghcup/env +``` + +Install [Haskell Language Server](https://haskell-language-server.readthedocs.io/en/latest/configuration.html) for Sublime Text + + +## Creating the repository and project +Create the repository as normal: create the project in Gitolite, clone it, and insert the `.gitignore` and `README.md` files. + +There's one package per day, with the code for each package in sub-directories of the root directory. + +Create the basic `cabal` project. + +``` +cabal init +``` + +Modify the `advent-of-code21.cabal` file as needed, such as updating the Cabal version and writing the `common` stanzas. + +## Creating subsequent days + +Each day lives in a separate directory, with its own `package.yaml` file and code in the `src` directory. (I based this configuration from [mstksg's setup](https://github.com/mstksg/advent-of-code-2018).) + +Compile with +``` +cabal build +``` +or +``` +cabal build advent01 +``` + +Run with +``` +cabal run advent01 +``` + +If you want to pass in additional RTS parameters, do it like this: +``` +stack exec -- advent01 +RTS -K0 -RTS +``` + +Run interactively with +``` +cabal repl advent01 +``` +or +``` +stack ghci advent01:exe:advent01 +``` +if the first form is ambiguous. + +To profile, use +``` +stack build --executable-profiling --library-profiling --ghc-options="-fprof-auto -rtsopts" advent01 +``` +then run with +``` +stack exec --profile -- advent01 +RTS -p -hy +``` +Generate the profile graph with +``` +stack exec hp2ps advent01.hp +``` + +For Cabal, look at [profiling with Cabal sandboxes](https://nikita-volkov.github.io/profiling-cabal-projects/) + + +# Packages + +Stack is using the [14.16-lts resolver](https://www.stackage.org/lts-16.25) for packages, so make sure you read the [correct documentation for the packages included in it](https://www.stackage.org/lts-16.25/docs). + +Packages I used a lot: + +* [Containers](https://hackage.haskell.org/package/containers) (and some [better documentation](https://haskell-containers.readthedocs.io/en/latest/intro.html)); [Unordered containers](https://hackage.haskell.org/package/unordered-containers) is a mostly-equivalent alternative. +* [Attoparsec](https://hackage.haskell.org/package/attoparsec) (and [Megaparsec](https://hackage.haskell.org/package/megaparsec), and [ReadP](https://hackage.haskell.org/package/base-4.14.1.0/docs/Text-ParserCombinators-ReadP.html) once). + +There are somewhat decent [tutorials on Megaparsec](https://markkarpov.com/tutorial/megaparsec.html) and [Attoparsec](https://www.schoolofhaskell.com/school/starting-with-haskell/libraries-and-frameworks/text-manipulation/attoparsec). + +Packages I didn't use much, but need to remember: + +* [Arithmoi](https://hackage.haskell.org/package/arithmoi) for number theory +* [Pointed List](https://hackage.haskell.org/package/pointedlist-0.6.1) for zipper lists (sometimes circular) +* [Vector](https://hackage.haskell.org/package/vector) for array-like things +* [Linear](https://hackage.haskell.org/package/linear) for coordinate-vector like things +* [Grid](https://hackage.haskell.org/package/grid) for 2-d grids +* [Graph-wrapper](https://hackage.haskell.org/package/graph-wrapper) for graphs +* [Lens](https://hackage.haskell.org/package/lens) (and a [summary of operators](https://github.com/ekmett/lens/wiki/Operators)). I didn't use these much this year, but did a lot last year. +* [RWS](https://hackage.haskell.org/package/mtl-2.2.2/docs/Control-Monad-RWS-Lazy.html) (Reader-Writer-State monad stack); again, used a lot last year but not this year +* [Monad loops](https://hackage.haskell.org/package/monad-loops-0.4.3/docs/Control-Monad-Loops.html), and [a description](https://conscientiousprogrammer.com/blog/2015/12/11/24-days-of-hackage-2015-day-11-monad-loops-avoiding-writing-recursive-functions-by-refactoring/) +* [Replace-Megaparsec](https://github.com/jamesdbrock/replace-megaparsec), for using Mpc for all sorts of things traditionally done with regex substitutions. + +# Readme + +Build this readme file wth +``` +pandoc -s README.md > README.html +``` + +(Using the [Modest style](https://github.com/markdowncss/modest).) diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/advent-of-code-21.sublime-project b/advent-of-code-21.sublime-project new file mode 100644 index 0000000..24db303 --- /dev/null +++ b/advent-of-code-21.sublime-project @@ -0,0 +1,8 @@ +{ + "folders": + [ + { + "path": "." + } + ] +} diff --git a/advent-of-code21.cabal b/advent-of-code21.cabal new file mode 100644 index 0000000..54f3668 --- /dev/null +++ b/advent-of-code21.cabal @@ -0,0 +1,87 @@ +cabal-version: 3.6 +-- Initial package description 'advent-of-code21.cabal' generated by 'cabal +-- init'. For further documentation, see +-- http://haskell.org/cabal/users-guide/ + +name: advent-of-code21 +version: 0.1.0.0 +synopsis: Advent of Code 21 solutions +-- description: +-- bug-reports: +license: MIT +-- license-file: LICENSE +author: Neil Smith +maintainer: neil.git@njae.me.uk +-- copyright: +-- category: +build-type: Simple +extra-source-files: CHANGELOG.md, README.md + +common common-extensions + default-extensions: AllowAmbiguousTypes + , ApplicativeDo + , BangPatterns + , BlockArguments + , DataKinds + , DeriveFoldable + , DeriveFunctor + , DeriveGeneric + , DeriveTraversable + , EmptyCase + , FlexibleContexts + , FlexibleInstances + , FunctionalDependencies + , GADTs + , GeneralizedNewtypeDeriving + , ImplicitParams + , KindSignatures + , LambdaCase + , MonadComprehensions + , MonoLocalBinds + , MultiParamTypeClasses + , MultiWayIf + , NamedFieldPuns + , NegativeLiterals + , NumDecimals + , OverloadedLists + , OverloadedStrings + , PartialTypeSignatures + , PatternGuards + , PatternSynonyms + , PolyKinds + , RankNTypes + , RecordWildCards + , ScopedTypeVariables + , TemplateHaskell + , TransformListComp + , TupleSections + , TypeApplications + , TypeFamilies + , TypeInType + , TypeOperators + , ViewPatterns + +common build-directives + build-depends: base ^>=4.14 + default-language: Haskell2010 + ghc-options: -O2 + -Wall + -threaded + -rtsopts "-with-rtsopts=-N" + +executable advent-of-code21 + main-is: Main.hs + -- other-modules: + -- other-extensions: + build-depends: base >=4.13 && < 4.15 + -- hs-source-dirs: + default-language: Haskell2010 + +executable advent01 + import: common-extensions, build-directives + main-is: advent01/Main.hs + -- other-modules: + -- other-extensions: + -- build-depends: base >=4.13 && < 4.15 + -- hs-source-dirs: + -- default-language: Haskell2010 \ No newline at end of file diff --git a/advent01/Main.hs b/advent01/Main.hs new file mode 100644 index 0000000..535fdf4 --- /dev/null +++ b/advent01/Main.hs @@ -0,0 +1,18 @@ +import Data.List + +main :: IO () +main = + do numStrs <- readFile "data/advent01.txt" + let nums = map (read @Int) $ lines numStrs + print $ part1 nums + print $ part2 nums + +part1 :: [Int] -> Int +part1 = countIncreasing + +part2 :: [Int] -> Int +part2 nums = countIncreasing $ map sum windows + where windows = filter (\w -> length w == 3) $ map (take 3) $ tails nums + +countIncreasing :: [Int] -> Int +countIncreasing nums = length $ filter (> 0) $ zipWith (-) (tail nums) nums diff --git a/data/advent01.txt b/data/advent01.txt new file mode 100644 index 0000000..ad1abff --- /dev/null +++ b/data/advent01.txt @@ -0,0 +1,2000 @@ +173 +175 +171 +177 +179 +177 +174 +177 +178 +185 +189 +195 +194 +211 +227 +226 +227 +221 +224 +227 +228 +231 +232 +229 +226 +244 +252 +251 +258 +269 +263 +255 +259 +261 +232 +231 +241 +244 +245 +278 +258 +259 +273 +272 +281 +284 +288 +303 +306 +312 +313 +325 +327 +332 +335 +345 +346 +328 +329 +327 +330 +325 +326 +325 +351 +352 +353 +363 +364 +382 +402 +401 +380 +370 +371 +348 +359 +357 +366 +386 +401 +387 +388 +404 +409 +430 +435 +441 +475 +469 +475 +473 +478 +510 +507 +508 +510 +502 +500 +512 +517 +521 +519 +532 +533 +537 +538 +540 +541 +545 +556 +548 +543 +549 +561 +562 +563 +562 +561 +572 +574 +575 +568 +569 +570 +579 +591 +590 +602 +601 +581 +583 +593 +590 +591 +577 +576 +579 +581 +563 +559 +563 +564 +567 +569 +570 +582 +579 +601 +598 +583 +589 +591 +597 +611 +618 +621 +622 +641 +657 +658 +661 +631 +633 +646 +647 +652 +667 +670 +676 +680 +681 +683 +681 +687 +690 +683 +687 +690 +695 +691 +693 +696 +695 +700 +697 +696 +700 +713 +696 +693 +698 +701 +700 +699 +690 +692 +693 +696 +722 +744 +746 +758 +763 +768 +782 +776 +777 +787 +797 +800 +801 +789 +814 +815 +812 +790 +791 +790 +804 +813 +841 +845 +844 +848 +855 +847 +855 +858 +859 +858 +860 +867 +868 +869 +877 +887 +888 +895 +896 +904 +905 +907 +923 +932 +944 +945 +950 +955 +965 +990 +1019 +1017 +1025 +1040 +1041 +1066 +1060 +1033 +1034 +1047 +1057 +1060 +1061 +1068 +1071 +1080 +1081 +1090 +1096 +1097 +1098 +1099 +1093 +1096 +1100 +1101 +1112 +1118 +1119 +1121 +1123 +1125 +1126 +1152 +1155 +1149 +1161 +1166 +1178 +1181 +1182 +1189 +1190 +1176 +1169 +1183 +1196 +1183 +1205 +1207 +1198 +1200 +1186 +1172 +1162 +1177 +1179 +1175 +1163 +1164 +1170 +1168 +1171 +1173 +1172 +1174 +1175 +1172 +1173 +1167 +1169 +1173 +1176 +1177 +1178 +1179 +1181 +1185 +1186 +1196 +1183 +1181 +1176 +1190 +1200 +1216 +1240 +1238 +1234 +1224 +1247 +1257 +1258 +1246 +1233 +1234 +1223 +1229 +1231 +1232 +1231 +1232 +1249 +1255 +1254 +1257 +1268 +1298 +1300 +1302 +1325 +1337 +1339 +1345 +1348 +1336 +1341 +1342 +1343 +1344 +1343 +1336 +1351 +1360 +1362 +1359 +1357 +1358 +1364 +1370 +1372 +1373 +1374 +1378 +1409 +1390 +1398 +1410 +1411 +1417 +1418 +1431 +1450 +1451 +1452 +1456 +1468 +1469 +1472 +1475 +1465 +1469 +1453 +1457 +1458 +1474 +1464 +1454 +1457 +1460 +1467 +1469 +1470 +1455 +1456 +1468 +1476 +1498 +1502 +1500 +1514 +1522 +1529 +1528 +1516 +1511 +1516 +1521 +1503 +1523 +1498 +1515 +1527 +1526 +1527 +1556 +1567 +1586 +1607 +1616 +1615 +1611 +1612 +1621 +1599 +1600 +1601 +1625 +1632 +1633 +1628 +1656 +1644 +1646 +1669 +1671 +1675 +1676 +1682 +1681 +1658 +1657 +1671 +1669 +1668 +1669 +1670 +1691 +1708 +1709 +1708 +1724 +1731 +1738 +1748 +1766 +1767 +1769 +1756 +1757 +1758 +1759 +1760 +1773 +1775 +1777 +1780 +1782 +1793 +1813 +1795 +1796 +1798 +1797 +1804 +1806 +1811 +1812 +1813 +1818 +1822 +1829 +1824 +1814 +1811 +1806 +1825 +1844 +1847 +1837 +1841 +1844 +1836 +1825 +1828 +1841 +1846 +1839 +1840 +1847 +1856 +1869 +1870 +1871 +1879 +1884 +1890 +1888 +1859 +1861 +1873 +1870 +1871 +1876 +1885 +1886 +1887 +1888 +1887 +1895 +1888 +1889 +1891 +1890 +1884 +1885 +1854 +1857 +1860 +1841 +1837 +1838 +1841 +1859 +1863 +1865 +1866 +1864 +1853 +1855 +1865 +1867 +1875 +1876 +1877 +1880 +1877 +1876 +1886 +1894 +1901 +1903 +1910 +1901 +1903 +1905 +1911 +1913 +1928 +1938 +1940 +1946 +1956 +1951 +1953 +1955 +1961 +1957 +1960 +1967 +1966 +1970 +1976 +1979 +1980 +1979 +1967 +1974 +1980 +1974 +1975 +1976 +2005 +2012 +2015 +2022 +2023 +2024 +2018 +2017 +2024 +2041 +2042 +2043 +2074 +2075 +2077 +2084 +2090 +2091 +2096 +2097 +2100 +2103 +2090 +2063 +2081 +2082 +2079 +2095 +2093 +2095 +2103 +2084 +2093 +2098 +2116 +2123 +2124 +2123 +2117 +2115 +2120 +2121 +2132 +2138 +2146 +2158 +2162 +2163 +2167 +2177 +2178 +2183 +2178 +2198 +2174 +2187 +2196 +2221 +2224 +2228 +2232 +2237 +2238 +2257 +2262 +2263 +2266 +2280 +2287 +2293 +2280 +2281 +2289 +2290 +2289 +2291 +2307 +2316 +2322 +2321 +2320 +2335 +2339 +2345 +2348 +2357 +2360 +2361 +2367 +2375 +2380 +2382 +2389 +2398 +2384 +2388 +2390 +2367 +2369 +2371 +2366 +2370 +2371 +2379 +2364 +2365 +2368 +2369 +2370 +2377 +2378 +2390 +2392 +2398 +2402 +2393 +2404 +2417 +2441 +2446 +2453 +2459 +2462 +2463 +2464 +2476 +2477 +2481 +2482 +2483 +2477 +2481 +2489 +2500 +2504 +2491 +2490 +2487 +2474 +2475 +2476 +2478 +2489 +2491 +2498 +2501 +2513 +2514 +2532 +2546 +2547 +2553 +2559 +2562 +2580 +2588 +2590 +2602 +2601 +2608 +2613 +2616 +2623 +2626 +2651 +2652 +2654 +2650 +2651 +2654 +2658 +2657 +2660 +2654 +2668 +2669 +2662 +2665 +2647 +2660 +2670 +2672 +2680 +2677 +2678 +2677 +2684 +2677 +2678 +2684 +2702 +2703 +2707 +2727 +2728 +2738 +2739 +2738 +2757 +2759 +2766 +2771 +2775 +2788 +2790 +2794 +2797 +2800 +2798 +2801 +2800 +2802 +2803 +2804 +2831 +2820 +2821 +2824 +2827 +2813 +2816 +2826 +2827 +2829 +2834 +2835 +2841 +2849 +2854 +2855 +2867 +2877 +2894 +2900 +2918 +2917 +2898 +2899 +2901 +2902 +2903 +2901 +2919 +2920 +2931 +2939 +2945 +2946 +2934 +2936 +2947 +2956 +2955 +2958 +2946 +2947 +2951 +2955 +2957 +2960 +2964 +2965 +2974 +2976 +2992 +3009 +3014 +3015 +2997 +2996 +3003 +3000 +3006 +3026 +3019 +3031 +3012 +3013 +3020 +3010 +3014 +3018 +3019 +3031 +3007 +3017 +3018 +3031 +3033 +3025 +3037 +3039 +3033 +3000 +3001 +3003 +3014 +3016 +3034 +3033 +3035 +3038 +3040 +3038 +3020 +3018 +3020 +3021 +3039 +3043 +3034 +3036 +3043 +3059 +3074 +3076 +3090 +3096 +3103 +3101 +3102 +3113 +3114 +3115 +3119 +3127 +3146 +3140 +3145 +3146 +3147 +3151 +3152 +3153 +3154 +3144 +3149 +3157 +3163 +3172 +3175 +3180 +3206 +3207 +3212 +3215 +3211 +3212 +3220 +3229 +3230 +3226 +3227 +3256 +3296 +3299 +3301 +3303 +3301 +3302 +3308 +3324 +3323 +3313 +3314 +3317 +3318 +3317 +3330 +3358 +3360 +3369 +3363 +3368 +3371 +3377 +3381 +3385 +3382 +3379 +3381 +3383 +3385 +3386 +3389 +3388 +3392 +3396 +3393 +3391 +3393 +3394 +3398 +3400 +3403 +3404 +3408 +3424 +3425 +3426 +3424 +3415 +3417 +3420 +3439 +3442 +3447 +3454 +3478 +3480 +3477 +3478 +3470 +3472 +3477 +3476 +3477 +3479 +3509 +3519 +3542 +3547 +3548 +3564 +3565 +3569 +3570 +3584 +3591 +3590 +3589 +3598 +3603 +3605 +3609 +3608 +3628 +3624 +3644 +3652 +3654 +3648 +3650 +3652 +3659 +3661 +3675 +3676 +3690 +3692 +3699 +3700 +3702 +3703 +3706 +3715 +3719 +3720 +3725 +3721 +3730 +3722 +3740 +3750 +3751 +3752 +3761 +3763 +3778 +3777 +3778 +3780 +3777 +3794 +3793 +3792 +3802 +3803 +3806 +3817 +3814 +3823 +3824 +3825 +3826 +3831 +3834 +3835 +3844 +3856 +3857 +3864 +3879 +3904 +3906 +3923 +3933 +3935 +3934 +3935 +3937 +3935 +3944 +3941 +3936 +3937 +3935 +3936 +3935 +3937 +3938 +3949 +3950 +3949 +3952 +3953 +3980 +3989 +3990 +3991 +3992 +3988 +3993 +4003 +3969 +3959 +3964 +3973 +3981 +3987 +3986 +3975 +3982 +3981 +3983 +3981 +3984 +3992 +3991 +3984 +3999 +4003 +4004 +3996 +3992 +4035 +4043 +4042 +4034 +4027 +4051 +4052 +4048 +4051 +4049 +4060 +4059 +4062 +4061 +4063 +4062 +4053 +4056 +4067 +4055 +4057 +4058 +4072 +4077 +4075 +4060 +4057 +4058 +4061 +4060 +4061 +4060 +4070 +4088 +4097 +4093 +4105 +4107 +4105 +4103 +4105 +4109 +4086 +4111 +4112 +4115 +4110 +4118 +4119 +4127 +4128 +4129 +4130 +4134 +4136 +4135 +4138 +4139 +4140 +4135 +4158 +4137 +4138 +4158 +4157 +4154 +4156 +4175 +4176 +4179 +4184 +4198 +4196 +4199 +4180 +4188 +4193 +4192 +4201 +4200 +4192 +4207 +4220 +4218 +4230 +4229 +4247 +4248 +4249 +4253 +4254 +4256 +4265 +4266 +4272 +4268 +4273 +4295 +4296 +4305 +4295 +4310 +4311 +4312 +4311 +4314 +4307 +4305 +4294 +4306 +4321 +4316 +4326 +4330 +4331 +4337 +4336 +4337 +4338 +4340 +4342 +4345 +4347 +4345 +4370 +4384 +4405 +4406 +4419 +4420 +4435 +4439 +4443 +4445 +4447 +4431 +4424 +4433 +4418 +4417 +4416 +4417 +4420 +4424 +4440 +4442 +4454 +4461 +4481 +4483 +4479 +4480 +4484 +4485 +4495 +4498 +4499 +4524 +4527 +4528 +4539 +4541 +4545 +4543 +4559 +4569 +4571 +4568 +4573 +4570 +4571 +4580 +4579 +4580 +4583 +4588 +4589 +4590 +4597 +4632 +4625 +4626 +4618 +4621 +4632 +4642 +4644 +4647 +4650 +4665 +4669 +4666 +4673 +4674 +4677 +4681 +4686 +4651 +4657 +4658 +4664 +4665 +4667 +4685 +4688 +4695 +4712 +4714 +4715 +4717 +4731 +4734 +4738 +4737 +4743 +4745 +4752 +4753 +4748 +4763 +4768 +4769 +4771 +4774 +4801 +4802 +4830 +4845 +4850 +4847 +4873 +4883 +4884 +4885 +4886 +4887 +4896 +4891 +4913 +4914 +4937 +4938 +4953 +4959 +4979 +4984 +4990 +4982 +4979 +5008 +5007 +5008 +5004 +5015 +5017 +5038 +5066 +5067 +5069 +5078 +5091 +5101 +5086 +5088 +5086 +5092 +5097 +5098 +5088 +5070 +5072 +5083 +5082 +5073 +5077 +5080 +5076 +5073 +5065 +5066 +5068 +5069 +5081 +5082 +5084 +5083 +5086 +5089 +5092 +5095 +5130 +5133 +5119 +5129 +5130 +5138 +5140 +5148 +5147 +5150 +5151 +5155 +5163 +5188 +5190 +5192 +5189 +5196 +5180 +5191 +5193 +5197 +5182 +5162 +5163 +5147 +5154 +5155 +5168 +5207 +5216 +5223 +5228 +5227 +5229 +5221 +5218 +5221 +5219 +5220 +5230 +5259 +5260 +5233 +5256 +5258 +5251 +5246 +5230 +5234 +5242 +5245 +5260 +5261 +5269 +5281 +5285 +5296 +5297 +5296 +5297 +5298 +5313 +5314 +5313 +5319 +5313 +5322 +5324 +5325 +5333 +5346 +5354 +5355 +5345 +5347 +5349 +5350 +5352 +5339 +5349 +5345 +5361 +5362 +5363 +5404 +5398 +5424 +5415 +5420 +5433 +5435 +5436 +5437 +5438 +5455 +5454 +5460 +5455 +5453 +5454 +5466 +5469 +5471 +5481 +5482 +5502 +5503 +5501 +5484 +5460 +5461 +5465 +5466 +5470 +5454 +5460 +5486 +5482 +5483 +5502 +5512 +5514 +5516 +5518 +5525 +5526 +5521 +5515 +5518 +5521 +5528 +5539 +5557 +5561 +5577 +5571 +5572 +5579 +5576 +5577 +5589 +5592 +5595 +5596 +5595 +5601 +5587 +5560 +5563 +5562 +5571 +5598 +5606 +5621 +5636 +5637 +5663 +5665 +5678 +5677 +5678 +5679 +5684 +5687 +5684 +5688 +5691 +5690 +5693 +5696 +5707 +5725 +5727 +5731 +5734 +5738 +5748 +5767 +5768 +5763 +5767 +5758 +5760 +5791 +5777 +5778 +5782 +5773 +5776 +5777 +5791 +5792 +5793 +5795 +5781 +5786 +5793 +5805 +5807 +5818 +5822 +5821 +5826 +5827 +5846 +5847 +5864 +5886 +5878 +5873 +5868 +5878 +5876 +5881 +5876 +5888 +5890 +5893 +5894 +5895 +5900 +5907 +5908 +5915 +5916 +5937 +5936 +5927 +5938 +5945 +5944 +5935 +5942 +5943 +5945 +5948 +5977 +5985 +5975 +5985 +5998 +5999 +5996 +6027 +6047 +6031 +6033 +6034 +6022 +6023 +6025 +6030 +6029 +6030 +6034 +6046 +6055 +6061 +6058 +6067 +6070 +6077 +6069 +6088 +6084 +6090 +6100 +6102 +6107 +6111 +6108 +6103 +6104 +6114 +6118 +6107 +6114 +6102 +6112 +6113 +6115 +6116 +6139 +6135 +6143 +6154 +6155 +6160 +6163 +6160 +6163 +6169 +6184 +6176 +6199 +6205 +6204 +6219 +6222 +6231 +6207 +6218 +6219 +6221 +6222 +6221 +6200 +6194 +6203 +6204 +6210 +6209 +6210 +6209 +6210 +6230 +6238 +6239 +6245 +6249 +6264 +6271 +6262 +6275 +6252 +6253 +6240 +6245 +6219 +6220 +6221 +6222 +6225 +6231 +6236 +6238 +6267 +6272 +6273 +6278 +6287 +6286 +6287 +6281 +6264 +6269 +6270 +6274 +6247 +6248 +6259 +6264 +6267 +6276 +6281 +6286 +6284 +6289 +6287 +6275 +6247 +6263 +6261 +6264 +6265 +6270 +6271 +6272 +6271 +6280 +6282 +6283 +6291 +6302 +6303 +6315 +6335 +6361 +6358 +6359 +6362 +6363 +6349 +6348 +6355 +6357 +6358 +6357 +6375 +6374 +6367 +6342 +6350 +6354 +6353 +6354 +6357 +6369 +6371 +6382 +6384 +6371 +6403 +6402 +6412 +6413 +6415 +6416 +6417 +6418 +6419 +6420 +6438 +6436 +6438 +6443 +6454 +6440 +6439 +6431 +6442 +6441 +6444 +6446 +6450 +6422 +6424 +6418 +6426 +6437 +6438 +6439 +6449 +6451 +6452 +6463 +6464 +6475 +6492 +6499 +6506 +6519 +6548 +6545 +6543 +6556 +6565 +6567 +6564 +6553 +6554 +6556 +6564 +6584 +6580 +6581 +6582 +6584 +6585 +6586 +6595 +6596 +6595 +6598 +6575 +6594 +6595 +6593 +6591 +6602 +6603 +6575 +6573 +6577 +6586 +6587 +6615 +6624 +6647 +6677 +6678 +6679 +6683 +6682 +6684 +6689 +6704 +6709 +6723 +6751 +6754 +6755 +6757 +6758 +6774 +6787 +6791 +6816 +6837 +6838 +6846 +6847 +6845 +6847 +6850 +6864 +6863 +6853 +6874 +6875 +6874 +6883 +6891 +6899 +6918 +6920 +6921 +6937 +6934 +6935 +6951 +6950 +6969 +6971 +6976 +6978 +6979 +6987 +6989 +6987 +6989 +6991 +6990 +6991 +6980 +6979 +6963 +6964 +6968 +6972 +7000 +6992 +7003 +7006 +7019 +7022 +7028 +7040 +7035 +7034 +7055 +7063 +7065 +7066 +7071 +7079 +7092 +7102 +7118 +7115 +7121 diff --git a/problems/day01.html b/problems/day01.html new file mode 100644 index 0000000..42b5da6 --- /dev/null +++ b/problems/day01.html @@ -0,0 +1,181 @@ + + + + +Day 1 - Advent of Code 2021 + + + + + + + +

Advent of Code

Neil Smith 2*

       y(2021)

+ + + +
+ +

--- Day 1: Sonar Sweep ---

You're minding your own business on a ship at sea when the overboard alarm goes off! You rush to see if you can help. Apparently, one of the Elves tripped and accidentally sent the sleigh keys flying into the ocean!

+

Before you know it, you're inside a submarine the Elves keep ready for situations like this. It's covered in Christmas lights (because of course it is), and it even has an experimental antenna that should be able to track the keys if you can boost its signal strength high enough; there's a little meter that indicates the antenna's signal strength by displaying 0-50 stars.

+

Your instincts tell you that in order to save Christmas, you'll need to get all fifty stars by December 25th.

+

Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!

+

As the submarine drops below the surface of the ocean, it automatically performs a sonar sweep of the nearby sea floor. On a small screen, the sonar sweep report (your puzzle input) appears: each line is a measurement of the sea floor depth as the sweep looks further and further away from the submarine.

+

For example, suppose you had the following report:

+
199
+200
+208
+210
+200
+207
+240
+269
+260
+263
+
+

This report indicates that, scanning outward from the submarine, the sonar sweep found depths of 199, 200, 208, 210, and so on.

+

The first order of business is to figure out how quickly the depth increases, just so you know what you're dealing with - you never know if the keys will get carried into deeper water by an ocean current or a fish or something.

+

To do this, count the number of times a depth measurement increases from the previous measurement. (There is no measurement before the first measurement.) In the example above, the changes are as follows:

+
199 (N/A - no previous measurement)
+200 (increased)
+208 (increased)
+210 (increased)
+200 (decreased)
+207 (increased)
+240 (increased)
+269 (increased)
+260 (decreased)
+263 (increased)
+
+

In this example, there are 7 measurements that are larger than the previous measurement.

+

How many measurements are larger than the previous measurement?

+
+

Your puzzle answer was 1521.

--- Part Two ---

Considering every single measurement isn't as useful as you expected: there's just too much noise in the data.

+

Instead, consider sums of a three-measurement sliding window. Again considering the above example:

+
199  A      
+200  A B    
+208  A B C  
+210    B C D
+200  E   C D
+207  E F   D
+240  E F G  
+269    F G H
+260      G H
+263        H
+
+

Start by comparing the first and second three-measurement windows. The measurements in the first window are marked A (199, 200, 208); their sum is 199 + 200 + 208 = 607. The second window is marked B (200, 208, 210); its sum is 618. The sum of measurements in the second window is larger than the sum of the first, so this first comparison increased.

+

Your goal now is to count the number of times the sum of measurements in this sliding window increases from the previous sum. So, compare A with B, then compare B with C, then C with D, and so on. Stop when there aren't enough measurements left to create a new three-measurement sum.

+

In the above example, the sum of each three-measurement window is as follows:

+
A: 607 (N/A - no previous sum)
+B: 618 (increased)
+C: 618 (no change)
+D: 617 (decreased)
+E: 647 (increased)
+F: 716 (increased)
+G: 769 (increased)
+H: 792 (increased)
+
+

In this example, there are 5 sums that are larger than the previous sum.

+

Consider sums of a three-measurement sliding window. How many sums are larger than the previous sum?

+
+

Your puzzle answer was 1543.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your Advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also this puzzle.

+
+ + + + + + \ No newline at end of file -- 2.34.1