Is anyone thinking of partaking in Advent of Code 2024? @Kem_Tekinay introduced me to AoC last year, and I found it to be a fun learning experience.
I didn’t finish it last year, but I’ll be there again this year.
Since you already started the topic…
It’s that time of year again when the Advent of Code puzzles starts anew at midnight on the morning of Dec. 1 (roughly 14 hours from now).
It’s a fun way to challenge yourself to solve problems and learn new techniques so I encourage everyone to join.
If you’d like to be part of my Private Leaderboard, send me a private message here for the code. But either way, I hope you’ll participate.
I’m in for another year. Let’s see how long I last this time.
Day 1 wasn’t too tricky, just a lot of parsing.
Plus every time I do AOC I have to relearn dictionary syntax.
Hey guys,
I’m going to have a late start with AoC this year… a bit tied up with work at the moment… but I hope to join in as soon as I can.
Day 2 part 1 is pretty straightforward. Part 2 is too, if you think about it (which I didn’t).
Day 2 Part 2
Since any element can be removed to create a valid report, you have to try removing each one to see if it’s valid. In fact, you never have to check the complete report because a report that is entirely valid will still be valid after you remove the first element.
My check code is a bit verbose, but works:
Private Function CheckValues(values() As Integer) As Boolean
var isGood as boolean = true
var lastIndex as integer = values.LastIndex - 1
for i as integer = 0 to lastIndex
var v1 as integer = values( i )
var v2 as integer = values( i + 1 )
if v1 < v2 and abs( v1 - v2 ) <= 3 then
continue
end if
isGood = false
exit
next
if isGood then
return true
end if
for i as integer = values.LastIndex downto 1
var v1 as integer = values( i )
var v2 as integer = values( i - 1 )
if v1 < v2 and abs( v1 - v2 ) <= 3 then
continue
end if
return false
exit
next
return true
End Function
Lagging a bit behind because EOY is busiest time for me, but day one is done:
I initially interpreted the challenge as a much harder problem than it was. (I expected it to be really hard!)
Note to self: TEST WITH SAMPLE VALUES IF THEY ARE PROVIDED (and hopefully a useful note to others)
Doing so, made it clear the task was much less daunting and I finished the revised version in < 10 minutes.
Day 2 part 1 was easier. (for me)
So far, I find the most challenging part to be interpreting the (intentionally?) obtuse language used in describing the problems.
On to part 2 when time permits.
Also just completed day 1
Both parts of Day 2 done.
–
Kem - I tried to compare my results with yours (using formula from above) but always got a wrong result from your code snippet.
I probably just misunderstood something about how to use it. (577 was my answer)
Day 2 completed
Kem - I’m realizing your code was probably just for part 1. (it matches my part 1 answer)
No, it’s for both parts, but…
Day 2 spoiler
Outside that code, I methodically remove each element from the array and re-test using that function until I get True, or all the combinations are rejected.
FYI - I’m keeping all my work in a single project with each day being its own window (and a helper classes folder with any classes I used for that day in it)
It’ll be fun to see all the days and how I solved (or didn’t!) them.
I got “bit” by passing an array (and changing its length while it was passed to a method) by ref in a loop, and when method removed an element from the array, the loop was exiting “early” because the LastIndex value had changed .
Only real hitch on day 2 (for me)
It’s best not to try to read too much into the problem description. They’re very confusing. Just concentrate on the worked example. Fortunately, every problem comes with an example. Otherwise, it would be a nightmare.
Always test your code with the example data, and when you get the right answer, there’s a fair chance that it will work with the actual data.
Keeping in mind that the example data doesn’t usually include the twists you might find in the actual data.
For example, last year (I think) there was a puzzle where you had to replace text like “1two3” with “123”. But the example data didn’t illustrate that you might encounter “fiveightwo” to make that “582”.
Right. I made a really dumb mistake on Day 2, by noting that the example data all had the same number of items in each line, and then hard coding that number, even though I could see that it varied in the actual data. Took a minute or two to figure out why I was getting out of bounds exceptions.
Day 3 spoiler
Betcha doin backflips to avoid regular expressions.