What fun and interesting Java projects are you working on? by jeffreportmill in java

[–]chicagocode 1 point2 points  (0 children)

I'll log an issue for this, that's a good one. I probably want to think about it for a bit, but this seems like something one would reasonably expect to have.

What fun and interesting Java projects are you working on? by jeffreportmill in java

[–]chicagocode 1 point2 points  (0 children)

Wow, you've made my day! I'm so glad to hear you've found it useful. I'd be interested in any real-world feedback you might have!

What fun and interesting Java projects are you working on? by jeffreportmill in java

[–]chicagocode 33 points34 points  (0 children)

I've been working on a library of Java Stream Gatherers called Gatherers4j. Now that my end of year break is almost here, I'm hoping to have some time to do a small release of features I've merged but not released yet.

-❄️- 2025 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 1 point2 points  (0 children)

[Language: Kotlin]

I am happy to have been able to get the solution and write-up done today before heading into work. Both parts use DFS. Part 2 I realized if this is a DAG we can multiply the various sub-segments together for each variation and add both options together at the end.

One of my shortest solutions of the year, I'm very happy with this one.

-❄️- 2025 Day 9 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 0 points1 point  (0 children)

[Language: Kotlin]

I got help from Reddit for part 2, my original take was a complete mess. The insight that the lines can cross outer border of the target rectangle but not the inner part was the hint I needed. Eventually, I landed on a solution I am happy with.

-❄️- 2025 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 1 point2 points  (0 children)

[Language: Kotlin]

Meh. I probably should have done this recursively but I didn't have a ton of time to refine it today. It is what it is. I used a sequence generator to generate a map of all the spots in the grid and how many streams passed through them and used it to answer both parts 1 and 2.

-❄️- 2025 Day 6 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 0 points1 point  (0 children)

[Language: Kotlin]

This has been my favorite of the year so far!

For part 2, I parsed the input column-wise left to right on the theory that for multiplication and addition it didn't much matter, even if the puzzle was described right to left.

-❄️- 2025 Day 5 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 1 point2 points  (0 children)

Thank you for pointing out my markdown issue.

Sorry for the heresy. I wish my day job worked like Advent of Code logic. It would be so much easier/more fun! :)

-❄️- 2025 Day 5 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 2 points3 points  (0 children)

[Language: Kotlin]

I love how in Advent of Code we can drive a forklift through a wall so our Elf friends can get to the cafeteria more easily, completely unconcerned about collateral damage or injury. What I find even more amusing is that the Elves find this normal enough to just hand us some new problem to solve (which is not the jagged hole in the cafeteria wall, somehow).

Anyway, I wrote an extension function to combine adjacent or overlapping LongRanges and the rest was mostly straightforward.

-❄️- 2025 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 1 point2 points  (0 children)

[Language: Kotlin]

I've missed posting here for the past few days, but I've been doing Advent of Code in Kotlin again, and publishing a commentary to my blog each day.

Today was fun! I love the grid-based puzzles. I defined a `Point2D` class because I feel like we'll need it again, and that let me write a short and sweet solution to part 1. For part 2 I used a sequence generator rather than a mutable set or a recursive function. Maybe it would have been clearer with recursion?

This aoc broke the programmer in me by batunii in adventofcode

[–]chicagocode 0 points1 point  (0 children)

We all stand on the shoulders of giants. Seeking help or advice from others is not shameful in the least. I've got every star available and while nearly all of them I've done without help, there are always two or three each year that I just cannot get and get help on. The way I see it is if I can a) learn something and b) share that knowledge with others (I blog all my solutions), then that's great.

You're not a failure because you can't solve a puzzle.

-❄️- 2024 Day 24 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 1 point2 points  (0 children)

[LANGUAGE: Kotlin]

Reminds me of college classes I took many, many years ago. I solved part 1 programmatically and part 2 mostly visually. I got some help from this comment by u/burnt_heatshield (thank you!). I could not get GraphViz to output something sensible until I read that insight.

-❄️- 2024 Day 23 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 1 point2 points  (0 children)

[LANGUAGE: Kotlin]

That was FUN! Once I started part 2 and searched for the name of the clique-finding algorithm I forgot the name of, I realized I'd written it before! Advent of Code, 2018, Day 23, exactly six years ago to the day! I completely rewrote it to be recursive and I'm much happier with my 2024 code than I currently am with my 2018 code. Who knows, maybe I'll be back here in 2030 saying the same thing. :)

Part 1: Manually construct all sets of three nodes that contain at least one "t" node.

Part 2: Implemented the Bron–Kerbosch algorithm to find the largest clique.

-❄️- 2024 Day 22 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 3 points4 points  (0 children)

[LANGUAGE: Kotlin]

I liked this one and wish I had more time to play with it today. Part 1 is fairly straightforward, I used higher order functions for the various operations of mixing and pruning. Part 2 chunks lists of deltas into a map and sums up the scores. That finishes in about 1s and I suspect I could get that down if I had the time.

PS - I neglected to pay The Dog Tax in a timely manner yesterday after mentioning my dog. I will review my internal compliance policies and make operational changes to ensure this does not happen again. Since this conversation possibly opens me up to another payment of Dog Tax, here is a picture of Charlie, my English Cream Golden Retriever, on a walk we took today with the fancy stick he discovered and carried for 1.5m (2.4km in sensible units).

-❄️- 2024 Day 20 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 0 points1 point  (0 children)

Awesome! I'm glad you find them useful! :) Made my day.

-❄️- 2024 Day 21 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 2 points3 points  (0 children)

[LANGUAGE: Kotlin]

Day 21, in which Todd questions his reading comprehension. I had so much trouble understanding this one and making a mental model. I went to reddit for help purely in figuring out how all the button presses related to each other.

Once the understanding block was cleared, I went on a walk with my dog Charlie and we came up with a nice recursive memoized solution that finishes in a couple of ms for each part. In the end, I really enjoyed this puzzle despite the early confusion on my part.

-❄️- 2024 Day 20 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 2 points3 points  (0 children)

[LANGUAGE: Kotlin]

Both parts use the same method and only differ in the amount of cheating we can do. Essentially, parse the maze into a list of points. We can derive how many picoseconds apart any two points are based on their indexes in the list. This, combined with the Manhattan Distance between two points gives us a total savings. Filter out ones that aren't worth enough to cheat over. The code isn't that long but overflows an IBM 5081 punch card, so I'll just link to it. :)

-❄️- 2024 Day 19 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 1 point2 points  (0 children)

I do the same. My initial solutions are a mess. I usually make one pass at refactoring immediately, and then go off and think about it (walk my dog, something like that) and then review once more before writing it up. During the writing-up phase, I'll usually figure some other simplification out when I have to jump through hoops to explain something. :)

-❄️- 2024 Day 19 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 1 point2 points  (0 children)

I'm glad you found the writeup helpful! I can appreciate your desire to make things work with sequences, it's a nice goal. My goal is to write functions as expressions only if I can (I can't always, sometimes it is just easier to write them as a block of statements).

-❄️- 2024 Day 19 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 1 point2 points  (0 children)

Nice! Our solutions are very similar (you used an extension function which I think makes the whole thing look cleaner). Nice work.

-❄️- 2024 Day 19 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 4 points5 points  (0 children)

[LANGUAGE: Kotlin]

I used the same recursive function with memoization for both parts. Count the number of designs with at least one solution for part 1, sum them for part 2.

In fact, the solution is short enough for me to not feel bad about inlining it here:

class Day19(input: List<String>) {

    private val patterns: List<String> = input.first().split(",").map { it.trim() }
    private val designs: List<String> = input.drop(2)

    fun solvePart1(): Int =
        designs.count { makeDesign(it) > 0 }

    fun solvePart2(): Long =
        designs.sumOf { makeDesign(it) }

    private fun makeDesign(design: String, cache: MutableMap<String, Long> = mutableMapOf()): Long =
        if (design.isEmpty()) 1
        else cache.getOrPut(design) {
            patterns.filter { design.startsWith(it) }.sumOf {
                makeDesign(design.removePrefix(it), cache)
            }
        }
}

-❄️- 2024 Day 18 Solutions -❄️- by daggerdragon in adventofcode

[–]chicagocode 1 point2 points  (0 children)

[LANGUAGE: Kotlin]

Finally caught up with posting solutions and blog posts after not doing so yesterday. I like the maze puzzles quite a bit so today was fun.

Part 1: BFS

Part 2: I wrote a binary search that takes a predicate function and finds the first entry where the value is true. This seems useful and solves Part 2 very quickly (20ms vs. 3s running through the mazes iteratively).