#adventofcode2023 — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #adventofcode2023, aggregated by home.social.
-
Crazy how much difference the right data structure / #algorithm for a task makes.
This week I learned about #Deterministic #Finite #Automata and #Nondeterministic Finite Automata just to redo my clunky #AdventOfCode2023 day 12 challenge, written in #Rust #RustLang
Runtime for part 1 dropped from 1-2secs to milliseconds. Part 2 also milliseconds 😮
Are there any good Rust crates for DFAs/NFAs?
Many people solved that problem with #Dynamic #Programming - something else for the learn list 😉
-
Crazy how much difference the right data structure / #algorithm for a task makes.
This week I learned about #Deterministic #Finite #Automata and #Nondeterministic Finite Automata just to redo my clunky #AdventOfCode2023 day 12 challenge, written in #Rust #RustLang
Runtime for part 1 dropped from 1-2secs to milliseconds. Part 2 also milliseconds 😮
Are there any good Rust crates for DFAs/NFAs?
Many people solved that problem with #Dynamic #Programming - something else for the learn list 😉
-
Crazy how much difference the right data structure / #algorithm for a task makes.
This week I learned about #Deterministic #Finite #Automata and #Nondeterministic Finite Automata just to redo my clunky #AdventOfCode2023 day 12 challenge, written in #Rust #RustLang
Runtime for part 1 dropped from 1-2secs to milliseconds. Part 2 also milliseconds 😮
Are there any good Rust crates for DFAs/NFAs?
Many people solved that problem with #Dynamic #Programming - something else for the learn list 😉
-
Crazy how much difference the right data structure / #algorithm for a task makes.
This week I learned about #Deterministic #Finite #Automata and #Nondeterministic Finite Automata just to redo my clunky #AdventOfCode2023 day 12 challenge, written in #Rust #RustLang
Runtime for part 1 dropped from 1-2secs to milliseconds. Part 2 also milliseconds 😮
Are there any good Rust crates for DFAs/NFAs?
Many people solved that problem with #Dynamic #Programming - something else for the learn list 😉
-
Crazy how much difference the right data structure / #algorithm for a task makes.
This week I learned about #Deterministic #Finite #Automata and #Nondeterministic Finite Automata just to redo my clunky #AdventOfCode2023 day 12 challenge, written in #Rust #RustLang
Runtime for part 1 dropped from 1-2secs to milliseconds. Part 2 also milliseconds 😮
Are there any good Rust crates for DFAs/NFAs?
Many people solved that problem with #Dynamic #Programming - something else for the learn list 😉
-
D’éirigh liom an t-#AdventOfCode a chríochnú roimh teacht don Bhliain Úr! 🎉
Mo chuid réiteach in #Rust:
-
Managed to finish #AdventOfCode before the New Year! 🎉
My solutions in Rust:
-
Feeling Advent of Code burnout. I’ve 5 stars missing (parts 2 of days 21, 23, 24, and the whole 25th day) and can’t get around to doing any of that.
(Also honestly I’ve never done any graph algorithms so not even sure how to approach 25th)
-
CW: I cheesed AoC day 23 part 1
I wrote Dijkstra distance-like function, but choosing nodes with longest distances first; and the order of considered candidates with equal distance depends on the internal state of the HashMap (which in #RustLang is randomized). So it’s not guaranteed to actually always find the longest path, but sometimes it does. I ran it ~10 times and chose the largest result. Seems I got lucky (or the input is simple enough).
-
CW: AoC days 20–21
I failed to solve 2nd parts of those two puzzles myself. I looked at other people’s code/write-ups and I know how to approach them now (and I’ll try to finish them today).
But I don’t like those puzzles since it’s basically “let’s look at the input and try to get the answer for it specifically” rather than doing a “proper” general solution to the problem as outlined in the puzzle’s description.
-
#AdventOfCode 2023 Day 19: Aplenty
https://adventofcode.com/2023/day/19
That was fun. I had a small mistake in part 2. In order to debug it, I was looking for a tool to visualize the decision graph. I found that #networkx in combination with #cytoscape works fantastic. Attached are the graphs from the test input and my real input.
Code is here:
https://github.com/nharrer/AdventOfCode/blob/main/2023/day19/solve-day19.pyNetworkX: https://networkx.org/
Cytoscape: https://cytoscape.org/ -
CW: Advent of Code Day 12 Spoilers
#AdventOfCode 2023 Day 12
Oh my god, I had too much trouble with this. Haven't done #DynamicProgramming in years, so I completely spaced it until my solution was taking forever.
Memoization gave at a considerable speed boost. It's not the best solution, and it's far from readable, but it gets the job done and still takes under a second on my machine.
https://codeberg.org/Taywee/AdventOfCode-2023/src/branch/main/src/bin/day12.rs
-
I completed #Day09 of #AdventOfCode2023.
Part 1:
- Difficulty: 1/10
- Workout: 1/10Part 2:
- Difficulty: 0/10
- Workout: 1/10This one was too easy, done in half a hour! 2-dimension array to hold all difference sequences (including the original sequence, at index 0). No need to get to the all-zeros level, the one just above (all values are equal) is enough. Attention to index fiddling. That's it.
Since I still got time, I refactored the program to make it presentable. It's in the next post in this thread. Done in almost one hour.
-
I completed #Day08 of #AdventOfCode2023.
Part 1:
- Difficulty: 3/10
- Workout: 2/10Part 2:
- Difficulty: 3/10
- Workout: 5/10Part 1 was a straight simulation: instructions given, parse and table moves, loop for following instructions. Barely a half-hour of work.
Part 2 extends from one start point to several; it just means a list of places mapping to a list of places, instead of place mapping to place.
Brute force, like in part 1, turned out to be not viable: 1.8e9 iterations, and nothing. I tried to find repeatable sequences of places, starting with each place and instruction position, but the volume of data generated was getting too big.
I had to resort to r/AdventOfCode for tips. At once, I found: closed cycles and LCM. It was enough. I quickly found --Z to --Z cycles, and their periods; all multiples of the same number. A quick implementation of GCD, then LCM(a, b) = a * b / GCD(a, b), reduce list of periods by LCM, and done.
Total time, programming and wasting CPU: about 7 hours.
-
CW: Advent of Code
I just completed Day 7 of #AdventOfCode2023 in #Elixir
https://adventofcode.com/2023/day/7This was not particularly difficult, but rather verbose to code. All in all, one of those days I am truly happy I am a #FunctionalPrograming #fangirl, since pattern-matching makes my implementation almost a specification!
-
I completed #Day07 of #AdventOfCode2023.
Part 1:
- Difficulty: 2/10
- Workout: 4/10Part 2:
- Difficulty: 3/10
- Workout: 4/10Took me almost 4 hours to solve this one, mainly because of the tricky implementation for jokers in part 2. Turned out that my method was too clever by half, and introduced itself a subtle bug.
-
I completed #Day06 of #AdventOfCode2023.
Part 1:
- Difficulty: 1/10
- Workout: 1/10Part 2:
- Difficulty: 1/10
- Workout: 1/10Completed in just over 1 hour. The implementation of part 1 was straightforward: easy parsing, map, filter, length. Part 2 would work, too, but after a few seconds running, I did the smart thing: skip the loops entirely. Immediate solution.
Big hint: solve the equation
a * (t - a) > d
For integer a.
-
CW: Advent of Code Day 6 Spoilers
Day 6
Very easy day. Used my whiteboard to suss out that this was a #QuadraticEquation (yes, I had to use my whiteboard to do this, and I'm not ashamed of being an embarrassment). Naturally, my solution uses the #QuadraticFormula to find the answers.
https://codeberg.org/Taywee/AdventOfCode-2023/src/branch/main/src/bin/day06.rs
-
I (finally!) completed #Day05 of #AdventOfCode2023.
Part 1:
- Difficulty: 4/10
- Workout: 3/10Part 2:
- Difficulty: 5/10
- Workout: 7/10Part 1 was completed in 1 hour. Early in the game, I noticed that the mappings, with billions of elements, were too big to fit explicitly in memory. So, I created a function to pass one seed through the mapping, only checking the intervals' end points.
Then part 2 came, with billions of seeds to check. Brute forcing was a lost cause: tried it, lost 2 hours, expected another 6 to be done.
I had to resort to clever set operations (intersection and difference) over intervals: several folks had this idea. Split seed intervals over each mapping: common intervals are mapped to destination intervals, seeds not in common intervals make their own intervals and pass unchanged. The result is a list of intervals, to pass as input "seeds" to the next mapping.
Now part 2 was almost immediate, the seeds having been pulverized into just a few hundred intervals.
Total elapsed time: about 8 hours. Whew!
-
I completed #Day04 of #AdventOfCode2023.
Part 1:
- Difficulty: 1/10
- Workout: 1/10Part 2:
- Difficulty: 4/10
- Workout: 4/10More than 2 hours of intense work!
Part 1 was straightforward: 3 splits, number conversions, array difference, a simple scoring function, and a sum.
Then, part 2 threw me a curveball: an entirely different problem! Had to read and check more than thrice to actually understand it.
After an infinite recursion, and another that ended too early (don't stop if a card has no prize!), I managed to make it run correctly, but s-l-o-w-l-y: it was allocating the cards as they were replicated. Refactoring got rid of the card allocations: a Map from card number to (# of matching numbers, card count) is enough.
BTW, my answer to the 2nd part was a number upwards of 14 million. That's *a lot* of cards! ;-P
-
Let me just say this, many languages exist that are better suited for code golfing than Go 🤣 #adventofcode2023 #aoc2023 #golang #codegolfing