Hacker News new | past | comments | ask | show | jobs | submit login

I love looking at AoC solution megathreads on reddit. So many languages and so many different approaches are hard to find and observe anywhere.



I feel like those threads would make great research opportunities. We often hear people say that code should be for people to read, incidentally for machines to execute, just be amazed at how much the readability varies from answer to answer.

Skimming some, the core of Part 1 after people have parsed and sorted:

Python:

    sum([abs(x-y) for x,y in zip(left,right))
TypeScript:

    list1.reduce((acc, cur, i) => {
        return acc += Math.abs(cur - list2[i])
    }, 0)
Common Lisp:

    (reduce #'+ (mapcar (lambda (l r) (abs (- l r))) sorted-left sorted-right))))
Julia:

    sum(abs.(list1 .- list2))
Rust:

    Ok(zip(left, right).map(|(l, r)| l.abs_diff(r)).sum()

F#:

    Seq.map2 (fun x y -> abs (x - y)) xs ys |> Seq.sum
APL:

    +/|-⌿
Haskell:

     map abs $ zipWith (-) column2 column1
and then all the submissions which don't do anything like this, and have manual loops and indexing and clunky data representations or performance-optimized data representations, etc. etc.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: