-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ethan Diamond
committed
Dec 2, 2020
0 parents
commit a9ebb1c
Showing
5 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Advent of Code | ||
|
||
https://adventofcode.com/2020 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
1735 | ||
1700 | ||
1358 | ||
1908 | ||
1634 | ||
2006 | ||
762 | ||
1492 | ||
1917 | ||
1591 | ||
1571 | ||
1283 | ||
1744 | ||
1815 | ||
1383 | ||
1787 | ||
1832 | ||
1032 | ||
1845 | ||
1406 | ||
1978 | ||
1263 | ||
1450 | ||
1364 | ||
1594 | ||
1877 | ||
1346 | ||
1695 | ||
1501 | ||
1266 | ||
1729 | ||
1476 | ||
1558 | ||
1684 | ||
1295 | ||
1267 | ||
1341 | ||
1415 | ||
1491 | ||
1640 | ||
1756 | ||
1330 | ||
1987 | ||
1969 | ||
1844 | ||
1706 | ||
1654 | ||
1580 | ||
1405 | ||
1419 | ||
1367 | ||
1277 | ||
1992 | ||
1953 | ||
1499 | ||
1470 | ||
2000 | ||
1739 | ||
1889 | ||
1670 | ||
1776 | ||
1798 | ||
1308 | ||
1890 | ||
1626 | ||
1284 | ||
1315 | ||
1869 | ||
1514 | ||
1214 | ||
1648 | ||
1418 | ||
1329 | ||
1795 | ||
1385 | ||
1477 | ||
1984 | ||
1796 | ||
1515 | ||
2001 | ||
1155 | ||
1800 | ||
1965 | ||
1971 | ||
1100 | ||
1650 | ||
1686 | ||
1911 | ||
1560 | ||
1912 | ||
1721 | ||
1658 | ||
1738 | ||
1885 | ||
1028 | ||
266 | ||
1989 | ||
1704 | ||
1388 | ||
1498 | ||
1769 | ||
1453 | ||
925 | ||
1588 | ||
1828 | ||
1024 | ||
1671 | ||
1998 | ||
1942 | ||
1636 | ||
1382 | ||
993 | ||
1703 | ||
1475 | ||
1391 | ||
1970 | ||
1841 | ||
1952 | ||
1446 | ||
1347 | ||
1395 | ||
1440 | ||
1980 | ||
1386 | ||
1922 | ||
1857 | ||
1291 | ||
1808 | ||
1335 | ||
1876 | ||
1576 | ||
1436 | ||
634 | ||
1557 | ||
1782 | ||
1881 | ||
1955 | ||
1765 | ||
1736 | ||
1585 | ||
1858 | ||
1862 | ||
989 | ||
1661 | ||
1757 | ||
1775 | ||
1693 | ||
1842 | ||
1660 | ||
1647 | ||
870 | ||
1928 | ||
1597 | ||
1420 | ||
1646 | ||
1821 | ||
2009 | ||
1866 | ||
1947 | ||
1593 | ||
1788 | ||
1369 | ||
1525 | ||
1256 | ||
1846 | ||
1445 | ||
1907 | ||
1750 | ||
1906 | ||
1849 | ||
765 | ||
1342 | ||
1811 | ||
1260 | ||
1466 | ||
1424 | ||
1823 | ||
1767 | ||
1290 | ||
1840 | ||
1825 | ||
1287 | ||
1384 | ||
1996 | ||
1627 | ||
1983 | ||
1328 | ||
1674 | ||
1676 | ||
1727 | ||
1810 | ||
1394 | ||
799 | ||
1723 | ||
1293 | ||
1273 | ||
1317 | ||
1749 | ||
1552 | ||
1645 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "day-1", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"part_one": "node part_one.js", | ||
"part_two": "node part_two.js" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const fs = require('fs') | ||
const { exit } = require('process') | ||
const readline = require('readline') | ||
|
||
let numbers = new Set() | ||
fs.readFile('numbers.txt', 'utf-8', (err, data) => { | ||
data.split('\n').forEach(numberString => { | ||
const number = parseInt(numberString) | ||
if (numbers.has(2020 - number)) { | ||
console.log("Part 1:") | ||
console.log(`The numbers are ${number} and ${2020 - number}`) | ||
console.log(`The answer is ${number * (2020 - number)}`) | ||
exit(0) | ||
} | ||
numbers.add(number) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const fs = require('fs') | ||
const { exit } = require('process') | ||
const readline = require('readline') | ||
|
||
let baseNumbers = new Set() | ||
let sumNumbers = new Set() | ||
let sumNumberLookup = new Map() | ||
|
||
fs.readFile('numbers.txt', 'utf-8', (err, data) => { | ||
data.split('\n').forEach(numberString => { | ||
const number = parseInt(numberString) | ||
if (sumNumbers.has(2020 - number)) { | ||
let otherNumbers = sumNumberLookup[2020 - number] | ||
|
||
console.log("Part 2:") | ||
console.log(`The numbers are ${number}, ${otherNumbers[0]} and ${otherNumbers[1]}`) | ||
console.log(`The answer is ${number * otherNumbers[0] * otherNumbers[1]}`) | ||
exit(0) | ||
} | ||
|
||
baseNumbers.forEach(baseNumber => { | ||
const sum = baseNumber + number | ||
sumNumbers.add(sum) | ||
sumNumberLookup[sum] = [baseNumber, number] | ||
}) | ||
baseNumbers.add(number) | ||
}) | ||
}) |