Fork me on GitHub
#adventofcode
<
2019-12-06
>
lilactown02:12:40

I’m getting a position of -80 in my input

lilactown02:12:46

did anyone else encounter this?

mpcjanssen02:12:40

Yes I got invalid positions when my implementation was wrong 😉

mpcjanssen02:12:24

Are you always interpreting the target parameter as the address value without looking up the value st the address? That was my error

fellshard03:12:08

I may actually expand my visualization to serve as a diagnostic panel if this machine continues expanding in the future.

fellshard03:12:56

Makes for easier debugging of issues like that if you can also expose intermediary steps, like the mode-interpreted values.

fellshard03:12:11

Hmm. You could even time-travel it by storing a stack of state-diffs...

potetm04:12:56

ugh gotta stop checking in my puzzle inputs

potetm04:12:14

somehow mine’s the first non-loop-recur solution I’ve seen

potetm04:12:25

ah just saw uosl’s

potetm04:12:27

basically the exact same approach

Ben Grabow04:12:12

iterate is just a great general purpose way to unroll a loop-recur

Ben Grabow04:12:29

So much easier to inspect the result and compose it with other data

potetm04:12:42

use iterate, pull out all your immediate/position vals, and case it

potetm04:12:04

yeah.. well

potetm04:12:13

inspecting output wasn’t super duper for this problem

potetm04:12:17

big long list of numbers

potetm04:12:36

but ordinarily, yeah

potetm04:12:22

Really, for me, I reach for it because it’s easier to think about a single input/output than to think about flow control.

Ben Grabow04:12:36

I think I resisted iterate for day 5 because checking the terminate condition requires unpacking the step function a little

potetm04:12:46

unpacking?

Ben Grabow04:12:18

Er, breaking the pattern. Like you used ::halt as your return value

potetm04:12:30

right, sig term

Ben Grabow04:12:50

Normally I like to write my iterate step function so it "could" run forever, and it's the consumer's decision when to stop it

potetm04:12:16

yeah I considered returning the same input

Ben Grabow04:12:18

I couldn't think up an obvious way to do that here so I went the fn-recur route

potetm04:12:26

then I was like, “What are you some kind of zealot?”

Ben Grabow04:12:27

yeah you could return a fixed point

potetm04:12:03

what nobody sees don’t hurt em I figure

Ben Grabow04:12:16

Rich Hickey is watching you code

potetm04:12:20

iow implementation detail

potetm04:12:27

you ain’t read a lot of rich’s code

potetm04:12:28

apparently

Ben Grabow04:12:04

haha, sometimes I wonder wtf happened when I peek into a core function's implementation

potetm04:12:25

dude do it

potetm04:12:29

I do all the time

Ben Grabow04:12:37

It's like the least lispy, most complicated thing internally

Ben Grabow04:12:41

but outside it's a beautiful flower

potetm04:12:54

yeah, consider volatile

potetm04:12:35

DO YOU WANT SIMPLE OR COMPLECTED???

potetm04:12:11

really, it’s, like, a pragmatists view

misha06:12:02

well, core should be fast so that userspace could afford to be readable

potetm04:12:19

“Simple is nice. Working is better.”

Ben Grabow04:12:28

I can respect the person who hands me a gun when I say I want to shoot myself in the foot

😀 1
potetm04:12:55

how very… American

potetm04:12:29

ugh, I only just finished day 5

potetm04:12:34

and day 6 is out in 45min

clj 1
lilactown05:12:11

> Parameters that an instruction writes to will never be in immediate mode. this is the part I think my solution fails at

lilactown05:12:09

what is that supposed to mean?

d 1
potetm05:12:06

you always write to the position that the param says

potetm05:12:58

you never dereference the param and then write

potetm05:12:17

where write means “update the program state”

kenj05:12:14

Well day 6 problem description got vague at the end

misha06:12:17

visuals made it instantly obvious what's required, to me.

fellshard06:12:01

GraphViz to the rescue!

bellissimo 2
mchampine07:12:28

Day 6, was way easier than day 5 thank goodness. Part 1. Get the list of nodes by putting all the node names into a set, then follow the chain of orbits back to “COM” and sum all the chain lengths. Part 2. Find the first common node in the chains from “YOU” and “SAN” to back to “COM” and count the links to that common node.

yenda08:12:36

part 1 what do you mean by putting all the node names into a set? I put them into a map to follow the chain of orbits back to COM part 2 I put both chain of orbits into a set, count the diff, add both counts minus diff

misha08:12:02

I replaced my transducers solution with a sets one, and it went from 1.5ms to 3.5ms :) https://github.com/akovantsev/adventofcode/commit/c3b234ecaacd2014d360c4e20ee946086e6b5e73

😄 1
yenda10:12:10

Try set/intersection of p1 and p2 instead then sum of both counts - 2 diff

misha11:12:58

nah, not as readable

Ben Grabow16:12:48

(defn set-symmetric-difference [s1 s2]
  (set/difference (set/union s1 s2) (set/intersection s1 s2)))

(count (set-symmetric-difference p1 p2))

mpcjanssen07:12:06

main thing is to make a a orbits b data structure not b is orbited by a as it is in de data

uosl09:12:22

That iterate with a map as the first argument is awesome

2
fellshard09:12:00

Elegant! Good call that you don't need to find the least common ancestor - any ancestor will do

uosl09:12:53

I can't be the only one who found make-hierarchy perfect for day 6?

erwinrooijakkers10:12:17

I looked at this before solving it. I will try! 😄

erwinrooijakkers11:12:11

(def input
  (->> (-> (io/resource "2019/day6.txt")
           slurp
           (string/replace #"\)" "\n")
           (string/split-lines))
       (map keyword)))

(def universe
  (atom (make-hierarchy)))

(defn add-orbit! [p1 p2]
  (swap! universe derive p1 p2))

(defn add-orbits! [input]
  (doseq [[p1 p2] (partition 2 input)]
    (add-orbit! p1 p2)))

(defn count-orbits [p]
  (let [ps (parents @universe p)]
    (if (zero? (count ps))
      0
      (apply + (count (ancestors @universe p)) (map count-orbits ps)))))


;; Part 1

(add-orbits! input)
(count-orbits :COM)
StackOverFlow error 😉

uosl11:12:35

The hierarchy doesn't need to be in an atom, just pass it around like a first-class citizen. You might have to forgo tree recursion as well to avoid the overflow. If you want to see how I solved it: https://github.com/uosl/advent-of-code/blob/master/src/aoc2019/06.clj

erwinrooijakkers11:12:16

(defn count-orbits [planets]
  (apply + (map (comp count (partial ancestors @universe)) planets)))

erwinrooijakkers11:12:44

Where planets set of the planets

erwinrooijakkers11:12:31

I’ll check your answer later puzzle around for 2 first 😉

uosl11:12:55

Good luck [=

erwinrooijakkers11:12:14

Ah I changed it without the atom, just the global hierarchy 😉

erwinrooijakkers12:12:37

Nice use of reduce!

erwinrooijakkers12:12:07

Inspired by the make-hierarchy comment of @regen I decided to misuse the global hierarchy: https://github.com/transducer/adventofcode/blob/master/src/adventofcode/2019/day6.clj

😅 1
chrisblom12:12:17

nice, that is a clever hack

tws13:12:04

you can do the last bit with just set operations.

(defn part-2 [input]
  (let [orbits (make-hier (map parse-rel input))
        ys (ancestors orbits :YOU)
        ss (ancestors orbits :SAN)]
    (count (set/difference (set/union ys ss) (set/intersection ys ss)))))

tws13:12:56

(same make-hierarchy as the last few, i did not know about that core function!)

erwinrooijakkers15:12:46

I see. Why does that work? 😛

Mario C.19:12:30

Damn didn't even know make-hierarchy existed. That basically did all the work lol

erwinrooijakkers20:12:58

Did you look at @potetm? ubergraph does even more 😛

(let [g (graph (parse s))]
  (- (uga/cost-of-path (uga/shortest-path g "YOU" "SAN"))
     2)))

fellshard22:12:07

I may have to see about swapping my usual JGraphT dependency for Ubergraph...

fellshard22:12:29

it works pretty well with Clojure, but staying in purely idiomatic Clojure would be nice.

Average-user22:12:17

I did it just with a Map. I think it worked out okay <https://github.com/Average-user/adventofcode-clj-2019/blob/master/src/adventofcode_clj_2019/day06.clj>