My attempts to solve puzzles of Advent of Code
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

day1

+1143
+8
.ghci
··· 1 + :set -isrc 2 + :l src/AoC.hs 3 + :set -Wall 4 + :set -fno-warn-unused-binds 5 + :set -fno-warn-unused-do-bind 6 + :set -fno-warn-unused-imports 7 + :set -fno-warn-type-defaults 8 + :set -XOverloadedStrings
+20
.gitignore
··· 1 + .DS_Store 2 + .idea 3 + *.log 4 + tmp/ 5 + dist/ 6 + dist-newstyle/ 7 + TAGS 8 + tags 9 + .*.swp 10 + .*.swo 11 + *.o 12 + *.hi 13 + *~ 14 + *# 15 + cabal.project.local 16 + .cabal-sandbox/ 17 + cabal.sandbox.config 18 + .stack-work/ 19 + codex.tags 20 + .ghc.environment.*
+24
AoC.cabal
··· 1 + name: AoC 2 + version: 0.1.0.0 3 + license: BSD3 4 + license-file: LICENSE 5 + author: Kaushik Chakraborty 6 + maintainer: git@kaushikc.org 7 + category: Game 8 + build-type: Simple 9 + extra-source-files: CHANGELOG.md, README.org 10 + cabal-version: >=1.10 11 + 12 + library 13 + default-language: Haskell2010 14 + default-extensions: NoImplicitPrelude 15 + 16 + build-depends: base <5 && >=3 17 + , papa 18 + , text 19 + , containers 20 + 21 + hs-source-dirs: src 22 + 23 + exposed-modules: AoC 24 + AoC.Y2018.Day1
+8
AoC.nix
··· 1 + { mkDerivation, base, containers, papa, stdenv, text }: 2 + mkDerivation { 3 + pname = "AoC"; 4 + version = "0.1.0.0"; 5 + src = ./.; 6 + libraryHaskellDepends = [ base containers papa text ]; 7 + license = stdenv.lib.licenses.bsd3; 8 + }
+5
CHANGELOG.md
··· 1 + # Revision history for AoC 2 + 3 + ## 0.1.0.0 -- YYYY-mm-dd 4 + 5 + * First version. Released on an unsuspecting world.
+30
LICENSE
··· 1 + Copyright (c) 2018, Kaushik Chakraborty 2 + 3 + All rights reserved. 4 + 5 + Redistribution and use in source and binary forms, with or without 6 + modification, are permitted provided that the following conditions are met: 7 + 8 + * Redistributions of source code must retain the above copyright 9 + notice, this list of conditions and the following disclaimer. 10 + 11 + * Redistributions in binary form must reproduce the above 12 + copyright notice, this list of conditions and the following 13 + disclaimer in the documentation and/or other materials provided 14 + with the distribution. 15 + 16 + * Neither the name of Kaushik Chakraborty nor the names of other 17 + contributors may be used to endorse or promote products derived 18 + from this software without specific prior written permission. 19 + 20 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+2
README.org
··· 1 + #+TITLE: README 2 + My [[https://adventofcode.com/][Advent of Code]] attempts
+2
Setup.hs
··· 1 + import Distribution.Simple 2 + main = defaultMain
+988
data/input-d1-p1
··· 1 + +13 2 + +9 3 + +8 4 + +1 5 + -15 6 + +10 7 + +16 8 + +17 9 + +8 10 + +8 11 + +17 12 + +6 13 + +17 14 + +18 15 + -10 16 + -16 17 + +13 18 + +15 19 + -18 20 + -11 21 + -2 22 + +7 23 + -14 24 + -4 25 + +17 26 + +18 27 + -6 28 + +3 29 + -4 30 + -2 31 + -18 32 + -23 33 + +7 34 + -5 35 + -14 36 + -12 37 + +16 38 + +16 39 + +10 40 + +16 41 + -4 42 + -21 43 + -11 44 + -16 45 + -17 46 + +3 47 + -1 48 + +19 49 + +13 50 + +18 51 + +4 52 + +19 53 + -2 54 + +13 55 + +20 56 + +4 57 + -16 58 + +6 59 + +11 60 + -13 61 + -1 62 + +19 63 + +9 64 + +5 65 + +13 66 + +14 67 + -19 68 + +8 69 + -13 70 + -5 71 + +11 72 + -15 73 + -9 74 + +5 75 + -3 76 + +1 77 + -15 78 + -1 79 + +19 80 + +21 81 + +2 82 + +1 83 + +10 84 + -1 85 + +5 86 + -6 87 + +13 88 + +7 89 + -1 90 + +7 91 + +8 92 + -19 93 + +8 94 + -13 95 + +4 96 + +16 97 + +11 98 + +7 99 + +6 100 + -14 101 + +19 102 + +3 103 + +19 104 + +18 105 + +13 106 + +19 107 + +8 108 + +15 109 + +6 110 + -9 111 + +8 112 + +17 113 + -12 114 + +2 115 + +6 116 + +14 117 + -9 118 + +8 119 + +13 120 + +6 121 + +5 122 + +19 123 + -16 124 + +14 125 + -9 126 + +7 127 + +19 128 + -18 129 + -3 130 + -15 131 + -19 132 + -10 133 + +2 134 + -17 135 + +19 136 + -8 137 + -19 138 + +7 139 + -16 140 + -8 141 + +2 142 + -18 143 + -1 144 + +9 145 + +19 146 + -17 147 + +3 148 + +1 149 + +6 150 + -14 151 + -2 152 + +7 153 + -4 154 + +14 155 + -6 156 + +8 157 + +2 158 + +5 159 + +21 160 + +18 161 + +3 162 + +8 163 + -13 164 + +17 165 + -19 166 + +13 167 + +5 168 + -15 169 + +13 170 + -8 171 + +6 172 + +14 173 + +16 174 + +13 175 + +12 176 + +17 177 + +12 178 + +17 179 + -11 180 + +1 181 + +16 182 + -19 183 + -17 184 + -14 185 + -8 186 + +3 187 + +12 188 + +13 189 + +9 190 + -1 191 + -12 192 + +5 193 + -12 194 + +15 195 + +1 196 + +1 197 + +9 198 + +8 199 + +10 200 + -6 201 + +4 202 + -2 203 + +7 204 + +4 205 + -1 206 + -2 207 + +10 208 + +12 209 + +4 210 + -6 211 + +1 212 + +17 213 + +5 214 + -10 215 + -19 216 + -9 217 + -17 218 + +18 219 + -15 220 + +6 221 + +18 222 + +19 223 + -17 224 + +15 225 + -14 226 + -2 227 + +15 228 + -2 229 + -10 230 + -18 231 + -21 232 + +3 233 + -2 234 + -16 235 + +1 236 + -4 237 + +17 238 + -18 239 + -14 240 + +2 241 + +11 242 + -18 243 + +11 244 + -8 245 + -14 246 + -10 247 + +2 248 + -5 249 + -15 250 + -8 251 + -18 252 + -8 253 + +13 254 + +19 255 + +14 256 + -9 257 + +11 258 + -5 259 + +10 260 + +3 261 + +21 262 + -20 263 + -7 264 + +5 265 + +6 266 + -3 267 + +13 268 + -4 269 + +1 270 + -3 271 + -20 272 + -9 273 + -7 274 + +10 275 + +12 276 + +13 277 + +11 278 + +12 279 + -5 280 + +4 281 + +29 282 + -9 283 + -21 284 + -15 285 + +34 286 + +38 287 + +39 288 + +14 289 + +20 290 + +3 291 + -11 292 + -15 293 + +12 294 + +22 295 + -23 296 + -19 297 + -14 298 + +6 299 + +11 300 + +15 301 + -17 302 + +12 303 + +16 304 + +3 305 + +21 306 + -10 307 + +17 308 + +21 309 + +17 310 + -3 311 + -19 312 + -11 313 + -6 314 + +20 315 + +5 316 + +17 317 + +12 318 + +8 319 + +12 320 + +13 321 + +4 322 + -1 323 + +23 324 + -8 325 + +11 326 + +17 327 + +7 328 + -9 329 + -2 330 + -11 331 + +8 332 + +9 333 + +4 334 + +19 335 + +13 336 + -14 337 + +19 338 + +17 339 + -18 340 + -6 341 + +12 342 + -19 343 + -6 344 + +7 345 + +7 346 + +9 347 + -6 348 + -18 349 + +5 350 + -6 351 + -17 352 + +14 353 + -3 354 + -16 355 + -13 356 + -11 357 + +16 358 + +19 359 + -2 360 + +5 361 + +3 362 + -7 363 + -15 364 + -10 365 + +13 366 + +8 367 + -16 368 + -12 369 + -9 370 + -19 371 + -18 372 + -11 373 + -5 374 + +13 375 + -17 376 + +3 377 + +16 378 + +25 379 + -15 380 + +22 381 + -18 382 + -17 383 + +5 384 + +4 385 + -20 386 + -9 387 + +5 388 + -18 389 + +5 390 + -23 391 + +3 392 + -16 393 + +12 394 + -4 395 + -7 396 + +21 397 + -4 398 + +7 399 + +14 400 + +15 401 + -24 402 + -24 403 + +69 404 + +7 405 + +5 406 + +10 407 + +18 408 + +23 409 + +11 410 + +19 411 + -3 412 + +6 413 + -15 414 + +20 415 + +11 416 + +2 417 + +4 418 + +11 419 + -14 420 + +21 421 + -16 422 + -1 423 + -16 424 + +10 425 + -7 426 + +3 427 + +34 428 + +17 429 + -12 430 + +18 431 + +8 432 + +17 433 + -15 434 + +18 435 + -6 436 + +15 437 + -25 438 + -16 439 + +1 440 + +7 441 + -18 442 + +4 443 + -3 444 + +12 445 + -14 446 + -6 447 + +19 448 + +42 449 + +52 450 + +41 451 + -4 452 + +50 453 + +20 454 + +10 455 + -14 456 + -11 457 + -17 458 + +14 459 + +7 460 + +3 461 + +44 462 + -21 463 + -63 464 + -103 465 + +28 466 + +98 467 + -21 468 + -110 469 + -112 470 + +14 471 + +28 472 + -44 473 + -16 474 + +9 475 + -6 476 + -49 477 + -20 478 + +10 479 + +5 480 + +4 481 + +20 482 + +21 483 + -29 484 + +6 485 + -9 486 + -3 487 + -11 488 + -23 489 + +27 490 + -5 491 + +39 492 + -185 493 + -67702 494 + -14 495 + -9 496 + -11 497 + +6 498 + -14 499 + +9 500 + +15 501 + +9 502 + +14 503 + -7 504 + +5 505 + -4 506 + +10 507 + +4 508 + +19 509 + -2 510 + +17 511 + +3 512 + +7 513 + +12 514 + +2 515 + -3 516 + -6 517 + -11 518 + +12 519 + -3 520 + -5 521 + -11 522 + -1 523 + +2 524 + -10 525 + -20 526 + +14 527 + -2 528 + -8 529 + -7 530 + +11 531 + +1 532 + -17 533 + +18 534 + +9 535 + -18 536 + +5 537 + +16 538 + +2 539 + -13 540 + -16 541 + +4 542 + -8 543 + -5 544 + +3 545 + -7 546 + -13 547 + -9 548 + +10 549 + -16 550 + -4 551 + -16 552 + -13 553 + -6 554 + +18 555 + -1 556 + -19 557 + +11 558 + -17 559 + +16 560 + -19 561 + -11 562 + +17 563 + -13 564 + -1 565 + -5 566 + +15 567 + -1 568 + +14 569 + +8 570 + +19 571 + +2 572 + -19 573 + +16 574 + +11 575 + +5 576 + +11 577 + -4 578 + -4 579 + +9 580 + -8 581 + -6 582 + -1 583 + +17 584 + -12 585 + -16 586 + -12 587 + -13 588 + -6 589 + +2 590 + -1 591 + +8 592 + -17 593 + +3 594 + -11 595 + -13 596 + -17 597 + -16 598 + -13 599 + +2 600 + -6 601 + -19 602 + +4 603 + -8 604 + -13 605 + +7 606 + -5 607 + -15 608 + -17 609 + -12 610 + -7 611 + -12 612 + -19 613 + -10 614 + -19 615 + +18 616 + -1 617 + -10 618 + +4 619 + +10 620 + +2 621 + -21 622 + +4 623 + -17 624 + -14 625 + +7 626 + +10 627 + +5 628 + -17 629 + +10 630 + +14 631 + +10 632 + +17 633 + +1 634 + +1 635 + +4 636 + -15 637 + +16 638 + +13 639 + -6 640 + -11 641 + -14 642 + -17 643 + -19 644 + +4 645 + -10 646 + -10 647 + +2 648 + -10 649 + -17 650 + +7 651 + +17 652 + +4 653 + +8 654 + -5 655 + -16 656 + +8 657 + -9 658 + -11 659 + -2 660 + +1 661 + -9 662 + -13 663 + +10 664 + +4 665 + -3 666 + -15 667 + +6 668 + +3 669 + +13 670 + -10 671 + +17 672 + -1 673 + -8 674 + +20 675 + +3 676 + -1 677 + +8 678 + -17 679 + +11 680 + +13 681 + -11 682 + -1 683 + +17 684 + -4 685 + +8 686 + +6 687 + +2 688 + -6 689 + +14 690 + +12 691 + -1 692 + +13 693 + +10 694 + +11 695 + +12 696 + +4 697 + +1 698 + -2 699 + -7 700 + -13 701 + +9 702 + +14 703 + +4 704 + +18 705 + -11 706 + +8 707 + +15 708 + +17 709 + -1 710 + +5 711 + +1 712 + +1 713 + -11 714 + +3 715 + -11 716 + -9 717 + +19 718 + +6 719 + +15 720 + +8 721 + +14 722 + -12 723 + -18 724 + +10 725 + -6 726 + +9 727 + -15 728 + +17 729 + +13 730 + +4 731 + -5 732 + -13 733 + +11 734 + +11 735 + +2 736 + +7 737 + -2 738 + +6 739 + +19 740 + +3 741 + -14 742 + +5 743 + +15 744 + -17 745 + +12 746 + +9 747 + +1 748 + +13 749 + -17 750 + +6 751 + -25 752 + -20 753 + -5 754 + +17 755 + +13 756 + -6 757 + +17 758 + -12 759 + -15 760 + -4 761 + -4 762 + +10 763 + +15 764 + -18 765 + +19 766 + -5 767 + -6 768 + -3 769 + -11 770 + -20 771 + -12 772 + -17 773 + -9 774 + -9 775 + +4 776 + -9 777 + -2 778 + +8 779 + -10 780 + +1 781 + +14 782 + -4 783 + -19 784 + +6 785 + -14 786 + +21 787 + -11 788 + -3 789 + -5 790 + -17 791 + +13 792 + -3 793 + +2 794 + -15 795 + -13 796 + +1 797 + -2 798 + +11 799 + -14 800 + -11 801 + -12 802 + +11 803 + +9 804 + +4 805 + +12 806 + -5 807 + +26 808 + -7 809 + +14 810 + -25 811 + -29 812 + +23 813 + +16 814 + +24 815 + -12 816 + +27 817 + +2 818 + +21 819 + +5 820 + +5 821 + +7 822 + +14 823 + -2 824 + +4 825 + -6 826 + -23 827 + -24 828 + -10 829 + +27 830 + +4 831 + +19 832 + +20 833 + +14 834 + +13 835 + +16 836 + +1 837 + +6 838 + +17 839 + +18 840 + -5 841 + -11 842 + +2 843 + +19 844 + -11 845 + -7 846 + -11 847 + +16 848 + +17 849 + +2 850 + -14 851 + +25 852 + +14 853 + -2 854 + -4 855 + +31 856 + -9 857 + -15 858 + -4 859 + +2 860 + +8 861 + +31 862 + -11 863 + +16 864 + +21 865 + -17 866 + +22 867 + -8 868 + +5 869 + -15 870 + -5 871 + +8 872 + +16 873 + +17 874 + +16 875 + -17 876 + +19 877 + -10 878 + +17 879 + -19 880 + -3 881 + -18 882 + +17 883 + +13 884 + -14 885 + -11 886 + +20 887 + -6 888 + -16 889 + -17 890 + +21 891 + -20 892 + -6 893 + +10 894 + -18 895 + -12 896 + +8 897 + -28 898 + +10 899 + +13 900 + -14 901 + -62 902 + -3 903 + +5 904 + +116 905 + +18 906 + +4 907 + -17 908 + -2 909 + +1 910 + +37 911 + +10 912 + -8 913 + +19 914 + -6 915 + -2 916 + -10 917 + -4 918 + -4 919 + -8 920 + +17 921 + +20 922 + +11 923 + -7 924 + +9 925 + -21 926 + +2 927 + -27 928 + +10 929 + +5 930 + -16 931 + -10 932 + +5 933 + +4 934 + +9 935 + +42 936 + -1 937 + +41 938 + +36 939 + +27 940 + +13 941 + +15 942 + -61 943 + -14 944 + -27 945 + -94 946 + -10 947 + -13 948 + +21 949 + -35 950 + +23 951 + +33 952 + +13 953 + -235 954 + -43 955 + +6 956 + -55 957 + -9 958 + -70 959 + -3 960 + -6 961 + -1 962 + -87 963 + -9 964 + +8 965 + +12 966 + +18 967 + +15 968 + +18 969 + -1 970 + +14 971 + -30 972 + +39 973 + +14 974 + -13 975 + +19 976 + -122 977 + +3 978 + -16 979 + +26 980 + +20 981 + -221 982 + -6 983 + +30 984 + -51 985 + +470 986 + -67792 987 + +3 988 + +135555
+8
default.nix
··· 1 + { nixpkgs ? import <nixpkgs> {}, compiler ? "default" }: 2 + let 3 + inherit (nixpkgs) pkgs; 4 + haskellPackages = if compiler == "default" 5 + then pkgs.haskellPackages 6 + else pkgs.haskell.packages.${compiler}; 7 + in 8 + haskellPackages.callPackage ./AoC.nix {}
+7
shell.nix
··· 1 + { nixpkgs ? import <nixpkgs> {}, compiler ? "default"}: 2 + let 3 + inherit (nixpkgs) pkgs; 4 + drv = import ./default.nix { inherit nixpkgs compiler; }; 5 + drvWithTools = pkgs.haskell.lib.addBuildDepends drv [ pkgs.cabal-install ]; 6 + in 7 + if pkgs.lib.inNixShell then drvWithTools.env else drvWithTools
+3
src/AoC.hs
··· 1 + module AoC (module X) where 2 + 3 + import AoC.Y2018.Day1 as X
+38
src/AoC/Y2018/Day1.hs
··· 1 + module AoC.Y2018.Day1( 2 + makeFreqChanges 3 + , calcFreq 4 + , doPuzzle1 5 + , checkRepeating 6 + , doPuzzle2 7 + ) where 8 + 9 + import Papa 10 + import qualified Data.Set as S (Set,empty, insert, member) 11 + import qualified Data.Text as T (lines) 12 + import qualified Data.Text.IO as T (readFile) 13 + import qualified Data.Text.Read as T (signed, decimal) 14 + 15 + type FreqChanges = [Int] 16 + 17 + makeFreqChanges :: FilePath -> IO FreqChanges 18 + makeFreqChanges file = do 19 + input <- T.readFile file 20 + let ls = T.lines input 21 + return $ either (const 0) fst . T.signed T.decimal <$> ls 22 + 23 + calcFreq :: FreqChanges -> Int 24 + calcFreq = sum 25 + 26 + hasDuplicates :: S.Set Int -> Maybe (NonEmpty Int) -> Maybe Int 27 + hasDuplicates _ Nothing = Nothing 28 + hasDuplicates s (Just (x :| xs)) = if x `S.member` s then Just x else hasDuplicates (x `S.insert` s) (nonEmpty xs) 29 + 30 + checkRepeating :: FreqChanges -> Maybe Int 31 + checkRepeating = hasDuplicates S.empty . Just . scanl (+) 0 . cycle 32 + 33 + 34 + doPuzzle1 :: FilePath -> IO Int 35 + doPuzzle1 = (<$>) calcFreq . makeFreqChanges 36 + 37 + doPuzzle2 :: FilePath -> IO (Maybe Int) 38 + doPuzzle2 = (<$>) checkRepeating . makeFreqChanges