So, I decided, against my better judgement to take part in the advent of code. I'm having a blast right now even if day 3 looks a little intimidating for me. For reference I'm not a developer by trade, albeit, I used to code a lot as a kid, I haven't coded properly in upwards of 3+ years.
Day 1
Day one sets us up with quite a simple challenge: Take some numbers, find two that add up to 2020 then multiply them. Part two, take three, multiply them.
for (let i = 0; i < numbers.length; i++) {
for (let j = i+1; j < numbers.length; j++) {
if(numbers[i]+numbers[j] == 2020){
const answer = numbers[i] * numbers[j];
console.log(answer);
}
}
}
For part one, I thought the simplest way would be just to cycle through the options until we found the answer.
for (let i = 0; i < numbers.length; i++) {
for (let j = i+1; j < numbers.length; j++) {
for (let k = j+1; k < numbers.length; k++) {
if(numbers[i]+numbers[j]+numbers[k] == 2020){
const answer = numbers[i] * numbers[j] * numbers[k];
console.log(answer);
}
}
}
}
For part 2, I added another layer of recursion. I want to come back to this later and figure out a way to not need that third layer of recursion, but, for now, it's here to stay.
That's my day 1, I'll be releasing day 2 in a little bit. :)
Rin