diff --git a/2020/13/input.txt b/2020/13/input.txt new file mode 100644 index 0000000..66803ac --- /dev/null +++ b/2020/13/input.txt @@ -0,0 +1,2 @@ +1001796 +37,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,457,x,x,x,x,x,x,x,x,x,x,x,x,13,17,x,x,x,x,x,x,x,x,23,x,x,x,x,x,29,x,431,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,19 \ No newline at end of file diff --git a/2020/13/part1.js b/2020/13/part1.js new file mode 100644 index 0000000..828b543 --- /dev/null +++ b/2020/13/part1.js @@ -0,0 +1,21 @@ +// this was fairly simple; just keep increasing the wait until you find a bus that leaves. there is probably a more efficient solution but this works +const fs = require('fs'); +const input = fs.readFileSync('input.txt', 'utf-8').split('\n'); +const time = Number(input[0]); +const busses = input[1].split(',').filter(v=>v!='x').map(n => Number(n)); + +let isBus = false; +let timeDif = 0; +let busID; +for (; !isBus; timeDif++) { + for(bus of busses) { + if ((time + timeDif) % bus == 0){ + busID = bus; + isBus = true; + break; + } + } +} +// the for loop does an extra increment at the end oops +timeDif-- +console.log(timeDif*busID) \ No newline at end of file diff --git a/2020/13/part2.js b/2020/13/part2.js new file mode 100644 index 0000000..ad2c6a6 --- /dev/null +++ b/2020/13/part2.js @@ -0,0 +1,19 @@ +// this was a tough one. I still don't fully understand what the puzzle was asking for. but i played around in excel and found this method to find the solution. +const fs = require('fs'); +const input = fs.readFileSync('input.txt', 'utf-8').split('\n'); +const busses = input[1].split(',').map(n => Number(n)).map((v,i)=>[v,i]).filter(v => !isNaN(v[0])); +console.log(busses) +// start with a timestamp of 0 +let time = 0; +// if you incrment by the ID of the first bus, the first bus will always meet the pattern described in the puzzle. +let inc = busses[0][0] +for (let bus = 1; bus < busses.length; bus++){ + // continue incrementing until the next bus meets the pattern described in the puzzle + while (((time+busses[bus][1]) % busses[bus][0]) != 0) { + time += inc + } + // now you can increment by the new bus that met the pattern, and it will continue to meet the pattern + inc*=busses[bus][0] +} +// since we looped through all the busses, we know that all busses meet the pattern. +console.log(time) \ No newline at end of file diff --git a/2020/13/test.txt b/2020/13/test.txt new file mode 100644 index 0000000..e473080 --- /dev/null +++ b/2020/13/test.txt @@ -0,0 +1,2 @@ +939 +7,13,x,x,59,x,31,19 \ No newline at end of file diff --git a/2020/13/test2.txt b/2020/13/test2.txt new file mode 100644 index 0000000..267507d --- /dev/null +++ b/2020/13/test2.txt @@ -0,0 +1,2 @@ + +67,7,59,61 \ No newline at end of file diff --git a/2020/13/test3.txt b/2020/13/test3.txt new file mode 100644 index 0000000..f96fffd --- /dev/null +++ b/2020/13/test3.txt @@ -0,0 +1,2 @@ + +67,x,7,59,61 \ No newline at end of file diff --git a/2020/13/test4.txt b/2020/13/test4.txt new file mode 100644 index 0000000..7a02b4b --- /dev/null +++ b/2020/13/test4.txt @@ -0,0 +1,2 @@ + +67,7,x,59,61 \ No newline at end of file diff --git a/2020/13/test5.txt b/2020/13/test5.txt new file mode 100644 index 0000000..15576dd --- /dev/null +++ b/2020/13/test5.txt @@ -0,0 +1,2 @@ + +1789,37,47,1889 \ No newline at end of file diff --git a/README.md b/README.md index 0dc85b5..75c4fd9 100644 --- a/README.md +++ b/README.md @@ -53,15 +53,4 @@ if (advent) { 10. [:star: :star:](https://adventofcode.com/2020/day/10 "see puzzle") 11. [:star: :star:](https://adventofcode.com/2020/day/11 "see puzzle") 12. [:star: :star:](https://adventofcode.com/2020/day/12 "see puzzle") - -## Languages Used -* Python - - py -* Node JS - - js -* Java (Processing) - - pde -* HTML, CSS, JavaScript - - html - - css - - js \ No newline at end of file +13. [:star: :star:](https://adventofcode.com/2020/day/13 "see puzzle")