diff --git a/AdventOfCode2018/1stDay/challenge2/challenge.txt b/AdventOfCode2018/1stDay/challenge2/challenge.txt new file mode 100644 index 0000000..a19d994 --- /dev/null +++ b/AdventOfCode2018/1stDay/challenge2/challenge.txt @@ -0,0 +1,21 @@ +--- Part Two --- +You notice that the device repeats the same frequency change list over and over. To calibrate the device, you need to find the first frequency it reaches twice. + +For example, using the same list of changes above, the device would loop as follows: + +Current frequency 0, change of +1; resulting frequency 1. +Current frequency 1, change of -2; resulting frequency -1. +Current frequency -1, change of +3; resulting frequency 2. +Current frequency 2, change of +1; resulting frequency 3. +(At this point, the device continues from the start of the list.) +Current frequency 3, change of +1; resulting frequency 4. +Current frequency 4, change of -2; resulting frequency 2, which has already been seen. +In this example, the first frequency reached twice is 2. Note that your device might need to repeat its list of frequency changes many times before a duplicate frequency is found, and that duplicates might be found while in the middle of processing the list. + +Here are other examples: + ++1, -1 first reaches 0 twice. ++3, +3, +4, -2, -4 first reaches 10 twice. +-6, +3, +8, +5, -6 first reaches 5 twice. ++7, +7, -2, -7, -4 first reaches 14 twice. +What is the first frequency your device reaches twice? \ No newline at end of file diff --git a/AdventOfCode2018/1stDay/challenge2/index.js b/AdventOfCode2018/1stDay/challenge2/index.js new file mode 100644 index 0000000..76b25d3 --- /dev/null +++ b/AdventOfCode2018/1stDay/challenge2/index.js @@ -0,0 +1,24 @@ +const fs = require('fs'); +let input = fs.readFileSync('input.txt') + .toString() + .split('\n') + .map((x) => parseInt(x)); + +let seenFrequencies = new Set([0]); +let total = 0; +let i = 0; + +while (true) { + if (i === input.length) { + i = 0; + continue; + } + total += input[i]; + if (seenFrequencies.has(total)) { + break; + } + seenFrequencies.add(total); + i++; +} + +console.log(total) diff --git a/AdventOfCode2018/1stDay/challenge2/input.txt b/AdventOfCode2018/1stDay/challenge2/input.txt new file mode 100644 index 0000000..0d7449e --- /dev/null +++ b/AdventOfCode2018/1stDay/challenge2/input.txt @@ -0,0 +1,1008 @@ ++15 +-7 ++16 ++5 ++12 ++16 +-4 ++10 +-1 ++14 +-16 ++6 ++4 ++11 +-2 ++5 ++4 ++12 ++13 ++5 ++16 ++18 +-3 +-2 ++9 +-10 ++12 +-10 +-17 ++12 +-14 +-14 ++11 ++1 +-16 ++11 +-5 ++20 +-1 ++14 +-15 +-10 +-5 ++4 +-17 +-13 +-2 +-12 +-15 ++12 ++8 +-3 ++13 ++17 ++21 ++21 ++8 ++9 +-5 +-15 +-19 +-9 +-17 +-5 ++15 ++12 ++14 ++19 +-2 ++15 +-6 ++19 +-2 ++4 +-5 +-8 +-4 ++10 ++1 +-5 ++10 ++12 ++14 +-2 ++11 +-3 +-15 +-6 ++14 ++3 ++8 ++10 ++14 ++11 ++18 ++3 +-4 +-5 +-13 ++17 +-12 +-8 +-5 ++7 ++7 +-10 +-19 ++17 ++1 ++17 +-5 +-9 +-10 +-9 +-1 +-3 +-14 ++11 ++1 ++11 ++1 ++2 +-17 ++4 ++19 ++17 ++6 ++18 +-4 ++3 +-13 ++7 +-3 ++19 ++5 ++2 ++6 ++12 ++5 +-7 ++10 ++16 +-9 +-16 ++11 ++10 ++2 ++7 +-16 ++6 ++16 ++17 ++11 ++11 +-14 ++11 +-16 +-13 ++6 ++8 ++10 +-4 +-5 ++2 ++5 +-18 ++19 +-11 +-5 +-5 +-5 +-16 +-5 ++16 ++7 +-10 +-20 +-14 +-18 ++13 ++9 +-10 ++18 +-7 +-8 +-4 ++13 ++9 ++18 ++20 +-10 +-14 +-22 +-21 +-10 ++20 +-7 +-9 ++1 ++11 ++6 ++12 ++14 +-5 ++16 ++13 ++8 +-2 +-13 +-2 ++11 ++21 ++9 +-5 ++1 ++18 ++6 ++18 +-17 ++3 ++7 +-2 +-3 ++1 ++7 ++17 ++16 ++4 ++13 ++7 ++17 +-18 ++17 ++2 ++19 +-11 ++2 ++2 ++1 +-16 +-19 +-4 +-17 +-8 +-5 ++12 +-8 ++19 ++3 ++17 ++3 ++3 ++8 ++3 +-13 ++12 +-7 ++9 ++16 ++15 ++3 +-6 +-10 ++14 +-13 +-8 ++4 ++12 ++19 ++17 ++18 +-12 +-11 ++7 +-1 +-7 +-28 +-19 +-6 ++2 ++15 ++3 +-12 +-15 ++5 +-15 +-8 +-16 +-17 ++8 +-7 ++3 ++6 +-18 ++10 +-17 +-9 +-13 ++20 +-13 +-12 +-12 ++9 +-2 ++6 +-10 +-1 ++14 +-18 +-14 ++2 ++25 +-16 +-17 ++19 ++8 ++14 +-15 +-17 ++40 ++21 +-19 ++4 ++3 +-2 ++9 +-2 +-3 ++15 +-9 +-18 ++9 ++7 ++27 ++3 ++8 ++6 ++2 +-13 ++4 +-16 ++26 +-15 +-8 +-16 ++17 +-18 ++33 ++9 ++68 ++8 ++20 +-9 +-8 ++28 ++15 ++15 ++9 ++12 ++20 ++5 ++16 ++22 +-5 ++8 ++14 ++6 ++6 ++10 ++10 ++7 +-13 +-8 ++10 ++9 ++13 +-15 +-15 ++13 ++8 ++5 ++25 +-10 ++21 ++16 ++10 +-16 ++1 +-57 ++13 +-20 +-30 ++2 ++7 ++15 +-18 +-28 +-13 ++1 +-9 +-6 +-2 +-13 ++11 +-4 +-1 +-9 +-13 +-13 ++12 +-14 ++12 +-13 +-7 +-2 +-15 +-2 ++3 ++32 ++13 ++12 +-4 +-19 +-5 ++22 +-29 +-24 +-25 +-6 +-12 +-9 ++3 +-15 ++3 +-5 ++20 +-10 +-34 +-77 +-9 +-9 +-23 +-6 ++8 ++9 ++47 +-82 +-21 ++38 +-61 ++11 +-65 +-37 +-22 ++2 ++12 +-26 +-20 +-4 ++6 +-7 ++14 ++6 ++11 ++19 +-32 ++10 +-74 ++9 +-64 +-59 +-92 +-10 +-92 +-18 +-23 +-64754 +-2 +-16 +-6 +-19 ++6 +-12 +-10 ++14 ++9 ++11 ++12 ++15 ++2 +-14 +-11 ++13 +-1 +-18 +-3 ++19 ++16 ++12 ++14 +-19 +-11 ++9 +-7 ++13 ++20 +-1 ++2 ++13 ++10 ++15 ++15 ++13 +-15 +-7 +-10 ++9 ++2 ++7 ++18 +-9 ++6 +-8 ++4 ++18 +-17 ++12 ++14 ++14 +-15 +-12 +-17 ++18 +-16 ++6 +-13 +-23 +-5 ++9 +-10 +-16 +-19 ++1 ++12 +-18 +-9 +-1 ++5 +-9 ++11 ++1 ++1 ++17 +-20 ++5 +-17 +-13 +-9 +-18 +-11 +-19 +-13 ++11 +-4 ++19 +-5 ++9 ++18 ++8 +-12 +-10 +-14 ++17 ++20 ++12 ++15 +-22 +-12 ++9 +-5 +-19 ++18 ++19 +-8 +-23 +-18 +-1 +-4 +-16 ++1 +-16 ++19 +-11 +-19 +-8 +-15 +-12 +-4 +-15 ++10 ++3 ++15 +-19 ++11 ++5 ++8 +-19 ++3 +-18 ++4 +-8 ++1 ++5 +-13 +-20 ++7 +-8 +-2 ++16 ++13 +-8 +-12 ++2 ++3 ++13 +-9 ++15 ++9 +-16 +-1 +-21 ++8 +-17 +-6 +-2 +-18 +-10 +-6 +-13 +-19 +-1 ++10 +-3 +-9 +-9 ++8 ++2 ++17 +-3 ++5 +-6 +-17 ++13 ++16 +-10 ++3 ++12 ++15 +-13 +-12 +-23 ++10 ++16 ++3 +-14 +-6 +-14 ++11 ++13 ++20 ++8 +-15 ++19 +-10 ++1 +-6 ++14 ++13 ++7 +-15 +-1 +-5 +-3 +-19 ++4 ++7 +-13 +-12 +-19 ++4 +-2 +-15 +-1 ++10 +-13 +-1 +-10 ++7 ++11 +-1 +-9 ++14 +-9 +-15 ++14 +-7 +-15 +-16 +-14 ++12 +-5 +-5 ++11 +-5 ++7 ++18 +-1 +-14 +-14 +-1 +-12 ++1 ++1 ++6 ++18 +-11 +-12 +-14 +-2 ++1 +-3 +-20 +-8 +-8 +-3 ++17 ++7 ++4 ++21 ++19 +-10 ++6 ++20 ++16 +-17 ++7 +-11 ++7 ++8 +-2 ++20 +-14 ++21 ++4 ++3 ++3 +-7 ++23 +-17 +-24 ++5 ++15 +-27 +-10 +-2 +-12 +-23 ++2 +-25 +-11 ++19 +-30 +-17 +-15 ++2 ++16 ++8 ++10 ++1 +-15 +-10 ++9 +-18 +-17 ++23 +-15 ++17 ++6 +-19 ++15 +-7 ++2 +-15 ++21 +-24 +-15 +-4 ++14 ++2 ++18 ++34 ++6 ++8 +-19 +-6 +-12 ++3 +-15 +-12 +-37 ++2 ++9 +-22 +-31 +-5 ++1 +-16 ++19 ++10 +-19 +-22 +-14 +-6 +-18 ++10 +-6 ++17 ++18 +-19 +-15 ++3 +-16 ++20 ++10 +-19 ++10 +-6 ++20 ++19 ++11 +-17 ++13 +-20 +-4 ++20 +-18 +-12 +-8 +-18 +-18 ++6 +-2 ++5 +-17 +-7 +-12 +-5 +-9 ++11 +-9 +-11 +-12 +-4 +-4 +-1 +-2 ++14 +-13 ++17 +-12 +-19 ++23 ++12 +-5 ++16 ++15 +-9 +-12 +-11 +-17 +-17 +-6 ++22 ++21 ++12 ++19 ++13 ++22 ++19 +-11 ++2 +-7 ++8 +-12 +-18 ++6 +-5 +-13 +-34 +-11 +-1 +-4 ++20 ++63 +-4 +-14 +-24 +-20 +-31 +-90 +-8 +-9 +-21 +-16 ++27 +-19 +-9 +-183 +-3 +-10 +-16 ++9 +-10 ++11 ++11 ++19 ++32 +-2 +-3 +-81 ++12 ++16 ++5 +-1 ++17 +-28 ++32 ++22 ++39 +-115 +-2 ++183 ++108 ++1 +-19 ++14 ++3 ++39 +-10 ++33 ++14 +-161 +-885 +-63592 +-9 +-10 ++3 +-4 +-4 ++19 ++16 ++20 ++14 +-3 +-18 +-10 +-5 +-7 ++17 +-16 ++5 +-4 +-18 ++10 ++1 ++18 ++1 ++2 +-19 +-6 +-19 +-12 +-13 +-4 ++20 +-7 ++2 +-4 ++15 +-21 +-4 +-16 +-5 ++17 +-10 ++9 +-5 ++18 ++21 +-6 ++9 +-19 +-6 ++17 +-2 +-5 ++24 ++130793 \ No newline at end of file