Initial Commit - days 01-12
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
ex*-c
|
||||
core
|
||||
ex*-cob
|
||||
day13
|
31
Makefile
Normal file
31
Makefile
Normal file
@@ -0,0 +1,31 @@
|
||||
SUBDIRS := $(shell echo day??)
|
||||
INSTALLDIR := ~/dev/www/tk.bodiccea/advent-2020
|
||||
DEST := arwen:www/tk.bodiccea/advent-2020
|
||||
|
||||
EXCLUDE := --exclude 'cob-01/'
|
||||
|
||||
.PHONY: clean deploy $(SUBDIRS)
|
||||
|
||||
clean:
|
||||
for dir in $(SUBDIRS) ; do \
|
||||
make -C $$dir clean ; \
|
||||
done
|
||||
|
||||
deploy: clean
|
||||
rsync -aHixv $(EXCLUDE) --delete --delete-excluded ./ $(INSTALLDIR)
|
||||
rsync -aHixv $(EXCLUDE) ./ $(DEST) --delete --delete-excluded
|
||||
|
||||
all: $(SUBDIRS)
|
||||
|
||||
$(SUBDIRS):
|
||||
@echo "========================================="
|
||||
@echo "================= $@ ================="
|
||||
@echo "========================================="
|
||||
@echo
|
||||
@echo "+++++++++++++++++ ex1"
|
||||
@$(MAKE) --no-print-directory -C $@ ex1 2>&1
|
||||
@echo "+++++++++++++++++ ex2"
|
||||
@$(MAKE) --no-print-directory -C $@ ex2 2>&1
|
||||
|
||||
output:
|
||||
@$(MAKE) --no-print-directory all >OUTPUT 2>&1
|
344
OUTPUT
Normal file
344
OUTPUT
Normal file
@@ -0,0 +1,344 @@
|
||||
=========================================
|
||||
================= day01 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
ex1.bash : 33:1701 180:319 sum=2020 mul=542619
|
||||
time: 0:00.06 real, 0.06 user, 0.00 sys
|
||||
context-switch: 8+4, page-faults: 0+303
|
||||
|
||||
ex1-cob : res= 542619
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 1+1, page-faults: 0+171
|
||||
|
||||
ex1-c : 33:1701 180:319 sum=2020 mul=542619
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 2+1, page-faults: 0+75
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
ex2.bash : 80:1450 94:43 185:527 sum=2020 mul=32858450
|
||||
time: 0:10.10 real, 9.98 user, 0.03 sys
|
||||
context-switch: 1845+4, page-faults: 0+305
|
||||
|
||||
ex2-sort.bash : 0:43 2:527 81:1450 sum=2020 mul=32858450
|
||||
time: 0:00.01 real, 0.01 user, 0.00 sys
|
||||
context-switch: 1+7, page-faults: 0+476
|
||||
|
||||
ex2-pure-sort.bash : 0:43 2:527 81:1450 sum=2020 mul=32858450
|
||||
time: 0:00.61 real, 0.60 user, 0.00 sys
|
||||
context-switch: 136+4, page-faults: 0+309
|
||||
|
||||
ex2-sort-cob : res= 32858450
|
||||
time: 0:00.01 real, 0.00 user, 0.00 sys
|
||||
context-switch: 5+1, page-faults: 0+173
|
||||
|
||||
ex2-pure-sort-cob : res= 32858450
|
||||
time: 0:00.01 real, 0.01 user, 0.00 sys
|
||||
context-switch: 2+1, page-faults: 0+173
|
||||
|
||||
ex2-c : 80:1450 94:43 185:527 sum=2020 mul=32858450
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 1+1, page-faults: 0+74
|
||||
|
||||
=========================================
|
||||
================= day02 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
cc -w ex1-c.c -o ex1-c
|
||||
ex1.bash : lines: 1000 matched:607
|
||||
time: 0:00.07 real, 0.03 user, 0.00 sys
|
||||
context-switch: 5+3, page-faults: 0+154
|
||||
|
||||
ex1-c : lines: 1000 matched:607
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+75
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
cc -w ex2-c.c -o ex2-c
|
||||
ex2.bash : lines: 1000 matched:321
|
||||
time: 0:00.03 real, 0.03 user, 0.00 sys
|
||||
context-switch: 10+2, page-faults: 0+152
|
||||
|
||||
ex2-c : lines: 1000 matched:321
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 2+1, page-faults: 0+74
|
||||
|
||||
=========================================
|
||||
================= day03 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
cc -w ex1-c.c -o ex1-c
|
||||
ex1.bash : lines:322 pos=966 found:169
|
||||
time: 0:00.03 real, 0.01 user, 0.00 sys
|
||||
context-switch: 2+3, page-faults: 0+152
|
||||
|
||||
ex1-c : lines:322 pos:966 found:169
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+73
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
cc -w ex2-c.c -o ex2-c
|
||||
ex2.bash : lines=323 res=6847128288
|
||||
time: 0:00.05 real, 0.04 user, 0.00 sys
|
||||
context-switch: 6+2, page-faults: 0+156
|
||||
|
||||
ex2-c : lines=323 res=6847128288
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+74
|
||||
|
||||
=========================================
|
||||
================= day04 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
cc -w ex1-c.c -o ex1-c
|
||||
ex1.bash : valid=182/251
|
||||
time: 0:00.08 real, 0.07 user, 0.00 sys
|
||||
context-switch: 6+3, page-faults: 0+160
|
||||
|
||||
ex1-c : valid=182/251
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+74
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
cc -w ex2-c.c -o ex2-c
|
||||
ex2.bash : valid=109/251
|
||||
time: 0:00.20 real, 0.16 user, 0.00 sys
|
||||
context-switch: 52+2, page-faults: 0+193
|
||||
|
||||
ex2-c : valid=109/251
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 1+1, page-faults: 0+74
|
||||
|
||||
=========================================
|
||||
================= day05 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
cc -w ex1-c.c -o ex1-c
|
||||
ex1.bash : lines=743 max=838
|
||||
time: 0:01.04 real, 0.70 user, 0.39 sys
|
||||
context-switch: 72+4435, page-faults: 0+150958
|
||||
|
||||
ex1-c : lines=743 max=838
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+72
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
cc -w ex2-c.c -o ex2-c
|
||||
ex2.bash : lines=743 seat=714
|
||||
time: 0:01.19 real, 0.77 user, 0.50 sys
|
||||
context-switch: 80+4426, page-faults: 0+155986
|
||||
|
||||
ex2-c : lines=743 seat=714
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+75
|
||||
|
||||
=========================================
|
||||
================= day06 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
cc -w ex1-c.c -o ex1-c
|
||||
cc -w ex2-c.c -o ex2-c
|
||||
ex1.bash : groups=484 count=6585
|
||||
time: 0:01.44 real, 1.25 user, 0.22 sys
|
||||
context-switch: 132+1392, page-faults: 0+58723
|
||||
|
||||
ex1-bis.bash : groups=484 count=6585
|
||||
time: 0:01.26 real, 1.10 user, 0.17 sys
|
||||
context-switch: 110+1330, page-faults: 0+59995
|
||||
|
||||
ex1-c : groups=484 count=6585
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+73
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
ex2.bash : groups=484 count=3276
|
||||
time: 0:01.47 real, 1.27 user, 0.21 sys
|
||||
context-switch: 139+1399, page-faults: 0+60071
|
||||
|
||||
ex2-bis.bash : groups=484 count=3276
|
||||
time: 0:01.39 real, 1.16 user, 0.21 sys
|
||||
context-switch: 139+1354, page-faults: 0+58513
|
||||
|
||||
ex2-c : groups=484 count=3276
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+73
|
||||
|
||||
=========================================
|
||||
================= day07 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
cc -w ex1-c.c -o ex1-c
|
||||
ex1.bash : target=shinygold nkeys=594 res=287
|
||||
time: 0:07.19 real, 7.09 user, 0.01 sys
|
||||
context-switch: 1291+3, page-faults: 0+408
|
||||
|
||||
ex1-bis.bash : target=shinygold res=287
|
||||
time: 0:00.12 real, 0.11 user, 0.00 sys
|
||||
context-switch: 36+2, page-faults: 0+212
|
||||
|
||||
ex1-c : target=shinygold nkeys=594 res=287
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 1+1, page-faults: 0+118
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
cc -w ex2-c.c -o ex2-c
|
||||
ex2.bash : target=shinygold res=48160
|
||||
time: 0:00.34 real, 0.28 user, 0.06 sys
|
||||
context-switch: 69+251, page-faults: 0+12038
|
||||
|
||||
ex2-c : target=shinygold nkeys=594 res=48160
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+118
|
||||
|
||||
=========================================
|
||||
================= day08 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
cc -w ex1-c.c -o ex1-c
|
||||
ex1.bash : res=1594
|
||||
time: 0:00.06 real, 0.02 user, 0.00 sys
|
||||
context-switch: 3+6, page-faults: 0+301
|
||||
|
||||
ex1-c : res=1594
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+79
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
cc -w ex2-c.c -o ex2-c
|
||||
ex2.bash : res:758
|
||||
time: 0:02.27 real, 2.02 user, 0.26 sys
|
||||
context-switch: 276+1097, page-faults: 0+43723
|
||||
|
||||
ex2-c : res=758
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+81
|
||||
|
||||
=========================================
|
||||
================= day09 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
cc -w ex1-c.c -o ex1-c
|
||||
ex1.bash : res=167829540
|
||||
time: 0:00.41 real, 0.38 user, 0.00 sys
|
||||
context-switch: 41+3, page-faults: 0+176
|
||||
|
||||
ex1-c : res=167829540
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+76
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
cc -w ex2-c.c -o ex2-c
|
||||
ex2.bash : res=167829540 sum=28045630
|
||||
time: 0:02.95 real, 2.70 user, 0.25 sys
|
||||
context-switch: 227+937, page-faults: 0+49654
|
||||
|
||||
ex2-c : res=167829540 sum=28045630
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 1+1, page-faults: 0+76
|
||||
|
||||
=========================================
|
||||
================= day10 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
cc -w ex1-c.c -o ex1-c
|
||||
ex1.bash : diff1=71 diff2=27 res=1917
|
||||
time: 0:00.02 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+6, page-faults: 0+331
|
||||
|
||||
ex1-c : diff1=71 diff2=27 res=1917
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+74
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
cc -w ex2-c.c -o ex2-c
|
||||
ex2.bash : size=99 res=113387824750592
|
||||
time: 0:00.03 real, 0.01 user, 0.00 sys
|
||||
context-switch: 5+5, page-faults: 0+334
|
||||
|
||||
ex2-c : size=99 res=113387824750592
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+75
|
||||
|
||||
=========================================
|
||||
================= day11 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
ex1.bash : res=2386
|
||||
time: 0:41.70 real, 41.39 user, 0.07 sys
|
||||
context-switch: 6321+15, page-faults: 0+1315
|
||||
|
||||
ex1-c : res=2386
|
||||
time: 0:00.05 real, 0.00 user, 0.00 sys
|
||||
context-switch: 1+2, page-faults: 0+92
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
cc -w -O3 ex2-c.c -o ex2-c
|
||||
ex2.bash : res=2091
|
||||
time: 1:19.94 real, 79.78 user, 0.05 sys
|
||||
context-switch: 8678+11, page-faults: 0+1715
|
||||
|
||||
ex2-c : res=2091
|
||||
time: 0:00.01 real, 0.01 user, 0.00 sys
|
||||
context-switch: 3+1, page-faults: 0+91
|
||||
|
||||
=========================================
|
||||
================= day12 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
cc -w -O3 ex1-c.c -o ex1-c
|
||||
ex1.bash : res=1457
|
||||
time: 0:00.07 real, 0.01 user, 0.01 sys
|
||||
context-switch: 3+3, page-faults: 0+153
|
||||
|
||||
ex1-c : res=1457
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+73
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
cc -w -O3 ex2-c.c -o ex2-c
|
||||
ex2.bash : res=106860
|
||||
time: 0:00.10 real, 0.09 user, 0.00 sys
|
||||
context-switch: 11+2, page-faults: 0+154
|
||||
|
||||
ex2-c : res=106860
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+74
|
||||
|
||||
=========================================
|
||||
================= day13 =================
|
||||
=========================================
|
||||
|
||||
+++++++++++++++++ ex1
|
||||
ex1.bash : res=410
|
||||
time: 0:00.02 real, 0.00 user, 0.00 sys
|
||||
context-switch: 1+3, page-faults: 0+153
|
||||
|
||||
ex1-c : res=0
|
||||
time: 0:00.02 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+2, page-faults: 0+73
|
||||
|
||||
+++++++++++++++++ ex2
|
||||
i=45 - b=23
|
||||
i=56 - b=19
|
||||
i=54 - b=17
|
||||
i=0 - b=37
|
||||
./ex2.bash: line 43: (N+k) % i: division by 0 (error token is "i")
|
||||
ex2.bash : N=14145 INV=-6716
|
||||
time: 0:00.01 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+2, page-faults: 0+159
|
||||
|
||||
ex2-c : res=0
|
||||
time: 0:00.01 real, 0.00 user, 0.00 sys
|
||||
context-switch: 1+2, page-faults: 0+75
|
||||
|
4
README
Normal file
4
README
Normal file
@@ -0,0 +1,4 @@
|
||||
advent of code 2020:
|
||||
https://adventofcode.com/2020
|
||||
|
||||
Here are solutions to the 2 daily exercises in both C and bash.
|
200
day01/INPUT.txt
Normal file
200
day01/INPUT.txt
Normal file
@@ -0,0 +1,200 @@
|
||||
1899
|
||||
1358
|
||||
1824
|
||||
1541
|
||||
1801
|
||||
1950
|
||||
1441
|
||||
1848
|
||||
1259
|
||||
1715
|
||||
1222
|
||||
1097
|
||||
1127
|
||||
1531
|
||||
1330
|
||||
1841
|
||||
1662
|
||||
1075
|
||||
1631
|
||||
1844
|
||||
1209
|
||||
1940
|
||||
2006
|
||||
1085
|
||||
1615
|
||||
1132
|
||||
1345
|
||||
1736
|
||||
1885
|
||||
1919
|
||||
1995
|
||||
1893
|
||||
1464
|
||||
1701
|
||||
1373
|
||||
1390
|
||||
1717
|
||||
1238
|
||||
1707
|
||||
1088
|
||||
1566
|
||||
1971
|
||||
1804
|
||||
1630
|
||||
1920
|
||||
1445
|
||||
1948
|
||||
1123
|
||||
1917
|
||||
1944
|
||||
1448
|
||||
1965
|
||||
1118
|
||||
1986
|
||||
1498
|
||||
1847
|
||||
1730
|
||||
1418
|
||||
1771
|
||||
1352
|
||||
1207
|
||||
1276
|
||||
1716
|
||||
1502
|
||||
1922
|
||||
1473
|
||||
1528
|
||||
1038
|
||||
1228
|
||||
1983
|
||||
1746
|
||||
1695
|
||||
1698
|
||||
1910
|
||||
1283
|
||||
1145
|
||||
1967
|
||||
1304
|
||||
1651
|
||||
1898
|
||||
1450
|
||||
1042
|
||||
1051
|
||||
1619
|
||||
1505
|
||||
1643
|
||||
1136
|
||||
1517
|
||||
1907
|
||||
1354
|
||||
1960
|
||||
1733
|
||||
1769
|
||||
1942
|
||||
43
|
||||
1743
|
||||
1981
|
||||
1711
|
||||
1141
|
||||
1169
|
||||
1239
|
||||
1032
|
||||
1148
|
||||
1045
|
||||
1768
|
||||
1173
|
||||
1389
|
||||
2007
|
||||
1614
|
||||
1028
|
||||
1729
|
||||
1083
|
||||
1165
|
||||
1461
|
||||
1850
|
||||
1913
|
||||
1958
|
||||
1121
|
||||
1613
|
||||
1341
|
||||
1055
|
||||
1510
|
||||
1054
|
||||
1064
|
||||
1875
|
||||
1429
|
||||
1799
|
||||
1570
|
||||
1293
|
||||
1702
|
||||
1313
|
||||
1576
|
||||
1050
|
||||
1340
|
||||
1117
|
||||
1342
|
||||
1914
|
||||
1773
|
||||
1281
|
||||
1176
|
||||
1371
|
||||
1520
|
||||
1131
|
||||
1438
|
||||
1741
|
||||
1583
|
||||
1840
|
||||
1412
|
||||
1792
|
||||
1656
|
||||
1628
|
||||
1089
|
||||
1124
|
||||
1291
|
||||
1476
|
||||
1367
|
||||
1467
|
||||
1529
|
||||
1925
|
||||
1555
|
||||
1518
|
||||
1496
|
||||
1745
|
||||
1533
|
||||
1557
|
||||
1861
|
||||
1091
|
||||
1364
|
||||
1894
|
||||
1760
|
||||
1622
|
||||
1149
|
||||
1776
|
||||
1547
|
||||
1329
|
||||
1988
|
||||
1697
|
||||
989
|
||||
1604
|
||||
1296
|
||||
319
|
||||
1459
|
||||
1860
|
||||
1916
|
||||
1838
|
||||
527
|
||||
1370
|
||||
1881
|
||||
1213
|
||||
2003
|
||||
1223
|
||||
1095
|
||||
1560
|
||||
1784
|
||||
1157
|
||||
1573
|
||||
1023
|
||||
1758
|
||||
1857
|
||||
1723
|
40
day01/Makefile
Normal file
40
day01/Makefile
Normal file
@@ -0,0 +1,40 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w
|
||||
COBFLAGS=-fmfcomment -free -x
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2 output
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
compile: ex1-c ex2-c ex2-pure-sort-cob ex2-sort-cob
|
||||
|
||||
ex1: ex1-c ex1-cob
|
||||
@$(TIME) ex1.bash < $(INPUT)
|
||||
@echo -n "ex1-cob : res="
|
||||
@$(TIME) ex1-cob < $(INPUT)
|
||||
@$(TIME) ex1-c < $(INPUT)
|
||||
|
||||
ex2: ex2-c ex2-sort-cob ex2-pure-sort-cob
|
||||
@$(TIME) ex2.bash < $(INPUT)
|
||||
@$(TIME) ex2-sort.bash < $(INPUT)
|
||||
@$(TIME) ex2-pure-sort.bash < $(INPUT)
|
||||
@echo -n "ex2-sort-cob : res="
|
||||
@$(TIME) ex2-sort-cob < $(INPUT)
|
||||
@echo -n "ex2-pure-sort-cob : res="
|
||||
@$(TIME) ex2-pure-sort-cob < $(INPUT)
|
||||
@$(TIME) ex2-c < $(INPUT)
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core ex2-galoisgirl-cob ex2-cob
|
||||
|
||||
output:
|
||||
$(MAKE) --no-print-directory all >OUTPUT 2>&1
|
||||
|
||||
deploy:
|
||||
$(MAKE) -C .. deploy
|
||||
|
||||
%: %.cob
|
||||
cobc $(COBFLAGS) $^
|
36
day01/OUTPUT
Normal file
36
day01/OUTPUT
Normal file
@@ -0,0 +1,36 @@
|
||||
ex1.bash : 33:1701 180:319 sum=2020 mul=542619
|
||||
time: 0:00.06 real, 0.06 user, 0.00 sys
|
||||
context-switch: 20+4, page-faults: 0+305
|
||||
|
||||
ex1-cob : res= 542619
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+172
|
||||
|
||||
ex1-c : 33:1701 180:319 sum=2020 mul=542619
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+73
|
||||
|
||||
ex2.bash : 80:1450 94:43 185:527 sum=2020 mul=32858450
|
||||
time: 0:10.00 real, 10.00 user, 0.00 sys
|
||||
context-switch: 1005+3, page-faults: 0+302
|
||||
|
||||
ex2-sort.bash : 0:43 2:527 81:1450 sum=2020 mul=32858450
|
||||
time: 0:00.01 real, 0.01 user, 0.00 sys
|
||||
context-switch: 2+7, page-faults: 0+479
|
||||
|
||||
ex2-pure-sort.bash : 0:43 2:527 81:1450 sum=2020 mul=32858450
|
||||
time: 0:00.50 real, 0.50 user, 0.00 sys
|
||||
context-switch: 62+4, page-faults: 0+311
|
||||
|
||||
ex2-sort-cob : res= 32858450
|
||||
time: 0:00.01 real, 0.01 user, 0.00 sys
|
||||
context-switch: 1+1, page-faults: 0+170
|
||||
|
||||
ex2-pure-sort-cob : res= 32858450
|
||||
time: 0:00.01 real, 0.01 user, 0.00 sys
|
||||
context-switch: 1+1, page-faults: 0+173
|
||||
|
||||
ex2-c : 80:1450 94:43 185:527 sum=2020 mul=32858450
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+75
|
||||
|
45
day01/README
Normal file
45
day01/README
Normal file
@@ -0,0 +1,45 @@
|
||||
--- Day 1: Report Repair ---
|
||||
|
||||
After saving Christmas five years in a row, you've decided to take a vacation at a nice resort on a tropical island. Surely, Christmas will go on without you.
|
||||
|
||||
The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfish; the locals just call them stars. None of the currency exchanges seem to have heard of them, but somehow, you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room.
|
||||
|
||||
To save your vacation, you 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!
|
||||
|
||||
Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently, something isn't quite adding up.
|
||||
|
||||
Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together.
|
||||
|
||||
For example, suppose your expense report contained the following:
|
||||
|
||||
1721
|
||||
979
|
||||
366
|
||||
299
|
||||
675
|
||||
1456
|
||||
|
||||
In this list, the two entries that sum to 2020 are 1721 and 299. Multiplying them together produces 1721 * 299 = 514579, so the correct answer is 514579.
|
||||
|
||||
Of course, your expense report is much larger. Find the two entries that sum to 2020; what do you get if you multiply them together?
|
||||
|
||||
Your puzzle answer was 542619.
|
||||
--- Part Two ---
|
||||
|
||||
The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from a past vacation. They offer you a second one if you can find three numbers in your expense report that meet the same criteria.
|
||||
|
||||
Using the above example again, the three entries that sum to 2020 are 979, 366, and 675. Multiplying them together produces the answer, 241861950.
|
||||
|
||||
In your expense report, what is the product of the three entries that sum to 2020?
|
||||
|
||||
Your puzzle answer was 32858450.
|
||||
|
||||
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 [Share] this puzzle.
|
6
day01/TEST.txt
Normal file
6
day01/TEST.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
1721
|
||||
979
|
||||
366
|
||||
299
|
||||
675
|
||||
1456
|
99
day01/ex1-22.cob
Normal file
99
day01/ex1-22.cob
Normal file
@@ -0,0 +1,99 @@
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. AoC-2020-day-1-part-2.
|
||||
*> Inspired by https://github.com/GaloisGirl/Coding
|
||||
*> Compilation: cobc -F -fmfcomment -std=rm -x ex2-cob.cob
|
||||
*> Utilisation: ./ex2-cob < INPUT.txt
|
||||
AUTHOR. Bruno Raoult.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
SELECT INPUTFILE ASSIGN TO KEYBOARD
|
||||
ORGANIZATION IS LINE SEQUENTIAL.
|
||||
|
||||
DATA DIVISION.
|
||||
FILE SECTION.
|
||||
FD INPUTFILE.
|
||||
01 INPUTRECORD PIC 9(4).
|
||||
|
||||
WORKING-STORAGE SECTION.
|
||||
01 FILE-STATUS PIC 9 VALUE 0.
|
||||
01 LEN PIC 9(3) VALUE 0.
|
||||
01 ARRAY.
|
||||
02 ARR OCCURS 0 TO 1024 DEPENDING ON LEN.
|
||||
05 VAL PIC 9(5).
|
||||
01 S PIC 9(4).
|
||||
01 P PIC 9(12).
|
||||
01 FMT PIC Z(12)9.
|
||||
|
||||
LOCAL-STORAGE SECTION.
|
||||
01 I USAGE UNSIGNED-INT VALUE 1.
|
||||
01 J USAGE UNSIGNED-INT VALUE 1.
|
||||
01 K USAGE UNSIGNED-INT VALUE 1.
|
||||
01 TMP USAGE UNSIGNED-INT VALUE 1.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
01-MAIN.
|
||||
OPEN INPUT INPUTFILE.
|
||||
PERFORM 02-READ UNTIL FILE-STATUS = 1.
|
||||
CLOSE INPUTFILE.
|
||||
*> PERFORM 06-PRINT.
|
||||
MOVE 1 TO K
|
||||
*> PERFORM 05-BUBBLE
|
||||
SORT ARR ASCENDING KEY VAL
|
||||
*> DISPLAY "=========================".
|
||||
*> PERFORM 06-PRINT.
|
||||
PERFORM 04-LOOP
|
||||
STOP RUN.
|
||||
02-READ.
|
||||
READ INPUTFILE
|
||||
AT END MOVE 1 TO FILE-STATUS
|
||||
NOT AT END PERFORM 03-WRITE-TO-TABLE
|
||||
END-READ.
|
||||
|
||||
03-WRITE-TO-TABLE.
|
||||
ADD 1 TO LEN.
|
||||
UNSTRING INPUTRECORD INTO VAL(LEN).
|
||||
*> Wrong: "234" becomes 2340 instead of 0234
|
||||
*> COMPUTE VAL(LEN) = INPUTRECORD.
|
||||
*> DISPLAY VAL(LEN) " " LEN.
|
||||
04-LOOP.
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN
|
||||
ADD I 1 GIVING TMP
|
||||
PERFORM VARYING J FROM TMP BY 1 UNTIL J > LEN
|
||||
ADD J 1 GIVING TMP
|
||||
PERFORM VARYING K FROM TMP BY 1 UNTIL K > LEN
|
||||
ADD VAL(I) VAL(J) VAL(K) GIVING S
|
||||
*> DISPLAY I J K
|
||||
IF S = 2020 THEN
|
||||
MULTIPLY VAL(I) BY VAL(J) GIVING P
|
||||
MULTIPLY P BY VAL(K) GIVING P
|
||||
MOVE P TO FMT
|
||||
DISPLAY FMT
|
||||
EXIT PERFORM
|
||||
ELSE
|
||||
IF S > 2020 THEN
|
||||
EXIT PERFORM
|
||||
END-IF
|
||||
END-IF
|
||||
END-PERFORM
|
||||
END-PERFORM
|
||||
END-PERFORM.
|
||||
05-BUBBLE.
|
||||
MOVE 1 TO K
|
||||
PERFORM UNTIL K = 0
|
||||
MOVE 0 TO K
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN - 1
|
||||
ADD 1 I GIVING J
|
||||
IF VAL(I) > VAL(J)
|
||||
MOVE VAL(I) TO TMP
|
||||
MOVE VAL(J) TO VAL(I)
|
||||
MOVE TMP TO VAL(J)
|
||||
MOVE 1 TO K
|
||||
END-IF
|
||||
END-PERFORM
|
||||
END-PERFORM.
|
||||
06-PRINT.
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN
|
||||
DISPLAY VAL(I)
|
||||
END-PERFORM.
|
96
day01/ex1-23.cob
Normal file
96
day01/ex1-23.cob
Normal file
@@ -0,0 +1,96 @@
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. AoC-2020-day-1-part-2.
|
||||
*> Inspired by https://github.com/GaloisGirl/Coding
|
||||
*> Compilation: obc -F -fmfcomment -std=rm -x ex2-cob.cob
|
||||
AUTHOR. Bruno Raoult.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
SELECT INPUTFILE ASSIGN TO KEYBOARD
|
||||
ORGANIZATION IS LINE SEQUENTIAL.
|
||||
|
||||
DATA DIVISION.
|
||||
FILE SECTION.
|
||||
FD INPUTFILE.
|
||||
01 INPUTRECORD PIC 9(4).
|
||||
|
||||
WORKING-STORAGE SECTION.
|
||||
01 FILE-STATUS PIC 9 VALUE 0.
|
||||
01 LEN PIC 9(3) VALUE 0.
|
||||
01 ARR.
|
||||
05 VAL PIC 9(5) OCCURS 1024.
|
||||
01 S PIC 9(4).
|
||||
01 P PIC 9(12).
|
||||
01 FMT PIC Z(12)9.
|
||||
|
||||
LOCAL-STORAGE SECTION.
|
||||
01 I USAGE UNSIGNED-INT VALUE 1.
|
||||
01 J USAGE UNSIGNED-INT VALUE 1.
|
||||
01 K USAGE UNSIGNED-INT VALUE 1.
|
||||
01 TMP USAGE UNSIGNED-INT VALUE 1.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
01-MAIN.
|
||||
OPEN INPUT INPUTFILE.
|
||||
PERFORM 02-READ UNTIL FILE-STATUS = 1.
|
||||
CLOSE INPUTFILE.
|
||||
*> PERFORM 06-PRINT.
|
||||
MOVE 1 TO K
|
||||
PERFORM 05-BUBBLE
|
||||
*> DISPLAY "=========================".
|
||||
*> PERFORM 06-PRINT.
|
||||
PERFORM 04-LOOP.
|
||||
STOP RUN.
|
||||
02-READ.
|
||||
READ INPUTFILE
|
||||
AT END MOVE 1 TO FILE-STATUS
|
||||
NOT AT END PERFORM 03-WRITE-TO-TABLE
|
||||
END-READ.
|
||||
|
||||
03-WRITE-TO-TABLE.
|
||||
ADD 1 TO LEN.
|
||||
MOVE INPUTRECORD TO FMT
|
||||
MOVE FMT TO VAL(LEN)
|
||||
*> UNSTRING INPUTRECORD INTO VAL(LEN).
|
||||
DISPLAY VAL(LEN) " " LEN.
|
||||
04-LOOP.
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN
|
||||
ADD I 1 GIVING TMP
|
||||
PERFORM VARYING J FROM TMP BY 1 UNTIL J > LEN
|
||||
ADD J 1 GIVING TMP
|
||||
PERFORM VARYING K FROM TMP BY 1 UNTIL K > LEN
|
||||
ADD VAL(I) VAL(J) VAL(K) GIVING S
|
||||
*> DISPLAY I J K
|
||||
IF S = 2020 THEN
|
||||
MULTIPLY VAL(I) BY VAL(J) GIVING P
|
||||
MULTIPLY P BY VAL(K) GIVING P
|
||||
MOVE P TO FMT
|
||||
DISPLAY FMT
|
||||
EXIT PERFORM
|
||||
ELSE
|
||||
IF S > 2020 THEN
|
||||
EXIT PERFORM
|
||||
END-IF
|
||||
END-IF
|
||||
END-PERFORM
|
||||
END-PERFORM
|
||||
END-PERFORM.
|
||||
05-BUBBLE.
|
||||
MOVE 1 TO K
|
||||
PERFORM UNTIL K = 0
|
||||
MOVE 0 TO K
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN - 1
|
||||
ADD 1 I GIVING J
|
||||
IF VAL(I) > VAL(J)
|
||||
MOVE VAL(I) TO TMP
|
||||
MOVE VAL(J) TO VAL(I)
|
||||
MOVE TMP TO VAL(J)
|
||||
MOVE 1 TO K
|
||||
END-IF
|
||||
END-PERFORM
|
||||
END-PERFORM.
|
||||
06-PRINT.
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN
|
||||
DISPLAY VAL(I)
|
||||
END-PERFORM.
|
29
day01/ex1-c.c
Normal file
29
day01/ex1-c.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ex1-c:c: Advent2020 game, day 1/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
int numbers[1000]; /* should do differently :
|
||||
* either read twice, either create list
|
||||
*/
|
||||
int n=0, i, j, n1, n2;
|
||||
|
||||
while (scanf("%d", numbers+n) != EOF)
|
||||
n++;
|
||||
|
||||
for (i=0; i<n; ++i) {
|
||||
n1=numbers[i];
|
||||
for (j=i+1; j<n; ++j) {
|
||||
n2=numbers[j];
|
||||
if (n1+n2 == 2020) {
|
||||
printf("%s : %d:%d %d:%d sum=%d mul=%d\n", *av,
|
||||
i, n1, j, n2, n1+n2, n1*n2);
|
||||
exit (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
79
day01/ex1-cob.cob
Normal file
79
day01/ex1-cob.cob
Normal file
@@ -0,0 +1,79 @@
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. AoC-2020-day-1-part-1.
|
||||
*> Inspired by https://github.com/GaloisGirl/Coding
|
||||
*> Compilation: cobc -F -fmfcomment -std=rm -x ex2-cob.cob
|
||||
*> Utilisation: ./ex2-cob < INPUT.txt
|
||||
AUTHOR. Bruno Raoult.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
SELECT INPUTFILE ASSIGN TO KEYBOARD
|
||||
ORGANIZATION IS LINE SEQUENTIAL.
|
||||
|
||||
DATA DIVISION.
|
||||
FILE SECTION.
|
||||
FD INPUTFILE.
|
||||
01 INPUTRECORD PIC 9(4).
|
||||
|
||||
WORKING-STORAGE SECTION.
|
||||
01 FILE-STATUS PIC 9 VALUE 0.
|
||||
01 LEN PIC 9(3) VALUE 0.
|
||||
01 ARRAY.
|
||||
02 ARR OCCURS 0 TO 1024 DEPENDING ON LEN.
|
||||
05 VAL PIC 9(5).
|
||||
01 S PIC 9(4).
|
||||
01 P PIC 9(12).
|
||||
01 FMT PIC Z(12)9.
|
||||
|
||||
LOCAL-STORAGE SECTION.
|
||||
01 I USAGE UNSIGNED-INT VALUE 1.
|
||||
01 J USAGE UNSIGNED-INT VALUE 1.
|
||||
01 K USAGE UNSIGNED-INT VALUE 1.
|
||||
01 TMP USAGE UNSIGNED-INT VALUE 1.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
01-MAIN.
|
||||
OPEN INPUT INPUTFILE.
|
||||
PERFORM 02-READ UNTIL FILE-STATUS = 1.
|
||||
CLOSE INPUTFILE.
|
||||
*> PERFORM 06-PRINT.
|
||||
SORT ARR ASCENDING KEY VAL
|
||||
*> DISPLAY "=========================".
|
||||
*> PERFORM 06-PRINT.
|
||||
PERFORM 04-LOOP
|
||||
STOP RUN.
|
||||
02-READ.
|
||||
READ INPUTFILE
|
||||
AT END MOVE 1 TO FILE-STATUS
|
||||
NOT AT END PERFORM 03-WRITE-TO-TABLE
|
||||
END-READ.
|
||||
|
||||
03-WRITE-TO-TABLE.
|
||||
ADD 1 TO LEN.
|
||||
UNSTRING INPUTRECORD INTO VAL(LEN).
|
||||
*> Wrong: "234" becomes 2340 instead of 0234
|
||||
*> COMPUTE VAL(LEN) = INPUTRECORD.
|
||||
*> DISPLAY VAL(LEN) " " LEN.
|
||||
04-LOOP.
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN
|
||||
ADD I 1 GIVING TMP
|
||||
PERFORM VARYING J FROM TMP BY 1 UNTIL J > LEN
|
||||
ADD VAL(I) VAL(J) GIVING S
|
||||
*> DISPLAY I J K
|
||||
IF S = 2020 THEN
|
||||
MULTIPLY VAL(I) BY VAL(J) GIVING P
|
||||
MOVE P TO FMT
|
||||
DISPLAY FMT
|
||||
EXIT PERFORM
|
||||
ELSE
|
||||
IF S > 2020 THEN
|
||||
EXIT PERFORM
|
||||
END-IF
|
||||
END-IF
|
||||
END-PERFORM
|
||||
END-PERFORM.
|
||||
06-PRINT.
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN
|
||||
DISPLAY VAL(I)
|
||||
END-PERFORM.
|
23
day01/ex1.bash
Executable file
23
day01/ex1.bash
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 1/game 1
|
||||
|
||||
CMD=$(basename "$0")
|
||||
|
||||
readarray -t numbers
|
||||
|
||||
declare -i i j a b
|
||||
|
||||
for ((i=0; i<${#numbers[@]}; ++i)); do
|
||||
a=$((numbers[i]))
|
||||
for ((j=i+1; j<${#numbers[@]}; ++j)); do
|
||||
b=$((numbers[j]))
|
||||
if ((a+b == 2020)); then
|
||||
printf "${CMD} : %d:%d %d:%d sum=%d mul=%d\n" \
|
||||
$i $a $j $b \
|
||||
$((a+b)) $((a*b))
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done
|
||||
exit 0
|
31
day01/ex2-c.c
Normal file
31
day01/ex2-c.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ex2-c:c: Advent2020 game, day 1/game 2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
int numbers[1000]; /* should do differently :
|
||||
* either read twice, either create list
|
||||
*/
|
||||
int n=0, i, j, k, n1, n2, n3;
|
||||
|
||||
while (scanf("%d", numbers+n) != EOF)
|
||||
n++;
|
||||
for (i=0; i<n; ++i) {
|
||||
n1=numbers[i];
|
||||
for (j=i+1; j<n; ++j) {
|
||||
n2=numbers[j];
|
||||
for (k=j+1; k<n; ++k) {
|
||||
n3=numbers[k];
|
||||
if (n1+n2+n3 == 2020) {
|
||||
printf("%s : %d:%d %d:%d %d:%d sum=%d mul=%d\n", *av,
|
||||
i, n1, j, n2, k, n3, n1+n2+n3, n1*n2*n3);
|
||||
exit (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
96
day01/ex2-pure-sort-cob.cob
Normal file
96
day01/ex2-pure-sort-cob.cob
Normal file
@@ -0,0 +1,96 @@
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. AoC-2020-day-1-part-2.
|
||||
*> Inspired by https://github.com/GaloisGirl/Coding
|
||||
*> Compilation: cobc -F -fmfcomment -std=rm -x ex2-cob.cob
|
||||
*> Utilisation: ./ex2-cob < INPUT.txt
|
||||
AUTHOR. Bruno Raoult.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
SELECT INPUTFILE ASSIGN TO KEYBOARD
|
||||
ORGANIZATION IS LINE SEQUENTIAL.
|
||||
|
||||
DATA DIVISION.
|
||||
FILE SECTION.
|
||||
FD INPUTFILE.
|
||||
01 INPUTRECORD PIC 9(4).
|
||||
|
||||
WORKING-STORAGE SECTION.
|
||||
01 FILE-STATUS PIC 9 VALUE 0.
|
||||
01 LEN PIC 9(3) VALUE 0.
|
||||
01 ARR.
|
||||
05 VAL PIC 9(5) OCCURS 1024.
|
||||
01 S PIC 9(4).
|
||||
01 P PIC 9(12).
|
||||
01 FMT PIC Z(12)9.
|
||||
|
||||
LOCAL-STORAGE SECTION.
|
||||
01 I USAGE UNSIGNED-INT VALUE 1.
|
||||
01 J USAGE UNSIGNED-INT VALUE 1.
|
||||
01 K USAGE UNSIGNED-INT VALUE 1.
|
||||
01 TMP USAGE UNSIGNED-INT VALUE 1.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
01-MAIN.
|
||||
OPEN INPUT INPUTFILE.
|
||||
PERFORM 02-READ UNTIL FILE-STATUS = 1.
|
||||
CLOSE INPUTFILE.
|
||||
*> PERFORM 06-PRINT.
|
||||
PERFORM 05-BUBBLE
|
||||
*> DISPLAY "=========================".
|
||||
*> PERFORM 06-PRINT.
|
||||
PERFORM 04-LOOP
|
||||
STOP RUN.
|
||||
02-READ.
|
||||
READ INPUTFILE
|
||||
AT END MOVE 1 TO FILE-STATUS
|
||||
NOT AT END PERFORM 03-WRITE-TO-TABLE
|
||||
END-READ.
|
||||
|
||||
03-WRITE-TO-TABLE.
|
||||
ADD 1 TO LEN.
|
||||
UNSTRING INPUTRECORD INTO VAL(LEN).
|
||||
*> Wrong: "234" becomes 2340 instead of 0234
|
||||
*> COMPUTE VAL(LEN) = INPUTRECORD.
|
||||
*> DISPLAY VAL(LEN) " " LEN.
|
||||
04-LOOP.
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN
|
||||
ADD I 1 GIVING TMP
|
||||
PERFORM VARYING J FROM TMP BY 1 UNTIL J > LEN
|
||||
ADD J 1 GIVING TMP
|
||||
PERFORM VARYING K FROM TMP BY 1 UNTIL K > LEN
|
||||
ADD VAL(I) VAL(J) VAL(K) GIVING S
|
||||
*> DISPLAY I J K
|
||||
IF S = 2020 THEN
|
||||
MULTIPLY VAL(I) BY VAL(J) GIVING P
|
||||
MULTIPLY P BY VAL(K) GIVING P
|
||||
MOVE P TO FMT
|
||||
DISPLAY FMT
|
||||
EXIT PERFORM
|
||||
ELSE
|
||||
IF S > 2020 THEN
|
||||
EXIT PERFORM
|
||||
END-IF
|
||||
END-IF
|
||||
END-PERFORM
|
||||
END-PERFORM
|
||||
END-PERFORM.
|
||||
05-BUBBLE.
|
||||
MOVE 1 TO K
|
||||
PERFORM UNTIL K = 0
|
||||
MOVE 0 TO K
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN - 1
|
||||
ADD 1 I GIVING J
|
||||
IF VAL(I) > VAL(J)
|
||||
MOVE VAL(I) TO TMP
|
||||
MOVE VAL(J) TO VAL(I)
|
||||
MOVE TMP TO VAL(J)
|
||||
MOVE 1 TO K
|
||||
END-IF
|
||||
END-PERFORM
|
||||
END-PERFORM.
|
||||
06-PRINT.
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN
|
||||
DISPLAY VAL(I)
|
||||
END-PERFORM.
|
55
day01/ex2-pure-sort.bash
Executable file
55
day01/ex2-pure-sort.bash
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex2-pure-sort.bash: Advent2020 game, day 1/game 2, bash bubble sort.
|
||||
|
||||
CMD=${0##*/}
|
||||
|
||||
readarray -t numbers
|
||||
|
||||
# simple bubble sort for numeric array (ascending)
|
||||
# args: 1: the array
|
||||
# todo: add a parameter for asc/desc order.
|
||||
sort_n() {
|
||||
local -a array=( "$@" )
|
||||
local -i max=$(( ${#array[@]} - 1 ))
|
||||
|
||||
for (( max= $(( ${#array[@]} - 1 )); max > 0; max-- )); do
|
||||
local -i i
|
||||
for (( i=0; i<max; i++ )); do
|
||||
local -i val1=${array[$i]}
|
||||
local -i val2=${array[$((i + 1))]}
|
||||
|
||||
# switch if necessary
|
||||
if (( val1 > val2 )); then
|
||||
local tmp=$val1
|
||||
array[$i]=$val2
|
||||
array[$((i + 1))]=$tmp
|
||||
fi
|
||||
done
|
||||
done
|
||||
echo "${array[@]}"
|
||||
}
|
||||
|
||||
sorted=( $(sort_n "${numbers[@]}") )
|
||||
|
||||
declare -i i j k a b c
|
||||
|
||||
for ((i=0; i<${#sorted[@]}; ++i)); do
|
||||
a=$((sorted[i]))
|
||||
for ((j=i+1; j<${#sorted[@]}; ++j)); do
|
||||
b=$((sorted[j]))
|
||||
((a+b > 2020)) && break
|
||||
for ((k=j+1; k<${#sorted[@]}; ++k)); do
|
||||
c=$((sorted[k]))
|
||||
((a+b+c > 2020)) && break
|
||||
if ((a+b+c == 2020)); then
|
||||
printf "${CMD} : %d:%d %d:%d %d:%d sum=%d mul=%d\n" \
|
||||
$i $a $j $b $k $c \
|
||||
$((a+b+c)) \
|
||||
$((a*b*c))
|
||||
break 3
|
||||
fi
|
||||
done
|
||||
done
|
||||
done
|
||||
exit 0
|
99
day01/ex2-sort-cob.cob
Normal file
99
day01/ex2-sort-cob.cob
Normal file
@@ -0,0 +1,99 @@
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. AoC-2020-day-1-part-2.
|
||||
*> Inspired by https://github.com/GaloisGirl/Coding
|
||||
*> Compilation: cobc -F -fmfcomment -std=rm -x ex2-cob.cob
|
||||
*> Utilisation: ./ex2-cob < INPUT.txt
|
||||
AUTHOR. Bruno Raoult.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
SELECT INPUTFILE ASSIGN TO KEYBOARD
|
||||
ORGANIZATION IS LINE SEQUENTIAL.
|
||||
|
||||
DATA DIVISION.
|
||||
FILE SECTION.
|
||||
FD INPUTFILE.
|
||||
01 INPUTRECORD PIC 9(4).
|
||||
|
||||
WORKING-STORAGE SECTION.
|
||||
01 FILE-STATUS PIC 9 VALUE 0.
|
||||
01 LEN PIC 9(3) VALUE 0.
|
||||
01 ARRAY.
|
||||
02 ARR OCCURS 0 TO 1024 DEPENDING ON LEN.
|
||||
05 VAL PIC 9(5).
|
||||
01 S PIC 9(4).
|
||||
01 P PIC 9(12).
|
||||
01 FMT PIC Z(12)9.
|
||||
|
||||
LOCAL-STORAGE SECTION.
|
||||
01 I USAGE UNSIGNED-INT VALUE 1.
|
||||
01 J USAGE UNSIGNED-INT VALUE 1.
|
||||
01 K USAGE UNSIGNED-INT VALUE 1.
|
||||
01 TMP USAGE UNSIGNED-INT VALUE 1.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
01-MAIN.
|
||||
OPEN INPUT INPUTFILE.
|
||||
PERFORM 02-READ UNTIL FILE-STATUS = 1.
|
||||
CLOSE INPUTFILE.
|
||||
*> PERFORM 06-PRINT.
|
||||
MOVE 1 TO K
|
||||
*> PERFORM 05-BUBBLE
|
||||
SORT ARR ASCENDING KEY VAL
|
||||
*> DISPLAY "=========================".
|
||||
*> PERFORM 06-PRINT.
|
||||
PERFORM 04-LOOP
|
||||
STOP RUN.
|
||||
02-READ.
|
||||
READ INPUTFILE
|
||||
AT END MOVE 1 TO FILE-STATUS
|
||||
NOT AT END PERFORM 03-WRITE-TO-TABLE
|
||||
END-READ.
|
||||
|
||||
03-WRITE-TO-TABLE.
|
||||
ADD 1 TO LEN.
|
||||
UNSTRING INPUTRECORD INTO VAL(LEN).
|
||||
*> Wrong: "234" becomes 2340 instead of 0234
|
||||
*> COMPUTE VAL(LEN) = INPUTRECORD.
|
||||
*> DISPLAY VAL(LEN) " " LEN.
|
||||
04-LOOP.
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN
|
||||
ADD I 1 GIVING TMP
|
||||
PERFORM VARYING J FROM TMP BY 1 UNTIL J > LEN
|
||||
ADD J 1 GIVING TMP
|
||||
PERFORM VARYING K FROM TMP BY 1 UNTIL K > LEN
|
||||
ADD VAL(I) VAL(J) VAL(K) GIVING S
|
||||
*> DISPLAY I J K
|
||||
IF S = 2020 THEN
|
||||
MULTIPLY VAL(I) BY VAL(J) GIVING P
|
||||
MULTIPLY P BY VAL(K) GIVING P
|
||||
MOVE P TO FMT
|
||||
DISPLAY FMT
|
||||
EXIT PERFORM
|
||||
ELSE
|
||||
IF S > 2020 THEN
|
||||
EXIT PERFORM
|
||||
END-IF
|
||||
END-IF
|
||||
END-PERFORM
|
||||
END-PERFORM
|
||||
END-PERFORM.
|
||||
05-BUBBLE.
|
||||
MOVE 1 TO K
|
||||
PERFORM UNTIL K = 0
|
||||
MOVE 0 TO K
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN - 1
|
||||
ADD 1 I GIVING J
|
||||
IF VAL(I) > VAL(J)
|
||||
MOVE VAL(I) TO TMP
|
||||
MOVE VAL(J) TO VAL(I)
|
||||
MOVE TMP TO VAL(J)
|
||||
MOVE 1 TO K
|
||||
END-IF
|
||||
END-PERFORM
|
||||
END-PERFORM.
|
||||
06-PRINT.
|
||||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LEN
|
||||
DISPLAY VAL(I)
|
||||
END-PERFORM.
|
28
day01/ex2-sort.bash
Executable file
28
day01/ex2-sort.bash
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex2-sort.bash: Advent2020 game, day 1/game 2, with sort.
|
||||
|
||||
CMD=$(basename "$0")
|
||||
|
||||
readarray -t numbers <<< "$(sort -n)"
|
||||
|
||||
declare -i i j k a b c m1 m2
|
||||
for ((i=0; i<${#numbers[@]}; ++i)); do
|
||||
a=$((numbers[i]))
|
||||
for ((j=i+1; j<${#numbers[@]}; ++j)); do
|
||||
b=$((numbers[j]))
|
||||
((a+b > 2020)) && break
|
||||
for ((k=j+1; k<${#numbers[@]}; ++k)); do
|
||||
c=$((numbers[k]))
|
||||
((a+b+c > 2020)) && break
|
||||
if ((a+b+c == 2020)); then
|
||||
printf "${CMD} : %d:%d %d:%d %d:%d sum=%d mul=%d\n" \
|
||||
$i $a $j $b $k $c \
|
||||
$((a+b+c)) \
|
||||
$((a*b*c))
|
||||
break 3
|
||||
fi
|
||||
done
|
||||
done
|
||||
done
|
||||
exit 0
|
24
day01/ex2.bash
Executable file
24
day01/ex2.bash
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex2.bash: Advent2020 game, day 1/game 2
|
||||
|
||||
CMD=$(basename "$0")
|
||||
|
||||
readarray -t numbers
|
||||
|
||||
declare -i i j k
|
||||
|
||||
for ((i=0; i<${#numbers[@]}; ++i)); do
|
||||
for ((j=i+1; j<${#numbers[@]}; ++j)); do
|
||||
for ((k=j+1; k<${#numbers[@]}; ++k)); do
|
||||
if ((numbers[i] + numbers[j] + numbers[k] == 2020)); then
|
||||
printf "${CMD} : %d:%d %d:%d %d:%d sum=%d mul=%d\n" \
|
||||
$i $((numbers[i])) $j $((numbers[j])) $k $((numbers[k])) \
|
||||
$((numbers[i]+numbers[j]+numbers[k])) \
|
||||
$((numbers[i]*numbers[j]*numbers[k]))
|
||||
break 3
|
||||
fi
|
||||
done
|
||||
done
|
||||
done
|
||||
exit 0
|
1000
day02/INPUT.txt
Normal file
1000
day02/INPUT.txt
Normal file
File diff suppressed because it is too large
Load Diff
26
day02/Makefile
Normal file
26
day02/Makefile
Normal file
@@ -0,0 +1,26 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
|
||||
ex1: ex1-c
|
||||
@$(TIME) ex1.bash < $(INPUT)
|
||||
@$(TIME) ex1-c < $(INPUT)
|
||||
|
||||
ex2: ex2-c
|
||||
@$(TIME) ex2.bash < $(INPUT)
|
||||
@#$(TIME) ex2-sort.bash < $(INPUT)
|
||||
@$(TIME) ex2-c < $(INPUT)
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
12
day02/OUTPUT
Normal file
12
day02/OUTPUT
Normal file
@@ -0,0 +1,12 @@
|
||||
ex1.bash : lines: 1000 matched:607
|
||||
time: 0:00.03 real, 0.03 user, 0.00 sys
|
||||
|
||||
ex1-c : lines: 1000 matched:607
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
|
||||
ex2.bash : lines: 1000 matched:321
|
||||
time: 0:00.03 real, 0.03 user, 0.00 sys
|
||||
|
||||
ex2-c : lines: 1000 matched:321
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
|
48
day02/README
Normal file
48
day02/README
Normal file
@@ -0,0 +1,48 @@
|
||||
--- Day 2: Password Philosophy ---
|
||||
|
||||
Your flight departs in a few days from the coastal airport; the easiest way down to the coast from here is via toboggan.
|
||||
|
||||
The shopkeeper at the North Pole Toboggan Rental Shop is having a bad day. "Something's wrong with our computers; we can't log in!" You ask if you can take a look.
|
||||
|
||||
Their password database seems to be a little corrupted: some of the passwords wouldn't have been allowed by the Official Toboggan Corporate Policy that was in effect when they were chosen.
|
||||
|
||||
To try to debug the problem, they have created a list (your puzzle input) of passwords (according to the corrupted database) and the corporate policy when that password was set.
|
||||
|
||||
For example, suppose you have the following list:
|
||||
|
||||
1-3 a: abcde
|
||||
1-3 b: cdefg
|
||||
2-9 c: ccccccccc
|
||||
|
||||
Each line gives the password policy and then the password. The password policy indicates the lowest and highest number of times a given letter must appear for the password to be valid. For example, 1-3 a means that the password must contain a at least 1 time and at most 3 times.
|
||||
|
||||
In the above example, 2 passwords are valid. The middle password, cdefg, is not; it contains no instances of b, but needs at least 1. The first and third passwords are valid: they contain one a or nine c, both within the limits of their respective policies.
|
||||
|
||||
How many passwords are valid according to their policies?
|
||||
|
||||
Your puzzle answer was 607.
|
||||
--- Part Two ---
|
||||
|
||||
While it appears you validated the passwords correctly, they don't seem to be what the Official Toboggan Corporate Authentication System is expecting.
|
||||
|
||||
The shopkeeper suddenly realizes that he just accidentally explained the password policy rules from his old job at the sled rental place down the street! The Official Toboggan Corporate Policy actually works a little differently.
|
||||
|
||||
Each policy actually describes two positions in the password, where 1 means the first character, 2 means the second character, and so on. (Be careful; Toboggan Corporate Policies have no concept of "index zero"!) Exactly one of these positions must contain the given letter. Other occurrences of the letter are irrelevant for the purposes of policy enforcement.
|
||||
|
||||
Given the same example list from above:
|
||||
|
||||
1-3 a: abcde is valid: position 1 contains a and position 3 does not.
|
||||
1-3 b: cdefg is invalid: neither position 1 nor position 3 contains b.
|
||||
2-9 c: ccccccccc is invalid: both position 2 and position 9 contain c.
|
||||
|
||||
How many passwords are valid according to the new interpretation of the policies?
|
||||
|
||||
Your puzzle answer was 321.
|
||||
|
||||
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 [Share] this puzzle.
|
31
day02/ex1-c.c
Normal file
31
day02/ex1-c.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ex1-c: Advent2020 game, day 2/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ccount(char *str, char c)
|
||||
{
|
||||
int count=0;
|
||||
|
||||
for (int i=0; str[i]; i++)
|
||||
count += (str[i] == c);
|
||||
return count;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
int beg, end, nc, found=0, nlines=0;
|
||||
char c, str[80];
|
||||
|
||||
while (scanf("%d-%d %c: %s", &beg, &end, &c, str) != EOF) {
|
||||
nc=ccount(str, c);
|
||||
if (nc >= beg && nc <= end)
|
||||
found++;
|
||||
|
||||
nlines++;
|
||||
}
|
||||
printf ("%s : lines: %d matched:%d\n", *av, nlines, found);
|
||||
exit (0);
|
||||
}
|
18
day02/ex1.bash
Executable file
18
day02/ex1.bash
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 2/game 1
|
||||
|
||||
CMD=${0##*/}
|
||||
|
||||
declare -i beg end num found=0 nlines=0
|
||||
|
||||
IFS=$':- \t'
|
||||
while read -r beg end char str; do
|
||||
stripped=${str//[^$char]} # keep only specified char
|
||||
((num = ${#stripped})) # occurences of this char
|
||||
((num >= beg && num <= end && found++)) # match ?
|
||||
((nlines++))
|
||||
done
|
||||
printf "${CMD} : lines: %d matched:%d\n" "$nlines" "$found"
|
||||
|
||||
exit 0
|
24
day02/ex2-c.c
Normal file
24
day02/ex2-c.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/* ex2-c: Advent2020 game, day 2/game 2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ccount(char *str, char c, int pos1, int pos2)
|
||||
{
|
||||
return ((str[pos1-1] == c) + (str[pos2-1] == c)) == 1;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
int beg, end, nc, found=0, nlines=0;
|
||||
char c, str[80];
|
||||
|
||||
while (scanf("%d-%d %c: %s", &beg, &end, &c, str) != EOF) {
|
||||
found += ccount(str, c, beg, end);
|
||||
nlines++;
|
||||
}
|
||||
printf ("%s : lines: %d matched:%d\n", *av, nlines, found);
|
||||
exit (0);
|
||||
}
|
20
day02/ex2.bash
Executable file
20
day02/ex2.bash
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex2.bash: Advent2020 game, day 2/game 2.
|
||||
|
||||
CMD=${0##*/}
|
||||
|
||||
declare -i beg end num found=0 nlines=0
|
||||
|
||||
IFS=$':- \t'
|
||||
while read -r beg end char str; do
|
||||
num=0
|
||||
[[ ${str:beg-1:1} == "$char" ]] && ((num++))
|
||||
[[ ${str:end-1:1} == "$char" ]] && ((num++))
|
||||
#((num == 1 && found++))
|
||||
((found += num == 1))
|
||||
((nlines++))
|
||||
done
|
||||
printf "${CMD} : lines: %d matched:%d\n" "$nlines" "$found"
|
||||
|
||||
exit 0
|
323
day03/INPUT.txt
Normal file
323
day03/INPUT.txt
Normal file
@@ -0,0 +1,323 @@
|
||||
....#............#.###...#.#.#.
|
||||
.#.#....##.........#.....##.#..
|
||||
.#..#.#...####.##..#......#..##
|
||||
......#...#...#.......#........
|
||||
........#...###..#.#....#....#.
|
||||
..##.....#.....#.#.........#.#.
|
||||
.##.......#.#.#...#..#...##...#
|
||||
...##.....#....##....#...###.#.
|
||||
..#...#......##.#.##.....#.#..#
|
||||
.#....#.###.........#..........
|
||||
.#.#..##.....###.....###....#.#
|
||||
....###....#......#...#......##
|
||||
......##...#.##.........#.#..#.
|
||||
##.#....##...#..##....#.#..#.##
|
||||
.#...#..#.....#.#.......#...#..
|
||||
..........#..###.###......##..#
|
||||
..#.##.#..#......#.......###.#.
|
||||
...#...#.#.#..#...#.#..........
|
||||
#........#..#..#.#....#.##..###
|
||||
#...#.....#..####.........####.
|
||||
.....###..........#.#...##...#.
|
||||
.....#...#..#.......#....##.#..
|
||||
...........#..##.....#...#..#..
|
||||
......##..#........#...........
|
||||
#.#..#.#.#..#.....#....#.....#.
|
||||
..#....##....##...#.....#......
|
||||
.#.#....#..#.#......#..###...#.
|
||||
.......#...#.#....##..#..#..#..
|
||||
.#.#.#.......#....#.#.#.......#
|
||||
.#..........#.##.#...#..#.#.##.
|
||||
..#.#..........#.#....##.#.##..
|
||||
###..#..#.#...##.#.#..#........
|
||||
##....#...#....#....#...#.#....
|
||||
#...#.#....#.##..##...#.#......
|
||||
......#...#.###......##....#...
|
||||
.................#.###......#..
|
||||
##..#....#....##...###.#.#..###
|
||||
..#..........#..####..##..#...#
|
||||
.#......#..#.#...........##.#..
|
||||
.#..#......#...#.#.#..#.#.#.#.#
|
||||
.#......###.....#.#.#......##..
|
||||
#..........#.##...#...........#
|
||||
..#....#.##....#.........#.....
|
||||
.#..##....#...##.........#..#..
|
||||
....##..#.###..#.#...#..###..#.
|
||||
..#......#........#...#.#......
|
||||
........#..#..#..#...#.##......
|
||||
.##.#.#......#...#.........#...
|
||||
#..###.#...#....###.##..###....
|
||||
........##.............#....#..
|
||||
...#...............#....#.#....
|
||||
#..........#..#..#.#.....#...#.
|
||||
.#.............#...#.......#..#
|
||||
.#..#..#...#........##.........
|
||||
.....#.#..#.#..#..##.........#.
|
||||
..#..##...#....#.#...#.###..#..
|
||||
#...........##.....#...#.##....
|
||||
#.#.#.#........##......#...#.#.
|
||||
......#..#.###.#...#.##.##....#
|
||||
.#....#...#....#........#....#.
|
||||
..#.#..........#..##.......#..#
|
||||
.....#...##..#................#
|
||||
.#...............##...#.##...##
|
||||
#.####....##.....#.......#.##..
|
||||
......#.##.#...##..###..#.#....
|
||||
.#.##.#...##..#.......#.#..#...
|
||||
#...#.##..........##..........#
|
||||
#.###...#...#..#.....#.#.##..##
|
||||
.##.....#....#...##.....##.....
|
||||
...#........#..###.###...#.....
|
||||
##..#....#.....#...#.#....#.#..
|
||||
#....#....#.#..........#...#..#
|
||||
...##..#......#..#..#..#..#....
|
||||
.....##...#..####..##.........#
|
||||
.....#..#.#...#..#....##..##...
|
||||
..#.......##.#..#.##...#.#....#
|
||||
.#..#.#...##..##....#..#......#
|
||||
..##.##..##...###..#....#...#..
|
||||
........##.......##...##.....##
|
||||
.#....###...#..#..#..#.......#.
|
||||
#.###............#....##.....#.
|
||||
..........#...#...##..#...#....
|
||||
..#......#.##.......#....##..##
|
||||
..#..###.....#...#.......#.....
|
||||
#.#...##.....#...#....#.......#
|
||||
....##.##.#....#.....#.#....#..
|
||||
...#....#.###............#..###
|
||||
#..##..#.........##.....#.#...#
|
||||
....#.......##......#....#...#.
|
||||
....#..##.#..........#.........
|
||||
....#...#.###.......#...#.#....
|
||||
#..#..#...#.......##...#..#.##.
|
||||
#.......#...##.##......#.......
|
||||
##..##...##...#......#...#...##
|
||||
..#...#.#.####.#...##.....##...
|
||||
#...#..#..#...##......#.#..#..#
|
||||
..##..##.#.#..#...####.....###.
|
||||
.#........#..##.###...#.##.#...
|
||||
........#..#...##......#.#....#
|
||||
..#...###.......##..##..#....#.
|
||||
.##...#.#..#.##.......##.###...
|
||||
#....#.#.#........#....#..#.##.
|
||||
....#.##.#.##..#.#####.....###.
|
||||
#.#..#..#...#.#..#.......#.#...
|
||||
....#...#....###...............
|
||||
.###.#.....#.#.......###......#
|
||||
##...#.#.###....##..#...##.....
|
||||
...#.#..#.###.#.......#...#.#..
|
||||
.#...#....#...#..####....###...
|
||||
..#....##.....##.#.#.##....#...
|
||||
#....#..##.......#...##.##....#
|
||||
.##..#.......#..#....###.......
|
||||
#.##.....##.#.........#......##
|
||||
.####.#...#.....#..#...#.##..#.
|
||||
....#...........#.....#........
|
||||
.#............##...#.......#.#.
|
||||
#....#.##........#....#.#..#..#
|
||||
#....#.##....#...##...#..#..#..
|
||||
...#..#.####.#....#............
|
||||
....#......#.........#.........
|
||||
#....##....###.....#......#.#..
|
||||
...#..#....#........###..#...#.
|
||||
..#.#........#.#.#.###..#.#.#..
|
||||
.....###.....##.#....###.#.....
|
||||
##.#....#....##...##.###.#.##..
|
||||
.###.#..#.......##...#...##....
|
||||
.#...###........#.......##.##..
|
||||
#......####...#...##.#.######..
|
||||
....##.............#..##.##...#
|
||||
...........#..##.#...#.#.#...#.
|
||||
###.......#.##..#....#...#....#
|
||||
.........#.....#.#.#..##.#.....
|
||||
#...##..#....#..#.............#
|
||||
...#.......#.##.............#.#
|
||||
.....#..#...##......####..#....
|
||||
.#.#.#.....#...####..#...##...#
|
||||
#...#.#..#..#.#..#.##..........
|
||||
.....#.##..#.#.##..#.#.#....#.#
|
||||
...##..#...#...#..#....#.......
|
||||
........#.#..#...#...#.#...#...
|
||||
##..#........#..#.....#......##
|
||||
.........#..#...#......#......#
|
||||
..#.#.#........##...#.##.....##
|
||||
.###....##....#...#....#..#....
|
||||
.#.............###...#..##..###
|
||||
.##.##.##.......###.........#.#
|
||||
..#..###...#...#....#..#.#..#.#
|
||||
......#..#.#..#.....#.#........
|
||||
......#...####...#.#.....#.....
|
||||
.#...##.......#..#......#...#..
|
||||
#..#...#.......###..#..#.#.#.#.
|
||||
.....#.....###.##....#.#.##.#.#
|
||||
#........#....##...#..#.##..#..
|
||||
...#.#........##....#.#..###.#.
|
||||
#...#...##.........#........###
|
||||
##...#.##..##...#.....#.###.#..
|
||||
#.###.#.#..#...........##..#...
|
||||
........#.......#..#..#.###....
|
||||
#........#....#......###.......
|
||||
..#.###.######...#.###..#......
|
||||
...#...######..#.....#....#.#..
|
||||
..#.......#..#..#.........#...#
|
||||
.#...#..##.##.........##.......
|
||||
.........#.#.##.#..#....#.#...#
|
||||
#.......#....#......#.....###.#
|
||||
##..............#.###........#.
|
||||
..#.##..#.##.....#...#.#.#..###
|
||||
..#.#......#..#..##.#........#.
|
||||
..#.....#...#.#...#...###..#.#.
|
||||
.......#...........#..#..#.#.##
|
||||
.......#...##..#.###...........
|
||||
.#........#.###.#..#..#..#..#..
|
||||
##.#.##....#..###..#.##.##...#.
|
||||
.....#....##.#........#.#.#....
|
||||
....##....#..#..#....##....#.#.
|
||||
#.....##....#.....#.###.#....#.
|
||||
.#.##.##..#..#...#...........##
|
||||
...#..###..#.....##....#.......
|
||||
...#..##..###.#..#..#.#........
|
||||
......##..#.......#..##.....###
|
||||
.#...##.#.#.#......#...#.#.#.##
|
||||
....#.#....#...#........#...#..
|
||||
....#.#......#.#.###.#.#.##.#..
|
||||
#..#........###..#..#..#.....#.
|
||||
...#....#...##...#........##.##
|
||||
.....#..#..#.....#....#.#...#..
|
||||
..#.###....#.#..##......#.##.#.
|
||||
..####......#..#.#.#..#.#####..
|
||||
.......##..#..###.#............
|
||||
..###.#........#..........##.##
|
||||
#.#.........#.##.#......#..#...
|
||||
...#.....#.....##..#..##.##..#.
|
||||
#.#.##....#.......###....##....
|
||||
...##.#..#...##.#..#......#..#.
|
||||
..##.........#.##.#####...#.#..
|
||||
.#....#...#....#.#.....##...###
|
||||
##.....#..####............###.#
|
||||
......#...........#....#.......
|
||||
.#......#.....##...........###.
|
||||
#......##.......#.#.#..##.....#
|
||||
...###.#.....##.#...#.#....#.#.
|
||||
...###.......#...#.............
|
||||
..#..#.#....#.#.###.#.#.##..##.
|
||||
..##...#..#.#..##.#.##....##...
|
||||
..#...........#..#....#....#...
|
||||
#.##...........#..#.#..##.#.#..
|
||||
...##...##................#..#.
|
||||
.#...#.##......#.#......#.####.
|
||||
#.##....#....#.........#....###
|
||||
.....###........#.#.#.##...#.##
|
||||
.....#....#.#....#.........#..#
|
||||
..#...#.#.#.#...#...#...##.#..#
|
||||
###.......#.....#.............#
|
||||
#.####.#.......#.#.#.#..#.#....
|
||||
#..#..#####......#....#..##....
|
||||
...............#.....#.#....###
|
||||
.###.....#...#.##..#.#..#.#####
|
||||
#.##.....#......##.......##....
|
||||
..........###.......#...#.#....
|
||||
..#.#..#...##.....#........#.#.
|
||||
........##.##....#####.#.#..##.
|
||||
..##.#.#...#####..........#.#.#
|
||||
#.........#......##...#.....#..
|
||||
.##.#........#...#..##...#...#.
|
||||
.......##..#...#.....#.##......
|
||||
....#.#...##..##..#....##......
|
||||
#........#..........##..####.#.
|
||||
...###...#.#.###.#...#....#.#.#
|
||||
.....##.#.....#........#.#....#
|
||||
#.......#....#...##..#......#..
|
||||
...#..........#.#.#...#.#.###.#
|
||||
....##.....#.##..#.#.#.........
|
||||
#.##..##..#....#.........#...#.
|
||||
.###..........#...##.#..#......
|
||||
.....####.............##...###.
|
||||
.#..#....#..#...#..#...........
|
||||
#..#..##..#...#.##..#.###.#...#
|
||||
......#.#..###...#..#.....#..#.
|
||||
##.##......#...#.#...#.........
|
||||
....##.#.......#.#..##....#.#.#
|
||||
#..##..#...###.#....##.........
|
||||
.............#.#....#...##..#..
|
||||
..#....#...#.....#.##.#..##..##
|
||||
##.#..##.#..##.#.#.##.#...#.#..
|
||||
.##.#..#.#........##.#...##....
|
||||
#.........##....##..#......#...
|
||||
.#.#.......##...#..#......###.#
|
||||
........#.#.#.#......#....#..#.
|
||||
...##..#...#...#.##..#....#.#..
|
||||
...#.#.#.#.......#.......###..#
|
||||
...#..##..#####.#.....##.#..#..
|
||||
.......#.#.....#.....#...#...##
|
||||
#...#...#......##.#....##......
|
||||
#.....#.#.#.....#....#......#..
|
||||
..#..#.##.#......##..#.#..#..##
|
||||
####...#.....#....#.#..........
|
||||
....#.....###...#...##......#..
|
||||
.....#....#...#............#...
|
||||
...#...#..##.........#...#...##
|
||||
#.#..#.#...##.#.......#..#.#...
|
||||
.#.....#...##.............#...#
|
||||
.....#..##..#....#......#.##..#
|
||||
....#...###.................#..
|
||||
...###...#....#...#...#........
|
||||
....#.##.#.......#..#..........
|
||||
...#..#......#.#...###...#.#...
|
||||
..#.#..#...#.......#.......#.#.
|
||||
.#.#...#.#.##........#.........
|
||||
...#..#...#....#.#.#.#.#..###..
|
||||
.#..##......#.#.##..#.##....#..
|
||||
#....#.......##.....#.#........
|
||||
..###..#.#.#.......##....#.....
|
||||
........#.#.#....##...##..#....
|
||||
#....##.#....#...##..##...#....
|
||||
...#..##.#.....#...#.....##....
|
||||
.#.#..#..#...#....#..##.#....#.
|
||||
##.#.##....#.....#....#....#.#.
|
||||
.##......#............##...#...
|
||||
#..##.#.####.#.#....#..#..#.#.#
|
||||
#...##...#......##....###.....#
|
||||
..#.##.....#....#....#......#..
|
||||
.##.#...#.....#.#.#.#........##
|
||||
.#..#....#.#...........#...#...
|
||||
#.....#..#.....#.#.##.#.....#..
|
||||
....#.....#..#.#....###........
|
||||
.....###...........#.#..##.#.#.
|
||||
....###....#.......###..#...#.#
|
||||
.###.....#...##.#...##........#
|
||||
..#..#.#..#...#.#...#.#..#...#.
|
||||
#.####.......#....##.#..#.#..#.
|
||||
....#.#.##.#..###.........##.#.
|
||||
..#..#.#....#....#.##..........
|
||||
..##.###..#.#..#.#......#....#.
|
||||
.#..#.....##...#.#......##.#..#
|
||||
#.#....#..#.#.#........#.###...
|
||||
...#....##....##..###.###.#.#..
|
||||
..#....#.....#....##.#.........
|
||||
#.......#....#.........##..#...
|
||||
.#..#...#.#..#.#....#.#........
|
||||
...#..###...#.....#......##....
|
||||
..#...........#.....#..........
|
||||
....###.#...#......#...#..#....
|
||||
.....#.##..#..#....#.......#..#
|
||||
....##..#.#.#..............#.#.
|
||||
.#.#..#..#.#......#...#.#......
|
||||
....#.......#.##....##.#.#.#..#
|
||||
............#.#.#.....##.......
|
||||
........#...##.#..#......#...##
|
||||
.........#...#...#....#...#.##.
|
||||
..#.....#......#......#.....#..
|
||||
#....#...##..#.#....#.#...#.###
|
||||
.......#..#..#..#.#...#.....#.#
|
||||
...#.#...#......##.....#..#....
|
||||
...#.#.####..##.#..#...........
|
||||
..##..##....#.....####...#....#
|
||||
###.......#...##.#...#...#...#.
|
||||
.##..#.....#..####......#....#.
|
||||
#.....#..#..##..##...#..#..#...
|
||||
.#....#.....#...####..####.....
|
||||
..#....#...#......#........#.#.
|
||||
##.#.......#..#.....#..##..##..
|
||||
.#..#..#.#.#...#....##...#.##.#
|
||||
##...#..#....#.........##......
|
26
day03/Makefile
Normal file
26
day03/Makefile
Normal file
@@ -0,0 +1,26 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
|
||||
ex1: ex1-c
|
||||
@$(TIME) ex1.bash < $(INPUT)
|
||||
@$(TIME) ex1-c < $(INPUT)
|
||||
|
||||
ex2: ex2-c
|
||||
@$(TIME) ex2.bash < $(INPUT)
|
||||
@#$(TIME) ex2-sort.bash < $(INPUT)
|
||||
@$(TIME) ex2-c < $(INPUT)
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
12
day03/OUTPUT
Normal file
12
day03/OUTPUT
Normal file
@@ -0,0 +1,12 @@
|
||||
ex1.bash : lines:322 pos=966 found:169
|
||||
time: 0:00.01 real, 0.01 user, 0.00 sys
|
||||
|
||||
ex1-c : lines:322 pos:966 found:169
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
|
||||
ex2.bash : lines=323 res=6847128288
|
||||
time: 0:00.04 real, 0.03 user, 0.00 sys
|
||||
|
||||
ex2-c : lines=323 res=6847128288
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
|
82
day03/README
Normal file
82
day03/README
Normal file
@@ -0,0 +1,82 @@
|
||||
--- Day 3: Toboggan Trajectory ---
|
||||
|
||||
With the toboggan login problems resolved, you set off toward the airport. While travel by toboggan might be easy, it's certainly not safe: there's very minimal steering and the area is covered in trees. You'll need to see which angles will take you near the fewest trees.
|
||||
|
||||
Due to the local geology, trees in this area only grow on exact integer coordinates in a grid. You make a map (your puzzle input) of the open squares (.) and trees (#) you can see. For example:
|
||||
|
||||
..##.......
|
||||
#...#...#..
|
||||
.#....#..#.
|
||||
..#.#...#.#
|
||||
.#...##..#.
|
||||
..#.##.....
|
||||
.#.#.#....#
|
||||
.#........#
|
||||
#.##...#...
|
||||
#...##....#
|
||||
.#..#...#.#
|
||||
|
||||
These aren't the only trees, though; due to something you read about once involving arboreal genetics and biome stability, the same pattern repeats to the right many times:
|
||||
|
||||
..##.........##.........##.........##.........##.........##....... --->
|
||||
#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
|
||||
.#....#..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
|
||||
..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
|
||||
.#...##..#..#...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
|
||||
..#.##.......#.##.......#.##.......#.##.......#.##.......#.##..... --->
|
||||
.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
|
||||
.#........#.#........#.#........#.#........#.#........#.#........#
|
||||
#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...
|
||||
#...##....##...##....##...##....##...##....##...##....##...##....#
|
||||
.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.# --->
|
||||
|
||||
You start on the open square (.) in the top-left corner and need to reach the bottom (below the bottom-most row on your map).
|
||||
|
||||
The toboggan can only follow a few specific slopes (you opted for a cheaper model that prefers rational numbers); start by counting all the trees you would encounter for the slope right 3, down 1:
|
||||
|
||||
From your starting position at the top-left, check the position that is right 3 and down 1. Then, check the position that is right 3 and down 1 from there, and so on until you go past the bottom of the map.
|
||||
|
||||
The locations you'd check in the above example are marked here with O where there was an open square and X where there was a tree:
|
||||
|
||||
..##.........##.........##.........##.........##.........##....... --->
|
||||
#..O#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
|
||||
.#....X..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
|
||||
..#.#...#O#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
|
||||
.#...##..#..X...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
|
||||
..#.##.......#.X#.......#.##.......#.##.......#.##.......#.##..... --->
|
||||
.#.#.#....#.#.#.#.O..#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
|
||||
.#........#.#........X.#........#.#........#.#........#.#........#
|
||||
#.##...#...#.##...#...#.X#...#...#.##...#...#.##...#...#.##...#...
|
||||
#...##....##...##....##...#X....##...##....##...##....##...##....#
|
||||
.#..#...#.#.#..#...#.#.#..#...X.#.#..#...#.#.#..#...#.#.#..#...#.# --->
|
||||
|
||||
In this example, traversing the map using this slope would cause you to encounter 7 trees.
|
||||
|
||||
Starting at the top-left corner of your map and following a slope of right 3 and down 1, how many trees would you encounter?
|
||||
|
||||
Your puzzle answer was 169.
|
||||
--- Part Two ---
|
||||
|
||||
Time to check the rest of the slopes - you need to minimize the probability of a sudden arboreal stop, after all.
|
||||
|
||||
Determine the number of trees you would encounter if, for each of the following slopes, you start at the top-left corner and traverse the map all the way to the bottom:
|
||||
|
||||
Right 1, down 1.
|
||||
Right 3, down 1. (This is the slope you already checked.)
|
||||
Right 5, down 1.
|
||||
Right 7, down 1.
|
||||
Right 1, down 2.
|
||||
|
||||
In the above example, these slopes would find 2, 7, 3, 4, and 2 tree(s) respectively; multiplied together, these produce the answer 336.
|
||||
|
||||
What do you get if you multiply together the number of trees encountered on each of the listed slopes?
|
||||
|
||||
Your puzzle answer was 7560370818.
|
||||
|
||||
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 [Share] this puzzle.
|
11
day03/TEST.txt
Normal file
11
day03/TEST.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
..##.........##.........##.........##.........##.........##.......
|
||||
#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
|
||||
.#....#..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
|
||||
..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
|
||||
.#...##..#..#...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
|
||||
..#.##.......#.##.......#.##.......#.##.......#.##.......#.##.....
|
||||
.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
|
||||
.#........#.#........#.#........#.#........#.#........#.#........#
|
||||
#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...
|
||||
#...##....##...##....##...##....##...##....##...##....##...##....#
|
||||
.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#
|
38
day03/ex1-c.c
Normal file
38
day03/ex1-c.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ex1-c: Advent2020 game, day 3/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define XMOVE 3
|
||||
|
||||
int my_strlen(str)
|
||||
char *str;
|
||||
{
|
||||
int i;
|
||||
for (i=0; *str; ++i, ++str)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
|
||||
int col=0, line=0, linelen=0, mod=0, count=0;
|
||||
char str[80];
|
||||
|
||||
scanf("%s", str); /* ignore 1st line */
|
||||
|
||||
while (scanf("%s", str) != EOF) {
|
||||
line++;
|
||||
col+=XMOVE;
|
||||
linelen=my_strlen(str);
|
||||
mod=col%linelen;
|
||||
if (*(str+mod) == '#')
|
||||
count++;
|
||||
}
|
||||
printf ("%s : lines:%d pos:%d found:%d\n", *av, line, col, count);
|
||||
exit (0);
|
||||
}
|
21
day03/ex1.bash
Executable file
21
day03/ex1.bash
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 3/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
|
||||
XMOVE=3 # 3 right
|
||||
|
||||
declare -i xpos=0 ypos=0 count=0 linelen=0 modpos=0
|
||||
|
||||
read -r line # ignore 1st line
|
||||
|
||||
while read -r line; do
|
||||
(( ypos++ ))
|
||||
(( xpos += XMOVE )) # move right
|
||||
(( linelen = ${#line} ))
|
||||
(( modpos = (xpos % linelen) ))
|
||||
[[ ${line:modpos:1} = \# ]] && ((count++))
|
||||
done
|
||||
printf "%s : lines:%d pos=%d found:%d\n" "$CMD" $ypos $xpos $count
|
||||
exit 0
|
56
day03/ex2-c.c
Normal file
56
day03/ex2-c.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/* ex1-c: Advent2020 game, day 3/game 2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct {
|
||||
int dx;
|
||||
int dy;
|
||||
int pos;
|
||||
int count;
|
||||
} set[] = {
|
||||
{ 1, 1, 0, 0},
|
||||
{ 3, 1, 0, 0},
|
||||
{ 5, 1, 0, 0},
|
||||
{ 7, 1, 0, 0},
|
||||
{ 1, 2, 0, 0},
|
||||
{-1, -1, 0, 0} /* end marker - not necessary */
|
||||
};
|
||||
|
||||
int my_strlen(str)
|
||||
char *str;
|
||||
{
|
||||
int i;
|
||||
for (i=0; *str; ++i, ++str)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
int ac;
|
||||
char **av;
|
||||
{
|
||||
int line=1, linelen=0, mod=0, i;
|
||||
unsigned long res=1;
|
||||
char str[80];
|
||||
|
||||
scanf("%s", str); /* ignore 1st line */
|
||||
|
||||
while (scanf("%s", str) != EOF) {
|
||||
line++;
|
||||
linelen=my_strlen(str);
|
||||
for (i=0; set[i].dx >= 0; ++i) {
|
||||
if (! (line % set[i].dy )) { /* line ok for this set */
|
||||
set[i].pos += set[i].dx; /* increment set column */
|
||||
mod = set[i].pos % linelen;
|
||||
if ( str[mod] == '#')
|
||||
set[i].count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i=0; set[i].dx != -1; ++i)
|
||||
res*=set[i].count;
|
||||
printf ("%s : lines=%d res=%lu\n", *av, line, res);
|
||||
exit (0);
|
||||
}
|
31
day03/ex2.bash
Executable file
31
day03/ex2.bash
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 3/game 2.
|
||||
|
||||
CMD=${0##*/}
|
||||
|
||||
XMOVES=(1 3 5 7 1) # moves right
|
||||
YMOVES=(1 1 1 1 2) # moves down
|
||||
declare -i linelen=0 modpos=0 res=1 ypos=1
|
||||
declare -a xpos xcount
|
||||
|
||||
read -r line # ignore 1st line
|
||||
|
||||
while read -r line; do
|
||||
(( ypos++ ))
|
||||
(( linelen = ${#line} ))
|
||||
|
||||
for ((i=0; i<${#XMOVES[@]}; ++i)); do
|
||||
if ((ypos % YMOVES[i] == 0)); then
|
||||
(( xpos[i] += XMOVES[i] )) # move right
|
||||
(( modpos = (xpos[i] % linelen) ))
|
||||
[[ ${line:modpos:1} = \# ]] && ((xcount[i]++))
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
for ((i=0; i<${#XMOVES[@]}; ++i)); do
|
||||
(( res *= xcount[i] ))
|
||||
done
|
||||
printf "%s : lines=%d res=%d\n " "$CMD" $ypos $res
|
||||
exit 0
|
957
day04/INPUT.txt
Normal file
957
day04/INPUT.txt
Normal file
@@ -0,0 +1,957 @@
|
||||
byr:1971
|
||||
iyr:2017 hgt:160cm
|
||||
eyr:2020 ecl:hzl
|
||||
pid:157096267
|
||||
|
||||
hgt:183cm
|
||||
pid:368895060
|
||||
ecl:oth eyr:2020
|
||||
iyr:2013
|
||||
byr:1966
|
||||
|
||||
ecl:lzr cid:279 pid:192cm
|
||||
hcl:1f7352 iyr:2014 hgt:70cm eyr:1983
|
||||
byr:2004
|
||||
|
||||
hcl:#602927 iyr:2018 byr:1938 ecl:blu
|
||||
eyr:2024 hgt:172cm
|
||||
pid:839621424
|
||||
|
||||
ecl:#12f268
|
||||
hcl:#6b5442
|
||||
iyr:2012 byr:2011
|
||||
eyr:1933 pid:189cm hgt:155in
|
||||
|
||||
byr:1954
|
||||
ecl:gry pid:664227667 eyr:2028
|
||||
hgt:151cm
|
||||
iyr:2019
|
||||
|
||||
ecl:gry
|
||||
byr:1931 iyr:2017
|
||||
pid:459927933 eyr:2028
|
||||
hgt:67in hcl:#fffffd
|
||||
|
||||
cid:322 hgt:163cm
|
||||
byr:1969 hcl:#a97842 pid:472877556
|
||||
iyr:2019
|
||||
ecl:amb eyr:2030
|
||||
|
||||
hcl:#733820 ecl:brn byr:2000 eyr:2022 iyr:2014 cid:320 pid:751634349
|
||||
hgt:180cm
|
||||
|
||||
ecl:blu eyr:2028
|
||||
hcl:#866857 byr:2029 hgt:191cm iyr:2010
|
||||
pid:170cm cid:123
|
||||
|
||||
pid:258660154 byr:1921 hgt:161cm
|
||||
eyr:2030
|
||||
cid:217 iyr:2012
|
||||
hcl:#4dd6d4 ecl:grn
|
||||
|
||||
hgt:170cm byr:1978 eyr:2022 pid:399347273
|
||||
iyr:2010 cid:109 ecl:blu hcl:#602927
|
||||
|
||||
pid:172106685
|
||||
hgt:183cm
|
||||
ecl:gry iyr:2020 eyr:2025 hcl:#18171d byr:1980 cid:289
|
||||
|
||||
cid:77 ecl:#254ad9
|
||||
byr:2017 pid:169290741 iyr:2003 hgt:85 hcl:z
|
||||
|
||||
hgt:155cm byr:1987 ecl:oth hcl:#fffffd
|
||||
iyr:2010
|
||||
|
||||
ecl:brn iyr:2014 cid:74
|
||||
hcl:#623a2f
|
||||
hgt:187cm byr:1955 pid:008305281 eyr:2025
|
||||
|
||||
pid:428624233 ecl:grn
|
||||
eyr:2027 hgt:167cm hcl:#623a2f byr:1960 iyr:2016
|
||||
|
||||
eyr:2027 pid:358876826 hgt:171cm ecl:oth byr:1957 iyr:2018
|
||||
hcl:#ceb3a1
|
||||
cid:314
|
||||
|
||||
ecl:grn eyr:2030
|
||||
hgt:73in iyr:2011 hcl:#602927
|
||||
|
||||
hgt:76in byr:2029
|
||||
pid:2703176 iyr:2020
|
||||
eyr:2037 ecl:#95d926
|
||||
hcl:9574d2
|
||||
|
||||
eyr:2020 hgt:164cm
|
||||
byr:1949 hcl:#fffffd pid:591281293 iyr:2014 cid:136
|
||||
|
||||
cid:268 hgt:73in hcl:#6b5442 eyr:2025 ecl:brn byr:1988 pid:899417027 iyr:2015
|
||||
|
||||
iyr:2020 hcl:#b6652a hgt:177cm
|
||||
eyr:2028 ecl:hzl
|
||||
byr:1995 pid:594197202
|
||||
|
||||
hcl:#a97842 hgt:179cm byr:1930
|
||||
ecl:brn pid:010268954 eyr:2020 iyr:2010
|
||||
|
||||
iyr:2022 pid:93390086
|
||||
cid:321 eyr:2034 hcl:#a97842 hgt:168in byr:2006 ecl:#a8f84c
|
||||
|
||||
eyr:2028 ecl:blu byr:1935
|
||||
hcl:#6b5442 pid:187679418
|
||||
hgt:174cm iyr:2016
|
||||
|
||||
iyr:2019 hgt:164cm pid:704379775
|
||||
ecl:oth hcl:#888785 byr:1930
|
||||
eyr:2025
|
||||
|
||||
hcl:#6b5442 cid:168
|
||||
hgt:171cm eyr:1944 iyr:2018 pid:675364934
|
||||
byr:1962
|
||||
ecl:hzl
|
||||
|
||||
hcl:z
|
||||
eyr:2039
|
||||
ecl:zzz pid:26281402 cid:144 iyr:1928
|
||||
hgt:166cm
|
||||
|
||||
ecl:hzl hcl:#7d3b0c
|
||||
eyr:2022 pid:011589584
|
||||
hgt:64in byr:1945 iyr:2014
|
||||
|
||||
byr:1950 hcl:#18171d pid:685748669 eyr:2028 iyr:2010 hgt:176cm ecl:grn
|
||||
|
||||
byr:1989
|
||||
hgt:163cm hcl:#18171d ecl:grn iyr:2020 pid:721397788 cid:308 eyr:2020
|
||||
|
||||
pid:443496560 iyr:1999
|
||||
eyr:2027 hcl:z
|
||||
hgt:69in ecl:zzz byr:2019
|
||||
cid:108
|
||||
|
||||
pid:#c9d804 eyr:2011
|
||||
ecl:#574df9 iyr:2027 hcl:z byr:2018
|
||||
hgt:64
|
||||
|
||||
hgt:69cm
|
||||
iyr:1926 hcl:fdcce6
|
||||
ecl:#28b358
|
||||
eyr:2026
|
||||
byr:1994
|
||||
pid:76404593
|
||||
|
||||
eyr:2020
|
||||
ecl:hzl pid:978839539 hcl:#efcc98
|
||||
byr:1935 cid:121
|
||||
hgt:165cm
|
||||
|
||||
ecl:amb
|
||||
byr:1951 hgt:186cm pid:812513486 iyr:2012 eyr:2029 hcl:#fffffd
|
||||
|
||||
hcl:fcdd61 hgt:168in ecl:grt pid:8474140699 byr:1924 iyr:2027 eyr:2023
|
||||
|
||||
ecl:oth hcl:#866857
|
||||
byr:1965 pid:533941934 hgt:166cm iyr:2019 eyr:2040
|
||||
|
||||
eyr:2032 pid:0795438812 iyr:2009 hcl:z
|
||||
byr:2028 hgt:131 ecl:gmt
|
||||
|
||||
cid:102 byr:1923 eyr:2025
|
||||
pid:222102208 iyr:2019 hcl:#341e13
|
||||
hgt:167cm
|
||||
ecl:amb
|
||||
|
||||
hgt:180cm byr:1956 iyr:2014 eyr:2022
|
||||
ecl:oth cid:175 hcl:#888785
|
||||
|
||||
cid:216 eyr:2022
|
||||
ecl:brn pid:002875069 iyr:2019 hcl:#cfa07d byr:1991 hgt:164cm
|
||||
|
||||
iyr:2014 byr:1933 pid:537809907
|
||||
hgt:185cm eyr:2029 hcl:#341e13 ecl:blu
|
||||
|
||||
cid:286 hgt:166cm byr:1977 iyr:2012 pid:541909675 ecl:oth eyr:2020
|
||||
hcl:#59eb12
|
||||
|
||||
hcl:#18171d cid:329 byr:1921 eyr:2027 iyr:2019
|
||||
pid:440820443 hgt:75in ecl:blu
|
||||
|
||||
hcl:#733820 hgt:177cm
|
||||
pid:085529831 eyr:2029 iyr:2010 ecl:amb byr:1972
|
||||
|
||||
pid:704125918 hcl:#b6652a byr:1981
|
||||
ecl:#698ae8 cid:141 iyr:2018 eyr:2026 hgt:66in
|
||||
|
||||
iyr:2020 eyr:2022
|
||||
hgt:191cm hcl:#7d3b0c
|
||||
ecl:blu byr:1943 pid:969407635
|
||||
|
||||
pid:10899196
|
||||
hgt:161cm
|
||||
ecl:lzr iyr:2023 hcl:#ceb3a1 byr:1986 eyr:2012
|
||||
|
||||
hcl:#7d3b0c ecl:utc eyr:2020
|
||||
byr:2028 pid:#f8c441 iyr:2030
|
||||
hgt:164cm
|
||||
|
||||
byr:2003 hcl:z iyr:2012 hgt:187in
|
||||
ecl:gry eyr:2030 pid:150cm
|
||||
|
||||
pid:427618420 hgt:155cm iyr:2012
|
||||
ecl:brn
|
||||
byr:1948 eyr:2029 hcl:#6b5442
|
||||
|
||||
ecl:oth hgt:81
|
||||
byr:2025 cid:66 pid:174cm hcl:z
|
||||
eyr:2021
|
||||
|
||||
byr:2027 ecl:lzr hcl:#888785 eyr:1923 hgt:110 cid:54 iyr:1939
|
||||
|
||||
hcl:#341e13 byr:1961 eyr:2022 hgt:163cm cid:137 ecl:amb
|
||||
iyr:2019
|
||||
|
||||
hcl:#866857
|
||||
iyr:2020
|
||||
byr:2005
|
||||
hgt:139 ecl:amb cid:181
|
||||
eyr:2016
|
||||
pid:181cm
|
||||
|
||||
byr:2030
|
||||
iyr:2014
|
||||
hcl:#733820 cid:74 eyr:2021 hgt:179cm
|
||||
pid:7938817872
|
||||
ecl:amb
|
||||
|
||||
hcl:91a6dd
|
||||
iyr:2019 byr:2024
|
||||
hgt:72cm
|
||||
ecl:gmt eyr:2023
|
||||
pid:8440093771
|
||||
|
||||
ecl:grn byr:1963 cid:60 iyr:2030
|
||||
hgt:74 eyr:2022
|
||||
pid:193189388
|
||||
hcl:#b6652a
|
||||
|
||||
pid:403849590 byr:2012
|
||||
eyr:1951 cid:90 iyr:2023
|
||||
hgt:69cm hcl:z ecl:gmt
|
||||
|
||||
iyr:2010 hcl:#341e13
|
||||
pid:011326174 hgt:185cm byr:1976 cid:207 eyr:2027 ecl:amb
|
||||
|
||||
hgt:64in
|
||||
pid:499837104 hcl:#3be285
|
||||
byr:1944
|
||||
eyr:2024 iyr:2017
|
||||
ecl:gry
|
||||
|
||||
eyr:2032 pid:#850d4e hcl:deddda ecl:brn hgt:172 byr:2004
|
||||
cid:244 iyr:2022
|
||||
|
||||
hcl:a3346d ecl:amb
|
||||
pid:#505713 hgt:74cm eyr:2010 iyr:2020
|
||||
|
||||
byr:1987
|
||||
ecl:oth iyr:2012 eyr:2023
|
||||
pid:131199420 cid:112 hcl:#a97842
|
||||
|
||||
cid:256 hcl:#a97842 byr:2000 iyr:2018 ecl:oth
|
||||
eyr:2022 pid:637777693 hgt:160cm
|
||||
|
||||
hgt:152cm
|
||||
cid:164 hcl:#866857 ecl:grn eyr:2025
|
||||
pid:495224989 iyr:2020 byr:1949
|
||||
|
||||
iyr:2010
|
||||
cid:288 byr:1986 ecl:blu
|
||||
pid:304077824
|
||||
eyr:2020
|
||||
|
||||
hgt:182cm
|
||||
ecl:blu
|
||||
hcl:#18171d pid:047931925 byr:1964
|
||||
iyr:2012 eyr:2030 cid:167
|
||||
|
||||
byr:1958
|
||||
hcl:#866857 iyr:2019 hgt:165cm pid:553631683
|
||||
cid:109 ecl:gry
|
||||
eyr:2023
|
||||
|
||||
cid:156
|
||||
iyr:2014 pid:811368482 eyr:2026 hcl:#b6652a byr:1994
|
||||
hgt:184cm ecl:brn
|
||||
|
||||
hcl:#733820
|
||||
hgt:183cm ecl:grn
|
||||
pid:265625165 byr:1943 cid:344
|
||||
iyr:2011
|
||||
|
||||
iyr:2017 hcl:#c0946f pid:716422629 cid:104 byr:1974
|
||||
hgt:160cm eyr:2021 ecl:brn
|
||||
|
||||
byr:2002 hgt:180cm hcl:#602927
|
||||
eyr:2025 ecl:grn iyr:2011 pid:887584172
|
||||
|
||||
hcl:#888785 ecl:brn eyr:2026
|
||||
pid:14483306 byr:1947
|
||||
hgt:177cm iyr:2015
|
||||
|
||||
hcl:#b6652a
|
||||
ecl:#64783e eyr:2020 hgt:163 pid:651615946
|
||||
iyr:2012 byr:1999
|
||||
|
||||
iyr:2014 ecl:gry hgt:188cm eyr:2028 pid:503058612 hcl:#a31066
|
||||
|
||||
hgt:178cm hcl:z
|
||||
ecl:amb
|
||||
pid:17656631
|
||||
eyr:2031 byr:2023
|
||||
|
||||
hgt:166cm pid:783568747 hcl:#341e13
|
||||
byr:1955 ecl:grn eyr:2023
|
||||
|
||||
iyr:2016 hgt:161cm byr:1989
|
||||
eyr:2023
|
||||
ecl:amb pid:133770783
|
||||
hcl:#fffffd
|
||||
|
||||
cid:75 byr:1986 eyr:2020 pid:099478576 ecl:blu
|
||||
hcl:#733820
|
||||
iyr:2011 hgt:158cm
|
||||
|
||||
pid:911200183 hcl:#602927 eyr:2029 iyr:2018 ecl:brn hgt:181cm
|
||||
byr:1937
|
||||
|
||||
iyr:1928 byr:2020 hcl:579202
|
||||
hgt:60 ecl:utc eyr:1963 pid:157cm
|
||||
cid:253
|
||||
|
||||
eyr:2028 iyr:1949
|
||||
pid:284455762 hcl:#a97842 ecl:oth byr:1947 hgt:163cm
|
||||
|
||||
hcl:#18171d eyr:2025 cid:222
|
||||
byr:1924 ecl:oth
|
||||
pid:898594506 hgt:182cm
|
||||
iyr:2017
|
||||
|
||||
byr:1935 iyr:2027
|
||||
hgt:160in pid:#c090c3
|
||||
hcl:#623a2f cid:162 eyr:1942 ecl:amb
|
||||
|
||||
iyr:2014 hgt:160cm eyr:2028 hcl:#623a2f byr:2010
|
||||
pid:684765216 ecl:blu
|
||||
|
||||
byr:1958
|
||||
hgt:154cm hcl:#a97842
|
||||
ecl:oth iyr:2015 eyr:2020 cid:334
|
||||
|
||||
pid:636691339 iyr:2018
|
||||
byr:1930
|
||||
hcl:#b6652a cid:86
|
||||
hgt:184cm ecl:oth
|
||||
eyr:2029
|
||||
|
||||
iyr:2025
|
||||
hgt:76cm ecl:#043004 hcl:z
|
||||
byr:2009 eyr:1999
|
||||
|
||||
eyr:2020 pid:56419390 iyr:2015 hcl:#ceb3a1 ecl:utc
|
||||
hgt:98
|
||||
|
||||
iyr:2014 byr:1927 hcl:#fffffd ecl:amb eyr:2022
|
||||
hgt:188cm pid:602778565
|
||||
|
||||
hcl:#cfa07d eyr:2029 byr:1937 pid:7912057436
|
||||
ecl:hzl
|
||||
cid:192 hgt:68in iyr:2012
|
||||
|
||||
hgt:155cm
|
||||
iyr:2015 byr:1954 pid:559203670
|
||||
ecl:blu hcl:#fffffd eyr:2025
|
||||
|
||||
hcl:#341e13 byr:1998 iyr:2019
|
||||
cid:312
|
||||
ecl:oth
|
||||
pid:230874778 hgt:161cm
|
||||
|
||||
iyr:2011 ecl:amb
|
||||
eyr:2026
|
||||
hgt:163cm byr:1932 hcl:#733820 pid:850176278
|
||||
|
||||
eyr:2030
|
||||
hgt:170cm
|
||||
iyr:2017 byr:1972
|
||||
pid:014731313
|
||||
hcl:#341e13 ecl:brn
|
||||
|
||||
pid:133005637
|
||||
hgt:167cm
|
||||
cid:317
|
||||
eyr:2025 hcl:#341e13 iyr:2012 ecl:gry byr:1950
|
||||
|
||||
iyr:2029 pid:745014772 hgt:68in
|
||||
eyr:2034 ecl:hzl
|
||||
hcl:ec07ce
|
||||
|
||||
hgt:165cm
|
||||
ecl:gry
|
||||
hcl:#a97842 byr:1921 cid:263 pid:609363367
|
||||
|
||||
pid:192cm hcl:18f308
|
||||
ecl:oth
|
||||
eyr:2037 cid:239 iyr:2026 byr:2010
|
||||
|
||||
hcl:d0e525 eyr:2037 iyr:2019
|
||||
cid:197
|
||||
pid:469740743
|
||||
hgt:186in ecl:brn byr:1977
|
||||
|
||||
ecl:hzl cid:254 hgt:165cm
|
||||
eyr:2024 byr:1996
|
||||
iyr:2021 pid:797277746 hcl:e286e8
|
||||
|
||||
hcl:#b6652a cid:142 ecl:oth hgt:190cm byr:1962 pid:997137384 iyr:2020
|
||||
eyr:2029
|
||||
|
||||
ecl:brn byr:1962 hcl:#866857 iyr:2020 hgt:152cm pid:701556397 cid:121 eyr:2029
|
||||
|
||||
eyr:2024 cid:186 hcl:z
|
||||
byr:1962 hgt:155cm pid:448098321 iyr:2017 ecl:grn
|
||||
|
||||
iyr:2016
|
||||
hgt:168cm byr:1999
|
||||
cid:286
|
||||
hcl:#18171d pid:223995430 eyr:2022 ecl:blu
|
||||
|
||||
pid:227780276 ecl:blu iyr:2017 byr:1985 hcl:#6b5442 hgt:183cm eyr:2028
|
||||
|
||||
hgt:190cm
|
||||
ecl:oth eyr:2030 cid:223 hcl:#888785 iyr:2010
|
||||
pid:115829664 byr:1967
|
||||
|
||||
eyr:1992 pid:0688674980 hcl:z
|
||||
byr:2028
|
||||
hgt:186in ecl:#849f7b
|
||||
iyr:2029
|
||||
cid:64
|
||||
|
||||
eyr:2025
|
||||
iyr:2013 byr:1958 ecl:grn
|
||||
hcl:#ceb3a1
|
||||
hgt:153cm pid:815357118
|
||||
|
||||
pid:038013822 hgt:180cm iyr:2013
|
||||
hcl:#623a2f
|
||||
ecl:grn eyr:2029 byr:1949
|
||||
|
||||
byr:1923
|
||||
cid:299 hgt:184cm iyr:2020
|
||||
hcl:#fffffd eyr:2027
|
||||
ecl:hzl
|
||||
|
||||
byr:1930
|
||||
iyr:2012
|
||||
ecl:grn hcl:#87f2c8 pid:787371085
|
||||
|
||||
iyr:2019
|
||||
eyr:2028 pid:107626362 hgt:183cm
|
||||
ecl:grt hcl:#623a2f byr:1985
|
||||
|
||||
byr:2011
|
||||
hgt:68in iyr:2002 ecl:#5dfa18 hcl:#341e13 pid:205853974
|
||||
|
||||
iyr:2014
|
||||
pid:179cm
|
||||
hcl:13b9e3 eyr:2022 ecl:#b1759b hgt:184in
|
||||
byr:1954
|
||||
|
||||
hgt:183cm hcl:#efcc98
|
||||
pid:428260080 cid:231 eyr:2025 ecl:grn
|
||||
iyr:2010
|
||||
byr:1957
|
||||
|
||||
iyr:2016
|
||||
ecl:gry
|
||||
pid:192cm eyr:2026
|
||||
byr:1956
|
||||
hgt:174cm hcl:#623a2f
|
||||
|
||||
eyr:2021 ecl:blu cid:230
|
||||
byr:1923
|
||||
pid:438732879 hgt:167cm
|
||||
hcl:#602927
|
||||
|
||||
byr:1948 ecl:xry
|
||||
pid:154cm hgt:179cm eyr:2029 iyr:2017
|
||||
hcl:#dd59ab
|
||||
|
||||
hcl:#ceb3a1
|
||||
iyr:2014 byr:1981 hgt:167cm ecl:grn
|
||||
eyr:2021
|
||||
pid:926925947
|
||||
|
||||
iyr:1985
|
||||
pid:652196636 hcl:#18171d ecl:#ff3e10 hgt:162cm byr:2012 eyr:2023 cid:171
|
||||
|
||||
eyr:2029
|
||||
hgt:166cm
|
||||
pid:499909488 byr:1929 hcl:#866857 ecl:brn iyr:2013
|
||||
|
||||
pid:440245122
|
||||
byr:1992 hgt:179cm iyr:2010 cid:181 ecl:brn hcl:#888785 eyr:2020
|
||||
|
||||
eyr:2029 hcl:#888785 pid:274994154 ecl:hzl
|
||||
iyr:2014 byr:1995
|
||||
|
||||
pid:3195072620
|
||||
hcl:z ecl:hzl cid:130 iyr:2030 eyr:2034 hgt:157
|
||||
|
||||
hcl:#1b0a51
|
||||
pid:129985083 eyr:2029
|
||||
hgt:192cm cid:236 byr:1996 ecl:blu iyr:2016
|
||||
|
||||
ecl:lzr pid:899902347 iyr:1982
|
||||
hcl:#cfa07d eyr:2028 byr:1927 hgt:155in
|
||||
|
||||
cid:187 eyr:2029 hcl:#efcc98 byr:1986 pid:760318090
|
||||
hgt:169cm iyr:2018 ecl:amb
|
||||
|
||||
hcl:#fffffd eyr:2021 pid:532530085 iyr:2019 byr:1995 hgt:169cm
|
||||
|
||||
iyr:1980
|
||||
hcl:z eyr:2019
|
||||
hgt:72cm pid:6532875244 ecl:#2f2221 byr:2006
|
||||
|
||||
hgt:174cm byr:1920
|
||||
ecl:gry pid:#14fae7 eyr:2026 hcl:#1814d1
|
||||
iyr:2013
|
||||
|
||||
hcl:#ceb3a1 ecl:grn
|
||||
iyr:2018
|
||||
byr:1978
|
||||
hgt:183cm pid:566862236
|
||||
eyr:2028
|
||||
|
||||
iyr:2020 ecl:amb
|
||||
pid:618246345 byr:1940
|
||||
hgt:60cm eyr:2027 cid:242 hcl:#b6652a
|
||||
|
||||
ecl:grn
|
||||
hcl:#18171d byr:1957 pid:325895714 iyr:2018
|
||||
eyr:2023 hgt:162cm
|
||||
|
||||
ecl:#a3ed7b
|
||||
byr:2024
|
||||
hcl:z eyr:2022 iyr:2016 cid:350 hgt:119 pid:185cm
|
||||
|
||||
iyr:2010
|
||||
byr:2004 eyr:2032 cid:326 hcl:6019c5
|
||||
ecl:gmt hgt:137
|
||||
|
||||
pid:477848102 eyr:2025 hgt:178cm hcl:#e31a3d ecl:brn
|
||||
byr:1943
|
||||
|
||||
pid:#65fca1 eyr:2026 hgt:192cm cid:293 ecl:blu byr:2026 iyr:2024 hcl:#a97842
|
||||
|
||||
eyr:2025 cid:181 hgt:186cm byr:1968
|
||||
ecl:brn pid:318405093 hcl:#341e13 iyr:2015
|
||||
|
||||
hcl:#c12f4b eyr:2025 cid:311 pid:652667870
|
||||
ecl:oth
|
||||
hgt:166cm
|
||||
byr:1981 iyr:2016
|
||||
|
||||
ecl:hzl
|
||||
byr:2025 iyr:2014
|
||||
hcl:138d5c eyr:2037 hgt:160in cid:206
|
||||
pid:#d9119b
|
||||
|
||||
pid:51419740 cid:141
|
||||
iyr:2012
|
||||
hgt:90 ecl:#9438f4 hcl:#7d3b0c byr:2021 eyr:2020
|
||||
|
||||
pid:#0bc613
|
||||
hcl:z byr:2017
|
||||
hgt:91 cid:284 eyr:1966 iyr:2008
|
||||
ecl:#974ceb
|
||||
|
||||
cid:344 iyr:1953 eyr:2020 ecl:hzl byr:2019 hcl:z pid:2969979
|
||||
|
||||
ecl:gry
|
||||
byr:1925 cid:113
|
||||
hcl:#a97842 pid:744660539 hgt:153cm iyr:2020
|
||||
|
||||
hgt:177 pid:856186682 eyr:1968 ecl:blu
|
||||
cid:167 byr:1986 hcl:#866857 iyr:2015
|
||||
|
||||
byr:1937 eyr:2021 iyr:2017
|
||||
cid:91 hgt:183cm hcl:#a97842 ecl:blu pid:149192621
|
||||
|
||||
hgt:154cm hcl:#602927 ecl:oth
|
||||
byr:1939 iyr:2018 pid:670669747 eyr:2029 cid:301
|
||||
|
||||
eyr:2025 pid:249412970 ecl:oth
|
||||
iyr:2016
|
||||
byr:1921 hcl:#a97842 hgt:176cm
|
||||
|
||||
byr:1969
|
||||
iyr:2019 hcl:9de0cb
|
||||
pid:644476999 hgt:75in
|
||||
ecl:oth eyr:2022
|
||||
|
||||
hgt:164cm iyr:2016
|
||||
byr:1988 ecl:gry
|
||||
eyr:2030
|
||||
hcl:#efcc98 pid:393258887
|
||||
|
||||
hgt:183cm pid:6930456 eyr:2023 cid:210 ecl:#766482 byr:2023 iyr:2017 hcl:z
|
||||
|
||||
iyr:2011 hgt:165cm eyr:2020 byr:1966
|
||||
hcl:#efcc98 pid:691169980 ecl:blu
|
||||
|
||||
iyr:2011 hcl:#602927 eyr:2029
|
||||
byr:1966
|
||||
ecl:oth hgt:165cm pid:945383793
|
||||
|
||||
pid:567096741 iyr:2025
|
||||
ecl:gry eyr:1944 hgt:187in byr:2026 hcl:8ac39a
|
||||
|
||||
byr:2025
|
||||
eyr:2025 iyr:2015
|
||||
hgt:191 pid:1659927272 ecl:grn
|
||||
|
||||
iyr:2027 hgt:63in byr:1963 pid:874200881
|
||||
ecl:oth hcl:#c0946f eyr:2029
|
||||
|
||||
hcl:#b37a48
|
||||
byr:1957 ecl:hzl
|
||||
eyr:2030
|
||||
iyr:2013
|
||||
|
||||
pid:#38e0fd eyr:2019 cid:103
|
||||
hgt:153in
|
||||
ecl:#956d7c
|
||||
iyr:2029 byr:2029 hcl:z
|
||||
|
||||
eyr:2021 pid:956654136
|
||||
hcl:#854d9d hgt:186cm byr:1960 iyr:2015
|
||||
|
||||
eyr:2020
|
||||
byr:1995
|
||||
hcl:#b6652a ecl:amb pid:746523744 iyr:2015
|
||||
hgt:178cm
|
||||
|
||||
eyr:2020 hgt:173cm cid:322 byr:1956 iyr:2020 ecl:blu
|
||||
pid:833595649
|
||||
|
||||
ecl:gry iyr:2017 eyr:2020 pid:537816651 hgt:183cm cid:160 byr:1996 hcl:#733820
|
||||
|
||||
iyr:1920
|
||||
byr:2013
|
||||
hcl:z eyr:1932 pid:169cm
|
||||
|
||||
eyr:2030 cid:258 iyr:2020 ecl:grn byr:1947 pid:571610070
|
||||
hgt:162cm hcl:#888785
|
||||
|
||||
byr:2025 hgt:155cm iyr:2030 ecl:amb eyr:2002
|
||||
|
||||
iyr:2020 ecl:hzl
|
||||
pid:090561426 hcl:#a97842
|
||||
byr:1923
|
||||
|
||||
ecl:hzl
|
||||
iyr:2019
|
||||
hcl:#c0946f eyr:2025
|
||||
byr:1999 hgt:178cm pid:026042669
|
||||
|
||||
hgt:74in
|
||||
eyr:2027 iyr:2015 ecl:gry
|
||||
byr:2005 pid:#28b09d
|
||||
|
||||
eyr:1953 byr:2014 ecl:lzr cid:202 hcl:1af88d
|
||||
iyr:2028
|
||||
|
||||
cid:99
|
||||
pid:706477697 iyr:2018 hgt:171cm eyr:2027
|
||||
ecl:oth
|
||||
byr:1978 hcl:#930aef
|
||||
|
||||
iyr:2017
|
||||
byr:1935
|
||||
eyr:2029
|
||||
ecl:amb pid:321873254 hgt:179cm hcl:#1b9aea cid:160
|
||||
|
||||
iyr:2013 ecl:hzl eyr:2023 cid:233 byr:1996 pid:605962483 hgt:175cm hcl:#ceb3a1
|
||||
|
||||
pid:754905579
|
||||
ecl:brn eyr:2021 hcl:#ceb3a1
|
||||
byr:1943 hgt:59in
|
||||
|
||||
cid:110 byr:1935 eyr:2021 hgt:172cm iyr:2020
|
||||
pid:643443673 hcl:#888785 ecl:brn
|
||||
|
||||
ecl:gmt hcl:#cfa07d
|
||||
hgt:148 iyr:2024 pid:635827422
|
||||
eyr:1935
|
||||
byr:1964
|
||||
|
||||
iyr:2012 byr:2016 hcl:z
|
||||
hgt:178cm pid:213073693 eyr:2005
|
||||
|
||||
ecl:#b3cc58 byr:2027 pid:172cm hcl:#888785 hgt:177cm eyr:1988
|
||||
iyr:2027
|
||||
|
||||
eyr:2029
|
||||
byr:1923
|
||||
hcl:#d9855b cid:134 pid:068598146 hgt:152cm ecl:blu
|
||||
|
||||
cid:309
|
||||
iyr:2010 ecl:oth hgt:188cm hcl:#18171d eyr:2028 pid:174227992 byr:1931
|
||||
|
||||
iyr:2010 hgt:72in cid:266 ecl:brn pid:0090854908
|
||||
hcl:#623a2f eyr:2032
|
||||
byr:1967
|
||||
|
||||
pid:192554211 eyr:2020 hgt:192cm ecl:gry cid:158 iyr:2015 byr:1940
|
||||
hcl:#efcc98
|
||||
|
||||
cid:248 hgt:75in eyr:2025 byr:1957 hcl:#c0946f
|
||||
iyr:2019
|
||||
ecl:brn
|
||||
|
||||
pid:96533216 hcl:z ecl:blu eyr:2027 hgt:193cm cid:224
|
||||
byr:1928 iyr:2014
|
||||
|
||||
iyr:2010
|
||||
eyr:2022 cid:276 hcl:#a97842 byr:1968 ecl:gry pid:808830560 hgt:188cm
|
||||
|
||||
hgt:158in
|
||||
pid:097590485 iyr:2030 eyr:1940 hcl:z cid:274
|
||||
ecl:#2ea9ec
|
||||
byr:2024
|
||||
|
||||
pid:616947922 byr:1982 iyr:2014 hgt:186cm ecl:oth hcl:#888785
|
||||
|
||||
byr:1941 pid:039744699 hcl:#efcc98 hgt:190cm iyr:2011
|
||||
eyr:2020 ecl:blu
|
||||
|
||||
byr:1971
|
||||
ecl:hzl hgt:65in
|
||||
pid:076133019 iyr:2019 eyr:2030
|
||||
|
||||
ecl:blu iyr:2011 byr:1928 hcl:#c0946f hgt:172cm eyr:2026 pid:171544458
|
||||
|
||||
byr:1929 pid:145819079 ecl:hzl
|
||||
hgt:192cm iyr:2015 eyr:2020 hcl:#b6652a
|
||||
|
||||
byr:1981 ecl:amb pid:123467924
|
||||
eyr:2024 hcl:#18171d
|
||||
hgt:184cm iyr:2017
|
||||
|
||||
byr:1957
|
||||
ecl:oth pid:881258191 hgt:65in iyr:2010
|
||||
hcl:#a97842
|
||||
|
||||
ecl:amb eyr:2020 hgt:152cm
|
||||
iyr:2021 pid:9448811025 hcl:#c0946f cid:204 byr:2030
|
||||
|
||||
eyr:2022 pid:208725350
|
||||
byr:1944 ecl:blu hcl:#18171d cid:164
|
||||
hgt:170cm iyr:2014
|
||||
|
||||
hcl:#18171d eyr:1952 iyr:1939 pid:788651896 hgt:157in byr:2007
|
||||
|
||||
byr:1944 cid:87 pid:463367304
|
||||
iyr:2020 hgt:188cm ecl:gry
|
||||
eyr:2027 hcl:#cfa07d
|
||||
|
||||
ecl:hzl
|
||||
iyr:2018 hgt:164cm byr:1972 cid:272 pid:990204374
|
||||
hcl:#6b5442
|
||||
|
||||
hgt:155cm pid:791416860 iyr:2015
|
||||
cid:278 hcl:#18171d byr:1994 ecl:brn
|
||||
eyr:2023
|
||||
|
||||
iyr:2017 cid:245 eyr:2026 byr:1932 ecl:blu
|
||||
hgt:159cm pid:904760812 hcl:#18171d
|
||||
|
||||
ecl:blu hcl:#6b5442
|
||||
iyr:2015 eyr:2023 pid:535891497 hgt:175cm cid:168 byr:1920
|
||||
|
||||
byr:2000 hcl:#6b5442 hgt:156cm
|
||||
pid:765444727 iyr:2012
|
||||
ecl:brn
|
||||
eyr:2028
|
||||
|
||||
eyr:2005 pid:9092484649
|
||||
byr:2028
|
||||
ecl:#5fc7fc hgt:81
|
||||
iyr:1988 hcl:8280e1
|
||||
|
||||
cid:275
|
||||
byr:1928 iyr:2010 hcl:#888785 pid:596954301 ecl:brn eyr:2020 hgt:166cm
|
||||
|
||||
cid:163
|
||||
byr:1984 eyr:2027 iyr:2020
|
||||
ecl:gry hgt:166cm pid:650001846
|
||||
hcl:#602927
|
||||
|
||||
iyr:1925 eyr:2030
|
||||
byr:1985 hcl:#cfa07d ecl:#f16a95 hgt:150cm pid:67853501
|
||||
|
||||
ecl:gry
|
||||
eyr:1949 cid:218 hgt:73cm byr:2004 pid:055108092
|
||||
iyr:1961
|
||||
|
||||
eyr:2024 iyr:2016 pid:133523002
|
||||
hgt:62in hcl:#d99c14
|
||||
byr:1996 ecl:hzl
|
||||
|
||||
eyr:2026 iyr:2019 hgt:189cm ecl:brn hcl:#623a2f
|
||||
byr:1979 pid:172111665
|
||||
|
||||
iyr:2017
|
||||
eyr:1937 ecl:#bfd0ee
|
||||
byr:1964 hcl:#733820
|
||||
hgt:169cm pid:33181449
|
||||
|
||||
eyr:2024 hcl:#6b5442
|
||||
iyr:2014
|
||||
hgt:68in pid:577055593 ecl:grn byr:1996
|
||||
|
||||
hcl:z cid:150 eyr:2039 byr:2015 pid:2453663020 ecl:brn
|
||||
hgt:154cm
|
||||
|
||||
hcl:#efcc98 eyr:2022
|
||||
ecl:grn hgt:167cm byr:1978 iyr:2010 pid:180446111
|
||||
|
||||
ecl:gry
|
||||
iyr:2020 hgt:152cm pid:#cce9cf eyr:2028
|
||||
byr:1942
|
||||
hcl:z
|
||||
|
||||
hcl:#341e13 ecl:brn iyr:2019
|
||||
pid:589837530 cid:157 byr:1925 hgt:183cm eyr:2020
|
||||
|
||||
byr:2009
|
||||
pid:179cm hgt:164cm
|
||||
iyr:1927 hcl:#cfa07d eyr:2034
|
||||
|
||||
ecl:oth iyr:2012
|
||||
eyr:2028 hcl:#866857 pid:716964854
|
||||
byr:1940 cid:113 hgt:193cm
|
||||
|
||||
byr:1985 iyr:2011 hcl:#866857 pid:454558712 eyr:2025 cid:301
|
||||
hgt:62in ecl:blu
|
||||
|
||||
hcl:#733820 eyr:2025 ecl:amb
|
||||
pid:855788635 iyr:2016
|
||||
byr:1965
|
||||
cid:140 hgt:183cm
|
||||
|
||||
hcl:#efcc98 cid:326 eyr:1961
|
||||
pid:001357810 iyr:1947 ecl:#8abfc8 hgt:75 byr:2012
|
||||
|
||||
hgt:60cm pid:#e28da4 byr:2014 iyr:2019 eyr:2040 ecl:utc
|
||||
|
||||
hcl:#733820 eyr:2022 pid:708208638 hgt:162cm cid:326 iyr:2018 ecl:oth byr:1997
|
||||
|
||||
iyr:1967 byr:2013 pid:8595504787 hgt:73cm ecl:dne
|
||||
|
||||
pid:808787977 hcl:#18171d
|
||||
cid:205 hgt:181cm
|
||||
byr:1986
|
||||
ecl:gry iyr:2013
|
||||
|
||||
ecl:dne iyr:2009
|
||||
byr:2027
|
||||
hgt:188in hcl:#c0946f
|
||||
pid:585147305 eyr:2024
|
||||
|
||||
hcl:#733820 iyr:2019
|
||||
eyr:2020
|
||||
hgt:190cm
|
||||
pid:042907748 ecl:grn byr:1920
|
||||
|
||||
ecl:#603ad1
|
||||
eyr:2026
|
||||
hcl:33f9f8
|
||||
pid:862887360 hgt:156in byr:1993
|
||||
iyr:2013
|
||||
|
||||
ecl:oth eyr:2030 byr:1960
|
||||
hcl:#a97842 cid:285
|
||||
hgt:60in pid:655974048 iyr:2016
|
||||
|
||||
iyr:2030
|
||||
hgt:143
|
||||
pid:65806846 byr:1948 hcl:#72a0d3 eyr:1934 ecl:#7cd402
|
||||
|
||||
hcl:z pid:#0f7c0a iyr:2012 hgt:161cm
|
||||
byr:2022 eyr:1937
|
||||
|
||||
hcl:#fffffd ecl:hzl
|
||||
hgt:191cm byr:1935 iyr:2015 cid:240 eyr:2030 pid:778049989
|
||||
|
||||
ecl:amb iyr:2011 hcl:#e196f6 pid:231470794 eyr:2026 hgt:179in byr:1979
|
||||
|
||||
ecl:oth hcl:#6b5442 pid:181cm hgt:72cm
|
||||
eyr:2040 iyr:2010
|
||||
|
||||
iyr:2016 eyr:2026 pid:113617276
|
||||
cid:117 hgt:176cm ecl:grn
|
||||
hcl:#c5b999
|
||||
|
||||
iyr:2016 byr:1941
|
||||
pid:846760253 hgt:60cm
|
||||
hcl:#7d3b0c ecl:zzz
|
||||
eyr:1972
|
||||
|
||||
eyr:2023 hcl:#623a2f
|
||||
cid:103 pid:476193829 hgt:181cm ecl:oth byr:1997
|
||||
iyr:2014
|
||||
|
||||
ecl:#b64a07 hcl:7bb40c byr:2028 eyr:2039 pid:#e2ba33 hgt:189 iyr:1940
|
||||
|
||||
pid:#3ecfd8 hcl:#7d3b0c iyr:2014 ecl:#30a5e7 hgt:73cm byr:1954
|
||||
|
||||
ecl:dne
|
||||
byr:2011 pid:512088455
|
||||
hcl:#18171d eyr:2023
|
||||
iyr:2024
|
||||
|
||||
byr:1996 eyr:2026 pid:268556486 ecl:brn
|
||||
hgt:150cm
|
||||
iyr:2013 hcl:#7d3b0c
|
||||
|
||||
iyr:2014
|
||||
ecl:grn pid:222910621 hcl:#602927
|
||||
eyr:2030 hgt:155cm
|
||||
|
||||
pid:530689228 byr:1938
|
||||
iyr:2015
|
||||
hgt:185cm ecl:hzl eyr:2022 hcl:#866857
|
||||
|
||||
hcl:#b6652a byr:2028 iyr:2018 cid:150 ecl:lzr pid:706073193 hgt:169cm
|
||||
|
||||
hgt:171cm ecl:gry hcl:#6b5442 byr:1953
|
||||
iyr:2011 pid:622763802 eyr:2026
|
||||
|
||||
eyr:2032 hgt:137
|
||||
pid:5033763648
|
||||
byr:1925 ecl:hzl hcl:#623a2f iyr:2024
|
||||
|
||||
byr:1930 pid:6999766453 ecl:#3e3e07
|
||||
hcl:#602927 iyr:2010 eyr:2039
|
||||
hgt:160cm
|
||||
|
||||
hgt:122 ecl:amb pid:105302121 iyr:2017
|
||||
hcl:#733820
|
||||
eyr:2027 byr:1955
|
||||
|
||||
hcl:#95f96b
|
||||
hgt:193cm iyr:2020 pid:719337690
|
||||
byr:1971
|
||||
ecl:brn eyr:2024
|
25
day04/Makefile
Normal file
25
day04/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
|
||||
ex1: ex1-c
|
||||
@$(TIME) ex1.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex1-c < $(INPUT) 2>&1
|
||||
|
||||
ex2: ex2-c
|
||||
@$(TIME) ex2.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex2-c < $(INPUT) 2>&1
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
12
day04/OUTPUT
Normal file
12
day04/OUTPUT
Normal file
@@ -0,0 +1,12 @@
|
||||
ex1.bash : valid=182/251
|
||||
time: 0:00.06 real, 0.06 user, 0.00 sys
|
||||
|
||||
ex1-c : valid=182/251
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
|
||||
ex2.bash : valid=109/251
|
||||
time: 0:00.16 real, 0.16 user, 0.00 sys
|
||||
|
||||
ex2-c : valid=109/251
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
|
127
day04/README
Normal file
127
day04/README
Normal file
@@ -0,0 +1,127 @@
|
||||
--- Day 4: Passport Processing ---
|
||||
|
||||
You arrive at the airport only to realize that you grabbed your North Pole Credentials instead of your passport. While these documents are extremely similar, North Pole Credentials aren't issued by a country and therefore aren't actually valid documentation for travel in most of the world.
|
||||
|
||||
It seems like you're not the only one having problems, though; a very long line has formed for the automatic passport scanners, and the delay could upset your travel itinerary.
|
||||
|
||||
Due to some questionable network security, you realize you might be able to solve both of these problems at the same time.
|
||||
|
||||
The automatic passport scanners are slow because they're having trouble detecting which passports have all required fields. The expected fields are as follows:
|
||||
|
||||
byr (Birth Year)
|
||||
iyr (Issue Year)
|
||||
eyr (Expiration Year)
|
||||
hgt (Height)
|
||||
hcl (Hair Color)
|
||||
ecl (Eye Color)
|
||||
pid (Passport ID)
|
||||
cid (Country ID)
|
||||
|
||||
Passport data is validated in batch files (your puzzle input). Each passport is represented as a sequence of key:value pairs separated by spaces or newlines. Passports are separated by blank lines.
|
||||
|
||||
Here is an example batch file containing four passports:
|
||||
|
||||
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
|
||||
byr:1937 iyr:2017 cid:147 hgt:183cm
|
||||
|
||||
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
|
||||
hcl:#cfa07d byr:1929
|
||||
|
||||
hcl:#ae17e1 iyr:2013
|
||||
eyr:2024
|
||||
ecl:brn pid:760753108 byr:1931
|
||||
hgt:179cm
|
||||
|
||||
hcl:#cfa07d eyr:2025 pid:166559648
|
||||
iyr:2011 ecl:brn hgt:59in
|
||||
|
||||
The first passport is valid - all eight fields are present. The second passport is invalid - it is missing hgt (the Height field).
|
||||
|
||||
The third passport is interesting; the only missing field is cid, so it looks like data from North Pole Credentials, not a passport at all! Surely, nobody would mind if you made the system temporarily ignore missing cid fields. Treat this "passport" as valid.
|
||||
|
||||
The fourth passport is missing two fields, cid and byr. Missing cid is fine, but missing any other field is not, so this passport is invalid.
|
||||
|
||||
According to the above rules, your improved system would report 2 valid passports.
|
||||
|
||||
Count the number of valid passports - those that have all required fields. Treat cid as optional. In your batch file, how many passports are valid?
|
||||
|
||||
Your puzzle answer was 182.
|
||||
--- Part Two ---
|
||||
|
||||
The line is moving more quickly now, but you overhear airport security talking about how passports with invalid data are getting through. Better add some data validation, quick!
|
||||
|
||||
You can continue to ignore the cid field, but each other field has strict rules about what values are valid for automatic validation:
|
||||
|
||||
byr (Birth Year) - four digits; at least 1920 and at most 2002.
|
||||
iyr (Issue Year) - four digits; at least 2010 and at most 2020.
|
||||
eyr (Expiration Year) - four digits; at least 2020 and at most 2030.
|
||||
hgt (Height) - a number followed by either cm or in:
|
||||
If cm, the number must be at least 150 and at most 193.
|
||||
If in, the number must be at least 59 and at most 76.
|
||||
hcl (Hair Color) - a # followed by exactly six characters 0-9 or a-f.
|
||||
ecl (Eye Color) - exactly one of: amb blu brn gry grn hzl oth.
|
||||
pid (Passport ID) - a nine-digit number, including leading zeroes.
|
||||
cid (Country ID) - ignored, missing or not.
|
||||
|
||||
Your job is to count the passports where all required fields are both present and valid according to the above rules. Here are some example values:
|
||||
|
||||
byr valid: 2002
|
||||
byr invalid: 2003
|
||||
|
||||
hgt valid: 60in
|
||||
hgt valid: 190cm
|
||||
hgt invalid: 190in
|
||||
hgt invalid: 190
|
||||
|
||||
hcl valid: #123abc
|
||||
hcl invalid: #123abz
|
||||
hcl invalid: 123abc
|
||||
|
||||
ecl valid: brn
|
||||
ecl invalid: wat
|
||||
|
||||
pid valid: 000000001
|
||||
pid invalid: 0123456789
|
||||
|
||||
Here are some invalid passports:
|
||||
|
||||
eyr:1972 cid:100
|
||||
hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926
|
||||
|
||||
iyr:2019
|
||||
hcl:#602927 eyr:1967 hgt:170cm
|
||||
ecl:grn pid:012533040 byr:1946
|
||||
|
||||
hcl:dab227 iyr:2012
|
||||
ecl:brn hgt:182cm pid:021572410 eyr:2020 byr:1992 cid:277
|
||||
|
||||
hgt:59cm ecl:zzz
|
||||
eyr:2038 hcl:74454a iyr:2023
|
||||
pid:3556412378 byr:2007
|
||||
|
||||
Here are some valid passports:
|
||||
|
||||
pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980
|
||||
hcl:#623a2f
|
||||
|
||||
eyr:2029 ecl:blu cid:129 byr:1989
|
||||
iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm
|
||||
|
||||
hcl:#888785
|
||||
hgt:164cm byr:2001 iyr:2015 cid:88
|
||||
pid:545766238 ecl:hzl
|
||||
eyr:2022
|
||||
|
||||
iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719
|
||||
|
||||
Count the number of valid passports - those that have all required fields and valid values. Continue to treat cid as optional. In your batch file, how many passports are valid?
|
||||
|
||||
Your puzzle answer was 109.
|
||||
|
||||
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 [Share] this puzzle.
|
13
day04/TEST.txt
Normal file
13
day04/TEST.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
|
||||
byr:1937 iyr:2017 cid:147 hgt:183cm
|
||||
|
||||
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
|
||||
hcl:#cfa07d byr:1929
|
||||
|
||||
hcl:#ae17e1 iyr:2013
|
||||
eyr:2024
|
||||
ecl:brn pid:760753108 byr:1931
|
||||
hgt:179cm
|
||||
|
||||
hcl:#cfa07d eyr:2025 pid:166559648
|
||||
iyr:2011 ecl:brn hgt:59in
|
146
day04/ex1-c.c
Normal file
146
day04/ex1-c.c
Normal file
@@ -0,0 +1,146 @@
|
||||
/* ex1-c: Advent2020 game, day 4/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct key {
|
||||
int mandatory;
|
||||
char *key;
|
||||
char val[80];
|
||||
} keys[] = {
|
||||
{ 1, "byr", "" },
|
||||
{ 1, "iyr", "" },
|
||||
{ 1, "eyr", "" },
|
||||
{ 1, "hgt", "" },
|
||||
{ 1, "hcl", "" },
|
||||
{ 1, "ecl", "" },
|
||||
{ 1, "pid", "" },
|
||||
{ 0, "cid", "" },
|
||||
{ -1, NULL, "" }
|
||||
};
|
||||
|
||||
int my_strlen(str)
|
||||
char *str;
|
||||
{
|
||||
int i;
|
||||
for (i=0; *str; ++i, ++str)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
int my_strcmp(str1, str2)
|
||||
char *str1, *str2;
|
||||
{
|
||||
for(; *str1 && (*str1==*str2); str1++, str2++)
|
||||
;
|
||||
return *str1 - *str2;
|
||||
}
|
||||
|
||||
char *my_strcpy(dst, src)
|
||||
char *dst, *src;
|
||||
{
|
||||
char *p=dst;
|
||||
while (*dst++ = *src++)
|
||||
;
|
||||
return p;
|
||||
}
|
||||
|
||||
struct key *get_key(key)
|
||||
char *key;
|
||||
{
|
||||
int i=0, found=0;
|
||||
|
||||
for (i=0; keys[i].mandatory != -1; ++i) {
|
||||
if (!my_strcmp(keys[i].key, key)) {
|
||||
found=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found? &keys[i]: NULL;
|
||||
}
|
||||
|
||||
struct key *set_key(key, val)
|
||||
char *key, *val;
|
||||
{
|
||||
struct key *thekey;
|
||||
|
||||
if (thekey=get_key(key))
|
||||
my_strcpy(thekey->val, val);
|
||||
return thekey;
|
||||
}
|
||||
|
||||
void print_keys()
|
||||
{
|
||||
int i=0;
|
||||
|
||||
printf("keys: \n");
|
||||
for (i=0; keys[i].mandatory != -1; ++i)
|
||||
printf("\t[%s]=[%s]\n", keys[i].key, keys[i].val);
|
||||
return;
|
||||
}
|
||||
|
||||
void reset_keys()
|
||||
{
|
||||
int i=0;
|
||||
for (i=0; keys[i].mandatory != -1; ++i)
|
||||
*keys[i].val='\0';
|
||||
return;
|
||||
}
|
||||
|
||||
int valid_passport()
|
||||
{
|
||||
int valid=1;
|
||||
struct key *key=&keys[0];
|
||||
|
||||
while (key->mandatory != -1) {
|
||||
if (key->mandatory && !*key->val) {
|
||||
valid=0;
|
||||
break;
|
||||
}
|
||||
key++;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
char *my_getkeyZOBI(str) /* search string before ':' */
|
||||
char *str;
|
||||
{
|
||||
char *p=str;
|
||||
|
||||
while (*str++ == ' ') /* skip spaces */
|
||||
;
|
||||
p=str;
|
||||
while (*p && *p++ != ':') /* skip spaces */
|
||||
;
|
||||
*p='\0';
|
||||
return my_strlen(str) ? str: NULL;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
int consumed, nkeys, nvalid=0, count=0;
|
||||
char line[160], key[80], val[80];
|
||||
char *p;
|
||||
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
nkeys=0;
|
||||
p=line;
|
||||
consumed=1;
|
||||
while (sscanf(p, "%[^:]: %s %n", key, val, &consumed)==2) {
|
||||
set_key(key, val);
|
||||
p+=consumed;
|
||||
nkeys++;
|
||||
}
|
||||
if (!nkeys) { /* empty line: reset */
|
||||
nvalid += valid_passport();
|
||||
count++;
|
||||
reset_keys();
|
||||
}
|
||||
}
|
||||
nvalid += valid_passport();
|
||||
count++;
|
||||
printf("%s : valid=%d/%d\n", *av, nvalid, count);
|
||||
exit (0);
|
||||
}
|
51
day04/ex1.bash
Executable file
51
day04/ex1.bash
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 4/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
|
||||
declare -A KEYS
|
||||
KEYS=( ["byr"]="" ["iyr"]="" ["eyr"]="" ["hgt"]="" ["hcl"]="" ["ecl"]=""
|
||||
["pid"]="" ["cid"]="" )
|
||||
|
||||
function reset_array() { # reset array values
|
||||
local -n array=${1}
|
||||
local key
|
||||
|
||||
#echo before reset: ${KEYS[@]}
|
||||
for key in "${!array[@]}"; do
|
||||
array[$key]=""
|
||||
done
|
||||
#echo after reset: ${KEYS[@]}
|
||||
}
|
||||
|
||||
function passport_valid() {
|
||||
local -i ret=0
|
||||
|
||||
for key in "${!KEYS[@]}"; do
|
||||
[[ $key != "cid" ]] && [[ -z ${KEYS[$key]} ]] && ret=1 && break
|
||||
done
|
||||
return $ret
|
||||
}
|
||||
|
||||
declare -i current=0 nvalids=0
|
||||
|
||||
while read -r line; do
|
||||
if [[ -z "$line" ]]; then
|
||||
((current++))
|
||||
passport_valid && ((nvalids ++))
|
||||
reset_array KEYS
|
||||
continue
|
||||
fi
|
||||
for pair in $line; do
|
||||
key=${pair%%:*}
|
||||
val=${pair##*:}
|
||||
[[ -v KEYS[$key] ]] && KEYS[$key]="$val" # valid key
|
||||
done
|
||||
done
|
||||
((current++))
|
||||
passport_valid && ((nvalids ++))
|
||||
printf "%s : valid=%d/%d\n" "$CMD" "$nvalids" "$current"
|
||||
|
||||
exit 0
|
247
day04/ex2-c.c
Normal file
247
day04/ex2-c.c
Normal file
@@ -0,0 +1,247 @@
|
||||
/* ex1-c: Advent2020 game, day 4/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define BYR 0
|
||||
#define IYR 1
|
||||
#define EYR 2
|
||||
#define HGT 3
|
||||
#define HCL 4
|
||||
#define ECL 5
|
||||
#define PID 6
|
||||
#define CID 7
|
||||
|
||||
struct key {
|
||||
int mandatory;
|
||||
char *key;
|
||||
char val[80];
|
||||
} keys[] = {
|
||||
{ 1, "byr", "" },
|
||||
{ 1, "iyr", "" },
|
||||
{ 1, "eyr", "" },
|
||||
{ 1, "hgt", "" },
|
||||
{ 1, "hcl", "" },
|
||||
{ 1, "ecl", "" },
|
||||
{ 1, "pid", "" },
|
||||
{ 0, "cid", "" },
|
||||
{ -1, NULL, "" }
|
||||
};
|
||||
|
||||
char *eyes[] = {
|
||||
"amb", "blu", "brn", "gry", "grn", "hzl", "oth", NULL
|
||||
};
|
||||
|
||||
int my_strlen(str)
|
||||
char *str;
|
||||
{
|
||||
int i;
|
||||
for (i=0; *str; ++i, ++str)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
int my_strcmp(str1, str2)
|
||||
char *str1, *str2;
|
||||
{
|
||||
for(; *str1 && (*str1==*str2); str1++, str2++)
|
||||
;
|
||||
return *str1 - *str2;
|
||||
}
|
||||
|
||||
char *my_strcpy(dst, src)
|
||||
char *dst, *src;
|
||||
{
|
||||
char *p=dst;
|
||||
while (*dst++ = *src++)
|
||||
;
|
||||
return p;
|
||||
}
|
||||
int my_digitstr(str)
|
||||
char *str;
|
||||
{
|
||||
for (; *str >= '0' && *str <= '9'; ++str)
|
||||
;
|
||||
return *str? 0: 1;
|
||||
}
|
||||
|
||||
struct key *get_key(key)
|
||||
char *key;
|
||||
{
|
||||
int i=0, found=0;
|
||||
|
||||
for (i=0; keys[i].mandatory != -1; ++i) {
|
||||
if (!my_strcmp(keys[i].key, key)) {
|
||||
found=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found? &keys[i]: NULL;
|
||||
}
|
||||
int get_key_num(key)
|
||||
char *key;
|
||||
{
|
||||
struct key *k=get_key(key);
|
||||
|
||||
return k? k-&keys[0]: -1;
|
||||
}
|
||||
|
||||
struct key *set_key(key, val)
|
||||
char *key, *val;
|
||||
{
|
||||
struct key *thekey;
|
||||
|
||||
if (thekey=get_key(key))
|
||||
my_strcpy(thekey->val, val);
|
||||
return thekey;
|
||||
}
|
||||
|
||||
void print_keys()
|
||||
{
|
||||
int i=0;
|
||||
|
||||
printf("keys: \n");
|
||||
for (i=0; keys[i].mandatory != -1; ++i)
|
||||
printf("\t[%s]=[%s]\n", keys[i].key, keys[i].val);
|
||||
return;
|
||||
}
|
||||
|
||||
void reset_keys()
|
||||
{
|
||||
int i=0;
|
||||
for (i=0; keys[i].mandatory != -1; ++i)
|
||||
*keys[i].val='\0';
|
||||
return;
|
||||
}
|
||||
int check_eyes(val)
|
||||
char *val;
|
||||
{
|
||||
int ret=0;
|
||||
char **col=eyes;
|
||||
|
||||
while (*col) {
|
||||
if (!my_strcmp(val, *col)) {
|
||||
ret=1;
|
||||
break;
|
||||
}
|
||||
col++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int valid_key(keypos)
|
||||
int keypos;
|
||||
{
|
||||
int good=0, i, len;
|
||||
char *val=keys[keypos].val, buf[80];
|
||||
|
||||
len=my_strlen(val);
|
||||
switch (keypos) {
|
||||
case BYR:
|
||||
if (len == 4 && my_digitstr(val)) {
|
||||
i=atoi(val);
|
||||
if (i >= 1920 && i <= 2002)
|
||||
good=1;
|
||||
}
|
||||
break;
|
||||
case IYR:
|
||||
if (len == 4 && my_digitstr(val)) {
|
||||
i=atoi(val);
|
||||
if (i >= 2010 && i <= 2020)
|
||||
good=1;
|
||||
}
|
||||
break;
|
||||
case EYR:
|
||||
if (len == 4 && my_digitstr(val)) {
|
||||
i=atoi(val);
|
||||
if (i >= 2020 && i <= 2030)
|
||||
good=1;
|
||||
}
|
||||
break;
|
||||
case HGT:
|
||||
if (sscanf(val, "%d%s", &i, buf) == 2) {
|
||||
if ((!my_strcmp(buf, "cm") && i >= 150 && i <= 193 ) ||
|
||||
(!my_strcmp(buf, "in") && i >= 59 && i <= 76 ))
|
||||
good=1;
|
||||
}
|
||||
break;
|
||||
case HCL:
|
||||
if (len == 7 && *val == '#') {
|
||||
i = sscanf(val+1, "%[a-f0-9]", buf);
|
||||
good = 1;
|
||||
}
|
||||
break;
|
||||
case ECL:
|
||||
good=check_eyes(val);
|
||||
break;
|
||||
case PID:
|
||||
if (my_strlen(val) == 9 &&
|
||||
my_digitstr(val)) {
|
||||
good=1;
|
||||
}
|
||||
break;
|
||||
case CID:
|
||||
good=1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return good;
|
||||
}
|
||||
|
||||
int valid_passport()
|
||||
{
|
||||
int valid=1;
|
||||
struct key *key=&keys[0];
|
||||
|
||||
while (key->mandatory != -1) {
|
||||
if (!valid_key(key-&keys[0])) {
|
||||
valid=0;
|
||||
break;
|
||||
}
|
||||
key++;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
char *my_getkeyZOBI(str) /* search string before ':' */
|
||||
char *str;
|
||||
{
|
||||
char *p=str;
|
||||
|
||||
while (*str++ == ' ') /* skip spaces */
|
||||
;
|
||||
p=str;
|
||||
while (*p && *p++ != ':') /* skip spaces */
|
||||
;
|
||||
*p='\0';
|
||||
return my_strlen(str) ? str: NULL;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
int consumed, nkeys, nvalid=0, count=0;
|
||||
char line[160], key[80], val[80];
|
||||
char *p;
|
||||
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
nkeys=0;
|
||||
p=line;
|
||||
consumed=1;
|
||||
while (sscanf(p, "%[^:]: %s %n", key, val, &consumed)==2) {
|
||||
set_key(key, val);
|
||||
p+=consumed;
|
||||
nkeys++;
|
||||
}
|
||||
if (!nkeys) { /* empty line: reset */
|
||||
nvalid+=valid_passport();
|
||||
count++;
|
||||
reset_keys();
|
||||
}
|
||||
}
|
||||
nvalid += valid_passport();
|
||||
count++;
|
||||
printf("%s : valid=%d/%d\n", *av, nvalid, count);
|
||||
exit (0);
|
||||
}
|
125
day04/ex2.bash
Executable file
125
day04/ex2.bash
Executable file
@@ -0,0 +1,125 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex2.bash: Advent2020 game, day 4/game 2.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
|
||||
declare -A KEYS=( ["byr"]="" ["iyr"]="" ["eyr"]="" ["hgt"]="" ["hcl"]="" ["ecl"]=""
|
||||
["pid"]="" ["cid"]="" )
|
||||
NKEYS=${#KEYS[@]}
|
||||
|
||||
function reset_array() { # reset array values
|
||||
local -n array=${1}
|
||||
local key
|
||||
|
||||
#echo before reset: ${KEYS[@]}
|
||||
for key in "${!array[@]}"; do
|
||||
array[$key]=""
|
||||
done
|
||||
#echo after reset: ${KEYS[@]}
|
||||
}
|
||||
|
||||
# returns 1 if $1 length is $2
|
||||
function check_length() {
|
||||
return $((${#1} != $2))
|
||||
}
|
||||
function check_digits() {
|
||||
[[ "$1" =~ ^[[:digit:]]+$ ]] && return 0 || return 1
|
||||
}
|
||||
# returns 1 if $1 is between $2 and $3
|
||||
function check_range() {
|
||||
(($1 >= $2 && $1 <= $3)) && return 0 || return 1
|
||||
}
|
||||
declare -A COLORS=( ["amb"]="" ["blu"]="" ["brn"]="" ["gry"]=""
|
||||
["grn"]="" ["hzl"]="" ["oth"]="" )
|
||||
function check_eye() {
|
||||
[[ -v COLORS["$1"] ]] && return 0 || return 1
|
||||
}
|
||||
function check_height() {
|
||||
local -i ret=1
|
||||
local val="$1" unit=${val: -2}
|
||||
local num=${val%%$unit}
|
||||
|
||||
#printf "unit=%s hgt=%s\n" "$unit" "$num"
|
||||
case "$unit" in
|
||||
"cm") check_digits "$num" && check_range "$num" 150 193 && ret=0
|
||||
;;
|
||||
"in") check_digits "$num" && check_range "$num" 59 76 && ret=0
|
||||
;;
|
||||
esac
|
||||
return $ret
|
||||
}
|
||||
function check_hair() {
|
||||
[[ "$1" =~ ^#[a-f0-9]{6}$ ]] && return 0 || return 1
|
||||
}
|
||||
|
||||
function check_key() {
|
||||
local -i valid=0
|
||||
local key="$1" val="${KEYS[$key]}"
|
||||
|
||||
#printf "KEY/VAL = %s=[%s]\n" "$key" "$val"
|
||||
case "$key" in
|
||||
cid) valid=1
|
||||
;;
|
||||
byr) check_digits "$val" &&
|
||||
check_length "$val" 4 &&
|
||||
check_range "$val" 1920 2002 && valid=1
|
||||
;;
|
||||
iyr) check_digits "$val" &&
|
||||
check_length "$val" 4 &&
|
||||
check_range "$val" 2010 2020 && valid=1
|
||||
;;
|
||||
eyr) check_digits "$val" &&
|
||||
check_length "$val" 4 &&
|
||||
check_range "$val" 2020 2030 && valid=1
|
||||
;;
|
||||
pid) check_digits "$val" &&
|
||||
check_length "$val" 9 && valid=1
|
||||
;;
|
||||
ecl) check_eye "$val" && valid=1
|
||||
;;
|
||||
hcl) check_hair "$val" && valid=1
|
||||
;;
|
||||
hgt) check_height "$val" && valid=1
|
||||
;;
|
||||
# TODO
|
||||
*) valid=1
|
||||
;;
|
||||
esac
|
||||
#printf "%s=[%s] : valid=%d\n" "$key" "$val" $valid
|
||||
#[[ ! $key == "cid" ]] && [[ -z ${KEYS[$key]} ]] && valid=0 && break
|
||||
return $valid
|
||||
}
|
||||
|
||||
function passport_valid() {
|
||||
local -i ret=0
|
||||
|
||||
for key in "${!KEYS[@]}"; do
|
||||
#printf "current key: %s\n" "$key"
|
||||
[[ $key != "cid" ]] && #[[ -z ${KEYS[$key]} ]] &&
|
||||
check_key "$key" && ret=1 && break
|
||||
done
|
||||
return $ret
|
||||
}
|
||||
|
||||
declare -i current=0 nvalids=0
|
||||
|
||||
while read -r line; do
|
||||
if [[ -z "$line" ]]; then
|
||||
((current++))
|
||||
passport_valid && ((nvalids ++))
|
||||
reset_array KEYS
|
||||
continue
|
||||
fi
|
||||
for pair in $line; do
|
||||
key=${pair%%:*}
|
||||
val=${pair##*:}
|
||||
[[ -v KEYS[$key] ]] && KEYS[$key]="$val" # valid key
|
||||
done
|
||||
done
|
||||
((current++))
|
||||
passport_valid && ((nvalids ++))
|
||||
printf "%s : valid=%d/%d\n" "$CMD" "$nvalids" "$current"
|
||||
|
||||
exit 0
|
743
day05/INPUT.txt
Normal file
743
day05/INPUT.txt
Normal file
@@ -0,0 +1,743 @@
|
||||
FBBFBFFRRL
|
||||
BBFFBFBRRR
|
||||
BFBBFFFLRR
|
||||
FFBFFFBLLR
|
||||
BFBBBBBRLR
|
||||
FBFFFBFLRL
|
||||
BFBBBBFLRR
|
||||
FFBBBFBRRL
|
||||
FBFBBFBLRL
|
||||
BBFFFFBRRR
|
||||
FBBBBBBRRR
|
||||
FFBBFFBLLL
|
||||
BBFFFFFRRR
|
||||
BFFBFBFRLL
|
||||
BFBFFFBRLR
|
||||
FBBBFFFLRL
|
||||
BFBFBBFLRL
|
||||
BFFFBBBRRR
|
||||
FBFFBBFRRL
|
||||
BBFBFFFLLR
|
||||
FBBFBBBRLL
|
||||
BBFFBFBRLR
|
||||
BFFFFFBRLL
|
||||
BBFFFBBRRR
|
||||
FBFFBBFRLL
|
||||
FBBBBBFRRL
|
||||
BBFBFFFLRL
|
||||
BFBFBBBRLR
|
||||
FBBFBBBRRR
|
||||
BFBBBFFLLL
|
||||
BFFFFFFLLL
|
||||
BFBFFFBLRL
|
||||
FBBFBBBLLR
|
||||
BFFFBFBRLL
|
||||
FFBFFBFLRL
|
||||
FBFBFFBRLR
|
||||
BBFFFBBLLR
|
||||
BFFBFFFRRR
|
||||
FBFFBBBLLL
|
||||
BFBFFFFRLL
|
||||
FBFBBFFRRL
|
||||
BFBFBBBLLL
|
||||
BFBFBFFRLR
|
||||
FBBFBFFLRL
|
||||
BFFFFBBLLR
|
||||
FBBBFBBRRR
|
||||
FBBBFFFLRR
|
||||
FFBBBBFLRR
|
||||
BFFFFFFRRL
|
||||
BBFFFFFLRL
|
||||
BFFBFBFRLR
|
||||
FFBBBBBLLR
|
||||
FBFFBFBRLL
|
||||
BFBBFFBLRR
|
||||
BFFFFBFLLR
|
||||
FBBBBFFRLL
|
||||
FBBBFFBLLR
|
||||
BFFBBBFLLL
|
||||
FFBFBBBLLL
|
||||
BBFBFFFLRR
|
||||
FBFBFFFLRL
|
||||
BFFBBFFRRL
|
||||
FBFBFBBLRR
|
||||
FFBBFBBRLL
|
||||
FFBBFBFRLL
|
||||
BFFFBFBRRL
|
||||
BFBBBBFRLL
|
||||
BFFFBFBLLL
|
||||
BFFFBBBLLL
|
||||
FBBBBFBRRL
|
||||
BFBBFFBRLL
|
||||
BFBBFFFRLR
|
||||
FFBBBBFLLL
|
||||
FFBBFFBRLL
|
||||
FFBFBFFLRR
|
||||
FBBBFBBRRL
|
||||
FFBFBBBLRR
|
||||
BFBFFFFRRR
|
||||
BFFBBFBRRR
|
||||
BFFFFBBRLL
|
||||
BFFFBBFRRR
|
||||
BFFFBFBRLR
|
||||
FFBBBFFRRR
|
||||
BFFBFBFRRL
|
||||
FFBBBBBRLR
|
||||
FBBFBFBRRL
|
||||
FFBBBBBLRL
|
||||
FFBBFBBRRR
|
||||
BFFBBBFLLR
|
||||
FFBFBFFRRR
|
||||
BFBBFFBRRL
|
||||
BFBBFBBLLR
|
||||
FBBBFFBRLR
|
||||
BFFBBFFLLR
|
||||
FBBFFBFRRR
|
||||
FFBFFFBLRR
|
||||
FFFBBBBRRL
|
||||
FBBFBFBLLR
|
||||
FBBBBFFRRR
|
||||
FFFBBBBLRL
|
||||
FBBBFFBRRL
|
||||
BFBBFBFLRL
|
||||
FBBFBBFRRL
|
||||
FBBFBBFRLR
|
||||
BBFFBBFRLL
|
||||
BBFFFFBLLR
|
||||
FFBFFBFLLL
|
||||
FFBBFFBRRL
|
||||
FBBFFFBLLL
|
||||
FFFBBBBLLR
|
||||
FBBBFFBLLL
|
||||
FFBFBBFLLR
|
||||
FBBFBBFLRL
|
||||
BBFFBBFRLR
|
||||
FBFBBBBRLR
|
||||
BFBFBFFRRL
|
||||
BFBBFBBLLL
|
||||
FBFBBBBRRL
|
||||
FFBFBFBRLL
|
||||
BFFBBBFRRL
|
||||
BFFBFFBRLR
|
||||
FBFBBFBLRR
|
||||
FFBBFFFLRL
|
||||
BBFFFBBRLR
|
||||
FFBBBFFLLR
|
||||
FBFFFBBRRR
|
||||
BFFBBFBRRL
|
||||
BFBBFFFRLL
|
||||
FBFBBFBRLR
|
||||
FBBBBFFLLL
|
||||
FFBBFBFLLR
|
||||
BFFBBBFRLR
|
||||
BFFFBBBRLL
|
||||
BFBFBFBLRL
|
||||
BFFFFFFRRR
|
||||
FBFBFBBRRL
|
||||
BFBFFBFRRL
|
||||
FBFFFFFLRR
|
||||
FFBBBBFRRL
|
||||
FFBBBBBRRR
|
||||
BFBFFBBRRL
|
||||
BBFFFBFLRL
|
||||
FBBBBFBRLR
|
||||
BFBFFBFRRR
|
||||
FFBBBFBRLL
|
||||
FFBFFBBLLL
|
||||
BFBBBFBLRL
|
||||
BFFBBBBLLR
|
||||
FFBFBBFRLL
|
||||
BFFFBBBLRR
|
||||
BBFBFFFRRL
|
||||
BBFFBFFRLL
|
||||
BFBBFBFRRR
|
||||
FFBFBFBLRL
|
||||
BFBBFFBLLR
|
||||
FBBFBFBRLR
|
||||
FFBBBFBRLR
|
||||
FBFBBBFLRL
|
||||
FBFBBFFLRR
|
||||
FBBBFBBRLR
|
||||
FBFBBBFRRL
|
||||
BFFBBFBLRR
|
||||
FFFBBFBLLL
|
||||
BFBFFBFLRL
|
||||
FBBBBFFLLR
|
||||
FBFFFFFRRR
|
||||
FBFBFBFLLL
|
||||
BFBBFFFRRR
|
||||
BFBBBFBLRR
|
||||
BFBBFBFRLR
|
||||
FFBFFBFRLL
|
||||
BFBFBBFRRR
|
||||
BFBFFBFRLL
|
||||
BBFFBBBLLR
|
||||
FBFFBFBRLR
|
||||
FBBBFBFLRL
|
||||
BBFFBBFLLR
|
||||
BFBBBFFLRR
|
||||
FBBBFFFLLL
|
||||
FFBBFBFRRL
|
||||
FBFFBBFLLR
|
||||
FFBFFBBLRL
|
||||
FFBFBFBLLR
|
||||
FFFBBFFLLL
|
||||
BFBBFBBRRL
|
||||
BFBFBFBRLL
|
||||
BFFBFFFRLR
|
||||
BFFFBBFLLR
|
||||
FBFFFFFLLR
|
||||
FBFFFFBLLR
|
||||
FFFBBBFLRL
|
||||
FFBBFBBLRL
|
||||
FFBFBBBRRL
|
||||
FBBFBFBRRR
|
||||
BFFFFFBLLL
|
||||
BFBFBBBLRL
|
||||
BFFFFFBRRR
|
||||
FFBFBFFRLL
|
||||
BFFBFFBLLR
|
||||
BFFBFFFLLL
|
||||
BFBBBFFRLR
|
||||
BFBBBBBLLR
|
||||
FBFBFBBRLR
|
||||
BFFFBBBRLR
|
||||
FFFBBBFRLL
|
||||
BFBBBBBLLL
|
||||
FBBFFBBLLR
|
||||
BFBFFBBLLL
|
||||
FBFBBBBRRR
|
||||
FFBBFFFLLR
|
||||
BFFBFFBLRR
|
||||
BFFFFBFLRR
|
||||
FFBFFFBLLL
|
||||
FFBFBBFRRL
|
||||
FBBFFFFLRR
|
||||
FBFBFBBRLL
|
||||
BFFBFBFLRR
|
||||
BFFBBFBRLR
|
||||
BFFBFBBLRR
|
||||
BFFFBBBLLR
|
||||
FBFBFFBRRL
|
||||
BFBBBFFRRR
|
||||
BFBFFBBRLR
|
||||
FBFFBBFLRR
|
||||
FFFBBFFRRR
|
||||
BBFFBFFLRL
|
||||
FBFBBFBRRR
|
||||
FBFFFFBRLR
|
||||
FFBFFFFRLL
|
||||
FBBBFFBLRL
|
||||
FBBBBBBLLR
|
||||
BFFFBFBRRR
|
||||
FBBBBBFLLR
|
||||
BFFBFBBLLL
|
||||
FBBBFBFRRR
|
||||
FBBBFBFLLR
|
||||
FFBFBFFLRL
|
||||
BFFFBFBLRR
|
||||
FFFBFBBRRR
|
||||
BFBFBBFRLL
|
||||
FFBFBBBRLR
|
||||
BFBFBFFLRL
|
||||
FFBBFFBRRR
|
||||
BFBBFBBRLL
|
||||
FBFBBBFLLL
|
||||
BFBFFBFRLR
|
||||
FBBFBFFRLR
|
||||
BFFFFFFRLL
|
||||
BFFFFFBLRL
|
||||
FBBFBBFRRR
|
||||
FBBFBBFRLL
|
||||
FBFBFFFRLR
|
||||
FFBFFBFLLR
|
||||
FBBBFFFLLR
|
||||
BFBBBBBLRR
|
||||
FBFBBFFLLL
|
||||
FFFBBBBLRR
|
||||
FBBBBBBLRL
|
||||
FFBFFBBLRR
|
||||
FBBFFFFRRR
|
||||
BFBFBBFRLR
|
||||
FFBFBBFLRL
|
||||
BFBBFFFLLL
|
||||
BFBBBBFRRL
|
||||
FBBBFBFRRL
|
||||
FBFFBBBRLL
|
||||
FFBBFFFRLL
|
||||
FBFBBBBLRR
|
||||
FFBBBBFRLR
|
||||
FBFBBFFLRL
|
||||
FFBBFFBRLR
|
||||
FBBBFBFLRR
|
||||
FBFFFBFRLR
|
||||
FFBBBFFLLL
|
||||
FBFFBBFLRL
|
||||
FFBFFBFLRR
|
||||
FBFFBFFLLR
|
||||
FFFBBFFLRR
|
||||
FBBFFBBRRL
|
||||
BFBBBFBRRR
|
||||
BBFFBBBRRR
|
||||
BFFFBBFLRL
|
||||
FBFBFFBLRL
|
||||
FBBFFBFLLL
|
||||
BFFBBBFRRR
|
||||
BFFFBFFRRL
|
||||
FBFFFBFRRR
|
||||
FFBBFFBLRL
|
||||
BBFFFFBRLR
|
||||
FBFBBFBLLR
|
||||
FFBFFBFRLR
|
||||
BFBBFBFRLL
|
||||
FFBBFBFRRR
|
||||
BBFFBFBLLL
|
||||
FBBFBBBLLL
|
||||
FBBFFBFLRL
|
||||
FBFFFBFRRL
|
||||
FBBBFBBLRR
|
||||
FBBFFFFRRL
|
||||
FBBBBBFLRR
|
||||
FFBBFFFLLL
|
||||
BFBBBFBRLL
|
||||
FBFFFFBRLL
|
||||
BFBFBBFLLR
|
||||
FFBBBFFLRL
|
||||
FBBFBBBRLR
|
||||
BFBFBFFLLR
|
||||
BFFBBFBRLL
|
||||
FFFBBFFRRL
|
||||
FFBFFFFLRR
|
||||
BFFFFBFRLR
|
||||
FBFFFBBLLL
|
||||
FFBFBFFRRL
|
||||
FBFFFBBLRR
|
||||
FBFFBFFRLR
|
||||
FBBFBBBRRL
|
||||
FBFFBFBRRL
|
||||
FBFFFBFLLL
|
||||
BFFBFFBRLL
|
||||
BFFBBFBLLL
|
||||
BFFFFBBRRR
|
||||
FBFFFFBLLL
|
||||
FBBFBFFLRR
|
||||
FFFBBBFRRR
|
||||
BBFFFFFLLL
|
||||
BFFBFBBLRL
|
||||
BBFFFBBLRR
|
||||
FBFFBFBLLL
|
||||
BFBFFFBLLL
|
||||
BBFFBBFRRR
|
||||
FFBBFBBRRL
|
||||
FBBBBBBRRL
|
||||
FBFFFBFLLR
|
||||
BBFBFFFLLL
|
||||
BFFBBBBRRR
|
||||
FBBFFBBRRR
|
||||
FBBBBFFRLR
|
||||
FBBFBBFLRR
|
||||
FBBFFFFRLR
|
||||
BFBBBBFRLR
|
||||
FBFBFFBRLL
|
||||
BFFBFFFLLR
|
||||
FBFFBFBLLR
|
||||
FFFBBBFRLR
|
||||
FBBBFFBRRR
|
||||
BFFBBBBLRL
|
||||
BFFFFBBLLL
|
||||
BFFBBFFLRR
|
||||
BFFBFFFLRL
|
||||
FBBFBBBLRR
|
||||
FFFBBFBLRR
|
||||
FFBBBFBLRR
|
||||
FBFFFBBLRL
|
||||
FBFFBFFRRL
|
||||
FFBFBFFLLL
|
||||
FFBBBBBLRR
|
||||
FFBBFBFLLL
|
||||
FBFBFBFRLL
|
||||
BFFBBBFLRR
|
||||
FFBFBFBRRR
|
||||
FBBFFFBLRL
|
||||
FBBBFFBLRR
|
||||
BFBBBBFLRL
|
||||
BFBBFBFRRL
|
||||
FFBBBFFRLL
|
||||
BBFFFFFRLL
|
||||
BBFFFBBRRL
|
||||
FBBBFBBLLR
|
||||
FBBBBBBLRR
|
||||
FFBBFBFRLR
|
||||
FFBFFBFRRL
|
||||
FBBBBBFLRL
|
||||
BFBFBFBRRR
|
||||
BBFFBBFLLL
|
||||
BFFFBBFRLL
|
||||
FBFBBBBLRL
|
||||
BFFFBFFLRL
|
||||
FBBBFFFRRR
|
||||
BFFFFBFLLL
|
||||
BFFBBBFRLL
|
||||
FBFFFBBRLL
|
||||
FBFBFFBLLL
|
||||
FBBBBFBLRL
|
||||
FBBFBFFRRR
|
||||
FFFBBBBLLL
|
||||
FFBFBFBRLR
|
||||
BFBFBFBRRL
|
||||
BFBFBBBLRR
|
||||
FBFFFFFRLL
|
||||
BFBBBBBRRL
|
||||
FBBFFFFLLR
|
||||
FBBBBFBLLR
|
||||
FBBFFFFLRL
|
||||
FBBFBFBLLL
|
||||
BFFFFBBLRR
|
||||
FBBBBFFLRR
|
||||
BBFFFBFRRR
|
||||
FBFBBBFRLL
|
||||
BFFFFFBRRL
|
||||
BFFFFFFLRR
|
||||
FFBFFFBRLL
|
||||
FBFFBFFLLL
|
||||
BFBBFFBRRR
|
||||
BFBBFBFLRR
|
||||
BFBBFFBLLL
|
||||
FBBFFBFRLL
|
||||
BFBFBBFLRR
|
||||
FFBFFFFRLR
|
||||
FBFBBFBRLL
|
||||
FBFFBBBLRR
|
||||
FBBFBFBLRL
|
||||
FBFFBFBLRL
|
||||
FFBFFFFRRR
|
||||
BFFBBBBLLL
|
||||
BFFBFFFRRL
|
||||
BFBFBBBRRL
|
||||
BBFFFBFLLL
|
||||
FBBBFFBRLL
|
||||
BFFFFFFRLR
|
||||
FFFBBFBLRL
|
||||
BFBFBFBLLR
|
||||
FBFBFFFRRR
|
||||
FBFBFFBRRR
|
||||
BBFFFFBLRR
|
||||
BFBBBBFLLR
|
||||
FBFBFBFLRR
|
||||
FBBBBBFRLR
|
||||
BFFFBBFLRR
|
||||
BBFFBFBLRL
|
||||
BBFFFFFLRR
|
||||
FBFBFBFLLR
|
||||
FFFBBBBRRR
|
||||
BFFBBFFLLL
|
||||
FBBFBBBLRL
|
||||
BFFFBFFLRR
|
||||
BFBBBFBRLR
|
||||
FFBBFBBLLL
|
||||
BBFFBBBLLL
|
||||
BFFFBFBLLR
|
||||
FFBBBFBRRR
|
||||
BBFFFFFRLR
|
||||
FFBBBFFRRL
|
||||
FFBBFFBLLR
|
||||
FBBFBFFLLL
|
||||
FBBFFBBLLL
|
||||
BFFBFBBRLR
|
||||
FFBBFFFLRR
|
||||
BFFBFBBLLR
|
||||
FFBFFBBRRL
|
||||
FFBFBBBLLR
|
||||
BFFFBBFLLL
|
||||
FBBFFBFRLR
|
||||
BFFFBFFRRR
|
||||
FFFBBFFLLR
|
||||
FBFBBBFRRR
|
||||
BFFFFFBLRR
|
||||
FFBBFFFRRL
|
||||
FFBFBBBLRL
|
||||
FBBFFBFLRR
|
||||
BFFFFBBRLR
|
||||
FFBBBFBLLR
|
||||
FFFBBFBRLR
|
||||
BBFBFFFRLL
|
||||
FBFFBFFRLL
|
||||
FBBBBFBRLL
|
||||
BBFFFBBLRL
|
||||
BFFBFFFRLL
|
||||
FBFFFFFRRL
|
||||
BBFFBBBRLR
|
||||
BBFFFFFRRL
|
||||
BBFFBBBRLL
|
||||
BFFBFFBRRR
|
||||
BFBBFFFLLR
|
||||
BFFFBBFRLR
|
||||
FBBBFBFLLL
|
||||
BFBBFBBRLR
|
||||
FBBBFBBLLL
|
||||
BFBFBBBRLL
|
||||
BBFFFBFLLR
|
||||
BFBBFFFLRL
|
||||
FFBFBBFRRR
|
||||
FFBBBBBRRL
|
||||
BBFFBBFLRR
|
||||
FBFBBBFLRR
|
||||
FFBFFBBRRR
|
||||
FBBFFFBRLR
|
||||
BFBBBFFRRL
|
||||
FBFBFBFRLR
|
||||
FBBBBFBRRR
|
||||
FBBFFBBLRL
|
||||
BBFFFFBLRL
|
||||
FFFBBBBRLR
|
||||
FBFBBFFRLR
|
||||
BFBFFBBLLR
|
||||
BFFFFBBRRL
|
||||
BFBFFFBRLL
|
||||
FBFFBFBRRR
|
||||
FFBBFBBLLR
|
||||
BFFBBFFRRR
|
||||
FBFFFBBLLR
|
||||
FBFBBFBRRL
|
||||
FFBFFFFLLL
|
||||
BFFBBBBRLR
|
||||
BFFBBFBLRL
|
||||
BFFBFBBRRL
|
||||
FFBFFBBLLR
|
||||
FBBFFFBRRL
|
||||
BFBFFBBRLL
|
||||
FBFFFFBRRR
|
||||
BFFFFFFLLR
|
||||
FBFFBBFLLL
|
||||
FFFBBFBRLL
|
||||
BFBFFBFLLL
|
||||
BFBBFBBLRL
|
||||
BFFFBFFLLR
|
||||
FBFFFBBRRL
|
||||
BBFFFFBRLL
|
||||
FFBBBBBRLL
|
||||
FBFBFBFRRR
|
||||
BBFFBBFLRL
|
||||
FBBBBFBLLL
|
||||
BFBFBFFRRR
|
||||
FFBFBFFRLR
|
||||
BBFFBFBLRR
|
||||
BFBFFFFLRL
|
||||
BFFFBBFRRL
|
||||
FFBFBBBRRR
|
||||
FBFFFBFRLL
|
||||
BFFFFBFRRR
|
||||
BFBFBFFRLL
|
||||
FBBBFBFRLR
|
||||
BFFFFFBLLR
|
||||
BFBBBFBRRL
|
||||
BFFBBFFRLR
|
||||
FBBBFBBLRL
|
||||
BFFFBFFRLR
|
||||
BBFFFBFRLR
|
||||
BFFFBFFRLL
|
||||
FBBBBFFRRL
|
||||
BBFFBBFRRL
|
||||
BBFFBFFRRR
|
||||
BBFFBFFRRL
|
||||
FBBBBFBLRR
|
||||
BBFFFBBRLL
|
||||
FBBFBFBLRR
|
||||
BFFBBFFLRL
|
||||
BFBBBFBLLL
|
||||
BBFFBFBRLL
|
||||
FFBFFFBRLR
|
||||
BBFFBBBLRL
|
||||
FFBBFBBLRR
|
||||
FFBBBFBLLL
|
||||
BFFBFFFLRR
|
||||
FFBFBFFLLR
|
||||
FFBFFBBRLL
|
||||
BFBBBBBLRL
|
||||
BBFFFBFLRR
|
||||
BFBFBFFLRR
|
||||
BFFBFBFLLL
|
||||
FFBFFFFRRL
|
||||
FFBBBBFRLL
|
||||
FBFBFBBLRL
|
||||
BBFFFBFRRL
|
||||
FFBFFBFRRR
|
||||
FBBFFBBRLR
|
||||
FBBFBFBRLL
|
||||
BFBFBFBRLR
|
||||
BFFBFFBLRL
|
||||
BFBBFFBRLR
|
||||
FBFBFFFLLR
|
||||
BFFFFFFLRL
|
||||
FBBFBBFLLL
|
||||
FFBBBFBLRL
|
||||
BFBFBBFLLL
|
||||
BBFFFBFRLL
|
||||
FBFBFFBLRR
|
||||
FBBBFFFRLR
|
||||
BFBBBFFLRL
|
||||
FFBBFFBLRR
|
||||
BBFFBFFLLR
|
||||
FBFFBFFRRR
|
||||
FBFFBBBRLR
|
||||
BFBFBFBLRR
|
||||
BFFBBBBRLL
|
||||
FBFFFFBLRL
|
||||
FBBFBFFLLR
|
||||
FBFBFFFLRR
|
||||
FBBBBBBRLL
|
||||
FBFFBBBRRR
|
||||
FBBFFBBLRR
|
||||
BFFFBFBLRL
|
||||
FBBFFFFRLL
|
||||
BFBFFBBRRR
|
||||
BBFFBBBLRR
|
||||
BFBFFFBLLR
|
||||
FBFBFBBRRR
|
||||
FFFBBBFLLR
|
||||
BFBFFFFLLL
|
||||
FBFFBBBLRL
|
||||
FBFBFBBLLL
|
||||
FFBFFFFLRL
|
||||
FBFBBBBLLR
|
||||
FBFBFBFLRL
|
||||
FBBBFBFRLL
|
||||
FBFBFFFRRL
|
||||
BBFFBBBRRL
|
||||
BBFFFFBLLL
|
||||
FBFFBBBRRL
|
||||
BFBFFFBRRL
|
||||
BBFFFFBRRL
|
||||
BFBFFBBLRR
|
||||
BFFBFFBRRL
|
||||
FFBFBFBRRL
|
||||
FFFBBFBRRR
|
||||
BBFFFBBLLL
|
||||
FBFBBFFRLL
|
||||
BFFFBFFLLL
|
||||
BFFBFBFLRL
|
||||
FBBBBBFRLL
|
||||
FBFBBBFLLR
|
||||
FFBBFFFRRR
|
||||
FBBBBBBLLL
|
||||
BFBFBBFRRL
|
||||
FBFBFBFRRL
|
||||
BFBFFFFRLR
|
||||
FFFBBFFRLR
|
||||
FFBBBFFRLR
|
||||
FFFBBFBRRL
|
||||
FBFFFFFRLR
|
||||
FBFFBBFRLR
|
||||
FFBFFFBLRL
|
||||
BFBFFFFLRR
|
||||
FFBFFFFLLR
|
||||
FFBBFFFRLR
|
||||
BFBFFFBLRR
|
||||
FBBBBBFRRR
|
||||
BFFBBBBRRL
|
||||
FFFBBFFLRL
|
||||
FBFFBFBLRR
|
||||
FBBFFBFRRL
|
||||
FBBFBFFRLL
|
||||
FFBFBBBRLL
|
||||
BFFFBBBLRL
|
||||
BFFBFBBRRR
|
||||
FBBBBBBRLR
|
||||
BFBFBBBRRR
|
||||
BBFFBFFRLR
|
||||
FBBBFFFRRL
|
||||
FFBBBBFRRR
|
||||
BFBBBFBLLR
|
||||
FFFBBBFRRL
|
||||
FFFBBBBRLL
|
||||
FBBBFBBRLL
|
||||
BFFFFFBRLR
|
||||
BFBFBBBLLR
|
||||
BFBFFBBLRL
|
||||
FBBFFFBRRR
|
||||
BFBBFBBLRR
|
||||
FBBFFBFLLR
|
||||
FBFBBBBRLL
|
||||
BFFBBFFRLL
|
||||
FFBBFBBRLR
|
||||
BFBFFBFLLR
|
||||
BFBBBFFLLR
|
||||
FBBFBBFLLR
|
||||
BFBBFBFLLR
|
||||
BFFBFBFRRR
|
||||
BFBFBFBLLL
|
||||
FBFFFFFLLL
|
||||
FFBFFFBRRL
|
||||
FBFFBBFRRR
|
||||
BBFFBFBRRL
|
||||
FBFFBFFLRR
|
||||
FBFBBFFRRR
|
||||
BFFFBBBRRL
|
||||
BFBFBFFLLL
|
||||
BFBFFFFLLR
|
||||
FBBBBBFLLL
|
||||
FFBFFBBRLR
|
||||
FFBBBBBLLL
|
||||
BFFBBBFLRL
|
||||
FFBBFBFLRL
|
||||
FFFBBBFLLL
|
||||
BFFFFBFLRL
|
||||
FBBFFFBLLR
|
||||
FBFBBBFRLR
|
||||
BBFFBFBLLR
|
||||
BFBBBBFRRR
|
||||
FBFBFFFRLL
|
||||
FBFBBFBLLL
|
||||
FBFBFFFLLL
|
||||
FFBFBBFLLL
|
||||
BFBFFFFRRL
|
||||
FFFBBFBLLR
|
||||
BFFBBFBLLR
|
||||
FFBFBFBLLL
|
||||
FBFBBFFLLR
|
||||
FFBFBFBLRR
|
||||
BFFBFBFLLR
|
||||
BFBBBBBRRR
|
||||
FBBFFFBLRR
|
||||
FBBFFFFLLL
|
||||
FFBBFBFLRR
|
||||
BBFFFFFLLR
|
||||
BFBBFBFLLL
|
||||
BFFFFBBLRL
|
||||
FBFFFFBLRR
|
||||
FFBBBFFLRR
|
||||
FFFBBFFRLL
|
||||
BFFBBBBLRR
|
||||
FBFFBBBLLR
|
||||
FFBFFFBRRR
|
||||
FBFFFFFLRL
|
||||
BFFFFBFRRL
|
||||
BFFFFBFRLL
|
||||
BFBFFBFLRR
|
||||
BFBBBFFRLL
|
||||
BFBBFBBRRR
|
||||
BBFBFFFRLR
|
||||
BBFFBFFLRR
|
||||
FFBFBBFRLR
|
||||
BFBBBBFLLL
|
||||
FBFFFBBRLR
|
||||
BFBBBBBRLL
|
||||
BBFFBFFLLL
|
||||
FBFFBFFLRL
|
||||
FBFBFBBLLR
|
||||
BFFBFFBLLL
|
||||
FFBBBBFLRL
|
||||
FBFBFFBLLR
|
||||
FFFBBBFLRR
|
||||
FBBBFFFRLL
|
||||
BFFBFBBRLL
|
||||
FFBFBBFLRR
|
||||
BFBBFFFRRL
|
||||
FFBBBBFLLR
|
||||
FBBFFFBRLL
|
||||
FBFBBBBLLL
|
||||
FBFFFBFLRR
|
||||
FBBBBFFLRL
|
||||
BFBFFFBRRR
|
||||
FBBFFBBRLL
|
||||
FBFFFFBRRL
|
25
day05/Makefile
Normal file
25
day05/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
|
||||
ex1: ex1-c
|
||||
@$(TIME) ex1.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex1-c < $(INPUT) 2>&1
|
||||
|
||||
ex2: ex2-c
|
||||
@$(TIME) ex2.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex2-c < $(INPUT) 2>&1
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
12
day05/OUTPUT
Normal file
12
day05/OUTPUT
Normal file
@@ -0,0 +1,12 @@
|
||||
ex1.bash : lines=743 max=838
|
||||
time: 0:00.94 real, 0.62 user, 0.41 sys
|
||||
|
||||
ex1-c : lines=743 max=838
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
|
||||
ex2.bash : lines=743 seat=714
|
||||
time: 0:00.99 real, 0.65 user, 0.43 sys
|
||||
|
||||
ex2-c : lines=743 seat=714
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
|
62
day05/README
Normal file
62
day05/README
Normal file
@@ -0,0 +1,62 @@
|
||||
--- Day 5: Binary Boarding ---
|
||||
|
||||
You board your plane only to discover a new problem: you dropped your boarding pass! You aren't sure which seat is yours, and all of the flight attendants are busy with the flood of people that suddenly made it through passport control.
|
||||
|
||||
You write a quick program to use your phone's camera to scan all of the nearby boarding passes (your puzzle input); perhaps you can find your seat through process of elimination.
|
||||
|
||||
Instead of zones or groups, this airline uses binary space partitioning to seat people. A seat might be specified like FBFBBFFRLR, where F means "front", B means "back", L means "left", and R means "right".
|
||||
|
||||
The first 7 characters will either be F or B; these specify exactly one of the 128 rows on the plane (numbered 0 through 127). Each letter tells you which half of a region the given seat is in. Start with the whole list of rows; the first letter indicates whether the seat is in the front (0 through 63) or the back (64 through 127). The next letter indicates which half of that region the seat is in, and so on until you're left with exactly one row.
|
||||
|
||||
For example, consider just the first seven characters of FBFBBFFRLR:
|
||||
|
||||
Start by considering the whole range, rows 0 through 127.
|
||||
F means to take the lower half, keeping rows 0 through 63.
|
||||
B means to take the upper half, keeping rows 32 through 63.
|
||||
F means to take the lower half, keeping rows 32 through 47.
|
||||
B means to take the upper half, keeping rows 40 through 47.
|
||||
B keeps rows 44 through 47.
|
||||
F keeps rows 44 through 45.
|
||||
The final F keeps the lower of the two, row 44.
|
||||
|
||||
The last three characters will be either L or R; these specify exactly one of the 8 columns of seats on the plane (numbered 0 through 7). The same process as above proceeds again, this time with only three steps. L means to keep the lower half, while R means to keep the upper half.
|
||||
|
||||
For example, consider just the last 3 characters of FBFBBFFRLR:
|
||||
|
||||
Start by considering the whole range, columns 0 through 7.
|
||||
R means to take the upper half, keeping columns 4 through 7.
|
||||
L means to take the lower half, keeping columns 4 through 5.
|
||||
The final R keeps the upper of the two, column 5.
|
||||
|
||||
So, decoding FBFBBFFRLR reveals that it is the seat at row 44, column 5.
|
||||
|
||||
Every seat also has a unique seat ID: multiply the row by 8, then add the column. In this example, the seat has ID 44 * 8 + 5 = 357.
|
||||
|
||||
Here are some other boarding passes:
|
||||
|
||||
BFFFBBFRRR: row 70, column 7, seat ID 567.
|
||||
FFFBBBFRRR: row 14, column 7, seat ID 119.
|
||||
BBFFBBFRLL: row 102, column 4, seat ID 820.
|
||||
|
||||
As a sanity check, look through your list of boarding passes. What is the highest seat ID on a boarding pass?
|
||||
|
||||
Your puzzle answer was 838.
|
||||
--- Part Two ---
|
||||
|
||||
Ding! The "fasten seat belt" signs have turned on. Time to find your seat.
|
||||
|
||||
It's a completely full flight, so your seat should be the only missing boarding pass in your list. However, there's a catch: some of the seats at the very front and back of the plane don't exist on this aircraft, so they'll be missing from your list as well.
|
||||
|
||||
Your seat wasn't at the very front or back, though; the seats with IDs +1 and -1 from yours will be in your list.
|
||||
|
||||
What is the ID of your seat?
|
||||
|
||||
Your puzzle answer was 714.
|
||||
|
||||
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 [Share] this puzzle.
|
5
day05/TEST.txt
Normal file
5
day05/TEST.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
FBFBBFFRLR
|
||||
BFFFBBFRRR
|
||||
FFFBBBFRRR
|
||||
BBFFBBFRLL
|
||||
BBBBBBBRRR
|
35
day05/ex1-c.c
Normal file
35
day05/ex1-c.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ex1-c: Advent2020 game, day 4/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int str2int(str)
|
||||
char *str;
|
||||
{
|
||||
int res=0;
|
||||
while (*str) {
|
||||
res <<= 1;
|
||||
if (*str == 'B' || *str == 'R')
|
||||
res ^= 1;
|
||||
str++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
int max=0, cur, count=0;
|
||||
char rowstr[80], colstr[80], line[80];
|
||||
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
count++;
|
||||
sscanf(line, "%[FB]%[RL]", rowstr, colstr);
|
||||
cur=(str2int(rowstr)<<3) ^ str2int(colstr);
|
||||
if (cur > max)
|
||||
max=cur;
|
||||
}
|
||||
printf("%s : lines=%d max=%d\n", *av, count, max);
|
||||
exit (0);
|
||||
}
|
33
day05/ex1.bash
Executable file
33
day05/ex1.bash
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 5/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
|
||||
function rownum() {
|
||||
local val=${1%%???}
|
||||
val=${val//F/0}
|
||||
val=${val//B/1}
|
||||
echo $((2#$val))
|
||||
}
|
||||
function colnum() {
|
||||
local val=${1##???????}
|
||||
val=${val//L/0}
|
||||
val=${val//R/1}
|
||||
echo $((2#$val))
|
||||
}
|
||||
|
||||
declare -i lines=0 max=0 row col res
|
||||
|
||||
while read -r line; do
|
||||
((lines++))
|
||||
row=$(rownum "$line")
|
||||
col=$(colnum "$line")
|
||||
res=$((row * 8 + col))
|
||||
((max < res)) && max=$res
|
||||
#echo "row=$row col=$col res=$res"
|
||||
done
|
||||
printf "%s : lines=%d max=%d\n" "$CMD" "$lines" "$max"
|
||||
|
||||
exit 0
|
53
day05/ex2-c.c
Normal file
53
day05/ex2-c.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* ex1-c: Advent2020 game, day 4/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int seats[128][8];
|
||||
|
||||
int str2int(str)
|
||||
char *str;
|
||||
{
|
||||
int res=0;
|
||||
while (*str) {
|
||||
res <<= 1;
|
||||
if (*str == 'B' || *str == 'R')
|
||||
res ^= 1;
|
||||
str++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void print_seats()
|
||||
{
|
||||
int i, j;
|
||||
printf("seats:\n");
|
||||
for (i=0; i<128; i++) {
|
||||
printf("%03d : ", i);
|
||||
for (j=0; j<8; ++j)
|
||||
printf("%d ", seats[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
int cur, count=0;
|
||||
char rowstr[80], colstr[80], line[80];
|
||||
int *pseats=(int *)seats;
|
||||
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
count++;
|
||||
sscanf(line, "%[FB]%[RL]", rowstr, colstr);
|
||||
cur=(str2int(rowstr)<<3) ^ str2int(colstr);
|
||||
*(pseats+cur)=1;
|
||||
}
|
||||
for (; *pseats == 0; ++pseats)
|
||||
;
|
||||
for (; *pseats == 1; ++pseats)
|
||||
;
|
||||
printf("%s : lines=%d seat=%ld\n", *av, count, pseats-(int *)seats);
|
||||
exit (0);
|
||||
}
|
40
day05/ex2.bash
Executable file
40
day05/ex2.bash
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex2.bash: Advent2020 game, day 5/game 2.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
declare -a seats
|
||||
|
||||
function rownum() {
|
||||
local val=${1%%???}
|
||||
val=${val//F/0}
|
||||
val=${val//B/1}
|
||||
echo $((2#$val))
|
||||
}
|
||||
function colnum() {
|
||||
local val=${1##???????}
|
||||
val=${val//L/0}
|
||||
val=${val//R/1}
|
||||
echo $((2#$val))
|
||||
}
|
||||
|
||||
declare -i lines=0 max=0 row col res next
|
||||
|
||||
while read -r line; do
|
||||
((lines++))
|
||||
row=$(rownum "$line")
|
||||
col=$(colnum "$line")
|
||||
res=$((row * 8 + col))
|
||||
seats[$res]=1
|
||||
#((max < res)) && max=$res
|
||||
#echo "row=$row col=$col res=$res"
|
||||
done
|
||||
|
||||
for seat in ${!seats[@]}; do
|
||||
((next=seat+1))
|
||||
[[ -v seats[$next] ]] || break
|
||||
done
|
||||
printf "%s : lines=%d seat=%d\n" "$CMD" "$lines" "$next"
|
||||
|
||||
exit 0
|
2199
day06/INPUT.txt
Normal file
2199
day06/INPUT.txt
Normal file
File diff suppressed because it is too large
Load Diff
41
day06/Makefile
Normal file
41
day06/Makefile
Normal file
@@ -0,0 +1,41 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
|
||||
ex1: compile
|
||||
@$(TIME) ex1.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex1-bis.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex1-c < $(INPUT) 2>&1
|
||||
|
||||
ex2: compile
|
||||
@$(TIME) ex2.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex2-bis.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex2-c < $(INPUT) 2>&1
|
||||
|
||||
bash:
|
||||
@$(TIME) $(MAKE) --no-print-directory bash-run
|
||||
|
||||
c: compile
|
||||
@$(TIME) $(MAKE) --no-print-directory c-run
|
||||
|
||||
bash-run:
|
||||
@ex1.bash < $(INPUT) 2>&1
|
||||
@ex2.bash < $(INPUT) 2>&1
|
||||
|
||||
c-run:
|
||||
@ex1-c < $(INPUT) 2>&1
|
||||
@ex2-c < $(INPUT) 2>&1
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
24
day06/OUTPUT
Normal file
24
day06/OUTPUT
Normal file
@@ -0,0 +1,24 @@
|
||||
ex1.bash : groups=484 count=6585
|
||||
time: 0:01.42 real, 1.26 user, 0.20 sys
|
||||
context-switch: 135+1393, page-faults: 0+59578
|
||||
|
||||
ex1-bis.bash : groups=484 count=6585
|
||||
time: 0:01.22 real, 1.09 user, 0.16 sys
|
||||
context-switch: 145+1311, page-faults: 0+60076
|
||||
|
||||
ex1-c : groups=484 count=6585
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+71
|
||||
|
||||
ex2.bash : groups=484 count=3276
|
||||
time: 0:01.35 real, 1.18 user, 0.20 sys
|
||||
context-switch: 139+1360, page-faults: 0+59397
|
||||
|
||||
ex2-bis.bash : groups=484 count=3276
|
||||
time: 0:01.30 real, 1.11 user, 0.22 sys
|
||||
context-switch: 112+1356, page-faults: 0+57986
|
||||
|
||||
ex2-c : groups=484 count=3276
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+72
|
||||
|
90
day06/README
Normal file
90
day06/README
Normal file
@@ -0,0 +1,90 @@
|
||||
--- Day 6: Custom Customs ---
|
||||
|
||||
As your flight approaches the regional airport where you'll switch to a much larger plane, customs declaration forms are distributed to the passengers.
|
||||
|
||||
The form asks a series of 26 yes-or-no questions marked a through z. All you need to do is identify the questions for which anyone in your group answers "yes". Since your group is just you, this doesn't take very long.
|
||||
|
||||
However, the person sitting next to you seems to be experiencing a language barrier and asks if you can help. For each of the people in their group, you write down the questions for which they answer "yes", one per line. For example:
|
||||
|
||||
abcx
|
||||
abcy
|
||||
abcz
|
||||
|
||||
In this group, there are 6 questions to which anyone answered "yes": a, b, c, x, y, and z. (Duplicate answers to the same question don't count extra; each question counts at most once.)
|
||||
|
||||
Another group asks for your help, then another, and eventually you've collected answers from every group on the plane (your puzzle input). Each group's answers are separated by a blank line, and within each group, each person's answers are on a single line. For example:
|
||||
|
||||
abc
|
||||
|
||||
a
|
||||
b
|
||||
c
|
||||
|
||||
ab
|
||||
ac
|
||||
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
|
||||
b
|
||||
|
||||
This list represents answers from five groups:
|
||||
|
||||
The first group contains one person who answered "yes" to 3 questions: a, b, and c.
|
||||
The second group contains three people; combined, they answered "yes" to 3 questions: a, b, and c.
|
||||
The third group contains two people; combined, they answered "yes" to 3 questions: a, b, and c.
|
||||
The fourth group contains four people; combined, they answered "yes" to only 1 question, a.
|
||||
The last group contains one person who answered "yes" to only 1 question, b.
|
||||
|
||||
In this example, the sum of these counts is 3 + 3 + 3 + 1 + 1 = 11.
|
||||
|
||||
For each group, count the number of questions to which anyone answered "yes". What is the sum of those counts?
|
||||
|
||||
Your puzzle answer was 6585.
|
||||
--- Part Two ---
|
||||
|
||||
As you finish the last group's customs declaration, you notice that you misread one word in the instructions:
|
||||
|
||||
You don't need to identify the questions to which anyone answered "yes"; you need to identify the questions to which everyone answered "yes"!
|
||||
|
||||
Using the same example as above:
|
||||
|
||||
abc
|
||||
|
||||
a
|
||||
b
|
||||
c
|
||||
|
||||
ab
|
||||
ac
|
||||
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
|
||||
b
|
||||
|
||||
This list represents answers from five groups:
|
||||
|
||||
In the first group, everyone (all 1 person) answered "yes" to 3 questions: a, b, and c.
|
||||
In the second group, there is no question to which everyone answered "yes".
|
||||
In the third group, everyone answered yes to only 1 question, a. Since some people did not answer "yes" to b or c, they don't count.
|
||||
In the fourth group, everyone answered yes to only 1 question, a.
|
||||
In the fifth group, everyone (all 1 person) answered "yes" to 1 question, b.
|
||||
|
||||
In this example, the sum of these counts is 3 + 0 + 1 + 1 + 1 = 6.
|
||||
|
||||
For each group, count the number of questions to which everyone answered "yes". What is the sum of those counts?
|
||||
|
||||
Your puzzle answer was 3276.
|
||||
|
||||
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 [Share] this puzzle.
|
15
day06/TEST.txt
Normal file
15
day06/TEST.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
abc
|
||||
|
||||
a
|
||||
b
|
||||
c
|
||||
|
||||
ab
|
||||
ac
|
||||
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
|
||||
b
|
4
day06/bash.sh
Executable file
4
day06/bash.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#! /bin/bash
|
||||
PATH=.:$PATH
|
||||
IN="$1"
|
||||
time { ex1.bash < $IN; ex2.bash < $IN; } 2>&1
|
5
day06/c.sh
Executable file
5
day06/c.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#! /bin/bash
|
||||
PATH=.:$PATH
|
||||
IN="$1"
|
||||
echo IN=$IN
|
||||
time for i in ex1-c ex2-c; do "$i" < "$IN"; done 2>&1
|
73
day06/ex1-bis.bash
Executable file
73
day06/ex1-bis.bash
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 6/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
declare -a Q=()
|
||||
|
||||
printf -v AC "%d" "'a"
|
||||
printf -v ZC "%d" "'z"
|
||||
(( NC = ZC-AC+1 ))
|
||||
|
||||
function reset_array() {
|
||||
Q=()
|
||||
#for (( elt=AC; elt<=ZC; ++elt )); do
|
||||
# Q[$elt]=0
|
||||
#done
|
||||
}
|
||||
function count_array() {
|
||||
#local -i count
|
||||
echo ${#Q[@]}
|
||||
#for ${!Q[@]}; do
|
||||
# ((Q[elt] > 0)) && ((count++))
|
||||
# #printf "%d=%d (%d)" "$elt" "${Q[$elt]}" "$count"
|
||||
#done
|
||||
#echo $count
|
||||
}
|
||||
|
||||
function set_array() {
|
||||
local str="$1"
|
||||
local c asc
|
||||
|
||||
for ((i=0; i<${#str}; ++i)); do
|
||||
c=${str:$i:1}
|
||||
if [[ "$c" =~ [a-z] ]]; then
|
||||
printf -v asc "%d" "'$c"
|
||||
Q[$asc]=1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
declare -i people=0 group=0 count=0
|
||||
declare line grouped
|
||||
function calcgroup() {
|
||||
set_array "$grouped"
|
||||
((group++))
|
||||
i=$(count_array)
|
||||
#printf "c=%d" $i
|
||||
((count += i))
|
||||
((people=0))
|
||||
grouped=""
|
||||
reset_array
|
||||
}
|
||||
|
||||
while read -r line; do
|
||||
if [[ -z "$line" ]]; then
|
||||
#echo "G=$grouped"
|
||||
#set_array "$grouped"
|
||||
calcgroup
|
||||
#for (( elt=AC; elt<=ZC; ++elt )); do
|
||||
#printf "%s=%s " "$elt" "${Q[$elt]}"
|
||||
#done
|
||||
#echo
|
||||
continue
|
||||
fi
|
||||
((people++))
|
||||
grouped+="$line"
|
||||
done
|
||||
calcgroup
|
||||
|
||||
printf "%s : groups=%d count=%d\n" "$CMD" $group $count
|
||||
|
||||
exit 0
|
78
day06/ex1-c.c
Normal file
78
day06/ex1-c.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/* ex1-c: Advent2020 game, day 4/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define QSIZE ('z'-'a'+1)
|
||||
static int Q[QSIZE];
|
||||
|
||||
void reset_array(){
|
||||
int i;
|
||||
for (i=0; i<QSIZE; ++i)
|
||||
Q[i]=0;
|
||||
}
|
||||
|
||||
void print_array()
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<QSIZE; i++) {
|
||||
printf("%d ", Q[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void set_array(str)
|
||||
char *str;
|
||||
{
|
||||
for (; *str; str++) {
|
||||
if (*str >= 'a' && *str <= 'z')
|
||||
Q[*str-'a']++;
|
||||
}
|
||||
}
|
||||
|
||||
int count_array ()
|
||||
{
|
||||
int count=0, i;
|
||||
for (i=0; i<QSIZE; ++i) {
|
||||
if (Q[i] > 0)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void calcgroup(group, count, people)
|
||||
int *group, *count, *people;
|
||||
{
|
||||
(*group)++;
|
||||
*count += count_array();
|
||||
*people=0;
|
||||
reset_array();
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
int people=0, group=0, count=0;
|
||||
char line[80];
|
||||
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
if (*line == '\n') {
|
||||
calcgroup(&group, &count, &people);
|
||||
continue;
|
||||
}
|
||||
people++;
|
||||
set_array(line);
|
||||
//sscanf(line, "%[FB]%[RL]", rowstr, colstr);
|
||||
//cur=(str2int(rowstr)<<3) ^ str2int(colstr);
|
||||
// *(pseats+cur)=1;
|
||||
}
|
||||
//for (; *pseats == 0; ++pseats)
|
||||
// ;
|
||||
//for (; *pseats == 1; ++pseats)
|
||||
// ;
|
||||
//printf("%s : lines=%d seat=%ld\n", *av, count, pseats-(int *)seats);
|
||||
calcgroup(&group, &count, &people);
|
||||
printf("%s : groups=%d count=%d\n", *av, group, count);
|
||||
exit (0);
|
||||
}
|
55
day06/ex1.bash
Executable file
55
day06/ex1.bash
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 6/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
declare -A Q=()
|
||||
|
||||
function reset_array() {
|
||||
for elt in {a..z}; do
|
||||
Q[$elt]=0
|
||||
done
|
||||
}
|
||||
function count_array() {
|
||||
local -i count
|
||||
for elt in "${!Q[@]}"; do
|
||||
(( Q[$elt] > 0 )) && ((count++))
|
||||
done
|
||||
echo $count
|
||||
}
|
||||
|
||||
function set_array() {
|
||||
local str="$1"
|
||||
local c
|
||||
|
||||
for ((i=0; i<${#str}; ++i)); do
|
||||
c=${str:$i:1}
|
||||
if [[ "$c" =~ [a-z] ]]; then
|
||||
Q[$c]=1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
declare -i people=0 group=0 count=0
|
||||
|
||||
function calcgroup() {
|
||||
((group++))
|
||||
((count += $(count_array)))
|
||||
((people=0))
|
||||
reset_array
|
||||
}
|
||||
|
||||
while read -r line; do
|
||||
if [[ -z "$line" ]]; then
|
||||
calcgroup
|
||||
continue
|
||||
fi
|
||||
((people++))
|
||||
set_array "$line"
|
||||
done
|
||||
calcgroup
|
||||
|
||||
printf "%s : groups=%d count=%d\n" "$CMD" $group $count
|
||||
|
||||
exit 0
|
59
day06/ex2-bis.bash
Executable file
59
day06/ex2-bis.bash
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 6/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
declare -A Q=()
|
||||
|
||||
function reset_array() {
|
||||
Q=()
|
||||
#for elt in {a..z}; do
|
||||
# Q[$elt]=0
|
||||
#done
|
||||
}
|
||||
function count_array() {
|
||||
local -i count=0 people="$1"
|
||||
for elt in "${!Q[@]}"; do
|
||||
if (( Q[$elt] == people )); then
|
||||
((count++))
|
||||
fi
|
||||
done
|
||||
echo $count
|
||||
}
|
||||
function set_array() {
|
||||
local str="$1"
|
||||
local c
|
||||
|
||||
for ((i=0; i<${#str}; ++i)); do
|
||||
c=${str:$i:1}
|
||||
if [[ "$c" =~ [a-z] ]]; then
|
||||
(( Q[$c]++ ))
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
declare -i people=0 group=0 count=0
|
||||
|
||||
function calcgroup() {
|
||||
local -i i
|
||||
i=$(count_array $people)
|
||||
((group++))
|
||||
(( count += i ))
|
||||
((people=0))
|
||||
reset_array
|
||||
}
|
||||
|
||||
while read -r line; do
|
||||
if [[ -z "$line" ]]; then
|
||||
calcgroup
|
||||
continue
|
||||
fi
|
||||
((people++))
|
||||
set_array "$line"
|
||||
done
|
||||
calcgroup
|
||||
|
||||
printf "%s : groups=%d count=%d\n" "$CMD" $group $count
|
||||
|
||||
exit 0
|
79
day06/ex2-c.c
Normal file
79
day06/ex2-c.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/* ex1-c: Advent2020 game, day 4/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define QSIZE ('z'-'a'+1)
|
||||
static int Q[QSIZE];
|
||||
|
||||
void reset_array(){
|
||||
int i;
|
||||
for (i=0; i<QSIZE; ++i)
|
||||
Q[i]=0;
|
||||
}
|
||||
|
||||
void print_array()
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<QSIZE; i++) {
|
||||
printf("%d ", Q[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void set_array(str)
|
||||
char *str;
|
||||
{
|
||||
for (; *str; str++) {
|
||||
if (*str >= 'a' && *str <= 'z')
|
||||
Q[*str-'a']++;
|
||||
}
|
||||
}
|
||||
|
||||
int count_array (people)
|
||||
int people;
|
||||
{
|
||||
int count=0, i;
|
||||
for (i=0; i<QSIZE; ++i) {
|
||||
if (Q[i] == people)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void calcgroup(group, count, people)
|
||||
int *group, *count, *people;
|
||||
{
|
||||
(*group)++;
|
||||
*count += count_array(*people);
|
||||
*people=0;
|
||||
reset_array();
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
int people=0, group=0, count=0;
|
||||
char line[80];
|
||||
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
if (*line == '\n') {
|
||||
calcgroup(&group, &count, &people);
|
||||
continue;
|
||||
}
|
||||
people++;
|
||||
set_array(line);
|
||||
//sscanf(line, "%[FB]%[RL]", rowstr, colstr);
|
||||
//cur=(str2int(rowstr)<<3) ^ str2int(colstr);
|
||||
// *(pseats+cur)=1;
|
||||
}
|
||||
//for (; *pseats == 0; ++pseats)
|
||||
// ;
|
||||
//for (; *pseats == 1; ++pseats)
|
||||
// ;
|
||||
//printf("%s : lines=%d seat=%ld\n", *av, count, pseats-(int *)seats);
|
||||
calcgroup(&group, &count, &people);
|
||||
printf("%s : groups=%d count=%d\n", *av, group, count);
|
||||
exit (0);
|
||||
}
|
58
day06/ex2.bash
Executable file
58
day06/ex2.bash
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 6/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
declare -A Q=()
|
||||
|
||||
function reset_array() {
|
||||
for elt in {a..z}; do
|
||||
Q[$elt]=0
|
||||
done
|
||||
}
|
||||
function count_array() {
|
||||
local -i count=0 people="$1"
|
||||
for elt in "${!Q[@]}"; do
|
||||
if (( Q[$elt] == people )); then
|
||||
((count++))
|
||||
fi
|
||||
done
|
||||
echo $count
|
||||
}
|
||||
function set_array() {
|
||||
local str="$1"
|
||||
local c
|
||||
|
||||
for ((i=0; i<${#str}; ++i)); do
|
||||
c=${str:$i:1}
|
||||
if [[ "$c" =~ [a-z] ]]; then
|
||||
(( Q[$c]++ ))
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
declare -i people=0 group=0 count=0
|
||||
|
||||
function calcgroup() {
|
||||
local -i i
|
||||
i=$(count_array $people)
|
||||
((group++))
|
||||
(( count += i ))
|
||||
((people=0))
|
||||
reset_array
|
||||
}
|
||||
|
||||
while read -r line; do
|
||||
if [[ -z "$line" ]]; then
|
||||
calcgroup
|
||||
continue
|
||||
fi
|
||||
((people++))
|
||||
set_array "$line"
|
||||
done
|
||||
calcgroup
|
||||
|
||||
printf "%s : groups=%d count=%d\n" "$CMD" $group $count
|
||||
|
||||
exit 0
|
594
day07/INPUT.txt
Normal file
594
day07/INPUT.txt
Normal file
@@ -0,0 +1,594 @@
|
||||
bright gray bags contain 2 bright gold bags, 5 dull lavender bags.
|
||||
pale olive bags contain 1 bright yellow bag, 1 mirrored salmon bag.
|
||||
mirrored magenta bags contain 4 shiny turquoise bags, 2 bright gold bags, 4 plaid fuchsia bags, 4 wavy lime bags.
|
||||
shiny blue bags contain 3 dim plum bags, 4 bright blue bags, 5 plaid fuchsia bags.
|
||||
dotted beige bags contain 5 faded bronze bags, 1 posh olive bag, 5 dark magenta bags, 2 plaid lime bags.
|
||||
drab tomato bags contain 4 faded fuchsia bags, 4 plaid beige bags, 4 clear red bags.
|
||||
drab blue bags contain 3 light beige bags, 4 dark gray bags.
|
||||
striped beige bags contain 1 wavy coral bag, 5 light salmon bags, 5 dark black bags.
|
||||
dull gold bags contain 5 light gold bags, 4 bright silver bags.
|
||||
wavy red bags contain 4 bright gray bags, 1 striped green bag.
|
||||
pale white bags contain 2 plaid fuchsia bags, 3 shiny blue bags, 1 pale black bag, 3 dull purple bags.
|
||||
bright orange bags contain 5 dim bronze bags.
|
||||
plaid yellow bags contain 3 light beige bags.
|
||||
clear red bags contain 2 bright white bags, 5 light orange bags, 3 clear purple bags.
|
||||
light tomato bags contain 1 plaid fuchsia bag, 5 dark gray bags, 2 striped tan bags, 5 striped lavender bags.
|
||||
pale yellow bags contain 3 clear indigo bags.
|
||||
shiny red bags contain 5 bright violet bags, 2 striped cyan bags, 2 bright silver bags, 5 clear indigo bags.
|
||||
bright maroon bags contain 2 posh aqua bags, 1 plaid purple bag, 5 dull lavender bags, 4 faded turquoise bags.
|
||||
dark crimson bags contain 1 plaid chartreuse bag.
|
||||
pale red bags contain 1 faded lavender bag.
|
||||
shiny lavender bags contain 2 light orange bags.
|
||||
dotted blue bags contain 3 clear turquoise bags, 2 shiny silver bags.
|
||||
bright lime bags contain 5 mirrored plum bags, 2 dim blue bags, 4 light brown bags, 2 vibrant lavender bags.
|
||||
bright lavender bags contain 5 posh gray bags.
|
||||
faded purple bags contain 5 muted tan bags, 2 bright salmon bags, 2 shiny olive bags.
|
||||
pale aqua bags contain 4 clear black bags, 4 posh indigo bags.
|
||||
wavy cyan bags contain 5 faded green bags, 1 wavy lime bag.
|
||||
dull maroon bags contain 5 light indigo bags, 1 clear purple bag, 3 dark salmon bags.
|
||||
muted fuchsia bags contain 5 dotted silver bags, 4 plaid tomato bags, 2 drab olive bags, 4 vibrant tomato bags.
|
||||
clear salmon bags contain 3 faded tomato bags, 1 dull crimson bag.
|
||||
drab maroon bags contain 4 dotted blue bags, 1 dotted violet bag.
|
||||
posh blue bags contain 3 dotted bronze bags, 5 shiny chartreuse bags, 4 vibrant tan bags.
|
||||
shiny gold bags contain 1 plaid tan bag, 3 light beige bags, 1 posh brown bag.
|
||||
light lavender bags contain 3 posh maroon bags, 2 plaid beige bags, 1 dark gray bag, 5 muted bronze bags.
|
||||
pale violet bags contain 5 dull beige bags, 3 clear orange bags.
|
||||
bright gold bags contain no other bags.
|
||||
wavy maroon bags contain 4 faded olive bags.
|
||||
wavy salmon bags contain 1 posh indigo bag, 1 clear fuchsia bag.
|
||||
vibrant orange bags contain 3 plaid tan bags, 4 dotted blue bags, 3 bright gold bags, 3 bright white bags.
|
||||
vibrant green bags contain 5 muted indigo bags, 4 muted aqua bags, 1 muted plum bag, 3 posh salmon bags.
|
||||
striped tan bags contain 1 plaid beige bag, 4 shiny bronze bags, 5 muted bronze bags, 4 clear indigo bags.
|
||||
wavy silver bags contain 4 muted fuchsia bags, 3 muted indigo bags, 1 vibrant cyan bag.
|
||||
pale beige bags contain 1 dim lavender bag, 1 clear lime bag, 4 faded lavender bags, 3 dull green bags.
|
||||
mirrored brown bags contain 1 plaid gray bag, 5 drab plum bags.
|
||||
faded green bags contain 5 light yellow bags, 2 plaid fuchsia bags, 1 drab magenta bag, 1 muted bronze bag.
|
||||
posh red bags contain 5 plaid magenta bags, 4 striped brown bags.
|
||||
wavy turquoise bags contain 2 posh coral bags, 3 faded violet bags, 4 striped green bags.
|
||||
drab indigo bags contain 2 mirrored red bags, 1 plaid blue bag.
|
||||
shiny black bags contain 3 clear crimson bags, 4 vibrant purple bags, 2 drab salmon bags.
|
||||
wavy fuchsia bags contain 4 wavy magenta bags, 5 plaid chartreuse bags, 4 posh salmon bags, 4 dull teal bags.
|
||||
clear teal bags contain 4 dark aqua bags.
|
||||
posh tan bags contain 2 clear silver bags, 1 faded coral bag.
|
||||
plaid lime bags contain 1 wavy lime bag.
|
||||
vibrant tomato bags contain 5 clear green bags, 3 posh olive bags, 5 mirrored beige bags.
|
||||
dull crimson bags contain 5 shiny blue bags, 5 dark magenta bags, 4 dim plum bags, 2 light lavender bags.
|
||||
dotted salmon bags contain 1 light maroon bag, 2 posh aqua bags, 2 light magenta bags.
|
||||
striped orange bags contain no other bags.
|
||||
vibrant bronze bags contain 4 shiny black bags, 1 bright crimson bag.
|
||||
posh black bags contain 4 shiny turquoise bags, 2 muted indigo bags.
|
||||
dim gray bags contain 2 plaid purple bags, 3 bright blue bags, 2 plaid beige bags.
|
||||
pale chartreuse bags contain 5 dull beige bags.
|
||||
wavy green bags contain 2 drab tomato bags, 3 faded yellow bags, 5 posh aqua bags.
|
||||
striped red bags contain 3 posh green bags, 1 plaid red bag, 2 muted white bags, 4 dull teal bags.
|
||||
muted black bags contain 4 dark gray bags, 2 plaid fuchsia bags, 4 shiny purple bags, 2 wavy aqua bags.
|
||||
vibrant gray bags contain 5 drab bronze bags, 2 muted black bags, 2 clear lime bags.
|
||||
dotted plum bags contain 4 shiny silver bags, 3 light maroon bags, 4 bright white bags.
|
||||
mirrored salmon bags contain 2 plaid gold bags.
|
||||
mirrored orange bags contain 3 pale bronze bags.
|
||||
dark gold bags contain 3 light yellow bags.
|
||||
muted orange bags contain 5 dark black bags, 2 bright crimson bags, 1 posh bronze bag.
|
||||
posh aqua bags contain 3 plaid purple bags.
|
||||
dotted lime bags contain 3 shiny yellow bags, 4 dull brown bags, 2 dark gray bags.
|
||||
drab lime bags contain 3 wavy beige bags, 3 dull purple bags, 4 clear tan bags, 4 muted indigo bags.
|
||||
bright blue bags contain 5 plaid teal bags.
|
||||
light orange bags contain 2 plaid tan bags, 2 striped orange bags, 3 clear indigo bags.
|
||||
dark chartreuse bags contain 3 muted teal bags, 5 faded tomato bags.
|
||||
clear gray bags contain 5 bright bronze bags, 1 mirrored cyan bag.
|
||||
vibrant lime bags contain 4 striped green bags, 5 dotted lavender bags.
|
||||
light black bags contain 5 dark tan bags, 3 light magenta bags, 2 clear green bags, 4 dull lavender bags.
|
||||
clear gold bags contain 4 dotted bronze bags.
|
||||
light aqua bags contain 1 posh chartreuse bag, 4 mirrored silver bags, 1 dotted gray bag.
|
||||
mirrored tan bags contain 3 bright chartreuse bags, 5 dull olive bags, 2 bright white bags.
|
||||
faded tomato bags contain 3 faded coral bags, 3 wavy blue bags, 3 light lime bags.
|
||||
drab chartreuse bags contain 1 shiny red bag, 1 dotted violet bag.
|
||||
striped tomato bags contain 2 wavy yellow bags.
|
||||
clear white bags contain 2 drab bronze bags, 3 clear gray bags, 2 posh white bags.
|
||||
shiny plum bags contain 5 dim plum bags, 1 wavy beige bag, 1 faded fuchsia bag, 3 plaid white bags.
|
||||
plaid violet bags contain 3 posh coral bags, 5 dim gray bags, 3 dim plum bags, 3 dull purple bags.
|
||||
dotted magenta bags contain 4 dotted salmon bags.
|
||||
mirrored cyan bags contain 3 dark salmon bags, 5 muted teal bags, 2 faded white bags, 4 vibrant fuchsia bags.
|
||||
muted teal bags contain 2 faded violet bags, 4 dull cyan bags.
|
||||
striped maroon bags contain 1 mirrored olive bag.
|
||||
mirrored turquoise bags contain 3 plaid fuchsia bags, 3 mirrored cyan bags, 1 dull black bag.
|
||||
shiny silver bags contain no other bags.
|
||||
striped green bags contain 1 wavy teal bag, 2 vibrant indigo bags, 2 dark lime bags.
|
||||
striped silver bags contain 4 bright yellow bags, 5 faded coral bags.
|
||||
wavy olive bags contain 4 posh gray bags, 5 dark cyan bags.
|
||||
clear brown bags contain 3 dull lavender bags, 4 dim gold bags.
|
||||
bright turquoise bags contain 3 faded lavender bags, 3 posh silver bags.
|
||||
muted tan bags contain 4 dim plum bags, 2 faded coral bags.
|
||||
dull green bags contain 1 shiny plum bag, 1 drab fuchsia bag, 5 dark white bags, 3 drab magenta bags.
|
||||
drab yellow bags contain 5 posh silver bags, 2 clear violet bags, 4 dull teal bags, 2 dotted salmon bags.
|
||||
plaid aqua bags contain 2 faded beige bags.
|
||||
vibrant chartreuse bags contain 2 wavy olive bags, 3 dotted salmon bags.
|
||||
light chartreuse bags contain 2 muted orange bags, 3 dotted black bags, 2 striped lavender bags, 4 striped red bags.
|
||||
vibrant tan bags contain 1 bright violet bag, 1 clear magenta bag, 4 dark orange bags.
|
||||
posh turquoise bags contain 5 bright gold bags, 3 striped violet bags.
|
||||
dotted fuchsia bags contain 5 faded lavender bags, 2 bright crimson bags, 5 muted yellow bags.
|
||||
dark turquoise bags contain 2 vibrant indigo bags, 5 dull tan bags.
|
||||
dotted chartreuse bags contain 5 pale red bags.
|
||||
light lime bags contain 4 bright gold bags, 5 shiny silver bags, 3 posh brown bags, 3 striped orange bags.
|
||||
mirrored teal bags contain 5 striped silver bags, 5 posh cyan bags, 4 light tomato bags, 4 dim gray bags.
|
||||
vibrant turquoise bags contain 2 drab plum bags, 4 dark blue bags, 2 dim violet bags, 2 plaid blue bags.
|
||||
clear blue bags contain 1 wavy indigo bag, 3 dotted yellow bags, 5 drab plum bags, 5 posh white bags.
|
||||
striped blue bags contain 1 wavy blue bag, 1 striped indigo bag, 4 dull black bags, 3 muted silver bags.
|
||||
muted silver bags contain 4 muted yellow bags, 1 plaid silver bag, 1 light lavender bag, 1 dotted blue bag.
|
||||
dotted indigo bags contain 5 clear tomato bags, 4 bright magenta bags, 5 dark crimson bags.
|
||||
vibrant teal bags contain 3 striped lavender bags, 4 wavy beige bags, 2 dull indigo bags.
|
||||
striped chartreuse bags contain 5 clear silver bags, 3 drab yellow bags, 5 striped indigo bags, 1 faded turquoise bag.
|
||||
dotted violet bags contain 5 dark plum bags, 5 dark white bags.
|
||||
light brown bags contain 3 faded tomato bags, 5 dark bronze bags, 3 shiny turquoise bags, 2 striped violet bags.
|
||||
posh indigo bags contain 2 vibrant coral bags, 2 wavy maroon bags, 4 drab coral bags, 2 clear fuchsia bags.
|
||||
drab violet bags contain 5 drab tomato bags, 1 light silver bag, 5 wavy beige bags.
|
||||
plaid plum bags contain 1 dull magenta bag, 3 dark black bags.
|
||||
dotted orange bags contain 5 mirrored crimson bags.
|
||||
dotted teal bags contain 3 clear silver bags.
|
||||
vibrant brown bags contain 5 vibrant indigo bags.
|
||||
clear orange bags contain 1 clear turquoise bag.
|
||||
bright magenta bags contain 1 dark orange bag, 2 dotted purple bags, 1 mirrored white bag, 5 vibrant yellow bags.
|
||||
clear tan bags contain 2 striped orange bags.
|
||||
dotted brown bags contain 2 mirrored coral bags, 4 wavy magenta bags, 2 pale purple bags, 1 drab black bag.
|
||||
vibrant plum bags contain 1 dotted teal bag.
|
||||
light indigo bags contain 5 light black bags, 1 vibrant purple bag, 3 muted olive bags, 4 mirrored brown bags.
|
||||
bright chartreuse bags contain 3 dull lime bags.
|
||||
clear turquoise bags contain 4 pale black bags, 5 plaid purple bags, 4 bright gold bags.
|
||||
dim crimson bags contain 3 wavy lime bags.
|
||||
pale tan bags contain 3 mirrored white bags, 3 drab bronze bags, 2 drab black bags.
|
||||
plaid gold bags contain 5 striped orange bags.
|
||||
striped crimson bags contain 1 muted brown bag, 4 drab red bags, 1 faded crimson bag.
|
||||
clear lavender bags contain 1 bright salmon bag, 2 clear teal bags, 4 drab plum bags.
|
||||
dark maroon bags contain 2 striped purple bags, 1 bright aqua bag, 3 faded white bags, 5 bright yellow bags.
|
||||
drab gray bags contain 5 posh silver bags, 2 bright chartreuse bags, 2 dim purple bags, 5 faded brown bags.
|
||||
faded olive bags contain 2 shiny turquoise bags, 5 drab green bags, 4 light maroon bags.
|
||||
muted gray bags contain 2 dim maroon bags, 5 muted tan bags, 3 faded salmon bags, 5 faded white bags.
|
||||
posh violet bags contain 2 faded crimson bags.
|
||||
shiny white bags contain 1 dark chartreuse bag, 5 posh green bags.
|
||||
mirrored indigo bags contain 5 clear purple bags, 3 dark turquoise bags, 3 clear aqua bags, 2 bright gray bags.
|
||||
dark brown bags contain 4 wavy gold bags.
|
||||
muted tomato bags contain 4 clear violet bags.
|
||||
striped black bags contain 4 plaid white bags, 3 dull tan bags.
|
||||
shiny crimson bags contain 2 plaid teal bags.
|
||||
bright coral bags contain 2 clear plum bags, 2 faded orange bags, 3 mirrored silver bags.
|
||||
dark yellow bags contain 1 plaid olive bag, 3 dotted white bags.
|
||||
faded beige bags contain 5 posh aqua bags, 1 pale purple bag.
|
||||
wavy magenta bags contain 3 dull yellow bags, 5 faded cyan bags.
|
||||
wavy bronze bags contain 5 dull lime bags.
|
||||
dim lavender bags contain 3 plaid red bags, 3 bright brown bags.
|
||||
dim indigo bags contain 3 dim violet bags, 4 bright silver bags.
|
||||
posh green bags contain 4 drab white bags, 3 plaid tan bags, 1 light orange bag.
|
||||
pale gray bags contain 1 muted indigo bag, 2 dotted fuchsia bags.
|
||||
mirrored gold bags contain 2 striped beige bags, 3 bright plum bags.
|
||||
striped white bags contain 5 dark blue bags, 5 dotted purple bags, 4 clear maroon bags.
|
||||
drab cyan bags contain 3 dotted white bags.
|
||||
vibrant aqua bags contain 4 posh yellow bags, 1 drab tomato bag.
|
||||
light gold bags contain 2 vibrant purple bags, 5 light black bags.
|
||||
dotted yellow bags contain 5 striped lavender bags, 2 posh aqua bags, 2 clear green bags, 2 dull green bags.
|
||||
vibrant cyan bags contain 2 dark gray bags, 2 dark lavender bags, 1 striped red bag, 2 striped indigo bags.
|
||||
posh yellow bags contain 3 wavy olive bags, 2 bright gray bags, 2 posh gray bags, 2 vibrant white bags.
|
||||
faded salmon bags contain 4 plaid beige bags, 1 drab teal bag.
|
||||
bright purple bags contain 1 faded white bag, 3 plaid teal bags, 3 light lime bags, 1 pale purple bag.
|
||||
dotted purple bags contain 3 mirrored salmon bags, 3 drab olive bags.
|
||||
plaid red bags contain 5 faded violet bags, 5 dotted white bags.
|
||||
vibrant maroon bags contain 3 faded green bags, 3 bright chartreuse bags, 4 clear orange bags, 2 dim tomato bags.
|
||||
clear crimson bags contain 1 vibrant purple bag, 5 light beige bags, 5 vibrant olive bags.
|
||||
clear cyan bags contain 1 posh plum bag, 2 vibrant chartreuse bags, 5 plaid silver bags.
|
||||
vibrant salmon bags contain 2 striped brown bags.
|
||||
striped olive bags contain 2 muted indigo bags.
|
||||
dim turquoise bags contain 3 striped violet bags, 1 wavy blue bag.
|
||||
bright brown bags contain 1 shiny yellow bag.
|
||||
mirrored tomato bags contain 1 bright violet bag, 1 faded green bag, 3 dotted gray bags, 3 muted silver bags.
|
||||
dark green bags contain 1 dull olive bag.
|
||||
wavy white bags contain 4 bright silver bags, 5 vibrant tomato bags, 2 vibrant salmon bags, 4 clear tomato bags.
|
||||
shiny green bags contain 1 dotted white bag.
|
||||
dotted aqua bags contain 1 faded lavender bag, 1 pale coral bag, 1 clear silver bag.
|
||||
shiny aqua bags contain 1 plaid white bag, 4 clear lime bags.
|
||||
dark lavender bags contain 3 bright aqua bags, 3 mirrored salmon bags, 5 pale red bags, 1 pale purple bag.
|
||||
dull violet bags contain 5 wavy gold bags, 1 shiny cyan bag, 5 plaid beige bags.
|
||||
drab tan bags contain 2 drab crimson bags, 1 drab cyan bag, 5 striped tan bags, 3 dotted fuchsia bags.
|
||||
plaid turquoise bags contain 1 posh silver bag, 4 posh turquoise bags, 5 posh tan bags.
|
||||
pale lavender bags contain 3 plaid gold bags, 5 pale gray bags, 4 dotted plum bags, 3 mirrored crimson bags.
|
||||
clear indigo bags contain 5 pale purple bags.
|
||||
wavy purple bags contain 3 bright yellow bags, 1 wavy gold bag, 3 light lavender bags.
|
||||
shiny salmon bags contain 3 light orange bags.
|
||||
mirrored crimson bags contain 4 dull salmon bags, 4 light yellow bags, 3 dark gray bags, 4 dotted blue bags.
|
||||
plaid chartreuse bags contain 2 shiny turquoise bags.
|
||||
pale orange bags contain 2 muted lavender bags.
|
||||
dark cyan bags contain 5 bright lavender bags, 3 wavy black bags, 2 shiny plum bags, 3 dim aqua bags.
|
||||
dim brown bags contain 1 shiny yellow bag, 2 posh plum bags, 3 muted black bags, 4 light white bags.
|
||||
pale blue bags contain 1 faded cyan bag, 3 faded crimson bags, 1 wavy indigo bag, 3 dark plum bags.
|
||||
vibrant red bags contain 5 plaid aqua bags, 2 clear fuchsia bags.
|
||||
dark salmon bags contain 4 striped violet bags.
|
||||
bright black bags contain 1 faded silver bag.
|
||||
vibrant white bags contain 2 vibrant yellow bags, 3 shiny plum bags.
|
||||
muted violet bags contain 4 pale lavender bags, 4 pale purple bags.
|
||||
wavy coral bags contain 5 vibrant tomato bags.
|
||||
striped salmon bags contain 3 dull magenta bags.
|
||||
faded blue bags contain 2 bright salmon bags, 2 clear salmon bags, 4 striped indigo bags.
|
||||
dim violet bags contain 1 striped brown bag, 5 bright blue bags, 4 bright bronze bags, 5 dull salmon bags.
|
||||
faded chartreuse bags contain 2 muted tan bags, 1 plaid aqua bag, 4 dotted white bags.
|
||||
posh silver bags contain 4 dull salmon bags.
|
||||
dim red bags contain 1 faded black bag, 2 dark aqua bags, 2 drab crimson bags, 5 dotted aqua bags.
|
||||
dull lime bags contain 3 pale indigo bags, 5 bright gold bags, 5 light orange bags.
|
||||
striped fuchsia bags contain 3 clear violet bags, 2 light fuchsia bags, 1 plaid red bag, 3 wavy aqua bags.
|
||||
vibrant lavender bags contain 1 dark teal bag, 1 dark beige bag, 4 dark cyan bags.
|
||||
dark gray bags contain 5 drab magenta bags, 3 muted bronze bags, 5 posh gray bags, 2 shiny silver bags.
|
||||
drab lavender bags contain 4 pale indigo bags, 4 bright salmon bags, 3 posh aqua bags, 4 bright lavender bags.
|
||||
mirrored white bags contain 3 striped black bags.
|
||||
bright aqua bags contain 4 plaid tomato bags, 3 clear fuchsia bags, 1 light silver bag.
|
||||
dark silver bags contain 3 bright tomato bags.
|
||||
drab fuchsia bags contain 5 dotted plum bags, 2 posh aqua bags, 2 clear red bags, 1 dark gray bag.
|
||||
bright teal bags contain 3 vibrant tan bags.
|
||||
striped indigo bags contain 5 wavy plum bags, 2 wavy lavender bags, 4 mirrored beige bags, 4 clear green bags.
|
||||
dark white bags contain 4 striped brown bags, 4 plaid teal bags, 2 posh brown bags, 2 wavy blue bags.
|
||||
mirrored maroon bags contain 2 clear cyan bags, 4 shiny aqua bags.
|
||||
wavy tan bags contain 5 bright maroon bags, 1 clear teal bag.
|
||||
wavy lime bags contain 3 pale purple bags, 5 plaid teal bags, 5 bright gold bags, 3 clear turquoise bags.
|
||||
dark plum bags contain 1 dotted orange bag.
|
||||
posh cyan bags contain 1 light lavender bag, 1 dark orange bag, 2 dull lime bags.
|
||||
pale crimson bags contain 3 faded fuchsia bags, 4 drab orange bags.
|
||||
clear yellow bags contain 4 posh tan bags.
|
||||
striped yellow bags contain 2 muted red bags, 1 light silver bag, 5 mirrored chartreuse bags.
|
||||
clear silver bags contain 2 dull lavender bags, 3 faded fuchsia bags.
|
||||
drab red bags contain 3 clear orange bags.
|
||||
dotted turquoise bags contain 4 bright lavender bags.
|
||||
striped purple bags contain 1 shiny plum bag, 2 clear orange bags, 3 mirrored turquoise bags, 3 striped orange bags.
|
||||
striped gray bags contain 1 posh silver bag.
|
||||
clear purple bags contain 4 muted bronze bags, 3 shiny silver bags, 4 pale salmon bags, 3 plaid fuchsia bags.
|
||||
light gray bags contain 5 dark fuchsia bags.
|
||||
dull tan bags contain 1 plaid fuchsia bag.
|
||||
muted blue bags contain 5 dark plum bags, 4 wavy chartreuse bags, 2 drab green bags.
|
||||
dull brown bags contain 1 pale gold bag.
|
||||
bright fuchsia bags contain 1 pale bronze bag, 2 bright yellow bags, 4 drab gold bags.
|
||||
plaid purple bags contain no other bags.
|
||||
drab silver bags contain 3 wavy blue bags, 2 wavy black bags, 2 dark olive bags.
|
||||
light salmon bags contain 5 wavy plum bags, 4 drab white bags, 5 muted bronze bags, 5 mirrored beige bags.
|
||||
drab beige bags contain 2 bright silver bags, 1 striped blue bag, 2 wavy white bags, 1 plaid lavender bag.
|
||||
posh beige bags contain 3 dotted tomato bags, 5 wavy chartreuse bags.
|
||||
muted cyan bags contain 4 dim bronze bags, 5 muted white bags, 3 pale black bags, 2 shiny silver bags.
|
||||
dull magenta bags contain 1 posh white bag.
|
||||
shiny cyan bags contain 1 shiny silver bag, 4 pale salmon bags, 5 faded turquoise bags.
|
||||
mirrored gray bags contain 4 mirrored red bags, 3 vibrant brown bags.
|
||||
bright cyan bags contain 1 dotted lavender bag.
|
||||
dotted crimson bags contain 3 wavy yellow bags, 1 shiny brown bag, 2 striped brown bags, 2 dull yellow bags.
|
||||
dim chartreuse bags contain 5 shiny purple bags.
|
||||
muted crimson bags contain 2 striped violet bags, 4 clear tan bags.
|
||||
dim aqua bags contain 1 mirrored magenta bag, 3 dim beige bags.
|
||||
wavy aqua bags contain 4 bright gray bags.
|
||||
bright beige bags contain 4 dotted chartreuse bags.
|
||||
posh purple bags contain 5 wavy aqua bags, 4 posh coral bags, 3 vibrant chartreuse bags.
|
||||
shiny fuchsia bags contain 1 shiny olive bag.
|
||||
wavy beige bags contain 2 pale purple bags, 3 pale indigo bags, 3 plaid purple bags.
|
||||
wavy crimson bags contain 4 shiny gold bags, 5 bright tomato bags.
|
||||
pale tomato bags contain 3 faded gold bags, 5 shiny gray bags.
|
||||
bright silver bags contain 1 dotted white bag.
|
||||
mirrored chartreuse bags contain 2 muted silver bags.
|
||||
mirrored aqua bags contain 4 plaid violet bags.
|
||||
wavy brown bags contain 4 faded beige bags, 4 faded brown bags, 2 mirrored blue bags, 3 clear red bags.
|
||||
dull purple bags contain 3 plaid fuchsia bags, 1 faded lavender bag.
|
||||
pale turquoise bags contain 4 mirrored violet bags, 3 faded salmon bags, 5 bright white bags.
|
||||
dull lavender bags contain 1 faded fuchsia bag.
|
||||
dull aqua bags contain 1 bright yellow bag.
|
||||
clear maroon bags contain 1 pale bronze bag, 2 clear aqua bags.
|
||||
wavy lavender bags contain 4 dotted blue bags.
|
||||
dull blue bags contain 5 wavy magenta bags.
|
||||
shiny olive bags contain 4 clear magenta bags, 1 vibrant orange bag.
|
||||
shiny teal bags contain 5 dotted magenta bags, 2 dark crimson bags, 3 dotted brown bags.
|
||||
dull teal bags contain 1 dull indigo bag, 4 wavy plum bags, 2 drab plum bags.
|
||||
dim bronze bags contain 5 striped silver bags, 5 posh green bags.
|
||||
muted bronze bags contain 4 dotted blue bags, 3 pale purple bags, 5 drab magenta bags.
|
||||
vibrant violet bags contain 3 dim tan bags, 3 striped lavender bags.
|
||||
dull turquoise bags contain 1 dim white bag.
|
||||
pale purple bags contain no other bags.
|
||||
drab aqua bags contain 4 dull beige bags, 5 clear brown bags, 2 mirrored orange bags, 3 mirrored blue bags.
|
||||
mirrored beige bags contain 4 posh aqua bags.
|
||||
pale plum bags contain 4 dull coral bags, 4 pale black bags, 1 posh chartreuse bag.
|
||||
dotted maroon bags contain 5 faded gold bags, 1 clear blue bag, 4 dark black bags.
|
||||
muted olive bags contain 5 dim violet bags, 4 dotted white bags, 5 plaid purple bags, 3 vibrant orange bags.
|
||||
wavy yellow bags contain 4 light beige bags.
|
||||
plaid salmon bags contain 4 pale black bags, 3 dim bronze bags, 1 dotted gold bag.
|
||||
faded indigo bags contain 3 plaid purple bags, 5 pale gold bags, 1 wavy beige bag.
|
||||
pale brown bags contain 2 wavy black bags.
|
||||
clear olive bags contain 4 vibrant tomato bags.
|
||||
vibrant gold bags contain 3 dull cyan bags.
|
||||
dark indigo bags contain 5 bright green bags, 1 dark white bag.
|
||||
drab gold bags contain 4 clear violet bags, 2 striped indigo bags.
|
||||
light bronze bags contain 3 shiny coral bags.
|
||||
vibrant black bags contain 2 light black bags, 5 clear orange bags, 2 clear silver bags.
|
||||
wavy tomato bags contain 1 faded maroon bag, 1 dim violet bag, 5 posh aqua bags.
|
||||
wavy orange bags contain 2 striped lime bags, 4 posh turquoise bags, 3 dotted purple bags, 1 wavy gold bag.
|
||||
dark blue bags contain 1 faded gray bag.
|
||||
drab magenta bags contain no other bags.
|
||||
posh crimson bags contain 1 mirrored olive bag, 1 striped tomato bag, 5 vibrant orange bags, 1 drab yellow bag.
|
||||
mirrored coral bags contain 4 drab purple bags, 4 bright gray bags, 4 plaid turquoise bags, 5 plaid aqua bags.
|
||||
faded crimson bags contain 3 plaid tan bags, 3 vibrant orange bags, 3 mirrored beige bags, 4 dim plum bags.
|
||||
dotted tan bags contain 1 wavy beige bag, 2 bright maroon bags.
|
||||
faded magenta bags contain 1 mirrored tan bag.
|
||||
light maroon bags contain 4 plaid tan bags, 5 shiny silver bags.
|
||||
dull chartreuse bags contain 2 dim gold bags, 1 faded blue bag, 1 striped violet bag, 4 drab tomato bags.
|
||||
plaid white bags contain 2 dark gray bags.
|
||||
plaid fuchsia bags contain no other bags.
|
||||
dark red bags contain 2 mirrored bronze bags, 2 pale blue bags, 5 plaid orange bags, 5 clear orange bags.
|
||||
dark fuchsia bags contain 2 faded green bags, 2 mirrored magenta bags, 3 pale red bags.
|
||||
dull plum bags contain 2 bright blue bags, 3 drab purple bags, 1 dim plum bag, 2 shiny purple bags.
|
||||
vibrant crimson bags contain 2 bright plum bags.
|
||||
clear magenta bags contain 1 drab bronze bag, 2 bright turquoise bags, 2 faded gray bags, 1 dim blue bag.
|
||||
dull indigo bags contain 5 light magenta bags.
|
||||
vibrant olive bags contain 3 light yellow bags, 3 mirrored silver bags, 2 plaid white bags, 2 dim beige bags.
|
||||
striped lavender bags contain 1 dull salmon bag, 1 pale purple bag.
|
||||
clear lime bags contain 4 dim gold bags.
|
||||
faded orange bags contain 5 light white bags, 4 shiny bronze bags, 3 plaid silver bags.
|
||||
posh lime bags contain 2 drab orange bags, 5 wavy beige bags.
|
||||
posh olive bags contain 5 drab green bags, 2 bright maroon bags, 3 vibrant orange bags.
|
||||
dim yellow bags contain 1 light silver bag, 5 vibrant gray bags, 4 faded turquoise bags, 2 dark blue bags.
|
||||
muted red bags contain 2 dim purple bags.
|
||||
pale salmon bags contain 3 vibrant orange bags.
|
||||
light beige bags contain 5 clear purple bags, 2 plaid teal bags.
|
||||
clear tomato bags contain 5 dull cyan bags, 4 dark brown bags.
|
||||
shiny gray bags contain 3 dark brown bags, 1 shiny bronze bag, 5 posh bronze bags, 4 dark indigo bags.
|
||||
vibrant fuchsia bags contain 4 wavy olive bags, 5 shiny blue bags, 5 light yellow bags.
|
||||
shiny violet bags contain 4 dull aqua bags, 1 pale fuchsia bag, 3 mirrored lime bags, 5 dark blue bags.
|
||||
plaid silver bags contain 1 faded fuchsia bag, 5 dull lavender bags.
|
||||
light white bags contain 1 plaid magenta bag, 4 striped beige bags.
|
||||
posh magenta bags contain 5 vibrant chartreuse bags, 3 drab silver bags, 4 striped bronze bags, 4 striped salmon bags.
|
||||
muted maroon bags contain 2 faded coral bags.
|
||||
light blue bags contain 3 dotted plum bags, 2 pale salmon bags, 4 striped coral bags, 1 bright lavender bag.
|
||||
pale teal bags contain 3 faded maroon bags, 5 wavy turquoise bags.
|
||||
posh gold bags contain 4 vibrant violet bags, 1 drab beige bag.
|
||||
shiny indigo bags contain 4 drab cyan bags.
|
||||
wavy teal bags contain 1 light maroon bag, 2 shiny silver bags, 2 bright white bags, 1 pale black bag.
|
||||
striped cyan bags contain 1 plaid brown bag.
|
||||
pale black bags contain no other bags.
|
||||
light green bags contain 2 dark salmon bags, 2 faded tomato bags, 1 wavy blue bag, 1 bright gray bag.
|
||||
mirrored green bags contain 2 striped salmon bags, 3 shiny black bags.
|
||||
dim orange bags contain 3 vibrant plum bags, 5 drab crimson bags.
|
||||
clear chartreuse bags contain 2 posh fuchsia bags, 3 vibrant olive bags.
|
||||
dull black bags contain 3 posh yellow bags, 5 dark bronze bags, 4 dark aqua bags, 5 dull teal bags.
|
||||
dotted tomato bags contain 2 faded crimson bags, 5 faded black bags.
|
||||
faded maroon bags contain 4 pale white bags, 5 posh green bags, 3 wavy black bags, 5 plaid tan bags.
|
||||
plaid cyan bags contain 3 striped blue bags, 3 wavy teal bags.
|
||||
dark bronze bags contain 2 clear purple bags.
|
||||
vibrant purple bags contain 2 striped orange bags, 1 wavy black bag.
|
||||
dotted silver bags contain 4 faded white bags, 5 dim blue bags, 1 dark white bag.
|
||||
mirrored yellow bags contain 5 dark black bags.
|
||||
dim lime bags contain 3 dim lavender bags, 5 shiny gold bags, 5 striped red bags.
|
||||
faded tan bags contain 4 clear black bags, 3 pale silver bags, 1 muted gold bag.
|
||||
drab plum bags contain 4 shiny gold bags.
|
||||
plaid lavender bags contain 3 drab blue bags, 3 faded tomato bags, 5 bright cyan bags.
|
||||
dark beige bags contain 3 dim indigo bags, 2 plaid white bags.
|
||||
dotted red bags contain 2 mirrored indigo bags.
|
||||
dull orange bags contain 3 mirrored cyan bags, 4 shiny gold bags, 5 posh white bags.
|
||||
striped bronze bags contain 1 drab coral bag, 1 dark teal bag, 5 posh yellow bags.
|
||||
wavy indigo bags contain 1 drab lavender bag, 2 posh aqua bags, 1 clear brown bag.
|
||||
light cyan bags contain 3 dim blue bags, 5 dark brown bags, 3 clear bronze bags.
|
||||
plaid orange bags contain 4 plaid tan bags, 1 posh tomato bag, 1 wavy crimson bag.
|
||||
faded turquoise bags contain 1 muted bronze bag, 1 wavy gold bag, 4 striped orange bags, 3 bright gold bags.
|
||||
shiny orange bags contain 1 wavy maroon bag.
|
||||
light tan bags contain 5 mirrored black bags, 4 dark tan bags.
|
||||
pale coral bags contain 1 faded coral bag, 4 dotted yellow bags.
|
||||
faded lavender bags contain 3 vibrant orange bags, 4 pale black bags, 2 posh aqua bags, 5 shiny gold bags.
|
||||
dull cyan bags contain 3 bright maroon bags, 4 light yellow bags, 4 faded tomato bags.
|
||||
shiny turquoise bags contain 1 posh gray bag.
|
||||
faded violet bags contain 5 posh tan bags, 3 dim blue bags.
|
||||
mirrored bronze bags contain 1 striped silver bag.
|
||||
dull tomato bags contain 1 dim black bag, 5 wavy olive bags, 1 faded olive bag.
|
||||
faded red bags contain 2 drab salmon bags, 2 posh aqua bags, 5 posh brown bags.
|
||||
dark magenta bags contain 1 posh silver bag, 5 bright lavender bags, 4 faded turquoise bags, 5 drab white bags.
|
||||
light turquoise bags contain 5 dotted turquoise bags, 2 dim plum bags, 2 posh olive bags, 4 mirrored gold bags.
|
||||
clear green bags contain 3 bright white bags, 2 dark tan bags.
|
||||
clear coral bags contain 3 clear turquoise bags, 2 striped black bags.
|
||||
dotted bronze bags contain 5 striped blue bags, 2 striped lavender bags, 4 bright salmon bags, 5 drab maroon bags.
|
||||
drab salmon bags contain 3 bright blue bags, 4 drab magenta bags.
|
||||
faded aqua bags contain 2 light magenta bags.
|
||||
bright violet bags contain 2 wavy indigo bags.
|
||||
mirrored silver bags contain 5 shiny gold bags.
|
||||
posh maroon bags contain 1 dark lime bag, 4 plaid gold bags, 4 light magenta bags, 4 dim aqua bags.
|
||||
striped brown bags contain 5 dull lavender bags.
|
||||
bright olive bags contain 3 striped coral bags.
|
||||
drab white bags contain 5 plaid teal bags, 3 shiny silver bags, 3 wavy plum bags, 1 bright white bag.
|
||||
faded teal bags contain 3 muted blue bags, 2 bright purple bags.
|
||||
striped plum bags contain 4 plaid turquoise bags, 5 vibrant fuchsia bags.
|
||||
dark coral bags contain 1 muted salmon bag, 1 mirrored bronze bag, 3 pale maroon bags, 5 dotted coral bags.
|
||||
drab orange bags contain 1 pale gold bag.
|
||||
bright tan bags contain 3 pale plum bags, 2 posh yellow bags.
|
||||
drab brown bags contain 1 plaid red bag, 4 pale tan bags.
|
||||
posh bronze bags contain 4 dim indigo bags, 4 drab purple bags, 2 dark bronze bags.
|
||||
mirrored purple bags contain 3 plaid beige bags, 3 bright tomato bags, 3 bright chartreuse bags, 4 wavy crimson bags.
|
||||
wavy blue bags contain 1 dotted blue bag, 1 pale purple bag, 3 light maroon bags.
|
||||
dim cyan bags contain 5 faded yellow bags, 2 shiny coral bags, 3 faded black bags, 4 vibrant chartreuse bags.
|
||||
plaid olive bags contain 1 dim aqua bag, 4 mirrored indigo bags, 4 muted silver bags.
|
||||
dark orange bags contain 5 faded fuchsia bags, 4 clear purple bags.
|
||||
drab olive bags contain 1 drab lavender bag.
|
||||
pale fuchsia bags contain 3 bright green bags, 4 striped red bags, 2 pale brown bags.
|
||||
shiny chartreuse bags contain 2 striped beige bags, 3 clear tomato bags.
|
||||
shiny brown bags contain 1 faded maroon bag, 2 muted brown bags, 2 vibrant coral bags.
|
||||
striped turquoise bags contain 4 pale bronze bags.
|
||||
dull gray bags contain 4 plaid gray bags.
|
||||
wavy chartreuse bags contain 2 wavy maroon bags, 4 muted yellow bags.
|
||||
bright green bags contain 2 dotted orange bags, 4 faded olive bags, 5 wavy beige bags, 1 bright yellow bag.
|
||||
dark olive bags contain 5 light indigo bags, 5 plaid chartreuse bags, 2 vibrant red bags, 5 dark lime bags.
|
||||
dark black bags contain 2 dark fuchsia bags, 1 dotted fuchsia bag.
|
||||
dim purple bags contain 5 posh gray bags, 3 faded lavender bags, 4 bright plum bags, 2 dotted salmon bags.
|
||||
pale gold bags contain 1 posh silver bag, 4 posh tan bags, 1 bright gold bag, 5 faded gray bags.
|
||||
pale maroon bags contain 2 drab fuchsia bags, 2 dark fuchsia bags, 5 plaid red bags.
|
||||
light plum bags contain 1 dim beige bag, 2 light orange bags.
|
||||
mirrored plum bags contain 5 light white bags, 5 bright tomato bags, 1 dim violet bag.
|
||||
dim coral bags contain 2 light lime bags, 2 clear tan bags.
|
||||
faded silver bags contain 4 striped violet bags, 2 mirrored brown bags.
|
||||
posh salmon bags contain 4 dull plum bags.
|
||||
shiny purple bags contain 2 posh gray bags.
|
||||
shiny maroon bags contain 2 vibrant turquoise bags, 4 drab teal bags.
|
||||
clear beige bags contain 2 mirrored white bags, 1 shiny turquoise bag, 5 faded bronze bags.
|
||||
muted plum bags contain 2 plaid violet bags.
|
||||
plaid green bags contain 3 drab white bags, 5 wavy gold bags, 3 bright maroon bags, 1 wavy cyan bag.
|
||||
faded white bags contain 1 dull cyan bag, 3 dull purple bags, 2 bright brown bags, 4 bright crimson bags.
|
||||
plaid gray bags contain 3 bright chartreuse bags, 2 plaid tomato bags, 2 dark brown bags.
|
||||
shiny yellow bags contain 5 drab salmon bags.
|
||||
mirrored violet bags contain 4 clear fuchsia bags.
|
||||
plaid beige bags contain 1 pale black bag.
|
||||
plaid black bags contain 1 dark chartreuse bag.
|
||||
mirrored fuchsia bags contain 5 light tomato bags, 4 shiny yellow bags, 1 plaid beige bag, 5 muted gold bags.
|
||||
pale indigo bags contain 1 pale black bag, 5 plaid teal bags.
|
||||
light magenta bags contain 1 mirrored silver bag, 4 dull salmon bags.
|
||||
striped teal bags contain 1 dotted lime bag, 3 shiny yellow bags, 3 wavy aqua bags.
|
||||
dark aqua bags contain 3 drab green bags.
|
||||
bright red bags contain 5 shiny chartreuse bags, 3 mirrored bronze bags, 1 pale beige bag.
|
||||
dim teal bags contain 2 shiny yellow bags, 3 drab turquoise bags, 1 striped black bag, 1 vibrant coral bag.
|
||||
drab crimson bags contain 5 light silver bags, 4 plaid chartreuse bags.
|
||||
dim silver bags contain 1 striped brown bag, 5 dark black bags, 1 light lime bag.
|
||||
drab bronze bags contain 1 dotted white bag.
|
||||
drab teal bags contain 2 dim blue bags, 4 light yellow bags, 5 dark gray bags.
|
||||
dark teal bags contain 5 posh gray bags, 4 faded green bags, 1 dotted yellow bag, 4 vibrant black bags.
|
||||
vibrant indigo bags contain 4 faded turquoise bags.
|
||||
mirrored black bags contain 2 muted bronze bags.
|
||||
dotted gray bags contain 3 faded cyan bags.
|
||||
posh plum bags contain 4 dark bronze bags, 3 drab olive bags, 4 dull beige bags, 3 plaid silver bags.
|
||||
drab black bags contain 1 wavy teal bag.
|
||||
faded gray bags contain 5 dull lime bags, 4 posh aqua bags.
|
||||
muted white bags contain 2 shiny lavender bags, 3 wavy olive bags, 4 bright brown bags.
|
||||
wavy gray bags contain 3 faded lavender bags, 5 posh silver bags.
|
||||
plaid magenta bags contain 1 shiny silver bag, 3 light silver bags, 5 posh gray bags, 2 faded green bags.
|
||||
muted coral bags contain 5 dull salmon bags, 4 shiny plum bags.
|
||||
plaid tomato bags contain 5 dotted blue bags.
|
||||
dark lime bags contain 1 striped orange bag, 1 pale black bag.
|
||||
vibrant coral bags contain 1 vibrant yellow bag, 1 plaid magenta bag, 3 pale gray bags, 2 vibrant indigo bags.
|
||||
drab turquoise bags contain 2 plaid tomato bags, 3 dim indigo bags, 2 shiny tomato bags, 1 plaid red bag.
|
||||
mirrored red bags contain 5 plaid chartreuse bags.
|
||||
plaid brown bags contain 5 drab blue bags, 1 mirrored olive bag.
|
||||
striped gold bags contain 3 vibrant aqua bags, 1 posh plum bag, 1 dotted blue bag, 3 light yellow bags.
|
||||
drab purple bags contain 2 clear green bags, 4 dull cyan bags, 3 posh tan bags, 5 faded violet bags.
|
||||
posh chartreuse bags contain 2 pale black bags.
|
||||
clear violet bags contain 1 dark tomato bag, 4 light lime bags, 4 faded magenta bags.
|
||||
striped magenta bags contain 5 wavy plum bags, 2 light maroon bags, 4 posh gray bags, 2 shiny silver bags.
|
||||
muted salmon bags contain 5 muted black bags, 5 vibrant coral bags.
|
||||
pale silver bags contain 3 light lime bags, 3 dotted orange bags, 4 plaid teal bags.
|
||||
striped lime bags contain 5 dim tomato bags, 2 clear purple bags, 2 mirrored brown bags.
|
||||
dull silver bags contain 2 wavy gold bags.
|
||||
dark violet bags contain 1 dotted plum bag, 5 faded turquoise bags, 4 light salmon bags.
|
||||
dim black bags contain 4 clear violet bags, 4 posh chartreuse bags, 1 plaid turquoise bag, 1 pale black bag.
|
||||
shiny beige bags contain 3 dim aqua bags.
|
||||
plaid tan bags contain no other bags.
|
||||
faded yellow bags contain 5 vibrant fuchsia bags.
|
||||
vibrant blue bags contain 2 vibrant olive bags, 4 faded cyan bags.
|
||||
mirrored lime bags contain 3 mirrored blue bags.
|
||||
dull white bags contain 5 dark brown bags.
|
||||
dim tomato bags contain 4 dark violet bags, 5 dotted tan bags, 1 plaid teal bag, 2 shiny plum bags.
|
||||
pale cyan bags contain 1 dotted coral bag, 4 dim green bags.
|
||||
light fuchsia bags contain 1 posh aqua bag, 3 posh coral bags.
|
||||
posh gray bags contain 5 faded green bags, 5 pale indigo bags, 3 plaid fuchsia bags, 4 faded beige bags.
|
||||
faded cyan bags contain 3 dark bronze bags, 1 wavy plum bag.
|
||||
plaid bronze bags contain 5 pale silver bags.
|
||||
dim olive bags contain 2 shiny gray bags.
|
||||
faded coral bags contain 4 wavy blue bags.
|
||||
pale lime bags contain 2 dull indigo bags.
|
||||
dim white bags contain 4 dotted tan bags, 5 dull indigo bags, 5 plaid red bags, 2 faded silver bags.
|
||||
muted turquoise bags contain 1 drab coral bag.
|
||||
clear bronze bags contain 5 dark lime bags.
|
||||
bright plum bags contain 4 faded coral bags, 2 pale indigo bags, 4 drab salmon bags.
|
||||
posh orange bags contain 2 muted brown bags, 1 light white bag, 2 faded blue bags.
|
||||
muted chartreuse bags contain 2 pale plum bags, 5 light purple bags.
|
||||
shiny bronze bags contain 3 faded turquoise bags, 5 wavy lavender bags.
|
||||
shiny coral bags contain 1 wavy coral bag, 5 mirrored olive bags.
|
||||
posh lavender bags contain 3 clear gray bags, 5 vibrant white bags.
|
||||
clear fuchsia bags contain 4 clear indigo bags, 3 wavy lavender bags, 2 wavy teal bags, 1 clear green bag.
|
||||
bright tomato bags contain 3 posh silver bags, 2 wavy beige bags, 4 plaid white bags.
|
||||
light yellow bags contain 2 plaid tan bags, 1 plaid purple bag, 3 bright gold bags.
|
||||
pale magenta bags contain 3 vibrant turquoise bags.
|
||||
bright bronze bags contain 2 shiny gold bags, 4 striped violet bags, 4 striped orange bags, 3 drab green bags.
|
||||
faded bronze bags contain 2 dim bronze bags, 4 plaid green bags, 3 light purple bags, 5 striped indigo bags.
|
||||
plaid coral bags contain 2 vibrant salmon bags, 4 drab coral bags, 5 light tan bags.
|
||||
dull coral bags contain 2 striped coral bags.
|
||||
muted purple bags contain 1 bright indigo bag.
|
||||
light silver bags contain 3 muted olive bags, 5 drab purple bags, 2 drab lavender bags.
|
||||
muted aqua bags contain 5 dull olive bags, 5 drab cyan bags, 5 pale red bags.
|
||||
posh white bags contain 4 dim plum bags, 3 wavy blue bags.
|
||||
dotted olive bags contain 4 light brown bags.
|
||||
muted lime bags contain 4 pale gold bags, 4 dull tan bags.
|
||||
vibrant magenta bags contain 3 muted olive bags, 2 drab silver bags, 5 posh purple bags.
|
||||
dotted coral bags contain 3 striped turquoise bags, 3 plaid magenta bags, 4 muted cyan bags.
|
||||
drab green bags contain 1 drab salmon bag, 3 vibrant purple bags, 3 shiny gold bags, 1 posh silver bag.
|
||||
vibrant silver bags contain 5 faded salmon bags.
|
||||
dull bronze bags contain 3 light plum bags.
|
||||
striped coral bags contain 1 posh brown bag, 4 drab green bags, 1 pale white bag, 1 posh bronze bag.
|
||||
dim blue bags contain 2 plaid beige bags, 2 faded gray bags.
|
||||
mirrored olive bags contain 2 plaid gray bags, 2 vibrant yellow bags, 3 dim magenta bags.
|
||||
bright salmon bags contain 3 bright yellow bags.
|
||||
bright crimson bags contain 2 plaid gold bags, 5 bright plum bags.
|
||||
vibrant yellow bags contain 1 bright chartreuse bag.
|
||||
plaid indigo bags contain 3 wavy silver bags.
|
||||
bright indigo bags contain 2 shiny black bags, 1 pale indigo bag.
|
||||
clear aqua bags contain 2 drab black bags, 3 clear tan bags, 5 drab purple bags, 1 plaid green bag.
|
||||
posh tomato bags contain 3 posh blue bags.
|
||||
dim tan bags contain 2 vibrant crimson bags, 4 dark lavender bags, 1 drab orange bag, 1 plaid tomato bag.
|
||||
dim plum bags contain 3 vibrant orange bags.
|
||||
posh teal bags contain 1 clear salmon bag, 3 light aqua bags.
|
||||
muted indigo bags contain 1 mirrored black bag, 1 vibrant purple bag.
|
||||
dull beige bags contain 4 bright gray bags, 5 pale silver bags.
|
||||
dotted cyan bags contain 4 bright maroon bags, 5 drab cyan bags, 1 bright tomato bag, 4 plaid aqua bags.
|
||||
faded fuchsia bags contain 2 light orange bags, 4 clear turquoise bags, 4 pale purple bags, 3 dotted blue bags.
|
||||
pale bronze bags contain 1 wavy cyan bag, 2 light silver bags, 1 light magenta bag, 3 plaid chartreuse bags.
|
||||
dim beige bags contain 2 striped lavender bags, 2 wavy teal bags, 1 dim plum bag, 4 bright maroon bags.
|
||||
muted beige bags contain 4 faded black bags, 4 plaid black bags, 4 clear magenta bags.
|
||||
dotted lavender bags contain 5 shiny silver bags, 1 plaid gold bag, 2 wavy lavender bags.
|
||||
pale green bags contain 2 pale gold bags.
|
||||
drab coral bags contain 1 posh yellow bag, 5 wavy maroon bags, 2 posh chartreuse bags, 2 bright gold bags.
|
||||
wavy plum bags contain 1 plaid tan bag, 3 pale black bags, 2 wavy lime bags, 5 pale purple bags.
|
||||
dotted green bags contain 1 dark black bag, 4 vibrant yellow bags.
|
||||
light violet bags contain 3 faded red bags.
|
||||
faded gold bags contain 3 clear teal bags, 2 faded magenta bags.
|
||||
muted magenta bags contain 5 striped black bags.
|
||||
light red bags contain 3 dark turquoise bags, 2 dim bronze bags.
|
||||
dim maroon bags contain 1 dull gold bag, 3 posh yellow bags.
|
||||
dull fuchsia bags contain 5 dotted salmon bags, 5 posh gray bags, 5 dark tan bags, 3 dull salmon bags.
|
||||
wavy gold bags contain 1 plaid teal bag, 5 light maroon bags.
|
||||
light coral bags contain 2 mirrored cyan bags, 3 posh salmon bags, 4 faded red bags.
|
||||
dark tan bags contain 3 wavy cyan bags.
|
||||
faded plum bags contain 1 dim gold bag, 4 muted crimson bags, 1 mirrored brown bag.
|
||||
wavy black bags contain 5 clear green bags.
|
||||
wavy violet bags contain 3 bright brown bags.
|
||||
light teal bags contain 1 pale olive bag.
|
||||
posh fuchsia bags contain 5 bright blue bags, 2 dotted yellow bags, 4 wavy coral bags.
|
||||
striped violet bags contain 5 wavy cyan bags, 1 faded lavender bag, 4 shiny silver bags, 2 striped lavender bags.
|
||||
plaid crimson bags contain 5 dull chartreuse bags, 2 dark orange bags, 4 pale black bags, 2 light purple bags.
|
||||
light olive bags contain 4 dull turquoise bags, 5 dark purple bags, 4 muted chartreuse bags, 3 dark teal bags.
|
||||
dim magenta bags contain 5 posh gray bags, 5 vibrant fuchsia bags, 1 posh chartreuse bag.
|
||||
striped aqua bags contain 1 pale violet bag, 3 drab lime bags, 1 dark beige bag, 3 light brown bags.
|
||||
dotted white bags contain 1 dark gray bag, 1 vibrant orange bag, 5 muted bronze bags, 5 posh gray bags.
|
||||
faded black bags contain 1 shiny purple bag, 2 mirrored blue bags, 5 vibrant coral bags, 5 shiny turquoise bags.
|
||||
dotted black bags contain 3 drab green bags, 4 plaid beige bags.
|
||||
dotted gold bags contain 2 dark bronze bags, 1 drab fuchsia bag.
|
||||
dark tomato bags contain 4 dotted plum bags, 4 mirrored crimson bags.
|
||||
shiny tan bags contain 2 pale brown bags.
|
||||
muted gold bags contain 1 light indigo bag.
|
||||
dim gold bags contain 5 light salmon bags.
|
||||
dull yellow bags contain 2 striped violet bags.
|
||||
bright white bags contain 1 pale black bag.
|
||||
light purple bags contain 1 faded salmon bag, 5 dim bronze bags, 3 shiny gray bags, 5 dull teal bags.
|
||||
shiny magenta bags contain 5 vibrant blue bags, 4 muted crimson bags, 4 faded white bags.
|
||||
faded brown bags contain 2 dotted plum bags, 1 dotted salmon bag.
|
||||
posh coral bags contain 5 dark gray bags.
|
||||
dim green bags contain 1 light turquoise bag, 2 dark aqua bags, 4 drab magenta bags, 2 faded maroon bags.
|
||||
dull red bags contain 5 faded red bags, 3 drab salmon bags, 1 faded blue bag.
|
||||
clear plum bags contain 2 dotted tan bags, 3 light blue bags, 3 clear magenta bags, 2 drab green bags.
|
||||
mirrored lavender bags contain 1 vibrant purple bag, 1 vibrant plum bag, 2 dark teal bags.
|
||||
dim salmon bags contain 5 drab fuchsia bags, 1 drab blue bag.
|
||||
plaid maroon bags contain 1 clear violet bag.
|
||||
dim fuchsia bags contain 5 dim gold bags, 4 mirrored indigo bags.
|
||||
dull olive bags contain 4 faded gray bags, 5 shiny bronze bags.
|
||||
muted brown bags contain 1 vibrant coral bag, 3 dark black bags, 4 dotted red bags.
|
||||
muted lavender bags contain 3 dim aqua bags, 5 wavy tomato bags.
|
||||
faded lime bags contain 4 dim chartreuse bags, 5 drab beige bags.
|
||||
muted yellow bags contain 3 dark white bags.
|
||||
dark purple bags contain 3 dotted teal bags, 1 wavy tomato bag.
|
||||
light crimson bags contain 1 muted cyan bag, 1 pale coral bag.
|
||||
muted green bags contain 2 faded plum bags, 2 light chartreuse bags, 4 dull chartreuse bags, 4 vibrant turquoise bags.
|
||||
vibrant beige bags contain 3 striped green bags, 1 wavy gold bag, 1 mirrored chartreuse bag.
|
||||
shiny tomato bags contain 1 posh bronze bag, 4 pale salmon bags, 4 vibrant orange bags, 1 faded aqua bag.
|
||||
bright yellow bags contain 2 dull lavender bags, 3 plaid purple bags, 4 light beige bags, 5 clear indigo bags.
|
||||
clear black bags contain 4 dark plum bags.
|
||||
posh brown bags contain 5 plaid fuchsia bags, 1 clear turquoise bag, 5 drab white bags.
|
||||
shiny lime bags contain 1 light beige bag.
|
||||
mirrored blue bags contain 4 drab salmon bags, 4 dim indigo bags.
|
||||
dull salmon bags contain 3 drab white bags, 2 vibrant orange bags.
|
||||
plaid teal bags contain no other bags.
|
||||
plaid blue bags contain 1 dull indigo bag, 4 wavy black bags, 4 clear red bags.
|
26
day07/Makefile
Normal file
26
day07/Makefile
Normal file
@@ -0,0 +1,26 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
|
||||
ex1: ex1-c
|
||||
@$(TIME) ex1.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex1-bis.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex1-c shinygold < $(INPUT) 2>&1
|
||||
|
||||
ex2: ex2-c
|
||||
@$(TIME) ex2.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex2-c shinygold < $(INPUT) 2>&1
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
20
day07/OUTPUT
Normal file
20
day07/OUTPUT
Normal file
@@ -0,0 +1,20 @@
|
||||
ex1.bash : target=shinygold nkeys=594 res=287
|
||||
time: 0:06.99 real, 6.99 user, 0.00 sys
|
||||
context-switch: 720+1, page-faults: 0+403
|
||||
|
||||
ex1-bis.bash : target=shinygold res=287
|
||||
time: 0:00.12 real, 0.12 user, 0.00 sys
|
||||
context-switch: 14+1, page-faults: 0+209
|
||||
|
||||
ex1-c : target=shinygold nkeys=594 res=287
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+117
|
||||
|
||||
ex2.bash : target=shinygold res=48160
|
||||
time: 0:00.34 real, 0.28 user, 0.06 sys
|
||||
context-switch: 37+253, page-faults: 0+12039
|
||||
|
||||
ex2-c : target=shinygold nkeys=594 res=48160
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+118
|
||||
|
72
day07/README
Normal file
72
day07/README
Normal file
@@ -0,0 +1,72 @@
|
||||
--- Day 7: Handy Haversacks ---
|
||||
|
||||
You land at the regional airport in time for your next flight. In fact, it looks like you'll even have time to grab some food: all flights are currently delayed due to issues in luggage processing.
|
||||
|
||||
Due to recent aviation regulations, many rules (your puzzle input) are being enforced about bags and their contents; bags must be color-coded and must contain specific quantities of other color-coded bags. Apparently, nobody responsible for these regulations considered how long they would take to enforce!
|
||||
|
||||
For example, consider the following rules:
|
||||
|
||||
light red bags contain 1 bright white bag, 2 muted yellow bags.
|
||||
dark orange bags contain 3 bright white bags, 4 muted yellow bags.
|
||||
bright white bags contain 1 shiny gold bag.
|
||||
muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.
|
||||
shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.
|
||||
dark olive bags contain 3 faded blue bags, 4 dotted black bags.
|
||||
vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.
|
||||
faded blue bags contain no other bags.
|
||||
dotted black bags contain no other bags.
|
||||
|
||||
These rules specify the required contents for 9 bag types. In this example, every faded blue bag is empty, every vibrant plum bag contains 11 bags (5 faded blue and 6 dotted black), and so on.
|
||||
|
||||
You have a shiny gold bag. If you wanted to carry it in at least one other bag, how many different bag colors would be valid for the outermost bag? (In other words: how many colors can, eventually, contain at least one shiny gold bag?)
|
||||
|
||||
In the above rules, the following options would be available to you:
|
||||
|
||||
A bright white bag, which can hold your shiny gold bag directly.
|
||||
A muted yellow bag, which can hold your shiny gold bag directly, plus some other bags.
|
||||
A dark orange bag, which can hold bright white and muted yellow bags, either of which could then hold your shiny gold bag.
|
||||
A light red bag, which can hold bright white and muted yellow bags, either of which could then hold your shiny gold bag.
|
||||
|
||||
So, in this example, the number of bag colors that can eventually contain at least one shiny gold bag is 4.
|
||||
|
||||
How many bag colors can eventually contain at least one shiny gold bag? (The list of rules is quite long; make sure you get all of it.)
|
||||
|
||||
Your puzzle answer was 287.
|
||||
--- Part Two ---
|
||||
|
||||
It's getting pretty expensive to fly these days - not because of ticket prices, but because of the ridiculous number of bags you need to buy!
|
||||
|
||||
Consider again your shiny gold bag and the rules from the above example:
|
||||
|
||||
faded blue bags contain 0 other bags.
|
||||
dotted black bags contain 0 other bags.
|
||||
vibrant plum bags contain 11 other bags: 5 faded blue bags and 6 dotted black bags.
|
||||
dark olive bags contain 7 other bags: 3 faded blue bags and 4 dotted black bags.
|
||||
|
||||
So, a single shiny gold bag must contain 1 dark olive bag (and the 7 bags within it) plus 2 vibrant plum bags (and the 11 bags within each of those): 1 + 1*7 + 2 + 2*11 = 32 bags!
|
||||
|
||||
Of course, the actual rules have a small chance of going several levels deeper than this example; be sure to count all of the bags, even if the nesting becomes topologically impractical!
|
||||
|
||||
Here's another example:
|
||||
|
||||
shiny gold bags contain 2 dark red bags.
|
||||
dark red bags contain 2 dark orange bags.
|
||||
dark orange bags contain 2 dark yellow bags.
|
||||
dark yellow bags contain 2 dark green bags.
|
||||
dark green bags contain 2 dark blue bags.
|
||||
dark blue bags contain 2 dark violet bags.
|
||||
dark violet bags contain no other bags.
|
||||
|
||||
In this example, a single shiny gold bag must contain 126 other bags.
|
||||
|
||||
How many individual bags are required inside your single shiny gold bag?
|
||||
|
||||
Your puzzle answer was 48160.
|
||||
|
||||
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 [Share] this puzzle.
|
9
day07/TEST.txt
Normal file
9
day07/TEST.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
light red bags contain 1 bright white bag, 2 muted yellow bags.
|
||||
dark orange bags contain 3 bright white bags, 4 muted yellow bags.
|
||||
bright white bags contain 1 shiny gold bag.
|
||||
muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.
|
||||
shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.
|
||||
dark olive bags contain 3 faded blue bags, 4 dotted black bags.
|
||||
vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.
|
||||
faded blue bags contain no other bags.
|
||||
dotted black bags contain no other bags.
|
7
day07/TEST2.txt
Normal file
7
day07/TEST2.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
shiny gold bags contain 2 dark red bags.
|
||||
dark red bags contain 2 dark orange bags.
|
||||
dark orange bags contain 2 dark yellow bags.
|
||||
dark yellow bags contain 2 dark green bags.
|
||||
dark green bags contain 2 dark blue bags.
|
||||
dark blue bags contain 2 dark violet bags.
|
||||
dark violet bags contain no other bags.
|
76
day07/ex1-bis.bash
Executable file
76
day07/ex1-bis.bash
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 7/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
|
||||
declare -A CONT
|
||||
declare -A match
|
||||
|
||||
function search() {
|
||||
local -i ret=1
|
||||
local val="$1" key="$2"
|
||||
local cont="${CONT[$key]}"
|
||||
if [[ $cont =~ $val ]]; then
|
||||
match[$key]=1
|
||||
ret=0
|
||||
fi
|
||||
return $ret
|
||||
}
|
||||
|
||||
function contains() {
|
||||
local -i
|
||||
local -a container
|
||||
local key="$1"
|
||||
|
||||
set ${CONT[$key]}
|
||||
while (( $# > 0 )); do
|
||||
[[ -v CONT[$1] ]] && contains "$1"
|
||||
match[$1]=1
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
function parse() {
|
||||
set $@
|
||||
local container="" in=""
|
||||
local -i i=0
|
||||
|
||||
while [[ ! "$1" =~ bag[s]* ]]; do
|
||||
container+="$1"
|
||||
shift
|
||||
done
|
||||
shift
|
||||
shift
|
||||
while (( $# > 0 )); do
|
||||
case "$1" in
|
||||
contain)
|
||||
echo contain
|
||||
;;
|
||||
[[:digit:]]*)
|
||||
;;
|
||||
bag*)
|
||||
CONT[$in]+="$container "
|
||||
in=""
|
||||
;;
|
||||
*)
|
||||
in+="$1"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
declare -a array
|
||||
while read -r line; do
|
||||
parse "$line"
|
||||
done
|
||||
|
||||
target="shinygold"
|
||||
match=()
|
||||
contains $target
|
||||
printf "%s : target=%s res=%d\n" "$CMD" "$target" "${#match[@]}"
|
||||
#printf "%s : lines=%d max=%d\n" "$CMD" "$lines" "$max"
|
||||
|
||||
exit 0
|
233
day07/ex1-c.c
Normal file
233
day07/ex1-c.c
Normal file
@@ -0,0 +1,233 @@
|
||||
/* ex1-c: Advent2020 game, day 7/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct node {
|
||||
struct chain *chain;
|
||||
struct node *next;
|
||||
int num;
|
||||
//int taken;
|
||||
};
|
||||
|
||||
struct chain {
|
||||
char key[80]; /* arbitrary, to avoid multiple mallocs.
|
||||
char* would be better */
|
||||
struct chain *next; /* if collision */
|
||||
struct node *contains; /* bags contained */
|
||||
struct node *isin; /* is part of */
|
||||
int taken;
|
||||
};
|
||||
|
||||
#define HASH_SIZE 1024
|
||||
static struct chain *thehash[HASH_SIZE];
|
||||
static nkeys=0;
|
||||
|
||||
unsigned long get_hash(str)
|
||||
char *str;
|
||||
{
|
||||
register unsigned long hash = 5381;
|
||||
register int c;
|
||||
|
||||
while (c = *str++)
|
||||
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
|
||||
return hash;
|
||||
}
|
||||
|
||||
struct chain *find_key(key)
|
||||
char *key;
|
||||
{
|
||||
unsigned long hash;
|
||||
struct chain *entry;
|
||||
|
||||
hash=get_hash(key)%HASH_SIZE;
|
||||
entry=thehash[hash];
|
||||
while (entry) {
|
||||
if (!strcmp(key, entry->key))
|
||||
break;
|
||||
entry=entry->next;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
struct chain *insert_key(key)
|
||||
char *key;
|
||||
{
|
||||
unsigned long hash;
|
||||
struct chain *entry;
|
||||
|
||||
if (!(entry=find_key(key))) {
|
||||
hash=get_hash(key)%HASH_SIZE;
|
||||
entry=malloc(sizeof (struct chain));
|
||||
|
||||
strcpy(entry->key, key);
|
||||
entry->next=thehash[hash];
|
||||
thehash[hash]=entry;
|
||||
|
||||
entry->contains=NULL;
|
||||
entry->isin=NULL;
|
||||
entry->taken=0;
|
||||
nkeys++;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
void insert_node(container, contained, num)
|
||||
struct chain *container;
|
||||
struct chain *contained;
|
||||
int num;
|
||||
{
|
||||
struct node *node;
|
||||
|
||||
node=malloc(sizeof node);
|
||||
node->chain=contained;
|
||||
node->num=num;
|
||||
//node->taken=0;
|
||||
node->next=container->contains;
|
||||
container->contains=node;
|
||||
|
||||
node=malloc(sizeof node);
|
||||
node->chain=container;
|
||||
node->num=0;
|
||||
//node->taken=0;
|
||||
node->next=contained->isin;
|
||||
contained->isin=node;
|
||||
}
|
||||
|
||||
void print_node_list(node)
|
||||
struct node*node;
|
||||
{
|
||||
while (node) {
|
||||
printf("\t\t%d %s", node->num, node->chain->key);
|
||||
node=node->next;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
}
|
||||
|
||||
int count_containers(chain)
|
||||
struct chain *chain;
|
||||
{
|
||||
struct chain *p;
|
||||
struct node *node;
|
||||
int i=0;
|
||||
|
||||
node = chain->isin;
|
||||
while (node) {
|
||||
p=node->chain;
|
||||
if (p->taken == 0) {
|
||||
i++;
|
||||
p->taken=1;
|
||||
i+=count_containers(p);
|
||||
}
|
||||
node=node->next;
|
||||
}
|
||||
chain->taken=1;
|
||||
return i;
|
||||
}
|
||||
int count_contained(chain)
|
||||
struct chain *chain;
|
||||
{
|
||||
struct chain *p;
|
||||
struct node *node;
|
||||
int i=1, num;
|
||||
|
||||
node = chain->contains;
|
||||
while (node) {
|
||||
p=node->chain;
|
||||
num=node->num;
|
||||
i+=num*count_contained(p);
|
||||
node=node->next;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void print_keys()
|
||||
{
|
||||
int i, j;
|
||||
struct chain *chain;
|
||||
struct node *node;
|
||||
|
||||
for (i=0; i<HASH_SIZE; ++i) {
|
||||
chain=thehash[i];
|
||||
j=0;
|
||||
while (chain) {
|
||||
printf("%d: %d=[%s]\n", i, j, chain->key);
|
||||
node=chain->contains;
|
||||
if (node) {
|
||||
printf("\tCONTAINS:");
|
||||
print_node_list(node);
|
||||
}
|
||||
|
||||
node=chain->isin;
|
||||
if (node) {
|
||||
printf("\tIS IN:");
|
||||
print_node_list(node);
|
||||
}
|
||||
|
||||
chain=chain->next;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char*sep=" \t\n"; /* separator */
|
||||
|
||||
char *getcolor(line)
|
||||
char *line;
|
||||
{
|
||||
static char buf[80], *tok, *ret=NULL;
|
||||
|
||||
if (tok=strtok(line, sep)) {
|
||||
strcpy(buf, tok);
|
||||
if (tok=strtok(NULL, sep)) {
|
||||
ret=strcat(buf, tok);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
int ac;
|
||||
char **av;
|
||||
{
|
||||
int num=0, count=0;
|
||||
char line[512], *color, *numstr;
|
||||
struct chain *entry, *isin;
|
||||
|
||||
if (ac != 2) {
|
||||
fprintf(stderr, "usage: %s key\n", *av);
|
||||
exit (1);
|
||||
}
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
count++;
|
||||
if (!(color=getcolor(line))) {
|
||||
continue;
|
||||
}
|
||||
entry=insert_key(color);
|
||||
|
||||
// skip "bag" and "contain"
|
||||
strtok(NULL, sep);
|
||||
strtok(NULL, sep);
|
||||
|
||||
while (numstr=strtok(NULL, sep)) {
|
||||
if (num=atoi(numstr)) {
|
||||
color=getcolor(NULL);
|
||||
isin=insert_key(color);
|
||||
insert_node(entry, isin, num);
|
||||
strtok(NULL, sep);
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
//print_keys();
|
||||
entry=find_key(*(av+1));
|
||||
//num=count_contained(entry)-1; /* ex 2 */
|
||||
num=count_containers(entry); /* ex 1 */
|
||||
|
||||
printf("%s : target=%s nkeys=%d res=%d\n", *av, *(av+1), nkeys, num);
|
||||
exit (0);
|
||||
}
|
78
day07/ex1.bash
Executable file
78
day07/ex1.bash
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 7/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
|
||||
declare -A CONT
|
||||
declare -A match
|
||||
|
||||
function search() {
|
||||
local -i ret=1
|
||||
local val="$1" key="$2"
|
||||
local cont="${CONT[$key]}"
|
||||
if [[ $cont =~ $val ]]; then
|
||||
match[$key]=1
|
||||
ret=0
|
||||
fi
|
||||
#printf "search val=%s key=%s cont=[%s] ret=%d\n" "$val" "$key" "$cont" "$ret"
|
||||
return $ret
|
||||
}
|
||||
|
||||
function contains() {
|
||||
local -i
|
||||
local value="$1"
|
||||
|
||||
for container in "${!CONT[@]}"; do
|
||||
if [[ ${match[$container]} = "" ]]; then
|
||||
if search "$value" "$container" ; then
|
||||
contains "$container"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function parse() {
|
||||
local -a val=("$@")
|
||||
local container="" in=""
|
||||
local -i i=0 num=0
|
||||
# get container
|
||||
while [[ ! "${val[$i]}" =~ bag[s]* ]]; do
|
||||
container+="${val[$i]}"
|
||||
((i++))
|
||||
done
|
||||
CONT[$container]=""
|
||||
((i++))
|
||||
while [[ -n "${val[$i]}" ]]; do
|
||||
case "${val[$i]}" in
|
||||
contain)
|
||||
#echo contain
|
||||
;;
|
||||
[[:digit:]]*)
|
||||
num=${val[$i]}
|
||||
;;
|
||||
bag*)
|
||||
CONT[$container]+="$num "
|
||||
CONT[$container]+="$in "
|
||||
in=""
|
||||
num=0
|
||||
;;
|
||||
*)
|
||||
in+="${val[$i]}"
|
||||
;;
|
||||
esac
|
||||
((i++))
|
||||
done
|
||||
}
|
||||
|
||||
declare -a array
|
||||
while read -r -a array; do
|
||||
parse "${array[@]}"
|
||||
done
|
||||
target="shinygold"
|
||||
match=()
|
||||
contains $target
|
||||
printf "%s : target=%s nkeys=%d res=%d\n" "$CMD" "$target" "${#CONT[@]}" "${#match[@]}"
|
||||
|
||||
exit 0
|
233
day07/ex2-c.c
Normal file
233
day07/ex2-c.c
Normal file
@@ -0,0 +1,233 @@
|
||||
/* ex2-c: Advent2020 game, day 7/game 2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct node {
|
||||
struct chain *chain;
|
||||
struct node *next;
|
||||
int num;
|
||||
//int taken;
|
||||
};
|
||||
|
||||
struct chain {
|
||||
char key[80]; /* arbitrary, to avoid multiple mallocs.
|
||||
char* would be better */
|
||||
struct chain *next; /* if collision */
|
||||
struct node *contains; /* bags contained */
|
||||
struct node *isin; /* is part of */
|
||||
int taken;
|
||||
};
|
||||
|
||||
#define HASH_SIZE 1024
|
||||
static struct chain *thehash[HASH_SIZE];
|
||||
static nkeys=0;
|
||||
|
||||
unsigned long get_hash(str)
|
||||
char *str;
|
||||
{
|
||||
register unsigned long hash = 5381;
|
||||
register int c;
|
||||
|
||||
while (c = *str++)
|
||||
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
|
||||
return hash;
|
||||
}
|
||||
|
||||
struct chain *find_key(key)
|
||||
char *key;
|
||||
{
|
||||
unsigned long hash;
|
||||
struct chain *entry;
|
||||
|
||||
hash=get_hash(key)%HASH_SIZE;
|
||||
entry=thehash[hash];
|
||||
while (entry) {
|
||||
if (!strcmp(key, entry->key))
|
||||
break;
|
||||
entry=entry->next;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
struct chain *insert_key(key)
|
||||
char *key;
|
||||
{
|
||||
unsigned long hash;
|
||||
struct chain *entry;
|
||||
|
||||
if (!(entry=find_key(key))) {
|
||||
hash=get_hash(key)%HASH_SIZE;
|
||||
entry=malloc(sizeof (struct chain));
|
||||
|
||||
strcpy(entry->key, key);
|
||||
entry->next=thehash[hash];
|
||||
thehash[hash]=entry;
|
||||
|
||||
entry->contains=NULL;
|
||||
entry->isin=NULL;
|
||||
entry->taken=0;
|
||||
nkeys++;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
void insert_node(container, contained, num)
|
||||
struct chain *container;
|
||||
struct chain *contained;
|
||||
int num;
|
||||
{
|
||||
struct node *node;
|
||||
|
||||
node=malloc(sizeof node);
|
||||
node->chain=contained;
|
||||
node->num=num;
|
||||
//node->taken=0;
|
||||
node->next=container->contains;
|
||||
container->contains=node;
|
||||
|
||||
node=malloc(sizeof node);
|
||||
node->chain=container;
|
||||
node->num=0;
|
||||
//node->taken=0;
|
||||
node->next=contained->isin;
|
||||
contained->isin=node;
|
||||
}
|
||||
|
||||
void print_node_list(node)
|
||||
struct node*node;
|
||||
{
|
||||
while (node) {
|
||||
printf("\t\t%d %s", node->num, node->chain->key);
|
||||
node=node->next;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
}
|
||||
|
||||
int count_containers(chain)
|
||||
struct chain *chain;
|
||||
{
|
||||
struct chain *p;
|
||||
struct node *node;
|
||||
int i=0;
|
||||
|
||||
node = chain->isin;
|
||||
while (node) {
|
||||
p=node->chain;
|
||||
if (p->taken == 0) {
|
||||
i++;
|
||||
p->taken=1;
|
||||
i+=count_containers(p);
|
||||
}
|
||||
node=node->next;
|
||||
}
|
||||
chain->taken=1;
|
||||
return i;
|
||||
}
|
||||
int count_contained(chain)
|
||||
struct chain *chain;
|
||||
{
|
||||
struct chain *p;
|
||||
struct node *node;
|
||||
int i=1, num;
|
||||
|
||||
node = chain->contains;
|
||||
while (node) {
|
||||
p=node->chain;
|
||||
num=node->num;
|
||||
i+=num*count_contained(p);
|
||||
node=node->next;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void print_keys()
|
||||
{
|
||||
int i, j;
|
||||
struct chain *chain;
|
||||
struct node *node;
|
||||
|
||||
for (i=0; i<HASH_SIZE; ++i) {
|
||||
chain=thehash[i];
|
||||
j=0;
|
||||
while (chain) {
|
||||
printf("%d: %d=[%s]\n", i, j, chain->key);
|
||||
node=chain->contains;
|
||||
if (node) {
|
||||
printf("\tCONTAINS:");
|
||||
print_node_list(node);
|
||||
}
|
||||
|
||||
node=chain->isin;
|
||||
if (node) {
|
||||
printf("\tIS IN:");
|
||||
print_node_list(node);
|
||||
}
|
||||
|
||||
chain=chain->next;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char*sep=" \t\n"; /* separator */
|
||||
|
||||
char *getcolor(line)
|
||||
char *line;
|
||||
{
|
||||
static char buf[80], *tok, *ret=NULL;
|
||||
|
||||
if (tok=strtok(line, sep)) {
|
||||
strcpy(buf, tok);
|
||||
if (tok=strtok(NULL, sep)) {
|
||||
ret=strcat(buf, tok);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
int ac;
|
||||
char **av;
|
||||
{
|
||||
int num=0, count=0;
|
||||
char line[512], *color, *numstr;
|
||||
struct chain *entry, *isin;
|
||||
|
||||
if (ac != 2) {
|
||||
fprintf(stderr, "usage: %s key\n", *av);
|
||||
exit (1);
|
||||
}
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
count++;
|
||||
if (!(color=getcolor(line))) {
|
||||
continue;
|
||||
}
|
||||
entry=insert_key(color);
|
||||
|
||||
// skip "bag" and "contain"
|
||||
strtok(NULL, sep);
|
||||
strtok(NULL, sep);
|
||||
|
||||
while (numstr=strtok(NULL, sep)) {
|
||||
if (num=atoi(numstr)) {
|
||||
color=getcolor(NULL);
|
||||
isin=insert_key(color);
|
||||
insert_node(entry, isin, num);
|
||||
strtok(NULL, sep);
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
//print_keys();
|
||||
entry=find_key(*(av+1));
|
||||
num=count_contained(entry)-1; /* ex 2 */
|
||||
//num=count_containers(entry); /* ex 1 */
|
||||
|
||||
printf("%s : target=%s nkeys=%d res=%d\n", *av, *(av+1), nkeys, num);
|
||||
exit (0);
|
||||
}
|
69
day07/ex2.bash
Executable file
69
day07/ex2.bash
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 7/game 2.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
|
||||
declare -A CONT
|
||||
|
||||
function contains() {
|
||||
local -i i size count=0 count2
|
||||
local -i nbags
|
||||
local key="$1" color
|
||||
local -a contents
|
||||
|
||||
read -ra contents <<< "${CONT[$key]}"
|
||||
((size = ${#contents[@]}/2))
|
||||
|
||||
for ((i=0; i<size; ++i)); do
|
||||
nbags=${contents[i*2]}
|
||||
color=${contents[i*2+1]}
|
||||
((count+=nbags))
|
||||
count2=$(contains "$color")
|
||||
((count+=count2*nbags))
|
||||
done
|
||||
echo "$count"
|
||||
return
|
||||
}
|
||||
|
||||
function parse() {
|
||||
local -a val=("$@")
|
||||
local container="" in=""
|
||||
local -i i=0 num=0
|
||||
while [[ ! "${val[$i]}" =~ bag[s]* ]]; do
|
||||
container+="${val[$i]}"
|
||||
((i++))
|
||||
done
|
||||
CONT[$container]=""
|
||||
((i++))
|
||||
while [[ -n "${val[$i]}" ]]; do
|
||||
case "${val[$i]}" in
|
||||
contain)
|
||||
;;
|
||||
[[:digit:]]*)
|
||||
num=${val[$i]}
|
||||
;;
|
||||
bag*)
|
||||
CONT[$container]+="$num "
|
||||
CONT[$container]+="$in "
|
||||
in=""
|
||||
num=0
|
||||
;;
|
||||
*)
|
||||
in+="${val[$i]}"
|
||||
;;
|
||||
esac
|
||||
((i++))
|
||||
done
|
||||
}
|
||||
|
||||
declare -a array
|
||||
while read -r -a array; do
|
||||
parse "${array[@]}"
|
||||
done
|
||||
target="shinygold"
|
||||
res=$(contains $target)
|
||||
printf "%s : target=%s res=%d\n" "$CMD" "$target" "$res"
|
||||
|
||||
exit 0
|
656
day08/INPUT.txt
Normal file
656
day08/INPUT.txt
Normal file
@@ -0,0 +1,656 @@
|
||||
acc -7
|
||||
acc +2
|
||||
acc +20
|
||||
acc +14
|
||||
jmp +191
|
||||
acc +47
|
||||
nop +339
|
||||
acc +49
|
||||
jmp +104
|
||||
jmp +629
|
||||
jmp +374
|
||||
acc +24
|
||||
jmp +220
|
||||
nop +474
|
||||
acc +25
|
||||
jmp +340
|
||||
acc +16
|
||||
acc +3
|
||||
acc +41
|
||||
jmp +566
|
||||
jmp +296
|
||||
acc +15
|
||||
jmp +452
|
||||
acc +21
|
||||
jmp +129
|
||||
acc +10
|
||||
acc -8
|
||||
acc +39
|
||||
jmp +396
|
||||
acc +5
|
||||
acc -4
|
||||
acc +0
|
||||
jmp +496
|
||||
nop +181
|
||||
acc +48
|
||||
acc +7
|
||||
jmp +1
|
||||
jmp +370
|
||||
acc +16
|
||||
acc -18
|
||||
acc +47
|
||||
acc +48
|
||||
jmp +99
|
||||
nop +17
|
||||
acc +25
|
||||
acc -15
|
||||
jmp +285
|
||||
nop +545
|
||||
nop +147
|
||||
nop +479
|
||||
acc -4
|
||||
jmp +386
|
||||
acc +36
|
||||
acc -12
|
||||
jmp +50
|
||||
acc +37
|
||||
nop +133
|
||||
acc +11
|
||||
acc +20
|
||||
jmp +32
|
||||
jmp +1
|
||||
nop +210
|
||||
acc -15
|
||||
acc -6
|
||||
jmp +446
|
||||
acc +25
|
||||
acc +1
|
||||
acc +17
|
||||
acc -4
|
||||
jmp +355
|
||||
acc -4
|
||||
jmp +292
|
||||
acc +16
|
||||
acc +44
|
||||
acc +26
|
||||
jmp +157
|
||||
acc -18
|
||||
acc +15
|
||||
acc -8
|
||||
acc -3
|
||||
jmp +46
|
||||
acc +30
|
||||
acc +16
|
||||
jmp -7
|
||||
acc +34
|
||||
jmp +515
|
||||
acc +11
|
||||
acc -8
|
||||
acc -9
|
||||
acc -3
|
||||
jmp +548
|
||||
jmp +278
|
||||
nop +332
|
||||
acc -19
|
||||
acc +49
|
||||
jmp +536
|
||||
acc -9
|
||||
acc +46
|
||||
jmp +124
|
||||
acc +41
|
||||
acc +47
|
||||
acc -5
|
||||
acc -13
|
||||
jmp +41
|
||||
nop +178
|
||||
acc +12
|
||||
acc +45
|
||||
jmp +461
|
||||
acc +37
|
||||
acc +12
|
||||
acc +38
|
||||
jmp -68
|
||||
acc -6
|
||||
nop +494
|
||||
acc -9
|
||||
jmp -63
|
||||
acc +42
|
||||
acc +16
|
||||
acc +30
|
||||
jmp +70
|
||||
acc +13
|
||||
jmp +1
|
||||
acc -18
|
||||
jmp +528
|
||||
acc +48
|
||||
jmp +493
|
||||
nop +402
|
||||
jmp +381
|
||||
acc -8
|
||||
jmp +372
|
||||
acc +20
|
||||
acc +25
|
||||
jmp +425
|
||||
acc -10
|
||||
jmp +510
|
||||
jmp +439
|
||||
nop +78
|
||||
acc +36
|
||||
acc +7
|
||||
nop +281
|
||||
jmp +504
|
||||
jmp -108
|
||||
acc +40
|
||||
jmp -122
|
||||
acc +23
|
||||
acc -2
|
||||
acc +7
|
||||
jmp +370
|
||||
acc +25
|
||||
nop -5
|
||||
acc +33
|
||||
acc +37
|
||||
jmp +70
|
||||
acc -6
|
||||
nop +336
|
||||
jmp +34
|
||||
jmp +1
|
||||
acc -18
|
||||
jmp +473
|
||||
jmp +1
|
||||
acc +20
|
||||
acc +4
|
||||
acc +25
|
||||
jmp -87
|
||||
acc -12
|
||||
acc +47
|
||||
acc +49
|
||||
jmp +323
|
||||
jmp +1
|
||||
jmp +1
|
||||
jmp +167
|
||||
acc -10
|
||||
acc +45
|
||||
jmp +355
|
||||
acc +32
|
||||
acc +38
|
||||
acc +2
|
||||
jmp -93
|
||||
acc +8
|
||||
acc +20
|
||||
acc +4
|
||||
acc -1
|
||||
jmp +108
|
||||
nop +164
|
||||
acc +41
|
||||
jmp +440
|
||||
acc -16
|
||||
acc +47
|
||||
jmp +355
|
||||
acc -13
|
||||
acc +29
|
||||
acc +50
|
||||
jmp -101
|
||||
acc -8
|
||||
jmp +316
|
||||
acc +27
|
||||
acc +31
|
||||
nop -29
|
||||
jmp +1
|
||||
jmp +250
|
||||
acc +12
|
||||
acc -13
|
||||
jmp +73
|
||||
jmp +72
|
||||
acc +36
|
||||
acc +44
|
||||
jmp +1
|
||||
jmp -33
|
||||
acc -18
|
||||
acc +16
|
||||
acc -8
|
||||
acc +6
|
||||
jmp +104
|
||||
jmp +295
|
||||
acc +10
|
||||
nop -80
|
||||
jmp +74
|
||||
acc -13
|
||||
jmp +1
|
||||
acc +22
|
||||
acc +50
|
||||
jmp +280
|
||||
jmp +265
|
||||
jmp +278
|
||||
acc +46
|
||||
acc -14
|
||||
acc -17
|
||||
jmp -19
|
||||
acc +39
|
||||
acc +31
|
||||
acc -11
|
||||
jmp +400
|
||||
jmp +80
|
||||
acc +0
|
||||
acc +27
|
||||
nop +209
|
||||
jmp -184
|
||||
acc +12
|
||||
acc +21
|
||||
acc +23
|
||||
jmp +352
|
||||
acc +29
|
||||
jmp -5
|
||||
acc +15
|
||||
acc +7
|
||||
jmp +6
|
||||
acc +31
|
||||
acc -5
|
||||
nop +83
|
||||
acc +31
|
||||
jmp -239
|
||||
acc +8
|
||||
acc -2
|
||||
acc +49
|
||||
acc -12
|
||||
jmp -52
|
||||
acc -15
|
||||
acc -14
|
||||
jmp +126
|
||||
jmp +385
|
||||
acc +30
|
||||
acc -5
|
||||
acc +6
|
||||
jmp -187
|
||||
acc +39
|
||||
acc +40
|
||||
acc +0
|
||||
acc +6
|
||||
jmp +24
|
||||
acc +20
|
||||
jmp +131
|
||||
jmp -127
|
||||
acc +8
|
||||
acc +30
|
||||
jmp -265
|
||||
acc -2
|
||||
jmp -265
|
||||
acc +22
|
||||
acc -19
|
||||
acc -9
|
||||
nop +10
|
||||
jmp +148
|
||||
acc -14
|
||||
acc +38
|
||||
acc +50
|
||||
acc -7
|
||||
jmp +197
|
||||
acc +11
|
||||
acc +22
|
||||
jmp +201
|
||||
jmp -155
|
||||
jmp -32
|
||||
acc +48
|
||||
nop -50
|
||||
jmp -99
|
||||
jmp -5
|
||||
acc +11
|
||||
acc -18
|
||||
jmp -186
|
||||
acc +6
|
||||
acc +43
|
||||
jmp +159
|
||||
jmp +249
|
||||
acc +44
|
||||
acc +29
|
||||
nop +313
|
||||
acc +23
|
||||
jmp +311
|
||||
jmp +152
|
||||
acc +0
|
||||
acc +41
|
||||
jmp -251
|
||||
jmp +102
|
||||
nop -17
|
||||
nop +176
|
||||
jmp +40
|
||||
acc +28
|
||||
jmp -21
|
||||
acc -4
|
||||
acc -10
|
||||
acc -19
|
||||
acc -15
|
||||
jmp +23
|
||||
nop +144
|
||||
acc +9
|
||||
acc +18
|
||||
jmp +141
|
||||
acc -19
|
||||
acc -10
|
||||
acc +48
|
||||
jmp -7
|
||||
acc +46
|
||||
acc -9
|
||||
jmp -174
|
||||
acc +30
|
||||
acc +30
|
||||
jmp -201
|
||||
acc +34
|
||||
acc +24
|
||||
acc +37
|
||||
acc +44
|
||||
jmp -158
|
||||
acc +4
|
||||
acc +39
|
||||
jmp -52
|
||||
jmp -329
|
||||
jmp +68
|
||||
acc +25
|
||||
nop -105
|
||||
acc -15
|
||||
acc +34
|
||||
jmp -6
|
||||
jmp +1
|
||||
acc +1
|
||||
jmp +163
|
||||
nop -285
|
||||
acc +8
|
||||
acc +48
|
||||
jmp +143
|
||||
acc -3
|
||||
nop -269
|
||||
acc -16
|
||||
jmp -310
|
||||
acc -5
|
||||
jmp -304
|
||||
acc +45
|
||||
nop -231
|
||||
jmp +1
|
||||
jmp +245
|
||||
nop -243
|
||||
jmp +187
|
||||
acc -6
|
||||
acc +7
|
||||
acc +17
|
||||
acc +6
|
||||
jmp -111
|
||||
acc +24
|
||||
acc -10
|
||||
acc +21
|
||||
jmp -97
|
||||
jmp +1
|
||||
acc -12
|
||||
acc +10
|
||||
jmp +127
|
||||
acc +0
|
||||
jmp -211
|
||||
acc -11
|
||||
acc +36
|
||||
acc +45
|
||||
acc -19
|
||||
jmp -182
|
||||
jmp -366
|
||||
acc +38
|
||||
acc -11
|
||||
acc +32
|
||||
jmp -260
|
||||
acc +6
|
||||
acc +31
|
||||
jmp +3
|
||||
acc +5
|
||||
jmp +101
|
||||
jmp -64
|
||||
acc +48
|
||||
acc +5
|
||||
nop +40
|
||||
acc -13
|
||||
jmp +95
|
||||
nop +76
|
||||
acc +44
|
||||
acc +43
|
||||
acc +43
|
||||
jmp +196
|
||||
acc +34
|
||||
jmp +161
|
||||
acc +5
|
||||
acc +45
|
||||
acc +7
|
||||
jmp +20
|
||||
acc +13
|
||||
jmp -127
|
||||
acc +5
|
||||
acc +18
|
||||
jmp -239
|
||||
jmp -76
|
||||
nop +214
|
||||
jmp -284
|
||||
acc +10
|
||||
acc -8
|
||||
jmp -81
|
||||
acc +48
|
||||
acc -3
|
||||
jmp -55
|
||||
nop -288
|
||||
acc +37
|
||||
acc +1
|
||||
acc -12
|
||||
jmp +1
|
||||
nop +91
|
||||
acc +20
|
||||
acc +18
|
||||
jmp +4
|
||||
acc -7
|
||||
acc -10
|
||||
jmp -229
|
||||
nop -230
|
||||
nop +45
|
||||
acc +37
|
||||
jmp +127
|
||||
jmp +69
|
||||
jmp -153
|
||||
acc -15
|
||||
acc -19
|
||||
acc +32
|
||||
jmp -33
|
||||
nop +164
|
||||
acc +32
|
||||
jmp -133
|
||||
acc +20
|
||||
acc -8
|
||||
jmp +8
|
||||
acc -11
|
||||
nop +82
|
||||
acc +7
|
||||
acc +40
|
||||
jmp +79
|
||||
acc +0
|
||||
jmp +159
|
||||
acc +4
|
||||
acc -8
|
||||
acc +20
|
||||
nop +143
|
||||
jmp -351
|
||||
acc -7
|
||||
jmp +78
|
||||
acc +0
|
||||
acc +4
|
||||
jmp +20
|
||||
jmp -3
|
||||
acc +2
|
||||
acc +23
|
||||
jmp -256
|
||||
acc +33
|
||||
jmp -473
|
||||
acc +29
|
||||
acc -13
|
||||
jmp +77
|
||||
jmp +158
|
||||
acc -16
|
||||
jmp -10
|
||||
jmp -181
|
||||
jmp -135
|
||||
nop -95
|
||||
acc +46
|
||||
acc +39
|
||||
acc -3
|
||||
jmp -94
|
||||
jmp -67
|
||||
acc +49
|
||||
nop -78
|
||||
nop -9
|
||||
jmp +107
|
||||
acc -19
|
||||
acc -1
|
||||
acc +0
|
||||
acc -4
|
||||
jmp -189
|
||||
acc +11
|
||||
jmp -106
|
||||
jmp -200
|
||||
jmp +122
|
||||
acc +8
|
||||
acc +48
|
||||
acc +15
|
||||
acc +0
|
||||
jmp -493
|
||||
acc +13
|
||||
jmp -8
|
||||
acc +36
|
||||
acc -10
|
||||
jmp +1
|
||||
acc +9
|
||||
jmp +7
|
||||
jmp +85
|
||||
acc +22
|
||||
acc -8
|
||||
nop -124
|
||||
jmp -517
|
||||
jmp -338
|
||||
acc +39
|
||||
nop -438
|
||||
acc -11
|
||||
jmp +69
|
||||
acc +8
|
||||
acc +34
|
||||
acc +34
|
||||
acc -9
|
||||
jmp -205
|
||||
nop -528
|
||||
jmp -495
|
||||
acc +47
|
||||
acc +40
|
||||
acc +30
|
||||
jmp -328
|
||||
acc -2
|
||||
acc +41
|
||||
jmp -475
|
||||
acc +42
|
||||
acc +48
|
||||
acc +2
|
||||
acc +7
|
||||
jmp -415
|
||||
nop -249
|
||||
acc -3
|
||||
jmp +65
|
||||
acc +23
|
||||
nop -4
|
||||
jmp -254
|
||||
acc -12
|
||||
acc +22
|
||||
acc +27
|
||||
jmp -176
|
||||
jmp -408
|
||||
acc -15
|
||||
acc +14
|
||||
acc +30
|
||||
acc +0
|
||||
jmp -363
|
||||
jmp -426
|
||||
acc +38
|
||||
nop -425
|
||||
jmp -440
|
||||
jmp +1
|
||||
acc +22
|
||||
jmp -63
|
||||
jmp -406
|
||||
nop -445
|
||||
acc -5
|
||||
acc +34
|
||||
nop -425
|
||||
jmp +65
|
||||
acc +33
|
||||
jmp -91
|
||||
acc -12
|
||||
jmp +1
|
||||
jmp -541
|
||||
nop -489
|
||||
jmp -490
|
||||
acc +20
|
||||
acc +20
|
||||
acc +38
|
||||
acc -18
|
||||
jmp -548
|
||||
acc +43
|
||||
acc -7
|
||||
jmp -351
|
||||
acc -9
|
||||
acc +50
|
||||
acc +1
|
||||
nop -587
|
||||
jmp -230
|
||||
jmp +1
|
||||
nop +43
|
||||
jmp -65
|
||||
acc +31
|
||||
acc +5
|
||||
acc +1
|
||||
jmp -105
|
||||
nop -477
|
||||
acc +21
|
||||
nop -92
|
||||
jmp -263
|
||||
acc +28
|
||||
jmp -265
|
||||
jmp -311
|
||||
acc +2
|
||||
acc +23
|
||||
acc +50
|
||||
jmp -4
|
||||
acc +42
|
||||
acc +42
|
||||
acc +31
|
||||
jmp -167
|
||||
acc +49
|
||||
acc +46
|
||||
jmp -73
|
||||
nop -135
|
||||
acc +43
|
||||
jmp -236
|
||||
acc -14
|
||||
acc -3
|
||||
jmp -406
|
||||
acc +2
|
||||
acc -3
|
||||
acc +47
|
||||
jmp -420
|
||||
acc -8
|
||||
acc +18
|
||||
jmp -604
|
||||
jmp -218
|
||||
acc +37
|
||||
acc -16
|
||||
nop -278
|
||||
acc -15
|
||||
jmp -214
|
||||
acc -6
|
||||
acc +18
|
||||
acc +7
|
||||
acc +0
|
||||
jmp -252
|
||||
acc +14
|
||||
jmp -266
|
||||
acc +27
|
||||
acc -16
|
||||
nop -533
|
||||
nop -534
|
||||
jmp +1
|
28
day08/Makefile
Normal file
28
day08/Makefile
Normal file
@@ -0,0 +1,28 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
output:
|
||||
@$(MAKE) --no-print-directory all 2>&1 > OUTPUT
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
|
||||
ex1: ex1-c
|
||||
@$(TIME) ex1.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex1-c shinygold < $(INPUT) 2>&1
|
||||
|
||||
ex2: ex2-c
|
||||
@$(TIME) ex2.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex2-c shinygold < $(INPUT) 2>&1
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
16
day08/OUTPUT
Normal file
16
day08/OUTPUT
Normal file
@@ -0,0 +1,16 @@
|
||||
ex1.bash : res=1594
|
||||
time: 0:00.01 real, 0.01 user, 0.00 sys
|
||||
context-switch: 0+4, page-faults: 0+303
|
||||
|
||||
ex1-c : res=1594
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 1+0, page-faults: 0+79
|
||||
|
||||
ex2.bash : res:758
|
||||
time: 0:02.26 real, 2.12 user, 0.16 sys
|
||||
context-switch: 212+1084, page-faults: 0+43039
|
||||
|
||||
ex2-c : res=758
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 1+1, page-faults: 0+78
|
||||
|
94
day08/README
Normal file
94
day08/README
Normal file
@@ -0,0 +1,94 @@
|
||||
--- Day 8: Handheld Halting ---
|
||||
|
||||
Your flight to the major airline hub reaches cruising altitude without incident. While you consider checking the in-flight menu for one of those drinks that come with a little umbrella, you are interrupted by the kid sitting next to you.
|
||||
|
||||
Their handheld game console won't turn on! They ask if you can take a look.
|
||||
|
||||
You narrow the problem down to a strange infinite loop in the boot code (your puzzle input) of the device. You should be able to fix it, but first you need to be able to run the code in isolation.
|
||||
|
||||
The boot code is represented as a text file with one instruction per line of text. Each instruction consists of an operation (acc, jmp, or nop) and an argument (a signed number like +4 or -20).
|
||||
|
||||
acc increases or decreases a single global value called the accumulator by the value given in the argument. For example, acc +7 would increase the accumulator by 7. The accumulator starts at 0. After an acc instruction, the instruction immediately below it is executed next.
|
||||
jmp jumps to a new instruction relative to itself. The next instruction to execute is found using the argument as an offset from the jmp instruction; for example, jmp +2 would skip the next instruction, jmp +1 would continue to the instruction immediately below it, and jmp -20 would cause the instruction 20 lines above to be executed next.
|
||||
nop stands for No OPeration - it does nothing. The instruction immediately below it is executed next.
|
||||
|
||||
For example, consider the following program:
|
||||
|
||||
nop +0
|
||||
acc +1
|
||||
jmp +4
|
||||
acc +3
|
||||
jmp -3
|
||||
acc -99
|
||||
acc +1
|
||||
jmp -4
|
||||
acc +6
|
||||
|
||||
These instructions are visited in this order:
|
||||
|
||||
nop +0 | 1
|
||||
acc +1 | 2, 8(!)
|
||||
jmp +4 | 3
|
||||
acc +3 | 6
|
||||
jmp -3 | 7
|
||||
acc -99 |
|
||||
acc +1 | 4
|
||||
jmp -4 | 5
|
||||
acc +6 |
|
||||
|
||||
First, the nop +0 does nothing. Then, the accumulator is increased from 0 to 1 (acc +1) and jmp +4 sets the next instruction to the other acc +1 near the bottom. After it increases the accumulator from 1 to 2, jmp -4 executes, setting the next instruction to the only acc +3. It sets the accumulator to 5, and jmp -3 causes the program to continue back at the first acc +1.
|
||||
|
||||
This is an infinite loop: with this sequence of jumps, the program will run forever. The moment the program tries to run any instruction a second time, you know it will never terminate.
|
||||
|
||||
Immediately before the program would run an instruction a second time, the value in the accumulator is 5.
|
||||
|
||||
Run your copy of the boot code. Immediately before any instruction is executed a second time, what value is in the accumulator?
|
||||
|
||||
Your puzzle answer was 1594.
|
||||
--- Part Two ---
|
||||
|
||||
After some careful analysis, you believe that exactly one instruction is corrupted.
|
||||
|
||||
Somewhere in the program, either a jmp is supposed to be a nop, or a nop is supposed to be a jmp. (No acc instructions were harmed in the corruption of this boot code.)
|
||||
|
||||
The program is supposed to terminate by attempting to execute an instruction immediately after the last instruction in the file. By changing exactly one jmp or nop, you can repair the boot code and make it terminate correctly.
|
||||
|
||||
For example, consider the same program from above:
|
||||
|
||||
nop +0
|
||||
acc +1
|
||||
jmp +4
|
||||
acc +3
|
||||
jmp -3
|
||||
acc -99
|
||||
acc +1
|
||||
jmp -4
|
||||
acc +6
|
||||
|
||||
If you change the first instruction from nop +0 to jmp +0, it would create a single-instruction infinite loop, never leaving that instruction. If you change almost any of the jmp instructions, the program will still eventually find another jmp instruction and loop forever.
|
||||
|
||||
However, if you change the second-to-last instruction (from jmp -4 to nop -4), the program terminates! The instructions are visited in this order:
|
||||
|
||||
nop +0 | 1
|
||||
acc +1 | 2
|
||||
jmp +4 | 3
|
||||
acc +3 |
|
||||
jmp -3 |
|
||||
acc -99 |
|
||||
acc +1 | 4
|
||||
nop -4 | 5
|
||||
acc +6 | 6
|
||||
|
||||
After the last instruction (acc +6), the program terminates by attempting to run the instruction below the last instruction in the file. With this change, after the program terminates, the accumulator contains the value 8 (acc +1, acc +1, acc +6).
|
||||
|
||||
Fix the program so that it terminates normally by changing exactly one jmp (to nop) or nop (to jmp). What is the value of the accumulator after the program terminates?
|
||||
|
||||
Your puzzle answer was 758.
|
||||
|
||||
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 [Share] this puzzle.
|
9
day08/TEST.txt
Normal file
9
day08/TEST.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
nop +0
|
||||
acc +1
|
||||
jmp +4
|
||||
acc +3
|
||||
jmp -3
|
||||
acc -99
|
||||
acc +1
|
||||
jmp -4
|
||||
acc +6
|
143
day08/ex1-c.c
Normal file
143
day08/ex1-c.c
Normal file
@@ -0,0 +1,143 @@
|
||||
/* ex1-c: Advent2020 game, day 8/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct instr {
|
||||
struct instr *next;
|
||||
int instr;
|
||||
int val;
|
||||
int visited;
|
||||
};
|
||||
|
||||
struct program {
|
||||
unsigned length;
|
||||
unsigned total;
|
||||
struct instr *prg;
|
||||
};
|
||||
|
||||
#define BLOCKSIZE 1024 /* number of elements for realloc() */
|
||||
#define NOP 0
|
||||
#define ACC 1
|
||||
#define JMP 2
|
||||
|
||||
void print_instr(prg, step, cur)
|
||||
struct program *prg;
|
||||
int step;
|
||||
int cur;
|
||||
{
|
||||
struct instr *instr=prg->prg+step;
|
||||
char *op="unknown";
|
||||
|
||||
switch (instr->instr) {
|
||||
case NOP:
|
||||
op="nop";
|
||||
break;
|
||||
case JMP:
|
||||
op="jmp";
|
||||
break;
|
||||
case ACC:
|
||||
op="acc";
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "%03d: [%s][%4d] -> %4d\n", step, op, instr->val, cur);
|
||||
}
|
||||
|
||||
void print_prg(prg)
|
||||
struct program *prg;
|
||||
{
|
||||
unsigned i, psize=prg->length;
|
||||
struct instr *pinstr=prg->prg;
|
||||
|
||||
fprintf(stderr, "PROGRAM: address=%p pinstr=%p size=%d\n", prg, pinstr, psize);
|
||||
for (i=0; i<psize; ++i)
|
||||
print_instr(prg, i, 0);
|
||||
}
|
||||
|
||||
static struct program *add_line(prg, line)
|
||||
struct program *prg;
|
||||
char *line;
|
||||
{
|
||||
char sinstr[80];
|
||||
int val;
|
||||
unsigned cur, total;
|
||||
struct instr *pinstr;
|
||||
|
||||
if (!prg) {
|
||||
prg=malloc(sizeof (struct program));
|
||||
prg->prg=malloc(sizeof(struct instr)*BLOCKSIZE);
|
||||
|
||||
//fprintf(stderr, "alloc buf: prg=%p prog=%p\n", prg, prg->prg);
|
||||
prg->length=0;
|
||||
prg->total=BLOCKSIZE;
|
||||
}
|
||||
cur=prg->length;
|
||||
total=prg->total;
|
||||
|
||||
if (cur == total) {
|
||||
total+=BLOCKSIZE;
|
||||
prg->total=total;
|
||||
prg->prg=realloc(prg->prg, sizeof(struct instr)*total);
|
||||
//fprintf(stderr, "realloc buf: cur=%d total=%d prog=%p\n", cur, total, prg->prg);
|
||||
}
|
||||
pinstr=prg->prg+cur;
|
||||
|
||||
sscanf(line, "%s %d", sinstr, &val);
|
||||
pinstr->visited=0;
|
||||
pinstr->val=val;
|
||||
if (!strcmp(sinstr, "jmp"))
|
||||
pinstr->instr=JMP;
|
||||
else if (!strcmp(sinstr, "acc"))
|
||||
pinstr->instr=ACC;
|
||||
else pinstr->instr=NOP;
|
||||
prg->length++;
|
||||
|
||||
return prg;
|
||||
}
|
||||
|
||||
int run(prg)
|
||||
struct program *prg;
|
||||
{
|
||||
int cur=0, length=prg->length;
|
||||
struct instr *instr=prg->prg;
|
||||
int res=0;
|
||||
|
||||
//fprintf(stderr, "RUN: address=%p prg=%p size=%d\n", prg, instr, length);
|
||||
while (cur>=0 && cur<length) {
|
||||
instr=prg->prg+cur;
|
||||
//print_instr(prg, cur, res);
|
||||
if (instr->visited) {
|
||||
break;
|
||||
}
|
||||
instr->visited=1;
|
||||
switch (instr->instr) {
|
||||
case NOP:
|
||||
cur++;
|
||||
break;
|
||||
case JMP:
|
||||
cur+=instr->val;
|
||||
break;
|
||||
case ACC:
|
||||
res+=instr->val;
|
||||
cur++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
char line[512];
|
||||
struct program *prg=NULL;
|
||||
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
prg=add_line(prg, line);
|
||||
}
|
||||
//print_prg(prg);
|
||||
printf("%s : res=%d\n", *av, run(prg));
|
||||
exit(0);
|
||||
}
|
58
day08/ex1.bash
Executable file
58
day08/ex1.bash
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 8/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
|
||||
#declare -i ACCUMULATOR=0
|
||||
|
||||
declare -a PRG=()
|
||||
declare -i ARG=()
|
||||
declare -i PRGSIZE=0
|
||||
|
||||
function run() {
|
||||
local -i arg cur=0 res=0
|
||||
local -a steps=()
|
||||
local instr
|
||||
|
||||
while [[ ${steps[$cur]} != 1 ]]; do
|
||||
instr=${PRG[$cur]}
|
||||
arg=${ARG[$cur]}
|
||||
steps[$cur]=1
|
||||
case "$instr" in
|
||||
acc)
|
||||
((res += arg))
|
||||
((cur++))
|
||||
;;
|
||||
nop)
|
||||
((cur++))
|
||||
;;
|
||||
jmp)
|
||||
((cur += arg))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo "$res"
|
||||
}
|
||||
|
||||
function print_prog()
|
||||
{
|
||||
local -i i
|
||||
for ((i=0; i<PRGSIZE; ++i)); do
|
||||
printf "%03d : [%s][%3d]\n" "$i" "${PRG[$i]}" "${ARG[$i]}"
|
||||
done
|
||||
}
|
||||
|
||||
while read -r instr arg; do
|
||||
PRG[$PRGSIZE]=$instr
|
||||
ARG[$PRGSIZE]=$arg
|
||||
((PRGSIZE++))
|
||||
done
|
||||
|
||||
#print_prog
|
||||
|
||||
res=$(run)
|
||||
printf "%s : res=%d\n" "${CMD}" "$res"
|
||||
|
||||
exit 0
|
184
day08/ex2-c.c
Normal file
184
day08/ex2-c.c
Normal file
@@ -0,0 +1,184 @@
|
||||
/* ex1-c: Advent2020 game, day 8/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct instr {
|
||||
struct instr *next;
|
||||
int instr;
|
||||
int val;
|
||||
int visited;
|
||||
};
|
||||
|
||||
struct program {
|
||||
unsigned length;
|
||||
unsigned total;
|
||||
struct instr *prg;
|
||||
};
|
||||
|
||||
#define BLOCKSIZE 1024 /* number of elements for realloc() */
|
||||
#define NOP 0
|
||||
#define ACC 1
|
||||
#define JMP 2
|
||||
|
||||
void print_instr(prg, step, cur)
|
||||
struct program *prg;
|
||||
int step;
|
||||
int cur;
|
||||
{
|
||||
struct instr *instr=prg->prg+step;
|
||||
char *op="unknown";
|
||||
|
||||
switch (instr->instr) {
|
||||
case NOP:
|
||||
op="nop";
|
||||
break;
|
||||
case JMP:
|
||||
op="jmp";
|
||||
break;
|
||||
case ACC:
|
||||
op="acc";
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "%03d: [%s][%4d] -> %4d\n", step, op, instr->val, cur);
|
||||
}
|
||||
|
||||
void print_prg(prg)
|
||||
struct program *prg;
|
||||
{
|
||||
unsigned i, psize=prg->length;
|
||||
struct instr *pinstr=prg->prg;
|
||||
|
||||
fprintf(stderr, "PROGRAM: address=%p pinstr=%p size=%d\n", prg, pinstr, psize);
|
||||
for (i=0; i<psize; ++i)
|
||||
print_instr(prg, i, 0);
|
||||
}
|
||||
|
||||
void reset_prg(prg)
|
||||
struct program *prg;
|
||||
{
|
||||
unsigned i, psize=prg->length;
|
||||
struct instr *pinstr=prg->prg;
|
||||
|
||||
for (i=0; i<psize; ++i)
|
||||
pinstr[i].visited=0;
|
||||
}
|
||||
|
||||
static struct program *add_line(prg, line)
|
||||
struct program *prg;
|
||||
char *line;
|
||||
{
|
||||
char sinstr[80];
|
||||
int val;
|
||||
unsigned cur, total;
|
||||
struct instr *pinstr;
|
||||
|
||||
if (!prg) {
|
||||
prg=malloc(sizeof (struct program));
|
||||
prg->prg=malloc(sizeof(struct instr)*BLOCKSIZE);
|
||||
|
||||
//fprintf(stderr, "alloc buf: prg=%p prog=%p\n", prg, prg->prg);
|
||||
prg->length=0;
|
||||
prg->total=BLOCKSIZE;
|
||||
}
|
||||
cur=prg->length;
|
||||
total=prg->total;
|
||||
|
||||
if (cur == total) {
|
||||
total+=BLOCKSIZE;
|
||||
prg->total=total;
|
||||
prg->prg=realloc(prg->prg, sizeof(struct instr)*total);
|
||||
//fprintf(stderr, "realloc buf: cur=%d total=%d prog=%p\n", cur, total, prg->prg);
|
||||
}
|
||||
pinstr=prg->prg+cur;
|
||||
|
||||
sscanf(line, "%s %d", sinstr, &val);
|
||||
pinstr->visited=0;
|
||||
pinstr->val=val;
|
||||
if (!strcmp(sinstr, "jmp"))
|
||||
pinstr->instr=JMP;
|
||||
else if (!strcmp(sinstr, "acc"))
|
||||
pinstr->instr=ACC;
|
||||
else pinstr->instr=NOP;
|
||||
prg->length++;
|
||||
|
||||
return prg;
|
||||
}
|
||||
|
||||
int run2(prg, ret)
|
||||
struct program *prg;
|
||||
int *ret;
|
||||
{
|
||||
int cur=0, length=prg->length;
|
||||
struct instr *instr=prg->prg;
|
||||
int res=0;
|
||||
|
||||
reset_prg(prg);
|
||||
//fprintf(stderr, "RUN: address=%p prg=%p size=%d\n", prg, instr, length);
|
||||
//print_prg(prg);
|
||||
while (cur>=0 && cur<length) {
|
||||
instr=prg->prg+cur;
|
||||
//print_instr(prg, cur, res);
|
||||
if (instr->visited) {
|
||||
return 1;
|
||||
}
|
||||
instr->visited=1;
|
||||
switch (instr->instr) {
|
||||
case NOP:
|
||||
cur++;
|
||||
break;
|
||||
case JMP:
|
||||
cur+=instr->val;
|
||||
break;
|
||||
case ACC:
|
||||
res+=instr->val;
|
||||
cur++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*ret=res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
char line[512];
|
||||
struct program *prg=NULL;
|
||||
struct instr *instr;
|
||||
int res=0, cur=0, length=0;
|
||||
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
prg=add_line(prg, line);
|
||||
}
|
||||
instr=prg->prg;
|
||||
length=prg->length;
|
||||
if (run2(prg, &res)) {
|
||||
do {
|
||||
while (cur<length && instr[cur].instr == ACC)
|
||||
cur++;
|
||||
if (cur < length) {
|
||||
int isav=instr[cur].instr;
|
||||
switch (isav) {
|
||||
case NOP:
|
||||
instr[cur].instr=JMP;
|
||||
break;
|
||||
case JMP:
|
||||
instr[cur].instr=NOP;
|
||||
break;
|
||||
}
|
||||
if (!run2(prg, &res))
|
||||
break;
|
||||
instr[cur].instr=isav;
|
||||
|
||||
} else
|
||||
break;
|
||||
cur++;
|
||||
} while (cur>=0 && cur<length);
|
||||
}
|
||||
printf("%s : res=%d\n", *av, res);
|
||||
exit(0);
|
||||
|
||||
}
|
78
day08/ex2.bash
Executable file
78
day08/ex2.bash
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 8/game 2.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
|
||||
declare -a PRG=()
|
||||
declare -i ARG=()
|
||||
|
||||
function run() {
|
||||
local -i arg cur=0 res=0 size=$1
|
||||
local instr
|
||||
local -a steps=()
|
||||
|
||||
while ((cur < size)) && [[ ${steps[$cur]} != 1 ]]; do
|
||||
instr=${PRG[$cur]}
|
||||
arg=${ARG[$cur]}
|
||||
steps[$cur]=1
|
||||
case "$instr" in
|
||||
acc)
|
||||
((res += arg))
|
||||
((cur++))
|
||||
;;
|
||||
nop)
|
||||
((cur++))
|
||||
;;
|
||||
jmp)
|
||||
((cur += arg))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo $res
|
||||
return $((cur < size))
|
||||
}
|
||||
|
||||
function print_prog()
|
||||
{
|
||||
local -i i
|
||||
for ((i=0; i<${#PRG[@]}; ++i)); do
|
||||
printf "%03d : [%s][%3d]\n" "$i" "${PRG[$i]}" "${ARG[$i]}"
|
||||
done
|
||||
}
|
||||
|
||||
declare -i i=0
|
||||
while read -r instr arg; do
|
||||
PRG[$i]=$instr
|
||||
ARG[$i]=$arg
|
||||
((i++))
|
||||
done
|
||||
|
||||
lastchanged=-1
|
||||
savstep=""
|
||||
while true; do
|
||||
res=$(run $i) && break
|
||||
|
||||
if ((lastchanged >= 0)); then
|
||||
PRG[$lastchanged]="$savstep"
|
||||
fi
|
||||
((lastchanged++))
|
||||
while ((lastchanged <= PRGSIZE)) && [[ ${PRG[$lastchanged]} == acc ]]; do
|
||||
((lastchanged++))
|
||||
done
|
||||
|
||||
savstep=${PRG[$lastchanged]}
|
||||
case $savstep in
|
||||
jmp)
|
||||
PRG[$lastchanged]="nop"
|
||||
;;
|
||||
nop)
|
||||
PRG[$lastchanged]="jmp"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
printf "%s : res:%d\n" "${CMD}" "$res"
|
||||
|
||||
exit 0
|
1000
day09/INPUT.txt
Normal file
1000
day09/INPUT.txt
Normal file
File diff suppressed because it is too large
Load Diff
28
day09/Makefile
Normal file
28
day09/Makefile
Normal file
@@ -0,0 +1,28 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
output:
|
||||
@$(MAKE) --no-print-directory all 2>&1 > OUTPUT
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
|
||||
ex1: ex1-c
|
||||
@$(TIME) ex1.bash 25 < $(INPUT) 2>&1
|
||||
@$(TIME) ex1-c 25 < $(INPUT) 2>&1
|
||||
|
||||
ex2: ex2-c
|
||||
@$(TIME) ex2.bash 25 < $(INPUT) 2>&1
|
||||
@$(TIME) ex2-c 25 < $(INPUT) 2>&1
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
16
day09/OUTPUT
Normal file
16
day09/OUTPUT
Normal file
@@ -0,0 +1,16 @@
|
||||
ex1.bash : res=167829540
|
||||
time: 0:00.42 real, 0.42 user, 0.00 sys
|
||||
context-switch: 57+1, page-faults: 0+172
|
||||
|
||||
ex1-c : res=167829540
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+76
|
||||
|
||||
ex2.bash : res=167829540 sum=28045630
|
||||
time: 0:03.22 real, 3.01 user, 0.21 sys
|
||||
context-switch: 359+921, page-faults: 0+49208
|
||||
|
||||
ex2-c : res=167829540 sum=28045630
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+75
|
||||
|
93
day09/README
Normal file
93
day09/README
Normal file
@@ -0,0 +1,93 @@
|
||||
--- Day 9: Encoding Error ---
|
||||
|
||||
With your neighbor happily enjoying their video game, you turn your attention to an open data port on the little screen in the seat in front of you.
|
||||
|
||||
Though the port is non-standard, you manage to connect it to your computer through the clever use of several paperclips. Upon connection, the port outputs a series of numbers (your puzzle input).
|
||||
|
||||
The data appears to be encrypted with the eXchange-Masking Addition System (XMAS) which, conveniently for you, is an old cypher with an important weakness.
|
||||
|
||||
XMAS starts by transmitting a preamble of 25 numbers. After that, each number you receive should be the sum of any two of the 25 immediately previous numbers. The two numbers will have different values, and there might be more than one such pair.
|
||||
|
||||
For example, suppose your preamble consists of the numbers 1 through 25 in a random order. To be valid, the next number must be the sum of two of those numbers:
|
||||
|
||||
26 would be a valid next number, as it could be 1 plus 25 (or many other pairs, like 2 and 24).
|
||||
49 would be a valid next number, as it is the sum of 24 and 25.
|
||||
100 would not be valid; no two of the previous 25 numbers sum to 100.
|
||||
50 would also not be valid; although 25 appears in the previous 25 numbers, the two numbers in the pair must be different.
|
||||
|
||||
Suppose the 26th number is 45, and the first number (no longer an option, as it is more than 25 numbers ago) was 20. Now, for the next number to be valid, there needs to be some pair of numbers among 1-19, 21-25, or 45 that add up to it:
|
||||
|
||||
26 would still be a valid next number, as 1 and 25 are still within the previous 25 numbers.
|
||||
65 would not be valid, as no two of the available numbers sum to it.
|
||||
64 and 66 would both be valid, as they are the result of 19+45 and 21+45 respectively.
|
||||
|
||||
Here is a larger example which only considers the previous 5 numbers (and has a preamble of length 5):
|
||||
|
||||
35
|
||||
20
|
||||
15
|
||||
25
|
||||
47
|
||||
40
|
||||
62
|
||||
55
|
||||
65
|
||||
95
|
||||
102
|
||||
117
|
||||
150
|
||||
182
|
||||
127
|
||||
219
|
||||
299
|
||||
277
|
||||
309
|
||||
576
|
||||
|
||||
In this example, after the 5-number preamble, almost every number is the sum of two of the previous 5 numbers; the only number that does not follow this rule is 127.
|
||||
|
||||
The first step of attacking the weakness in the XMAS data is to find the first number in the list (after the preamble) which is not the sum of two of the 25 numbers before it. What is the first number that does not have this property?
|
||||
|
||||
Your puzzle answer was 167829540.
|
||||
--- Part Two ---
|
||||
|
||||
The final step in breaking the XMAS encryption relies on the invalid number you just found: you must find a contiguous set of at least two numbers in your list which sum to the invalid number from step 1.
|
||||
|
||||
Again consider the above example:
|
||||
|
||||
35
|
||||
20
|
||||
15
|
||||
25
|
||||
47
|
||||
40
|
||||
62
|
||||
55
|
||||
65
|
||||
95
|
||||
102
|
||||
117
|
||||
150
|
||||
182
|
||||
127
|
||||
219
|
||||
299
|
||||
277
|
||||
309
|
||||
576
|
||||
|
||||
In this list, adding up all of the numbers from 15 through 40 produces the invalid number from step 1, 127. (Of course, the contiguous set of numbers in your actual list might be much longer.)
|
||||
|
||||
To find the encryption weakness, add together the smallest and largest number in this contiguous range; in this example, these are 15 and 47, producing 62.
|
||||
|
||||
What is the encryption weakness in your XMAS-encrypted list of numbers?
|
||||
|
||||
Your puzzle answer was 28045630.
|
||||
|
||||
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 [Share] this puzzle.
|
20
day09/TEST.txt
Normal file
20
day09/TEST.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
35
|
||||
20
|
||||
15
|
||||
25
|
||||
47
|
||||
40
|
||||
62
|
||||
55
|
||||
65
|
||||
95
|
||||
102
|
||||
117
|
||||
150
|
||||
182
|
||||
127
|
||||
219
|
||||
299
|
||||
277
|
||||
309
|
||||
576
|
103
day09/ex1-c.c
Normal file
103
day09/ex1-c.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/* ex1-c: Advent2020 game, day 8/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct list {
|
||||
unsigned size;
|
||||
unsigned last;
|
||||
unsigned long long *list;
|
||||
};
|
||||
|
||||
#define DEFNSUM 25
|
||||
#define BLOCKSIZE 1024 /* number of elements for realloc() */
|
||||
|
||||
void print_list(list)
|
||||
struct list *list;
|
||||
{
|
||||
unsigned i, psize=list->last;
|
||||
unsigned long long *ptr=list->list;
|
||||
|
||||
fprintf(stderr, "PROGRAM: address=%p pinstr=%p size=%d\n", list, ptr, psize);
|
||||
for (i=0; i<psize; ++i)
|
||||
printf("[%u] %llu\n", i, *(ptr+i));
|
||||
}
|
||||
|
||||
static struct list *add_line(list, line)
|
||||
struct list *list;
|
||||
char *line;
|
||||
{
|
||||
int val;
|
||||
unsigned cur, size;
|
||||
unsigned long long *ptr;
|
||||
|
||||
if (!list) {
|
||||
list=malloc(sizeof(struct list));
|
||||
list->list=malloc(sizeof(unsigned long long)*BLOCKSIZE);
|
||||
list->size=BLOCKSIZE;
|
||||
list->last=0;
|
||||
}
|
||||
cur=list->last;
|
||||
size=list->size;
|
||||
|
||||
if (cur == size) {
|
||||
size+=BLOCKSIZE;
|
||||
list->size=size;
|
||||
list->list=realloc(list->list, sizeof(unsigned long long)*size);
|
||||
fprintf(stderr, "realloc buf: cur=%d size=%d ptr=%p\n", cur, size, list->list);
|
||||
}
|
||||
ptr=list->list+cur;
|
||||
|
||||
sscanf(line, "%d", &val);
|
||||
*ptr=val;
|
||||
list->last++;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
unsigned long long calc(list, cur, nsum)
|
||||
struct list *list;
|
||||
int cur;
|
||||
unsigned nsum;
|
||||
{
|
||||
unsigned long long *ptr=list->list;
|
||||
unsigned long long res=*(ptr+cur);
|
||||
int start=cur-nsum, i, j;
|
||||
|
||||
for (i=start; i<cur; ++i) {
|
||||
for (j=i+1; j<cur; ++j) {
|
||||
if (ptr[i]+ptr[j] == res)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
int ac;
|
||||
char **av;
|
||||
{
|
||||
unsigned nsum=DEFNSUM;
|
||||
char line[80];
|
||||
struct list *list=NULL;
|
||||
unsigned i;
|
||||
unsigned long long res;
|
||||
|
||||
if (ac==2) {
|
||||
nsum=atoi(*(av+1));
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
list=add_line(list, line);
|
||||
}
|
||||
//print_list(list);
|
||||
for (i=nsum; i<list->last; ++i) {
|
||||
if (res=calc(list, i, nsum)) {
|
||||
printf("%s : res=%llu\n", *av, res);
|
||||
break;
|
||||
}
|
||||
}
|
||||
exit (0);
|
||||
}
|
51
day09/ex1.bash
Executable file
51
day09/ex1.bash
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 8/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
|
||||
declare -i N=5 SIZE
|
||||
declare -a LIST=()
|
||||
|
||||
function push25 () {
|
||||
local i
|
||||
for ((i=0; i<25; ++i)); do
|
||||
read -r i
|
||||
LIST+=("$i")
|
||||
done
|
||||
}
|
||||
|
||||
function push() {
|
||||
local i
|
||||
while read -r i; do
|
||||
LIST+=("$i")
|
||||
done
|
||||
SIZE=${#LIST[@]}
|
||||
}
|
||||
|
||||
function badnum() {
|
||||
local -i cur="$1" i j
|
||||
local -i res=${LIST[$cur]}
|
||||
local -i start=$((cur-N-1))
|
||||
for ((i=start; i<cur; ++i)); do
|
||||
for ((j=i+1; j<cur; ++j)); do
|
||||
if (((LIST[i]+LIST[j]) == res)); then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
done
|
||||
return 1
|
||||
}
|
||||
[[ $# = 1 ]] && N=$1
|
||||
|
||||
push
|
||||
declare -i i target
|
||||
for ((i=N; i<SIZE; ++i)); do
|
||||
badnum $i || break
|
||||
done
|
||||
target="${LIST[$i]}"
|
||||
|
||||
printf "%s : res=%d\n" "$CMD" "$target"
|
||||
|
||||
exit 0
|
134
day09/ex2-c.c
Normal file
134
day09/ex2-c.c
Normal file
@@ -0,0 +1,134 @@
|
||||
/* ex1-c: Advent2020 game, day 8/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct list {
|
||||
unsigned size;
|
||||
unsigned last;
|
||||
unsigned long long *list;
|
||||
};
|
||||
|
||||
#define DEFNSUM 25
|
||||
#define BLOCKSIZE 1024 /* number of elements for realloc() */
|
||||
|
||||
void print_list(list)
|
||||
struct list *list;
|
||||
{
|
||||
unsigned i, psize=list->last;
|
||||
unsigned long long *ptr=list->list;
|
||||
|
||||
fprintf(stderr, "PROGRAM: address=%p pinstr=%p size=%d\n", list, ptr, psize);
|
||||
for (i=0; i<psize; ++i)
|
||||
printf("[%u] %llu\n", i, *(ptr+i));
|
||||
}
|
||||
|
||||
static struct list *add_line(list, line)
|
||||
struct list *list;
|
||||
char *line;
|
||||
{
|
||||
int val;
|
||||
unsigned cur, size;
|
||||
unsigned long long *ptr;
|
||||
|
||||
if (!list) {
|
||||
list=malloc(sizeof(struct list));
|
||||
list->list=malloc(sizeof(unsigned long long)*BLOCKSIZE);
|
||||
list->size=BLOCKSIZE;
|
||||
list->last=0;
|
||||
}
|
||||
cur=list->last;
|
||||
size=list->size;
|
||||
|
||||
if (cur == size) {
|
||||
size+=BLOCKSIZE;
|
||||
list->size=size;
|
||||
list->list=realloc(list->list, sizeof(unsigned long long)*size);
|
||||
fprintf(stderr, "realloc buf: cur=%d size=%d ptr=%p\n", cur, size, list->list);
|
||||
}
|
||||
ptr=list->list+cur;
|
||||
|
||||
sscanf(line, "%d", &val);
|
||||
*ptr=val;
|
||||
list->last++;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
unsigned long long badnum(list, cur, nsum)
|
||||
struct list *list;
|
||||
int cur;
|
||||
unsigned nsum;
|
||||
{
|
||||
unsigned long long *ptr=list->list;
|
||||
unsigned long long res=*(ptr+cur);
|
||||
int start=cur-nsum, i, j;
|
||||
|
||||
for (i=start; i<cur; ++i) {
|
||||
for (j=i+1; j<cur; ++j) {
|
||||
if (ptr[i]+ptr[j] == res)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
unsigned long long findsum(list, target, start)
|
||||
struct list *list;
|
||||
unsigned long long target;
|
||||
int start;
|
||||
{
|
||||
unsigned long long sum=0;
|
||||
unsigned int i;
|
||||
unsigned size=list->last;
|
||||
unsigned long long *ptr=list->list, cur;
|
||||
unsigned long long min=*(ptr+start), max=min;
|
||||
|
||||
for (i=start; i<size && sum<target; ++i) {
|
||||
cur=*(ptr+i);
|
||||
sum+=cur;
|
||||
if (cur < min)
|
||||
min=cur;
|
||||
if (cur > max)
|
||||
max=cur;
|
||||
if (sum == target) {
|
||||
return min+max;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(ac, av)
|
||||
int ac;
|
||||
char **av;
|
||||
{
|
||||
unsigned nsum=DEFNSUM;
|
||||
char line[80];
|
||||
struct list *list=NULL;
|
||||
unsigned i;
|
||||
unsigned long long res1, res2;
|
||||
|
||||
if (ac==2) {
|
||||
nsum=atoi(*(av+1));
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof line, stdin)) {
|
||||
list=add_line(list, line);
|
||||
}
|
||||
//print_list(list);
|
||||
for (i=nsum; i<list->last; ++i) {
|
||||
if (res1=badnum(list, i, nsum)) {
|
||||
//printf("%s : res=%llu\n", *av, res1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i=0; i<list->last; ++i) {
|
||||
if (res2=findsum(list, res1, i)) {
|
||||
printf("%s : res=%llu sum=%llu\n", *av, res1, res2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
exit (0);
|
||||
}
|
75
day09/ex2.bash
Executable file
75
day09/ex2.bash
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 8/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
shopt -s extglob
|
||||
|
||||
declare -i N=5 SIZE
|
||||
declare -a LIST=()
|
||||
|
||||
function push25 () {
|
||||
local i
|
||||
for ((i=0; i<25; ++i)); do
|
||||
read -r i
|
||||
LIST+=("$i")
|
||||
done
|
||||
}
|
||||
|
||||
function push() {
|
||||
local i
|
||||
while read -r i; do
|
||||
LIST+=("$i")
|
||||
done
|
||||
SIZE=${#LIST[@]}
|
||||
}
|
||||
|
||||
function badnum() {
|
||||
local -i cur="$1" i j
|
||||
local -i res=${LIST[$cur]}
|
||||
local -i start=$((cur-N-1))
|
||||
for ((i=start; i<cur; ++i)); do
|
||||
for ((j=i+1; j<cur; ++j)); do
|
||||
if (((LIST[i]+LIST[j]) == res)); then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
function findsum() {
|
||||
local -i target=$1 start=$2 i
|
||||
local -i sum=0
|
||||
local -i small=${LIST[$start]}
|
||||
local -i high=$small
|
||||
|
||||
for ((i=start; i<SIZE && sum<target; ++i)); do
|
||||
((cur=${LIST[$i]}))
|
||||
((sum+=cur))
|
||||
((cur<small)) && small=$cur
|
||||
((cur>high)) && high=$cur
|
||||
|
||||
if ((sum==target)); then
|
||||
echo $((small+high))
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
[[ $# = 1 ]] && N=$1
|
||||
|
||||
push
|
||||
declare -i i target num
|
||||
for ((i=N; i<SIZE; ++i)); do
|
||||
badnum $i || break
|
||||
done
|
||||
target="${LIST[$i]}"
|
||||
for ((i=0; i<SIZE; ++i)); do
|
||||
num=$(findsum "$target" $i) && break
|
||||
done
|
||||
printf "%s : res=%d sum=%d\n" "$CMD" "$target" "$num"
|
||||
|
||||
exit 0
|
97
day10/INPUT.txt
Normal file
97
day10/INPUT.txt
Normal file
@@ -0,0 +1,97 @@
|
||||
8
|
||||
40
|
||||
45
|
||||
93
|
||||
147
|
||||
64
|
||||
90
|
||||
125
|
||||
149
|
||||
145
|
||||
111
|
||||
126
|
||||
9
|
||||
146
|
||||
38
|
||||
97
|
||||
103
|
||||
6
|
||||
122
|
||||
34
|
||||
18
|
||||
35
|
||||
96
|
||||
86
|
||||
116
|
||||
29
|
||||
59
|
||||
118
|
||||
102
|
||||
26
|
||||
66
|
||||
17
|
||||
74
|
||||
94
|
||||
5
|
||||
114
|
||||
128
|
||||
1
|
||||
75
|
||||
47
|
||||
141
|
||||
58
|
||||
65
|
||||
100
|
||||
63
|
||||
12
|
||||
53
|
||||
25
|
||||
106
|
||||
136
|
||||
15
|
||||
82
|
||||
22
|
||||
117
|
||||
2
|
||||
80
|
||||
79
|
||||
139
|
||||
7
|
||||
81
|
||||
129
|
||||
19
|
||||
52
|
||||
87
|
||||
115
|
||||
132
|
||||
140
|
||||
88
|
||||
109
|
||||
62
|
||||
73
|
||||
46
|
||||
24
|
||||
69
|
||||
101
|
||||
110
|
||||
16
|
||||
95
|
||||
148
|
||||
76
|
||||
135
|
||||
142
|
||||
89
|
||||
50
|
||||
72
|
||||
41
|
||||
39
|
||||
42
|
||||
56
|
||||
51
|
||||
57
|
||||
127
|
||||
83
|
||||
121
|
||||
33
|
||||
32
|
||||
23
|
28
day10/Makefile
Normal file
28
day10/Makefile
Normal file
@@ -0,0 +1,28 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
output:
|
||||
@$(MAKE) --no-print-directory all 2>&1 > OUTPUT
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
|
||||
ex1: ex1-c
|
||||
@$(TIME) ex1.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex1-c < $(INPUT) 2>&1
|
||||
|
||||
ex2: ex2-c
|
||||
@$(TIME) ex2.bash < $(INPUT) 2>&1
|
||||
@$(TIME) ex2-c < $(INPUT) 2>&1
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
18
day10/OUTPUT
Normal file
18
day10/OUTPUT
Normal file
@@ -0,0 +1,18 @@
|
||||
cc -w ex1-c.c -o ex1-c
|
||||
ex1.bash : diff1=71 diff2=27 res=1917
|
||||
time: 0:00.01 real, 0.00 user, 0.00 sys
|
||||
context-switch: 1+4, page-faults: 0+331
|
||||
|
||||
ex1-c : diff1=71 diff2=27 res=1917
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+73
|
||||
|
||||
cc -w ex2-c.c -o ex2-c
|
||||
ex2.bash : size=99 res=113387824750592
|
||||
time: 0:00.01 real, 0.01 user, 0.00 sys
|
||||
context-switch: 2+4, page-faults: 0+329
|
||||
|
||||
ex2-c : size=99 res=113387824750592
|
||||
time: 0:00.00 real, 0.00 user, 0.00 sys
|
||||
context-switch: 0+1, page-faults: 0+73
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user