2020 day 1 and 2 (:

This commit is contained in:
tristan 2020-12-02 13:24:30 +00:00
parent cbc02f04d5
commit de2fa19311
6 changed files with 1276 additions and 0 deletions

200
2020/01/input.txt Normal file
View file

@ -0,0 +1,200 @@
1408
1335
1648
1458
1627
1928
1967
1827
1606
1569
1893
1866
1768
1795
1264
1684
1552
1343
1917
1675
1731
1800
1413
1879
1664
1350
1694
1372
1851
1743
1735
833
748
1265
1885
1874
2007
1661
1895
1537
1622
1355
762
1533
1771
1966
1978
1572
1833
1969
1805
1820
1536
1911
2009
1817
1268
1998
1759
2008
2002
1187
1896
1850
1734
1849
1589
1302
444
1280
1590
1959
902
1709
1932
1277
1561
1301
1831
1286
1693
1927
1467
1384
1662
1401
716
1634
1785
1801
1380
1971
1292
1828
185
1560
1322
1787
1545
1395
1445
1807
1750
1867
1433
1894
1821
1983
1578
1669
1610
1549
1556
1346
1616
1999
1925
1387
1659
1457
1237
1808
69
1906
1449
1723
1974
1919
1914
1338
1305
1347
1903
1929
1712
1607
1400
197
1575
1282
1296
1737
1396
2003
1453
1660
1646
1991
1565
1416
1995
1784
1367
1420
1593
1654
1306
1916
1797
1594
1471
1405
1698
1541
1900
1963
1696
1574
1853
511
1603
1889
1940
1843
1979
272
1726
1294
1877
1441
1697
1644
1956
1689
1665
1631
1717
1781
1450
1618
1317
1799
1950
1722
1960
1628
1941
1977
1775
1529

19
2020/01/part1.js Normal file
View file

@ -0,0 +1,19 @@
const fs = require('fs');
let data = fs.readFileSync('input.txt', 'utf-8');
let lines = data.split('\n').map(x => parseInt(x));
let done = false
lines.forEach((number, index) => {
if (done) {return}
lines.forEach((number2, index2) => {
if (done) {return}
if (index != index2) {
//console.log(number, number2)
if (number + number2 == 2020){
done = true
console.log(number, number2, number*number2)
}
}
})
})

22
2020/01/part2.js Normal file
View file

@ -0,0 +1,22 @@
const fs = require('fs');
let data = fs.readFileSync('input.txt', 'utf-8');
let lines = data.split('\n').map(x => parseInt(x));
let done = false
lines.forEach((number, index) => {
if (done) {return}
lines.forEach((number2, index2) => {
if (done) {return}
lines.forEach((number3, index3) => {
if (done) {return}
if (index != index2 && index != index3 && index2 != index3) {
//console.log(number, number2)
if (number + number2 + number3 == 2020){
done = true
console.log(number, number2, number3, number*number2*number3)
}
}
})
})
})

1000
2020/02/input.txt Normal file

File diff suppressed because it is too large Load diff

17
2020/02/part1.js Normal file
View file

@ -0,0 +1,17 @@
const fs = require('fs');
let data = fs.readFileSync('input.txt', 'utf-8');
let lines = data.split('\n').map(x => x.split(" "));
let count = 0
for (let i = 0; i < lines.length; i++) {
let line = lines[i]
let lim = line[0].split("-")
let char = line[1].substring(0, 1)
let pass = line[2]
let match = pass.match(new RegExp(char, 'g'))
if (!match) { continue }
let matches = match.length
if (matches < lim[0] || matches > lim[1]) { continue }
console.log(pass)
count++
}
console.log(count)

18
2020/02/part2.js Normal file
View file

@ -0,0 +1,18 @@
const fs = require('fs');
let data = fs.readFileSync('input.txt', 'utf-8');
let lines = data.split('\n').map(x => x.split(" "));
let count = 0
for ( let i = 0; i < lines.length; i++){
let line = lines[i]
let lim = line[0].split("-")
let char = line[1].substring(0,1)
let pass = line[2]
let one = (pass.charAt(lim[0]-1) == char)
let other = (pass.charAt(lim[1]-1) == char)
if (one^other){
console.log(pass)
count++
}
}
console.log(count)