solve some 2015 problems
This commit is contained in:
parent
e521f241cb
commit
3203a0387d
26 changed files with 3029 additions and 0 deletions
1
2015/.envrc
Normal file
1
2015/.envrc
Normal file
|
@ -0,0 +1 @@
|
|||
export ADVENT_OF_CODE_SESSION=53616c7465645f5f92dfbc249005a7e94ec3c6e62cd4e5e9ddf8e368a48c0c80440b6c5e37d836cc0b294e19a9e8a7f1
|
4
2015/.formatter.exs
Normal file
4
2015/.formatter.exs
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Used by "mix format"
|
||||
[
|
||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||
]
|
26
2015/.gitignore
vendored
Normal file
26
2015/.gitignore
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
# The directory Mix will write compiled artifacts to.
|
||||
/_build/
|
||||
|
||||
# If you run "mix test --cover", coverage assets end up here.
|
||||
/cover/
|
||||
|
||||
# The directory Mix downloads your dependencies sources to.
|
||||
/deps/
|
||||
|
||||
# Where third-party dependencies like ExDoc output generated docs.
|
||||
/doc/
|
||||
|
||||
# Ignore .fetch files in case you like to edit your project deps locally.
|
||||
/.fetch
|
||||
|
||||
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||
erl_crash.dump
|
||||
|
||||
# Also ignore archive artifacts (built via "mix archive.build").
|
||||
*.ez
|
||||
|
||||
# Ignore package tarball (built via "mix hex.build").
|
||||
advent_of_code_2015-*.tar
|
||||
|
||||
# Temporary files, for example, from tests.
|
||||
/tmp/
|
1
2015/.iex.exs
Normal file
1
2015/.iex.exs
Normal file
|
@ -0,0 +1 @@
|
|||
import AOC.IEx
|
2
2015/.tool-versions
Normal file
2
2015/.tool-versions
Normal file
|
@ -0,0 +1,2 @@
|
|||
erlang 24.1.4
|
||||
elixir 1.12.3-otp-24
|
20
2015/README.md
Normal file
20
2015/README.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Advent of Code 2015
|
||||
|
||||
<details>
|
||||
<summary>Setup</summary>
|
||||
|
||||
Using [asdf](https://asdf-vm.com/#/):
|
||||
|
||||
```sh
|
||||
asdf plugin add erlang
|
||||
asdf plugin add elixir
|
||||
asdf install
|
||||
```
|
||||
</details>
|
||||
|
||||
| S | M | T | W | T | F | S |
|
||||
| :-: | :-: | :-: | :-: | :-: | :-: | :-: |
|
||||
| | | 1 | 2 | 3 | 4 | 5 |
|
||||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|
||||
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
|
||||
| 20 | 21 | 22 | 23 | 24 | 25 | |
|
8
2015/config/config.exs
Normal file
8
2015/config/config.exs
Normal file
|
@ -0,0 +1,8 @@
|
|||
import Config
|
||||
|
||||
config :nx, :default_defn_options, compiler: EXLA
|
||||
|
||||
config :advent_of_code_utils,
|
||||
year: 2015,
|
||||
auto_reload?: true,
|
||||
session: System.get_env("ADVENT_OF_CODE_SESSION")
|
1
2015/input/2015_1.txt
Normal file
1
2015/input/2015_1.txt
Normal file
File diff suppressed because one or more lines are too long
1000
2015/input/2015_2.txt
Normal file
1000
2015/input/2015_2.txt
Normal file
File diff suppressed because it is too large
Load diff
1
2015/input/2015_3.txt
Normal file
1
2015/input/2015_3.txt
Normal file
File diff suppressed because one or more lines are too long
1
2015/input/2015_4.txt
Normal file
1
2015/input/2015_4.txt
Normal file
|
@ -0,0 +1 @@
|
|||
ckczppom
|
1000
2015/input/2015_5.txt
Normal file
1000
2015/input/2015_5.txt
Normal file
File diff suppressed because it is too large
Load diff
300
2015/input/2015_6.txt
Normal file
300
2015/input/2015_6.txt
Normal file
|
@ -0,0 +1,300 @@
|
|||
turn on 489,959 through 759,964
|
||||
turn off 820,516 through 871,914
|
||||
turn off 427,423 through 929,502
|
||||
turn on 774,14 through 977,877
|
||||
turn on 410,146 through 864,337
|
||||
turn on 931,331 through 939,812
|
||||
turn off 756,53 through 923,339
|
||||
turn off 313,787 through 545,979
|
||||
turn off 12,823 through 102,934
|
||||
toggle 756,965 through 812,992
|
||||
turn off 743,684 through 789,958
|
||||
toggle 120,314 through 745,489
|
||||
toggle 692,845 through 866,994
|
||||
turn off 587,176 through 850,273
|
||||
turn off 674,321 through 793,388
|
||||
toggle 749,672 through 973,965
|
||||
turn on 943,30 through 990,907
|
||||
turn on 296,50 through 729,664
|
||||
turn on 212,957 through 490,987
|
||||
toggle 171,31 through 688,88
|
||||
turn off 991,989 through 994,998
|
||||
turn off 913,943 through 958,953
|
||||
turn off 278,258 through 367,386
|
||||
toggle 275,796 through 493,971
|
||||
turn off 70,873 through 798,923
|
||||
toggle 258,985 through 663,998
|
||||
turn on 601,259 through 831,486
|
||||
turn off 914,94 through 941,102
|
||||
turn off 558,161 through 994,647
|
||||
turn on 119,662 through 760,838
|
||||
toggle 378,775 through 526,852
|
||||
turn off 384,670 through 674,972
|
||||
turn off 249,41 through 270,936
|
||||
turn on 614,742 through 769,780
|
||||
turn on 427,70 through 575,441
|
||||
turn on 410,478 through 985,753
|
||||
turn off 619,46 through 931,342
|
||||
turn on 284,55 through 768,922
|
||||
turn off 40,592 through 728,685
|
||||
turn on 825,291 through 956,950
|
||||
turn on 147,843 through 592,909
|
||||
turn off 218,675 through 972,911
|
||||
toggle 249,291 through 350,960
|
||||
turn off 556,80 through 967,675
|
||||
toggle 609,148 through 968,279
|
||||
toggle 217,605 through 961,862
|
||||
toggle 407,177 through 548,910
|
||||
toggle 400,936 through 599,938
|
||||
turn off 721,101 through 925,455
|
||||
turn on 268,631 through 735,814
|
||||
toggle 549,969 through 612,991
|
||||
toggle 553,268 through 689,432
|
||||
turn off 817,668 through 889,897
|
||||
toggle 801,544 through 858,556
|
||||
toggle 615,729 through 832,951
|
||||
turn off 427,477 through 958,948
|
||||
turn on 164,49 through 852,946
|
||||
turn on 542,449 through 774,776
|
||||
turn off 923,196 through 980,446
|
||||
toggle 90,310 through 718,846
|
||||
turn off 657,215 through 744,252
|
||||
turn off 800,239 through 811,712
|
||||
turn on 502,90 through 619,760
|
||||
toggle 649,512 through 862,844
|
||||
turn off 334,903 through 823,935
|
||||
turn off 630,233 through 839,445
|
||||
turn on 713,67 through 839,865
|
||||
turn on 932,50 through 982,411
|
||||
turn off 480,729 through 984,910
|
||||
turn on 100,219 through 796,395
|
||||
turn on 758,108 through 850,950
|
||||
turn off 427,276 through 439,938
|
||||
turn on 178,284 through 670,536
|
||||
toggle 540,27 through 625,102
|
||||
turn off 906,722 through 936,948
|
||||
toggle 345,418 through 859,627
|
||||
toggle 175,775 through 580,781
|
||||
toggle 863,28 through 929,735
|
||||
turn off 824,858 through 905,973
|
||||
toggle 752,312 through 863,425
|
||||
turn on 985,716 through 988,852
|
||||
turn off 68,504 through 763,745
|
||||
toggle 76,209 through 810,720
|
||||
turn off 657,607 through 676,664
|
||||
toggle 596,869 through 896,921
|
||||
turn off 915,411 through 968,945
|
||||
turn off 368,39 through 902,986
|
||||
turn on 11,549 through 393,597
|
||||
turn off 842,893 through 976,911
|
||||
toggle 274,106 through 581,329
|
||||
toggle 406,403 through 780,950
|
||||
toggle 408,988 through 500,994
|
||||
toggle 217,73 through 826,951
|
||||
turn on 917,872 through 961,911
|
||||
toggle 394,34 through 510,572
|
||||
toggle 424,603 through 583,626
|
||||
toggle 106,159 through 755,738
|
||||
turn off 244,610 through 472,709
|
||||
turn on 350,265 through 884,690
|
||||
turn on 688,184 through 928,280
|
||||
toggle 279,443 through 720,797
|
||||
turn off 615,493 through 888,610
|
||||
toggle 118,413 through 736,632
|
||||
turn on 798,782 through 829,813
|
||||
turn off 250,934 through 442,972
|
||||
turn on 68,503 through 400,949
|
||||
toggle 297,482 through 313,871
|
||||
toggle 710,3 through 839,859
|
||||
turn on 125,300 through 546,888
|
||||
toggle 482,39 through 584,159
|
||||
turn off 536,89 through 765,962
|
||||
turn on 530,518 through 843,676
|
||||
turn on 994,467 through 994,676
|
||||
turn on 623,628 through 744,927
|
||||
toggle 704,912 through 837,983
|
||||
turn on 154,364 through 517,412
|
||||
toggle 344,409 through 780,524
|
||||
turn off 578,740 through 725,879
|
||||
turn on 251,933 through 632,957
|
||||
turn on 827,705 through 971,789
|
||||
toggle 191,282 through 470,929
|
||||
toggle 324,525 through 446,867
|
||||
toggle 534,343 through 874,971
|
||||
toggle 550,650 through 633,980
|
||||
toggle 837,404 through 881,915
|
||||
toggle 338,881 through 845,905
|
||||
turn on 469,462 through 750,696
|
||||
turn on 741,703 through 892,870
|
||||
turn off 570,215 through 733,562
|
||||
turn on 445,576 through 870,775
|
||||
turn on 466,747 through 554,878
|
||||
turn off 820,453 through 868,712
|
||||
turn off 892,706 through 938,792
|
||||
turn off 300,238 through 894,746
|
||||
turn off 306,44 through 457,444
|
||||
turn off 912,569 through 967,963
|
||||
toggle 109,756 through 297,867
|
||||
turn on 37,546 through 41,951
|
||||
turn on 321,637 through 790,910
|
||||
toggle 66,50 through 579,301
|
||||
toggle 933,221 through 933,791
|
||||
turn on 486,676 through 878,797
|
||||
turn on 417,231 through 556,317
|
||||
toggle 904,468 through 981,873
|
||||
turn on 417,675 through 749,712
|
||||
turn on 692,371 through 821,842
|
||||
toggle 324,73 through 830,543
|
||||
turn on 912,490 through 977,757
|
||||
turn off 634,872 through 902,949
|
||||
toggle 266,779 through 870,798
|
||||
turn on 772,982 through 990,996
|
||||
turn off 607,46 through 798,559
|
||||
turn on 295,602 through 963,987
|
||||
turn on 657,86 through 944,742
|
||||
turn off 334,639 through 456,821
|
||||
turn off 997,667 through 997,670
|
||||
turn off 725,832 through 951,945
|
||||
turn off 30,120 through 952,984
|
||||
turn on 860,965 through 917,976
|
||||
toggle 471,997 through 840,998
|
||||
turn off 319,307 through 928,504
|
||||
toggle 823,631 through 940,908
|
||||
toggle 969,984 through 981,993
|
||||
turn off 691,319 through 865,954
|
||||
toggle 911,926 through 938,929
|
||||
turn on 953,937 through 968,991
|
||||
toggle 914,643 through 975,840
|
||||
turn on 266,982 through 436,996
|
||||
turn off 101,896 through 321,932
|
||||
turn off 193,852 through 751,885
|
||||
turn off 576,532 through 863,684
|
||||
turn on 761,456 through 940,783
|
||||
turn on 20,290 through 398,933
|
||||
turn off 435,335 through 644,652
|
||||
turn on 830,569 through 905,770
|
||||
turn off 630,517 through 905,654
|
||||
turn on 664,53 through 886,976
|
||||
toggle 275,416 through 408,719
|
||||
turn on 370,621 through 515,793
|
||||
turn on 483,373 through 654,749
|
||||
turn on 656,786 through 847,928
|
||||
turn off 532,752 through 945,974
|
||||
toggle 301,150 through 880,792
|
||||
turn off 951,488 through 958,952
|
||||
turn on 207,729 through 882,828
|
||||
toggle 694,532 through 973,961
|
||||
toggle 676,639 through 891,802
|
||||
turn off 653,6 through 905,519
|
||||
toggle 391,109 through 418,312
|
||||
turn on 877,423 through 957,932
|
||||
turn on 340,145 through 563,522
|
||||
turn off 978,467 through 988,895
|
||||
turn off 396,418 through 420,885
|
||||
turn off 31,308 through 816,316
|
||||
turn on 107,675 through 758,824
|
||||
turn on 61,82 through 789,876
|
||||
turn on 750,743 through 754,760
|
||||
toggle 88,733 through 736,968
|
||||
turn off 754,349 through 849,897
|
||||
toggle 157,50 through 975,781
|
||||
turn off 230,231 through 865,842
|
||||
turn off 516,317 through 630,329
|
||||
turn off 697,820 through 829,903
|
||||
turn on 218,250 through 271,732
|
||||
toggle 56,167 through 404,431
|
||||
toggle 626,891 through 680,927
|
||||
toggle 370,207 through 791,514
|
||||
toggle 860,74 through 949,888
|
||||
turn on 416,527 through 616,541
|
||||
turn off 745,449 through 786,908
|
||||
turn on 485,554 through 689,689
|
||||
turn on 586,62 through 693,141
|
||||
toggle 506,759 through 768,829
|
||||
turn on 473,109 through 929,166
|
||||
turn on 760,617 through 773,789
|
||||
toggle 595,683 through 618,789
|
||||
turn off 210,775 through 825,972
|
||||
toggle 12,426 through 179,982
|
||||
turn on 774,539 through 778,786
|
||||
turn on 102,498 through 121,807
|
||||
turn off 706,897 through 834,965
|
||||
turn off 678,529 through 824,627
|
||||
turn on 7,765 through 615,870
|
||||
turn off 730,872 through 974,943
|
||||
turn off 595,626 through 836,711
|
||||
turn off 215,424 through 841,959
|
||||
toggle 341,780 through 861,813
|
||||
toggle 507,503 through 568,822
|
||||
turn on 252,603 through 349,655
|
||||
toggle 93,521 through 154,834
|
||||
turn on 565,682 through 951,954
|
||||
turn on 544,318 through 703,418
|
||||
toggle 756,953 through 891,964
|
||||
turn on 531,123 through 856,991
|
||||
turn on 148,315 through 776,559
|
||||
turn off 925,835 through 963,971
|
||||
turn on 895,944 through 967,964
|
||||
turn off 102,527 through 650,747
|
||||
toggle 626,105 through 738,720
|
||||
turn off 160,75 through 384,922
|
||||
toggle 813,724 through 903,941
|
||||
turn on 207,107 through 982,849
|
||||
toggle 750,505 through 961,697
|
||||
toggle 105,410 through 885,819
|
||||
turn on 226,104 through 298,283
|
||||
turn off 224,604 through 508,762
|
||||
turn on 477,368 through 523,506
|
||||
turn off 477,901 through 627,936
|
||||
turn off 887,131 through 889,670
|
||||
turn on 896,994 through 938,999
|
||||
toggle 401,580 through 493,728
|
||||
toggle 987,184 through 991,205
|
||||
turn on 821,643 through 882,674
|
||||
toggle 784,940 through 968,959
|
||||
turn off 251,293 through 274,632
|
||||
turn off 339,840 through 341,844
|
||||
turn off 675,351 through 675,836
|
||||
toggle 918,857 through 944,886
|
||||
toggle 70,253 through 918,736
|
||||
turn off 612,604 through 772,680
|
||||
turn off 277,40 through 828,348
|
||||
toggle 692,139 through 698,880
|
||||
toggle 124,446 through 883,453
|
||||
toggle 969,932 through 990,945
|
||||
toggle 855,692 through 993,693
|
||||
toggle 722,472 through 887,899
|
||||
toggle 978,149 through 985,442
|
||||
toggle 837,540 through 916,889
|
||||
turn off 612,2 through 835,82
|
||||
toggle 560,767 through 878,856
|
||||
turn on 461,734 through 524,991
|
||||
toggle 206,824 through 976,912
|
||||
turn on 826,610 through 879,892
|
||||
turn on 577,699 through 956,933
|
||||
turn off 9,250 through 50,529
|
||||
turn off 77,657 through 817,677
|
||||
turn on 68,419 through 86,426
|
||||
turn on 991,720 through 992,784
|
||||
turn on 668,20 through 935,470
|
||||
turn off 133,418 through 613,458
|
||||
turn off 487,286 through 540,328
|
||||
toggle 247,874 through 840,955
|
||||
toggle 301,808 through 754,970
|
||||
turn off 34,194 through 578,203
|
||||
turn off 451,49 through 492,921
|
||||
turn on 907,256 through 912,737
|
||||
turn off 479,305 through 702,587
|
||||
turn on 545,583 through 732,749
|
||||
toggle 11,16 through 725,868
|
||||
turn on 965,343 through 986,908
|
||||
turn on 674,953 through 820,965
|
||||
toggle 398,147 through 504,583
|
||||
turn off 778,194 through 898,298
|
||||
turn on 179,140 through 350,852
|
||||
turn off 241,118 through 530,832
|
||||
turn off 41,447 through 932,737
|
||||
turn off 820,663 through 832,982
|
||||
turn on 550,460 through 964,782
|
||||
turn on 31,760 through 655,892
|
||||
toggle 628,958 through 811,992
|
339
2015/input/2015_7.txt
Normal file
339
2015/input/2015_7.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
af AND ah -> ai
|
||||
NOT lk -> ll
|
||||
hz RSHIFT 1 -> is
|
||||
NOT go -> gp
|
||||
du OR dt -> dv
|
||||
x RSHIFT 5 -> aa
|
||||
at OR az -> ba
|
||||
eo LSHIFT 15 -> es
|
||||
ci OR ct -> cu
|
||||
b RSHIFT 5 -> f
|
||||
fm OR fn -> fo
|
||||
NOT ag -> ah
|
||||
v OR w -> x
|
||||
g AND i -> j
|
||||
an LSHIFT 15 -> ar
|
||||
1 AND cx -> cy
|
||||
jq AND jw -> jy
|
||||
iu RSHIFT 5 -> ix
|
||||
gl AND gm -> go
|
||||
NOT bw -> bx
|
||||
jp RSHIFT 3 -> jr
|
||||
hg AND hh -> hj
|
||||
bv AND bx -> by
|
||||
er OR es -> et
|
||||
kl OR kr -> ks
|
||||
et RSHIFT 1 -> fm
|
||||
e AND f -> h
|
||||
u LSHIFT 1 -> ao
|
||||
he RSHIFT 1 -> hx
|
||||
eg AND ei -> ej
|
||||
bo AND bu -> bw
|
||||
dz OR ef -> eg
|
||||
dy RSHIFT 3 -> ea
|
||||
gl OR gm -> gn
|
||||
da LSHIFT 1 -> du
|
||||
au OR av -> aw
|
||||
gj OR gu -> gv
|
||||
eu OR fa -> fb
|
||||
lg OR lm -> ln
|
||||
e OR f -> g
|
||||
NOT dm -> dn
|
||||
NOT l -> m
|
||||
aq OR ar -> as
|
||||
gj RSHIFT 5 -> gm
|
||||
hm AND ho -> hp
|
||||
ge LSHIFT 15 -> gi
|
||||
jp RSHIFT 1 -> ki
|
||||
hg OR hh -> hi
|
||||
lc LSHIFT 1 -> lw
|
||||
km OR kn -> ko
|
||||
eq LSHIFT 1 -> fk
|
||||
1 AND am -> an
|
||||
gj RSHIFT 1 -> hc
|
||||
aj AND al -> am
|
||||
gj AND gu -> gw
|
||||
ko AND kq -> kr
|
||||
ha OR gz -> hb
|
||||
bn OR by -> bz
|
||||
iv OR jb -> jc
|
||||
NOT ac -> ad
|
||||
bo OR bu -> bv
|
||||
d AND j -> l
|
||||
bk LSHIFT 1 -> ce
|
||||
de OR dk -> dl
|
||||
dd RSHIFT 1 -> dw
|
||||
hz AND ik -> im
|
||||
NOT jd -> je
|
||||
fo RSHIFT 2 -> fp
|
||||
hb LSHIFT 1 -> hv
|
||||
lf RSHIFT 2 -> lg
|
||||
gj RSHIFT 3 -> gl
|
||||
ki OR kj -> kk
|
||||
NOT ak -> al
|
||||
ld OR le -> lf
|
||||
ci RSHIFT 3 -> ck
|
||||
1 AND cc -> cd
|
||||
NOT kx -> ky
|
||||
fp OR fv -> fw
|
||||
ev AND ew -> ey
|
||||
dt LSHIFT 15 -> dx
|
||||
NOT ax -> ay
|
||||
bp AND bq -> bs
|
||||
NOT ii -> ij
|
||||
ci AND ct -> cv
|
||||
iq OR ip -> ir
|
||||
x RSHIFT 2 -> y
|
||||
fq OR fr -> fs
|
||||
bn RSHIFT 5 -> bq
|
||||
0 -> c
|
||||
14146 -> b
|
||||
d OR j -> k
|
||||
z OR aa -> ab
|
||||
gf OR ge -> gg
|
||||
df OR dg -> dh
|
||||
NOT hj -> hk
|
||||
NOT di -> dj
|
||||
fj LSHIFT 15 -> fn
|
||||
lf RSHIFT 1 -> ly
|
||||
b AND n -> p
|
||||
jq OR jw -> jx
|
||||
gn AND gp -> gq
|
||||
x RSHIFT 1 -> aq
|
||||
ex AND ez -> fa
|
||||
NOT fc -> fd
|
||||
bj OR bi -> bk
|
||||
as RSHIFT 5 -> av
|
||||
hu LSHIFT 15 -> hy
|
||||
NOT gs -> gt
|
||||
fs AND fu -> fv
|
||||
dh AND dj -> dk
|
||||
bz AND cb -> cc
|
||||
dy RSHIFT 1 -> er
|
||||
hc OR hd -> he
|
||||
fo OR fz -> ga
|
||||
t OR s -> u
|
||||
b RSHIFT 2 -> d
|
||||
NOT jy -> jz
|
||||
hz RSHIFT 2 -> ia
|
||||
kk AND kv -> kx
|
||||
ga AND gc -> gd
|
||||
fl LSHIFT 1 -> gf
|
||||
bn AND by -> ca
|
||||
NOT hr -> hs
|
||||
NOT bs -> bt
|
||||
lf RSHIFT 3 -> lh
|
||||
au AND av -> ax
|
||||
1 AND gd -> ge
|
||||
jr OR js -> jt
|
||||
fw AND fy -> fz
|
||||
NOT iz -> ja
|
||||
c LSHIFT 1 -> t
|
||||
dy RSHIFT 5 -> eb
|
||||
bp OR bq -> br
|
||||
NOT h -> i
|
||||
1 AND ds -> dt
|
||||
ab AND ad -> ae
|
||||
ap LSHIFT 1 -> bj
|
||||
br AND bt -> bu
|
||||
NOT ca -> cb
|
||||
NOT el -> em
|
||||
s LSHIFT 15 -> w
|
||||
gk OR gq -> gr
|
||||
ff AND fh -> fi
|
||||
kf LSHIFT 15 -> kj
|
||||
fp AND fv -> fx
|
||||
lh OR li -> lj
|
||||
bn RSHIFT 3 -> bp
|
||||
jp OR ka -> kb
|
||||
lw OR lv -> lx
|
||||
iy AND ja -> jb
|
||||
dy OR ej -> ek
|
||||
1 AND bh -> bi
|
||||
NOT kt -> ku
|
||||
ao OR an -> ap
|
||||
ia AND ig -> ii
|
||||
NOT ey -> ez
|
||||
bn RSHIFT 1 -> cg
|
||||
fk OR fj -> fl
|
||||
ce OR cd -> cf
|
||||
eu AND fa -> fc
|
||||
kg OR kf -> kh
|
||||
jr AND js -> ju
|
||||
iu RSHIFT 3 -> iw
|
||||
df AND dg -> di
|
||||
dl AND dn -> do
|
||||
la LSHIFT 15 -> le
|
||||
fo RSHIFT 1 -> gh
|
||||
NOT gw -> gx
|
||||
NOT gb -> gc
|
||||
ir LSHIFT 1 -> jl
|
||||
x AND ai -> ak
|
||||
he RSHIFT 5 -> hh
|
||||
1 AND lu -> lv
|
||||
NOT ft -> fu
|
||||
gh OR gi -> gj
|
||||
lf RSHIFT 5 -> li
|
||||
x RSHIFT 3 -> z
|
||||
b RSHIFT 3 -> e
|
||||
he RSHIFT 2 -> hf
|
||||
NOT fx -> fy
|
||||
jt AND jv -> jw
|
||||
hx OR hy -> hz
|
||||
jp AND ka -> kc
|
||||
fb AND fd -> fe
|
||||
hz OR ik -> il
|
||||
ci RSHIFT 1 -> db
|
||||
fo AND fz -> gb
|
||||
fq AND fr -> ft
|
||||
gj RSHIFT 2 -> gk
|
||||
cg OR ch -> ci
|
||||
cd LSHIFT 15 -> ch
|
||||
jm LSHIFT 1 -> kg
|
||||
ih AND ij -> ik
|
||||
fo RSHIFT 3 -> fq
|
||||
fo RSHIFT 5 -> fr
|
||||
1 AND fi -> fj
|
||||
1 AND kz -> la
|
||||
iu AND jf -> jh
|
||||
cq AND cs -> ct
|
||||
dv LSHIFT 1 -> ep
|
||||
hf OR hl -> hm
|
||||
km AND kn -> kp
|
||||
de AND dk -> dm
|
||||
dd RSHIFT 5 -> dg
|
||||
NOT lo -> lp
|
||||
NOT ju -> jv
|
||||
NOT fg -> fh
|
||||
cm AND co -> cp
|
||||
ea AND eb -> ed
|
||||
dd RSHIFT 3 -> df
|
||||
gr AND gt -> gu
|
||||
ep OR eo -> eq
|
||||
cj AND cp -> cr
|
||||
lf OR lq -> lr
|
||||
gg LSHIFT 1 -> ha
|
||||
et RSHIFT 2 -> eu
|
||||
NOT jh -> ji
|
||||
ek AND em -> en
|
||||
jk LSHIFT 15 -> jo
|
||||
ia OR ig -> ih
|
||||
gv AND gx -> gy
|
||||
et AND fe -> fg
|
||||
lh AND li -> lk
|
||||
1 AND io -> ip
|
||||
kb AND kd -> ke
|
||||
kk RSHIFT 5 -> kn
|
||||
id AND if -> ig
|
||||
NOT ls -> lt
|
||||
dw OR dx -> dy
|
||||
dd AND do -> dq
|
||||
lf AND lq -> ls
|
||||
NOT kc -> kd
|
||||
dy AND ej -> el
|
||||
1 AND ke -> kf
|
||||
et OR fe -> ff
|
||||
hz RSHIFT 5 -> ic
|
||||
dd OR do -> dp
|
||||
cj OR cp -> cq
|
||||
NOT dq -> dr
|
||||
kk RSHIFT 1 -> ld
|
||||
jg AND ji -> jj
|
||||
he OR hp -> hq
|
||||
hi AND hk -> hl
|
||||
dp AND dr -> ds
|
||||
dz AND ef -> eh
|
||||
hz RSHIFT 3 -> ib
|
||||
db OR dc -> dd
|
||||
hw LSHIFT 1 -> iq
|
||||
he AND hp -> hr
|
||||
NOT cr -> cs
|
||||
lg AND lm -> lo
|
||||
hv OR hu -> hw
|
||||
il AND in -> io
|
||||
NOT eh -> ei
|
||||
gz LSHIFT 15 -> hd
|
||||
gk AND gq -> gs
|
||||
1 AND en -> eo
|
||||
NOT kp -> kq
|
||||
et RSHIFT 5 -> ew
|
||||
lj AND ll -> lm
|
||||
he RSHIFT 3 -> hg
|
||||
et RSHIFT 3 -> ev
|
||||
as AND bd -> bf
|
||||
cu AND cw -> cx
|
||||
jx AND jz -> ka
|
||||
b OR n -> o
|
||||
be AND bg -> bh
|
||||
1 AND ht -> hu
|
||||
1 AND gy -> gz
|
||||
NOT hn -> ho
|
||||
ck OR cl -> cm
|
||||
ec AND ee -> ef
|
||||
lv LSHIFT 15 -> lz
|
||||
ks AND ku -> kv
|
||||
NOT ie -> if
|
||||
hf AND hl -> hn
|
||||
1 AND r -> s
|
||||
ib AND ic -> ie
|
||||
hq AND hs -> ht
|
||||
y AND ae -> ag
|
||||
NOT ed -> ee
|
||||
bi LSHIFT 15 -> bm
|
||||
dy RSHIFT 2 -> dz
|
||||
ci RSHIFT 2 -> cj
|
||||
NOT bf -> bg
|
||||
NOT im -> in
|
||||
ev OR ew -> ex
|
||||
ib OR ic -> id
|
||||
bn RSHIFT 2 -> bo
|
||||
dd RSHIFT 2 -> de
|
||||
bl OR bm -> bn
|
||||
as RSHIFT 1 -> bl
|
||||
ea OR eb -> ec
|
||||
ln AND lp -> lq
|
||||
kk RSHIFT 3 -> km
|
||||
is OR it -> iu
|
||||
iu RSHIFT 2 -> iv
|
||||
as OR bd -> be
|
||||
ip LSHIFT 15 -> it
|
||||
iw OR ix -> iy
|
||||
kk RSHIFT 2 -> kl
|
||||
NOT bb -> bc
|
||||
ci RSHIFT 5 -> cl
|
||||
ly OR lz -> ma
|
||||
z AND aa -> ac
|
||||
iu RSHIFT 1 -> jn
|
||||
cy LSHIFT 15 -> dc
|
||||
cf LSHIFT 1 -> cz
|
||||
as RSHIFT 3 -> au
|
||||
cz OR cy -> da
|
||||
kw AND ky -> kz
|
||||
lx -> a
|
||||
iw AND ix -> iz
|
||||
lr AND lt -> lu
|
||||
jp RSHIFT 5 -> js
|
||||
aw AND ay -> az
|
||||
jc AND je -> jf
|
||||
lb OR la -> lc
|
||||
NOT cn -> co
|
||||
kh LSHIFT 1 -> lb
|
||||
1 AND jj -> jk
|
||||
y OR ae -> af
|
||||
ck AND cl -> cn
|
||||
kk OR kv -> kw
|
||||
NOT cv -> cw
|
||||
kl AND kr -> kt
|
||||
iu OR jf -> jg
|
||||
at AND az -> bb
|
||||
jp RSHIFT 2 -> jq
|
||||
iv AND jb -> jd
|
||||
jn OR jo -> jp
|
||||
x OR ai -> aj
|
||||
ba AND bc -> bd
|
||||
jl OR jk -> jm
|
||||
b RSHIFT 1 -> v
|
||||
o AND q -> r
|
||||
NOT p -> q
|
||||
k AND m -> n
|
||||
as RSHIFT 2 -> at
|
26
2015/lib/2015/1.ex
Normal file
26
2015/lib/2015/1.ex
Normal file
|
@ -0,0 +1,26 @@
|
|||
import AOC
|
||||
|
||||
aoc 2015, 1 do
|
||||
def input_chars(), do: input_string() |> String.split("", trim: true)
|
||||
|
||||
def p1 do
|
||||
input_chars()
|
||||
|> Enum.reduce(0, fn
|
||||
"(", floor -> floor + 1
|
||||
")", floor -> floor - 1
|
||||
end)
|
||||
end
|
||||
|
||||
def p2 do
|
||||
input_string()
|
||||
|> find_step_entering_basement(0, 0)
|
||||
end
|
||||
|
||||
defp find_step_entering_basement(")" <> _, 0, step), do: step + 1
|
||||
|
||||
defp find_step_entering_basement("(" <> rest, floor, step),
|
||||
do: find_step_entering_basement(rest, floor + 1, step + 1)
|
||||
|
||||
defp find_step_entering_basement(")" <> rest, floor, step),
|
||||
do: find_step_entering_basement(rest, floor - 1, step + 1)
|
||||
end
|
32
2015/lib/2015/2.ex
Normal file
32
2015/lib/2015/2.ex
Normal file
|
@ -0,0 +1,32 @@
|
|||
import AOC
|
||||
|
||||
aoc 2015, 2 do
|
||||
def dimensions_stream(),
|
||||
do:
|
||||
input_stream()
|
||||
|> Stream.map(fn line ->
|
||||
[l, w, h] = String.split(line, "x") |> Enum.map(&String.to_integer/1)
|
||||
{l, w, h}
|
||||
end)
|
||||
|
||||
def p1 do
|
||||
dimensions_stream()
|
||||
|> Stream.map(fn {l, w, h} ->
|
||||
a = l * w
|
||||
b = w * h
|
||||
c = h * l
|
||||
2 * a + 2 * b + 2 * c + Enum.min([a, b, c])
|
||||
end)
|
||||
|> Enum.sum()
|
||||
end
|
||||
|
||||
def p2 do
|
||||
dimensions_stream()
|
||||
|> Stream.map(fn {l, w, h} ->
|
||||
[x, y | _] = Enum.sort([l, w, h])
|
||||
|
||||
2 * x + 2 * y + l * w * h
|
||||
end)
|
||||
|> Enum.sum()
|
||||
end
|
||||
end
|
46
2015/lib/2015/3.ex
Normal file
46
2015/lib/2015/3.ex
Normal file
|
@ -0,0 +1,46 @@
|
|||
import AOC
|
||||
|
||||
aoc 2015, 3 do
|
||||
def input_chars(), do: input_string() |> String.split("", trim: true)
|
||||
|
||||
def p1 do
|
||||
input_chars()
|
||||
|> run()
|
||||
|> then(fn {visited, _} -> MapSet.size(visited) end)
|
||||
end
|
||||
|
||||
def p2 do
|
||||
{santa, robo_santa} =
|
||||
input_chars()
|
||||
|> Enum.with_index()
|
||||
|> Enum.split_with(fn {_, i} -> Integer.mod(i, 2) == 0 end)
|
||||
|> then(fn {santa, robo_santa} ->
|
||||
{without_index(santa), without_index(robo_santa)}
|
||||
end)
|
||||
|
||||
{visited, _} = run(santa)
|
||||
{visited, _} = run(robo_santa, visited)
|
||||
|
||||
MapSet.size(visited)
|
||||
end
|
||||
|
||||
defp op("^"), do: {1, 0}
|
||||
defp op(">"), do: {0, 1}
|
||||
defp op("v"), do: {-1, 0}
|
||||
defp op("<"), do: {0, -1}
|
||||
|
||||
defp add({x, y}, {a, b}), do: {x + a, y + b}
|
||||
|
||||
defp run(inst, visited \\ MapSet.new()) do
|
||||
starting_position = {0, 0}
|
||||
visited = MapSet.put(visited, starting_position)
|
||||
|
||||
Enum.reduce(inst, {visited, starting_position}, fn command, {visited, current_position} ->
|
||||
current_position = add(current_position, op(command))
|
||||
visited = MapSet.put(visited, current_position)
|
||||
{visited, current_position}
|
||||
end)
|
||||
end
|
||||
|
||||
defp without_index(enum), do: Enum.map(enum, &elem(&1, 0))
|
||||
end
|
31
2015/lib/2015/4.ex
Normal file
31
2015/lib/2015/4.ex
Normal file
|
@ -0,0 +1,31 @@
|
|||
import AOC
|
||||
|
||||
aoc 2015, 4 do
|
||||
def p1 do
|
||||
input_string()
|
||||
|> String.trim()
|
||||
|> mine_advent_coin(5)
|
||||
end
|
||||
|
||||
defp mine_advent_coin(key, difficulty, nonce \\ 0)
|
||||
|
||||
defp mine_advent_coin(key, 5, nonce) do
|
||||
case :erlang.md5(key <> Integer.to_string(nonce)) do
|
||||
<<0::20, _::108>> -> nonce
|
||||
_ -> mine_advent_coin(key, 5, nonce + 1)
|
||||
end
|
||||
end
|
||||
|
||||
defp mine_advent_coin(key, 6, nonce) do
|
||||
case :erlang.md5(key <> Integer.to_string(nonce)) do
|
||||
<<0::24, _::104>> -> nonce
|
||||
_ -> mine_advent_coin(key, 6, nonce + 1)
|
||||
end
|
||||
end
|
||||
|
||||
def p2 do
|
||||
input_string()
|
||||
|> String.trim()
|
||||
|> mine_advent_coin(6)
|
||||
end
|
||||
end
|
29
2015/lib/2015/5.ex
Normal file
29
2015/lib/2015/5.ex
Normal file
|
@ -0,0 +1,29 @@
|
|||
import AOC
|
||||
|
||||
aoc 2015, 5 do
|
||||
@deny_list ~w(ab cd pq xy)
|
||||
|
||||
def p1 do
|
||||
input_stream()
|
||||
|> Stream.filter(&is_string_nice_p1?/1)
|
||||
|> Enum.count()
|
||||
end
|
||||
|
||||
defp is_string_nice_p1?(str) do
|
||||
contains_at_least_three_vowels = String.match?(str, ~r/(?:[aeiou].*){3}/)
|
||||
contains_double_letter = String.match?(str, ~r/(\w)\1/)
|
||||
does_not_contain_denylist = not Enum.any?(@deny_list, &String.contains?(str, &1))
|
||||
|
||||
contains_at_least_three_vowels and contains_double_letter and does_not_contain_denylist
|
||||
end
|
||||
|
||||
def p2 do
|
||||
input_stream()
|
||||
|> Stream.filter(&is_string_nice_p2?/1)
|
||||
|> Enum.count()
|
||||
end
|
||||
|
||||
defp is_string_nice_p2?(str) do
|
||||
String.match?(str, ~r/(\w)(\w).*\1\2/) and String.match?(str, ~r/(\w)\w\1/)
|
||||
end
|
||||
end
|
82
2015/lib/2015/6.ex
Normal file
82
2015/lib/2015/6.ex
Normal file
|
@ -0,0 +1,82 @@
|
|||
import AOC
|
||||
|
||||
aoc 2015, 6 do
|
||||
import NimbleParsec
|
||||
|
||||
defparsec(
|
||||
:coord,
|
||||
integer(min: 1)
|
||||
|> ignore(string(","))
|
||||
|> integer(min: 1)
|
||||
|> label("coordinate pair")
|
||||
)
|
||||
|
||||
defparsec(
|
||||
:command,
|
||||
choice([
|
||||
string("turn on"),
|
||||
string("turn off"),
|
||||
string("toggle")
|
||||
])
|
||||
|> ignore(string(" "))
|
||||
|> parsec(:coord)
|
||||
|> ignore(string(" through "))
|
||||
|> parsec(:coord)
|
||||
)
|
||||
|
||||
def parse_command(line) do
|
||||
command(line)
|
||||
|> then(fn {:ok, v, _, _, _, _} -> v end)
|
||||
|> then(fn
|
||||
["turn on", x1, y1, x2, y2] -> {:turn_on, {x1, y1}, {x2, y2}}
|
||||
["turn off", x1, y1, x2, y2] -> {:turn_off, {x1, y1}, {x2, y2}}
|
||||
["toggle", x1, y1, x2, y2] -> {:toggle, {x1, y1}, {x2, y2}}
|
||||
end)
|
||||
end
|
||||
|
||||
def command_stream(), do: input_stream() |> Stream.map(&parse_command/1)
|
||||
|
||||
def p1 do
|
||||
lights = for x <- 0..999, y <- 0..999, into: %{}, do: {{x, y}, 0}
|
||||
|
||||
command_stream()
|
||||
|> Enum.reduce(lights, fn
|
||||
{:turn_on, from, to}, lights ->
|
||||
set_range(lights, from, to, 1)
|
||||
|
||||
{:turn_off, from, to}, lights ->
|
||||
set_range(lights, from, to, 0)
|
||||
|
||||
{:toggle, from, to}, lights ->
|
||||
update_range(lights, from, to, fn
|
||||
0 -> 1
|
||||
1 -> 0
|
||||
end)
|
||||
end)
|
||||
|> Map.values()
|
||||
|> Enum.sum()
|
||||
end
|
||||
|
||||
def p2 do
|
||||
lights = for x <- 0..999, y <- 0..999, into: %{}, do: {{x, y}, 0}
|
||||
|
||||
command_stream()
|
||||
|> Enum.reduce(lights, fn
|
||||
{:turn_on, from, to}, lights -> update_range(lights, from, to, &(&1 + 1))
|
||||
{:turn_off, from, to}, lights -> update_range(lights, from, to, &max(0, &1 - 1))
|
||||
{:toggle, from, to}, lights -> update_range(lights, from, to, &(&1 + 2))
|
||||
end)
|
||||
|> Map.values()
|
||||
|> Enum.sum()
|
||||
end
|
||||
|
||||
def set_range(map, from, to, value), do: update_range(map, from, to, always(value))
|
||||
|
||||
def update_range(map, {x1, y1}, {x2, y2}, fun) do
|
||||
for x <- x1..x2, y <- y1..y2, reduce: map do
|
||||
map -> Map.update!(map, {x, y}, fun)
|
||||
end
|
||||
end
|
||||
|
||||
def always(v), do: fn _ -> v end
|
||||
end
|
14
2015/lib/2015/7.ex
Normal file
14
2015/lib/2015/7.ex
Normal file
|
@ -0,0 +1,14 @@
|
|||
import AOC
|
||||
|
||||
aoc 2015, 7 do
|
||||
import NimbleParsec
|
||||
|
||||
def parse_inst(line) do
|
||||
end
|
||||
|
||||
def p1 do
|
||||
end
|
||||
|
||||
def p2 do
|
||||
end
|
||||
end
|
18
2015/lib/advent_of_code2015.ex
Normal file
18
2015/lib/advent_of_code2015.ex
Normal file
|
@ -0,0 +1,18 @@
|
|||
defmodule AdventOfCode2015 do
|
||||
@moduledoc """
|
||||
Documentation for `AdventOfCode2015`.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Hello world.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> AdventOfCode2015.hello()
|
||||
:world
|
||||
|
||||
"""
|
||||
def hello do
|
||||
:world
|
||||
end
|
||||
end
|
30
2015/mix.exs
Normal file
30
2015/mix.exs
Normal file
|
@ -0,0 +1,30 @@
|
|||
defmodule AdventOfCode2015.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :advent_of_code_2015,
|
||||
version: "0.1.0",
|
||||
elixir: "~> 1.12",
|
||||
start_permanent: Mix.env() == :prod,
|
||||
deps: deps()
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help compile.app" to learn about applications.
|
||||
def application do
|
||||
[
|
||||
extra_applications: [:logger]
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help deps" to learn about dependencies.
|
||||
defp deps do
|
||||
[
|
||||
{:advent_of_code_utils, "~> 1.0"},
|
||||
{:exla, "~> 0.1.0-dev", github: "elixir-nx/nx", sparse: "exla"},
|
||||
{:nimble_parsec, "~> 1.0"},
|
||||
{:nx, "~> 0.1.0-dev", github: "elixir-nx/nx", sparse: "nx", override: true}
|
||||
]
|
||||
end
|
||||
end
|
8
2015/mix.lock
Normal file
8
2015/mix.lock
Normal file
|
@ -0,0 +1,8 @@
|
|||
%{
|
||||
"advent_of_code_utils": {:hex, :advent_of_code_utils, "1.0.0", "e9ce8be22988e095991168e9d2dde802afc213aaae64491e9fde84dd877db41c", [:mix], [], "hexpm", "1fa5217ccb95a38ce2312dd7ea6057b0d0002a3eba7490feab704df4b8a94038"},
|
||||
"elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"},
|
||||
"exla": {:git, "https://github.com/elixir-nx/nx.git", "e23a678bf0ebcbbafe03f1b5ed78623f052ad486", [sparse: "exla"]},
|
||||
"nimble_parsec": {:hex, :nimble_parsec, "1.2.0", "b44d75e2a6542dcb6acf5d71c32c74ca88960421b6874777f79153bbbbd7dccc", [:mix], [], "hexpm", "52b2871a7515a5ac49b00f214e4165a40724cf99798d8e4a65e4fd64ebd002c1"},
|
||||
"nx": {:git, "https://github.com/elixir-nx/nx.git", "e23a678bf0ebcbbafe03f1b5ed78623f052ad486", [sparse: "nx"]},
|
||||
"xla": {:hex, :xla, "0.2.0", "689887888afb22587168d461f0e9ff83d7b06040273ea7082dbf9ff7eca33dcc", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "a2e7b81413db49a159eabfb12dbd784a7c04b5c68c7b4057238d5ec9b110f2ec"},
|
||||
}
|
8
2015/test/advent_of_code2015_test.exs
Normal file
8
2015/test/advent_of_code2015_test.exs
Normal file
|
@ -0,0 +1,8 @@
|
|||
defmodule AdventOfCode2015Test do
|
||||
use ExUnit.Case
|
||||
doctest AdventOfCode2015
|
||||
|
||||
test "greets the world" do
|
||||
assert AdventOfCode2015.hello() == :world
|
||||
end
|
||||
end
|
1
2015/test/test_helper.exs
Normal file
1
2015/test/test_helper.exs
Normal file
|
@ -0,0 +1 @@
|
|||
ExUnit.start()
|
Loading…
Reference in a new issue