aboutsummaryrefslogtreecommitdiff
path: root/2020
diff options
context:
space:
mode:
authorj-james2020-12-09 05:43:41 +0000
committerj-james2020-12-09 05:43:41 +0000
commitc651051cf36e95c5603cd3f7aef2e6d278809333 (patch)
treecc3078033b25c7e9d64244ab292c1ff9beba84c0 /2020
parentdb5d72b57574042ca695704172ded112a9163e14 (diff)
Day Nine
Diffstat (limited to '2020')
-rw-r--r--2020/input/nine.txt1000
-rw-r--r--2020/nine.nim29
2 files changed, 1029 insertions, 0 deletions
diff --git a/2020/input/nine.txt b/2020/input/nine.txt
new file mode 100644
index 0000000..0f64783
--- /dev/null
+++ b/2020/input/nine.txt
@@ -0,0 +1,1000 @@
+2
+29
+23
+1
+49
+16
+14
+10
+45
+17
+48
+19
+5
+24
+6
+31
+37
+27
+40
+18
+22
+26
+9
+25
+39
+3
+7
+53
+12
+8
+11
+43
+34
+10
+13
+16
+14
+33
+15
+29
+92
+17
+19
+35
+41
+42
+18
+82
+20
+21
+23
+22
+24
+25
+26
+54
+32
+31
+46
+27
+37
+34
+36
+33
+78
+38
+67
+57
+39
+43
+56
+40
+41
+79
+44
+121
+49
+106
+103
+71
+68
+58
+61
+65
+63
+118
+69
+72
+100
+84
+81
+147
+101
+80
+83
+85
+105
+107
+93
+102
+159
+112
+119
+121
+123
+169
+209
+124
+128
+219
+141
+149
+152
+164
+185
+161
+181
+371
+192
+190
+178
+254
+195
+205
+306
+231
+233
+449
+245
+276
+447
+252
+265
+269
+349
+313
+527
+316
+454
+425
+437
+359
+509
+368
+373
+677
+717
+460
+743
+476
+561
+478
+649
+712
+517
+521
+581
+628
+689
+1017
+791
+675
+684
+741
+934
+1153
+727
+938
+1187
+851
+936
+1376
+1037
+1104
+1495
+995
+999
+1192
+1439
+1149
+1102
+2038
+1777
+1364
+1888
+1425
+1994
+1411
+1665
+1578
+1787
+2103
+1935
+2514
+1955
+2887
+2032
+2543
+2097
+2934
+2144
+2251
+3939
+2466
+2574
+2513
+3346
+2775
+2789
+3299
+3513
+2989
+4822
+4478
+3722
+3967
+4038
+5353
+4129
+3987
+4966
+4176
+4241
+4671
+4395
+4718
+4764
+4979
+5087
+7540
+5288
+5764
+5564
+6918
+6288
+8751
+9054
+7689
+7709
+7760
+9108
+8025
+8116
+12668
+8163
+9328
+8417
+8636
+9066
+9113
+14458
+9743
+10066
+10375
+10852
+11052
+12482
+11852
+15396
+20015
+15714
+15398
+15449
+18394
+15785
+16141
+17182
+16752
+16580
+16799
+17053
+29446
+25851
+19132
+18856
+19809
+20118
+27851
+32148
+26250
+22904
+24334
+27566
+30794
+30847
+43992
+34530
+31234
+32584
+68326
+32721
+33332
+33379
+36185
+36862
+35909
+47684
+88135
+37988
+65916
+39927
+50912
+47238
+59714
+57484
+55181
+79959
+58360
+61641
+80570
+63818
+63955
+66053
+65305
+68906
+66100
+76112
+75836
+72094
+72771
+73897
+85226
+131358
+77915
+87165
+90839
+98150
+120486
+141677
+167124
+113541
+120001
+122178
+137753
+136589
+127773
+129260
+146668
+131405
+135006
+138194
+157997
+150009
+144865
+227924
+151812
+163141
+176065
+227428
+274783
+188989
+211691
+233542
+241314
+265353
+235719
+283059
+280175
+257033
+259178
+298480
+266411
+269599
+276270
+279871
+327877
+400680
+448489
+296677
+422319
+410990
+487961
+365054
+416417
+422531
+424708
+506667
+469261
+477033
+559329
+492752
+516211
+523444
+893432
+743444
+691918
+545869
+823211
+556141
+797138
+776044
+956821
+1062808
+661731
+833521
+1200752
+1618949
+781471
+841125
+847239
+901741
+1693504
+946294
+969785
+1008963
+1039655
+1062080
+1266888
+1207600
+1248059
+1996476
+2157573
+1332185
+1337612
+1437775
+3312453
+1748980
+1508970
+1443202
+1886894
+1622596
+1628710
+1683212
+2054839
+1793533
+1848035
+1955257
+2517933
+2031865
+2948974
+2101735
+2946745
+2455659
+2539785
+3387024
+2775387
+2669797
+2769960
+3469640
+2880977
+2952172
+3065798
+3330096
+3416129
+3305808
+3422243
+3311922
+4871695
+4010096
+4568920
+5264164
+4410916
+4619668
+4133600
+5962028
+4557394
+5309745
+6891073
+7327354
+5439757
+5445184
+5550774
+9929413
+5833149
+10316879
+6017970
+10860519
+6838372
+6617730
+6728051
+7432339
+12167808
+8143696
+8421012
+9030584
+19004215
+8544516
+8753268
+9578784
+9867139
+17749218
+29321094
+10884941
+13566423
+10990531
+15648314
+11568744
+16896964
+11851119
+12635700
+12746021
+23735336
+13345781
+15038742
+17999796
+15576035
+27616357
+35586455
+16965528
+17575100
+18123300
+18411655
+18332052
+20463725
+20752080
+22453685
+31566219
+23736552
+22559275
+22841650
+23419863
+33498101
+30920881
+24486819
+28384523
+26091802
+28921816
+37598017
+30614777
+34540628
+33151135
+46796178
+35698400
+39419213
+35986755
+63155765
+38875380
+43305375
+41215805
+70137621
+46578202
+45400925
+67691763
+36845998
+46261513
+47906682
+64418982
+55013618
+102031145
+56706579
+59242937
+59536593
+77202560
+63765912
+68849535
+122603485
+71685155
+72544398
+72832753
+74862135
+75721378
+101591820
+92839715
+94484884
+82246923
+96088935
+123464073
+126934700
+128386128
+205588688
+102920300
+111720197
+128092472
+115949516
+116243172
+118779530
+167029282
+202656078
+132615447
+140534690
+144229553
+191670894
+145377151
+225055893
+204559912
+314376275
+208789231
+188928650
+176731807
+178335858
+306721986
+235022702
+300648847
+243454990
+214640497
+341299065
+227669713
+234729046
+261326667
+285911841
+251394977
+401861357
+273150137
+276845000
+284764243
+349937063
+322108958
+323713009
+355067665
+550176976
+385521038
+387125089
+365660457
+391372304
+544103837
+442310210
+449369543
+458095487
+511574046
+491485497
+462398759
+479064690
+486124023
+512721644
+635848904
+524545114
+809837032
+973972805
+608477252
+606873201
+645821967
+677176623
+915917418
+720728122
+845220576
+751181495
+752785546
+1135272110
+840741847
+941463449
+891679753
+907465030
+1326865870
+948522782
+953884256
+1199792812
+1263903139
+998845667
+1037266758
+1131418315
+1133022366
+1215350453
+1252695168
+1705065751
+1658646525
+1596402071
+1397904745
+1636645540
+1471909617
+1503967041
+1591923342
+1593527393
+2437143918
+1732421600
+2163873235
+2459888236
+2542050175
+1902407038
+2237059570
+1952729923
+2170289124
+2214196120
+2396750412
+2168685073
+2264440681
+3065437010
+2873996978
+2724604785
+2901871786
+2869814362
+4444457213
+2975876658
+3063832959
+4674084356
+5416047153
+3546257316
+3495934431
+3634828638
+4121414996
+3855136961
+4989045466
+6576491394
+4384485244
+4123019047
+4217170604
+4382881193
+4433125754
+7420333871
+6610090275
+5134255043
+11020948607
+7314271575
+7878815624
+5771686148
+6471811089
+9967745520
+6039709617
+7763427920
+7042191747
+7181085954
+14350626713
+7130763069
+7489965599
+7976551957
+8072307565
+8340189651
+8505900240
+8507504291
+10472835371
+11697152768
+15183761791
+9567380797
+12381776423
+13261651747
+11173964660
+18784376527
+11811395765
+15548091987
+12243497237
+29534388504
+16698143866
+13081901364
+14172954816
+14223277701
+14311849023
+19187118367
+14620728668
+15466517556
+16048859522
+16412497216
+16846089891
+18073281037
+20318900056
+21264533565
+27245244755
+21810878034
+31960589203
+24193172188
+26343553111
+25346919476
+24054893002
+27254856180
+49056122789
+27710014793
+27305179065
+41395778998
+30087246224
+28396232517
+28535126724
+32385130060
+30669588190
+31466818559
+37164989947
+32461356738
+48312908450
+34919370928
+57924444370
+41583433621
+46004050222
+67814928256
+62174227108
+55701411582
+48248065190
+51360072067
+49401812478
+63928175297
+54560035245
+55015193858
+55840305789
+56931359241
+58483478741
+64846486798
+60001945283
+59204714914
+97649877668
+62136406749
+79714883749
+117129159284
+113159395248
+126982893547
+76502804549
+87587483843
+89831498811
+108178277330
+99608137257
+100761884545
+102808100435
+116206558865
+103961847723
+104417006336
+109575229103
+178342965614
+112771665030
+114323784530
+115414837982
+191829380345
+119206660197
+121341121663
+164944507184
+138639211298
+141851290498
+156217688298
+203794042708
+179310904984
+225781787968
+279268291714
+224149222098
+190593383356
+345490343761
+203569984980
+523833309375
+206769948158
+237547680528
+338473006628
+304601045375
+223899013633
+240547781860
+252962995828
+229738622512
+365750304131
+277558809961
+259980332961
+263192412161
+332444673854
+280490501796
+321162195482
+503167305347
+369904288340
+428141063884
+573474273320
+536083727117
+397363331514
+394163368336
+410339933138
+427468998613
+756130301175
+539214622012
+476862009461
+464446795493
+483879346594
+453637636145
+731196446106
+482701618340
+489718955473
+939224577451
+537539142922
+523172745122
+601652697278
+612935175650
+887201942599
+691066483822
+764067656676
+1118535482435
+804503301474
+880064949854
+874786728631
+1173768102162
+1001985938415
+1344131621756
+881106634758
+943356591618
+947148413833
+1005874363462
+918084431638
+936339254485
+972420573813
+2262216053394
+1012891700595
+1327676046596
+1136107920772
+1487721904281
+1537991951763
+1214587872928
+1923038783909
+1455134140498
+1942213617947
+1568570958150
+2054874736920
+1679290030105
+2402282554331
+1811125983116
+2245760478234
+1799191066396
+1817445889243
+2474331206248
+3126867112992
+1953022777295
+1854423686123
+1908759828298
+2651710603918
+2500613604876
+2227479573523
+2148999621367
+2782810187094
+2350695793700
+2669722013426
+2752579824691
+3496735919348
+3960125604483
+3616636955639
+3247860988255
+3367762024546
+5314181808591
+5053993158249
+8930818764230
+3763183514421
+3671869575366
+3653614752519
+4604733381213
+4499695415067
+5275866734359
+4003423307490
+4637233873217
+4649613226243
+8597359477700
+4578175367223
+11281514557930
+4818721634793
+5103275618391
+6901475740774
+6000440812946
+6120341849237
+7723309118904
+6615623012801
+6864497943894
+7945937391769
+7021376777065
+7325484327885
+7416798266940
+8503118722557
+8367916895634
+7657038060009
+9149308641310
+8822144942283
+8581598674713
+8640657180707
+8653036533733
+10578616180169
+9227788593466
+19806404773635
+12946092262857
+13480120956695
+9921997253184
+11103716431337
+14066279241006
+12120782662183
+12735964862038
+16949515570347
+14272661072810
+20501497733760
+14346861104950
+17517225536944
+20271576590742
+17730907316023
+22629429598005
+16238636734722
+16297695240716
+22647877915719
+31270086778712
+17222255855420
+31300914449452
+31583504777950
+49031821765475
+19149785846650
+21025713684521
+23988276494190
+22657962115222
+22042779915367
+32129430115858
+26467643767133
+24856747524221
+27082825966988
+28619522177760
+46739220357875
+30585497839672
+30644556345666
+44690657831086
+37493832446162
+32536331975438
+33460892590142
+35447481087366
+33519951096136
+67983813062804
+42079003379641
+41210532349610
+52326628133973
+40175499531171
+41192565762017
+43138062340840
+55562731011503
+44700742030589
+49740788082210
+46899527439588
+57668323806660
+96755296773520
+57393079499659
+55702348144748
+59205020017432
+63180888321104
+61230054185338
diff --git a/2020/nine.nim b/2020/nine.nim
new file mode 100644
index 0000000..8b15391
--- /dev/null
+++ b/2020/nine.nim
@@ -0,0 +1,29 @@
+# Day Nine: Encoding Error
+import os, strutils, sequtils
+
+let input: string = paramStr(1)
+let xmas: seq[int] = map(split(strip(readFile(input)), '\n'), parseInt)
+const preamble: int = 25
+var encryption, weakness, smallest: int
+
+for i in preamble ..< len(xmas):
+ var valid: bool
+ for j in 0 .. preamble:
+ for k in 0 .. preamble:
+ if xmas[i - k] + xmas[i - j] == xmas[i]:
+ valid = true
+ if not valid:
+ encryption = xmas[i]
+for largest in 0 ..< len(xmas):
+ var sum: int = 0
+ for val in smallest .. largest:
+ inc(sum, xmas[val])
+ while sum > encryption:
+ dec(sum, xmas[smallest])
+ inc(smallest)
+ if sum == encryption:
+ weakness = xmas[smallest] + xmas[largest]
+ break
+
+echo encryption
+echo weakness