Initial commit
This commit is contained in:
commit
f242d2b0df
420 changed files with 62521 additions and 0 deletions
49
2020/day01/day01.c
Normal file
49
2020/day01/day01.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <input file>\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *fp = fopen(argv[1], "r");
|
||||
if (fp == NULL) {
|
||||
printf("Could not open file %s\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int input[1024] = {0};
|
||||
int d;
|
||||
int n = 0;
|
||||
while (fscanf(fp, "%d\n", &d) == 1) {
|
||||
input[n] = d;
|
||||
n++;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
int res = -1;
|
||||
for (int i = 0; i < n && res == -1; ++i) {
|
||||
for (int j = 0; j < n && res == -1; ++j) {
|
||||
if (input[i] + input[j] == 2020) {
|
||||
res = input[i] * input[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d\n", res);
|
||||
|
||||
res = -1;
|
||||
for (int i = 0; i < n && res == -1; ++i) {
|
||||
for (int j = 0; j < n && res == -1; ++j) {
|
||||
for (int k = 0; k < n && res == -1; ++k) {
|
||||
if (input[i] + input[j] + input[k] == 2020) {
|
||||
res = input[i] * input[j] * input[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d\n", res);
|
||||
|
||||
return 0;
|
||||
}
|
6
2020/day01/day01.dyalog
Normal file
6
2020/day01/day01.dyalog
Normal file
|
@ -0,0 +1,6 @@
|
|||
⎕io←0
|
||||
x←⍎¨⊃⎕nget'input'1
|
||||
⍝ Part 1
|
||||
×/x[⊃⍸2020=x∘.+x]
|
||||
⍝ Part 2
|
||||
×/x[⊃⍸2020=⊃∘.+/3⍴⊂x]
|
37
2020/day01/day01.rkt
Normal file
37
2020/day01/day01.rkt
Normal file
|
@ -0,0 +1,37 @@
|
|||
#lang racket
|
||||
|
||||
(module+ test
|
||||
(require rackunit))
|
||||
|
||||
(module+ main
|
||||
(displayln "Day 1"))
|
||||
|
||||
(define (read-input filename)
|
||||
(map string->number (file->lines filename)))
|
||||
|
||||
(define (part1 filename)
|
||||
(define expenses (read-input filename))
|
||||
(for*/last ([a (in-list expenses)]
|
||||
[b (in-list expenses)]
|
||||
#:final (= 2020 (+ a b)))
|
||||
(* a b)))
|
||||
|
||||
(module+ test
|
||||
(check-eq? (part1 "test") 514579))
|
||||
|
||||
(module+ main
|
||||
(displayln (part1 "input")))
|
||||
|
||||
(define (part2 filename)
|
||||
(define expenses (read-input filename))
|
||||
(for*/last ([a (in-list expenses)]
|
||||
[b (in-list expenses)]
|
||||
[c (in-list expenses)]
|
||||
#:final (= 2020 (+ a b c)))
|
||||
(* a b c)))
|
||||
|
||||
(module+ test
|
||||
(check-eq? (part2 "test") 241861950))
|
||||
|
||||
(module+ main
|
||||
(displayln (part2 "input")))
|
200
2020/day01/input
Normal file
200
2020/day01/input
Normal file
|
@ -0,0 +1,200 @@
|
|||
1688
|
||||
1463
|
||||
1461
|
||||
1842
|
||||
1441
|
||||
1838
|
||||
1583
|
||||
1891
|
||||
1876
|
||||
1551
|
||||
1506
|
||||
2005
|
||||
1989
|
||||
1417
|
||||
1784
|
||||
1975
|
||||
1428
|
||||
1485
|
||||
1597
|
||||
1871
|
||||
105
|
||||
788
|
||||
1971
|
||||
1892
|
||||
1854
|
||||
1466
|
||||
1584
|
||||
1565
|
||||
1400
|
||||
1640
|
||||
1780
|
||||
1774
|
||||
360
|
||||
1421
|
||||
1368
|
||||
1771
|
||||
1666
|
||||
1707
|
||||
1627
|
||||
1449
|
||||
1677
|
||||
1504
|
||||
1721
|
||||
1994
|
||||
1959
|
||||
1862
|
||||
1768
|
||||
1986
|
||||
1904
|
||||
1382
|
||||
1969
|
||||
1852
|
||||
1917
|
||||
1966
|
||||
1742
|
||||
1371
|
||||
1405
|
||||
1995
|
||||
1906
|
||||
1694
|
||||
1735
|
||||
1422
|
||||
1719
|
||||
1978
|
||||
1641
|
||||
1761
|
||||
1567
|
||||
1974
|
||||
1495
|
||||
1973
|
||||
1958
|
||||
1599
|
||||
1770
|
||||
1600
|
||||
1465
|
||||
1865
|
||||
1479
|
||||
1687
|
||||
1390
|
||||
1802
|
||||
2008
|
||||
645
|
||||
1435
|
||||
1589
|
||||
1949
|
||||
1909
|
||||
1526
|
||||
1667
|
||||
1831
|
||||
1864
|
||||
1713
|
||||
1718
|
||||
1232
|
||||
1868
|
||||
1884
|
||||
1825
|
||||
1999
|
||||
1590
|
||||
1759
|
||||
1391
|
||||
1757
|
||||
323
|
||||
1612
|
||||
1637
|
||||
1727
|
||||
1783
|
||||
1643
|
||||
1442
|
||||
1452
|
||||
675
|
||||
1812
|
||||
1604
|
||||
1518
|
||||
1894
|
||||
1933
|
||||
1801
|
||||
1914
|
||||
912
|
||||
1576
|
||||
1961
|
||||
1970
|
||||
1446
|
||||
1985
|
||||
1988
|
||||
1563
|
||||
1826
|
||||
1409
|
||||
1503
|
||||
1539
|
||||
1832
|
||||
1698
|
||||
1990
|
||||
1689
|
||||
1532
|
||||
765
|
||||
1546
|
||||
1384
|
||||
1519
|
||||
1615
|
||||
1556
|
||||
1754
|
||||
1983
|
||||
1394
|
||||
1763
|
||||
1823
|
||||
1788
|
||||
1407
|
||||
1946
|
||||
1751
|
||||
1837
|
||||
1680
|
||||
1929
|
||||
1814
|
||||
1948
|
||||
1919
|
||||
1953
|
||||
55
|
||||
1731
|
||||
1516
|
||||
1895
|
||||
1795
|
||||
1890
|
||||
1881
|
||||
1799
|
||||
1536
|
||||
1396
|
||||
1942
|
||||
1798
|
||||
1767
|
||||
1745
|
||||
1883
|
||||
2004
|
||||
1550
|
||||
1916
|
||||
1650
|
||||
1749
|
||||
1991
|
||||
1789
|
||||
1740
|
||||
1490
|
||||
1873
|
||||
1003
|
||||
1699
|
||||
1669
|
||||
1781
|
||||
2000
|
||||
1728
|
||||
1877
|
||||
1733
|
||||
1588
|
||||
1168
|
||||
1828
|
||||
1848
|
||||
1963
|
||||
1928
|
||||
1920
|
||||
1493
|
||||
1968
|
||||
1564
|
||||
1572
|
6
2020/day01/test
Normal file
6
2020/day01/test
Normal file
|
@ -0,0 +1,6 @@
|
|||
1721
|
||||
979
|
||||
366
|
||||
299
|
||||
675
|
||||
1456
|
Loading…
Add table
Add a link
Reference in a new issue