Unable to load image

rDrama Advent of Code Day 10: Hoof It

https://adventofcode.com/2024/day/10

I hope this fine morning finds you well, saars.

The word of the day is: graphs!

Rdrama leaderboard. Invite code: 632268-30587026, you need to log in first.

Announcement post with useful links.

@Merryvann please pin this and unpin Day 9.

17
Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17338210637713897.webp

I had hoped that the approach to Part 1 would be useful in Part 2, but the coding gods did not agree.

Fairly simple today, though that might just be because I'm comfortable with numpy.

I expect some fancy tart would do this with some kind of convolutional filter, but I haven't got time for that.

Jump in the discussion.

No email address required.

Me today:

1. Accidentally implement part 2 for part 1 because I didn't read the question properly

2. Wrestle with set comprehension TypeError: unhashable type: 'set' errors for 20 minutes

Another A+ AB10E AoC day. I am the best coder :marseyawardretard2:

Jump in the discussion.

No email address required.

val dir4 = listOf(1 to 0, -1 to 0, 0 to 1, 0 to -1)
typealias Pairs = MutableCollection<Pair<Int,Int>>
fun main () {
    val grid = File("src/d10.input").readLines().map { it.toCharArray()
        .map { c -> c.digitToInt() } }
    val rRange = grid.indices; val cRange = grid[0].indices

    fun recurse (r:Int,c:Int,v:Int,set:Pairs): Pairs {
        if (r in rRange && c in cRange && v == grid[r][c]) {
            if (v == 9)
                set.add(r to c)
            else
                dir4.forEach { (dr,dc) -> recurse(r+dr, c+dc, v+1, set) }
        }
        return set
    }

    fun fold (newSetFn:()->Pairs) = rRange.sumOf { r ->
        cRange.sumOf { c -> recurse(r,c,0,newSetFn()).size }
    }
    println(fold { HashSet() })   // Q1
    println(fold { ArrayList() }) // Q2
}

i may consider building one of them aoc libs for this (like grid creation, folding/summing),

but part of the fun for me is deriving this from language level abstractions, so idk

Jump in the discussion.

No email address required.

Reported by:

Jeet or just a kotlin enjoyer?

Jump in the discussion.

No email address required.

u think i'm a jeet? lol

nah i've been doing typescript for the last 5 years but recently took a java position to "enhance my BE skillset" (also FE engineers aren't real engineers)

god i hate java, and decided to do aoc in kotlin.

tbh i am really enjoying it

Jump in the discussion.

No email address required.

Kotlin isn't bad. Just usually see jeets on the jvm and then it sucks.

Jump in the discussion.

No email address required.

Indian devs generally only use the JVM with a disgusting framework like Spring or Java EE. They can't write Java directly. Ask them to write a method to sum two numbers and they'll add dependency injection.

Jump in the discussion.

No email address required.

they'll add dependency injection.

it's only been 2 months and i already feel triggered by this

Jump in the discussion.

No email address required.

I was once a consultant on a big project, one of maybe 150 software engineers in a room. One day we had a training session on Test Driven Development where everyone was given an hour to write a Roman numeral converter by writing unit tests then implementing the code. The idea was that you'd write a test for converting 1-10 into I-X, then write the code to make that test pass, and keep going up as high as you could.

At the end of the hour the instructor asked how high everyone had gone. One team of two senior Capgemini Java engineers (Indian) said "we didn't get anywhere because we couldn't figure out how to install JUnit". I looked over at their machines and they were on the JUnit website and had spent the whole hour trying to find "junit.exe".

Jump in the discussion.

No email address required.

i believe the codebase i just started on has mostly not been written by the jeets actually, it's probably better than ur average jvm codebase

but it's java, so it still stucks. grpc used for all objects. dagger injection half the things. a few services i can't even follow flow because some righteous dumbass decided to use dependency injection/production to determine overarching execution flow :marseygunshotsuicide:

it's not really even java anymore, it's an annotated monster bolted together to overcame java boilerplate heck,

but really just ends up in it's own wonky boilerplate heck

i wish we just used kotlin

Jump in the discussion.

No email address required.

Whoever wrote the codebase would have done the exact same thing in kotlin unfortunately.

Jump in the discussion.

No email address required.

magic dependency injection flow was written by a slav

Jump in the discussion.

No email address required.

got filtered yesterday so idc

yes i brute force all my solutions

i just started an hour before midnight because i was busy impregnating all day

Jump in the discussion.

No email address required.

BFS worked for both parts

https://i.rdrama.net/images/17338445245660663.webp

Jump in the discussion.

No email address required.

Not bad tonight. I'm a python scrub, so it was easy to modify part 1's "set of coordinates" to determine unique endpoints to a simple running sum for part 2

Jump in the discussion.

No email address required.

it was one line difference for me in my kotlin version, changed from HashSet->ArrayList for collecting the dfs ends

Jump in the discussion.

No email address required.

I spent so long optimising day 6 that I can't even see matrices any more, only graphs.

Sucks the paths were so short there was no point in edge contraction :marseygiveup:

https://i.rdrama.net/images/17338415539869306.webp

836.24µs runtime

Bonus content, came up with a generic path counter that could accept HashSet or Vec:

fn count_paths<T>(init: T, graph: &Graph) -> usize
where
    T: IntoIterator<Item = usize> + FromIterator<usize>,
    T::IntoIter: ExactSizeIterator,
{
    (0..9).fold(init, |acc, _| {
        acc.into_iter()
            .flat_map(|n| graph.get(&n).unwrap().clone())
            .collect::<T>()
    })
    .into_iter()
    .len()
}

Such a beautiful concise language :tayadmire:

Jump in the discussion.

No email address required.

I tried to cheat and use networkx. So after relatively trivial building the graph, the actual solution was four lines:

    sp = dict(networkx.all_pairs_all_shortest_paths(g))
    if second:
        return sum(sum(len(sp[s][e]) for e in ends if e in sp[s]) for s in starts)
    return sum(sum(1 for e in ends if e in sp[s]) for s in starts)

Three problems with that though: 1) it took me like ten minutes reading networkx documentation to see that it doesn't have a more sane implementation of Dijkstra with a fixed number of sources and targets, 2) so it ran for two minutes, and 3) it took some time to debug that bullshit for part two. Really running a DFS myself would be so much faster :/

Jump in the discussion.

No email address required.

You have 3 known reddit accounts, 2 of which are perm. banned for harassment, at least two twitter accounts that will crosspost between each other to create artificial engagement, and the rdrama account where you boasted about getting me banned for harassment, which ended up getting your main banned from reddit. I have no doubt in my mind that you're using an alt to send false crisis report.

Also, I wasn't the one who decided anything on your ban, Kicken was. Kicken knows way more about this than I do and I have never cared about anything you've tried to accuse me of. What I do care about is how disrespectful to real artists who put in years for their art you are. You think you're doing something that no one else can grasp but in reality you're just an /r/antiwork poster with a lot of free time on their hands. You have no idea what work means, get over yourself.

Snapshots:

https://adventofcode.com/2024/day/10:

Rdrama leaderboard.:

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.