Fork me on GitHub
#adventofcode
<
2019-12-08
>
Average-user02:12:04

I was looking to some clever solutions using Haskells lazy evaluation:

amplify program [a,b,c,d,e] = last oute
    where outa = intcode (a:0:oute) program 0
          outb = intcode (b:outa) program 0
          outc = intcode (c:outb) program 0
          outd = intcode (d:outc) program 0
          oute = intcode (e:outd) program 0

Average-user02:12:28

Would something like that possible in Clojure?

potetm02:12:50

@lucaspolymeris you have a link to the full program?

Average-user02:12:37

Yep, give ma sec. But anyway, intcode is just the regular function from day5

potetm03:12:34

thatโ€™s super cool

fellshard05:12:53

Today's is downright trivial in Clojure. :)

Average-user05:12:14

Unless you would want to read the output for part-2

fellshard05:12:06

Even that is pretty straightforward, minus a bit of forcing eagerness + string munging.

fellshard05:12:31

Visualization for this one is practically obvious, so I'm gonna take Quil for another spin

fellshard05:12:35

(As a total aside, since I discovered the 'fancy symbols' mode in Spacemacs' Clojure layer, I've used partial so much more)

erwinrooijakkers12:12:38

What is it? I do see prettify-symbols-mode that changes lambda to a symbol, but what do you mean? ๐Ÿ™‚

fellshard13:12:52

That's the mode, yeah. It does a similar transformation for partial into a... fancy P, I guess?

Average-user05:12:37

I meant, making the computer read it, and return the word as a string (not a grid)

fellshard05:12:57

Yeah, that'd be a headache ๐Ÿ˜…

misha06:12:36

this pissed me off really hard in day5 for day7:

(defn next-input [input]
  ;; reuse last input if all consumed
  (or (next input) input))

misha06:12:38

w/o it had nullpointers in few init combinations for part 2

mpcjanssen06:12:44

Today was some welcome relief indeed

๐Ÿ˜„ 4
mchampine06:12:18

Yep. Easy in Clojure. I wound up with 3 lines of code for part 1, 5 for part 2. Not exactly pretty though. I used โ€œascii artโ€ for the image, which was fastest and good enough.

fellshard06:12:01

(The non-graphical solution is much cleaner, but boy is this more fun. ๐Ÿ™‚ )

mchampine06:12:28

Thatโ€™s pretty neat. If there was extra credit youโ€™d earn a bunch. ๐Ÿ™‚

meikemertsch06:12:01

earlier experience showed that weekend riddles are harder. Not this year. Iโ€™m glad ๐Ÿ˜† It was a fun one today

pesterhazy09:12:23

yes I was relieved too ๐Ÿ™‚

erwinrooijakkers12:12:21

My Saturday was consumed by day 7 though ๐Ÿ™‚

lilactown06:12:48

I'm still working on day 7, but day 8 gave me something to work on while taking a break ๐Ÿ™‚

mpcjanssen06:12:16

@fellshard I assumw thats from de lowest layer to thw front?

fellshard07:12:43

Correct. ๐Ÿ™‚

fellshard07:12:05

The 'actual solution' does it front to back, though.

fingertoe08:12:33

I am pretty sure I re-wrote some magic core function that merges sets of vectors of that nature.. Got it done though. I have been struggling for motivation on the op-code puzzles.

mpcjanssen08:12:43

The protocol elf should have a stern talk

gbouvier08:12:54

I'm happy with my day7 solution, but I'm wondering how I can make my code more idiomatic: https://gitlab.com/gmbouvier/2019-aoc/blob/master/src/day7.clj I'm only a hobby clojurist but thinking about sharpening my skills for possible Clojure work so any feedback/conversation is appreciated ๐Ÿ™‚

misha08:12:22

(defn arity [opcode]
  (get {1 3, 2 3, 3 1, 4 1, 5 2, 6 2, 7 3, 8 3, 99 0} opcode))
->
(def arity {1 3, 2 3, 3 1, 4 1, 5 2, 6 2, 7 3, 8 3, 99 0})

misha08:12:07

{program :program pointer :pointer output :output} state
->
{:keys [program pointer output]} state

misha08:12:42

(cond
      (=  1 opcode) ...
->
(case opcode
  1 ...
or
(condp = opcode
  1 ...

misha08:12:36

you have a lot of fn indirection, which is hard to follow, like:

((-> {:program input :pointer 0}
        (next-cont-state)
        (:contfn)) i))
and
#((:m %))
and
((:i (last argslist)))

misha08:12:57

using last too much, working with vectors and using peek instead would be more performant (maybe not that much in this case)

misha08:12:08

(comp not zero?)
->
(complement zero?)

misha08:12:32

(fn [& args] :done)
->
(constantly :done)

misha08:12:15

after looking through all that, you begin to see things like: scanning op-code-seq multiple times:

(take-last 2)
and then
(reverse) (drop 2)
inside fn on the next line. etc.

misha09:12:43

(filter #(fn? (:contfn %)))
probably can be just
(filter :contfn)
since this key either mapped to fn or absent

misha09:12:51

this can be faster with

(last (map last (map :output amps)))
->
(last (:output (last amps)))
but it is way too many last s

misha09:12:02

(recur (concat (rest amps) [current-amp])
                   (last (:output current-amp)))))))))
this loop would be faster and without that many lasts if you put amps in a queue, and then pop and conj it instead of first and concat:
(loop [amps (into PersistentQueue/EMPTY amps) ...
and in the end of the loop: (-> amps vec peek ...) instead of (... (last amps))

gbouvier10:12:52

Thanks! Those are all useful points. As far as function indirection, would it be better if I assign the relevant fn in a let? Possibly more verbose but could add clarity... Or is there an issue in general with using fns as values in hash-maps?

misha11:12:38

in this particular case - it inhibits readablity for me, and feels like several unnecessary extra layers

pesterhazy09:12:04

I suspect that today's (relatively straightforward) puzzle is laying the foundation for future image-related puzzles

erwinrooijakkers12:12:39

https://github.com/transducer/adventofcode/blob/master/src/adventofcode/2019/day8.clj Is there a nicer pattern than reducing with a state parameter in the accumulator (as in (reduce (fn [[result highest :as acc] e] (if (> e highest) [(new-state e) e] acc) [nil 0]) )?

misha12:12:00

if you already use group-by on every layer, then just frequencies and sort-by it instead

๐Ÿ˜ฎ 8
erwinrooijakkers13:12:24

Thanks indeed ๐Ÿ™‚

chrisblom19:12:39

min-key and max-key can also come in handy in such situations

โ˜๏ธ 8
๐Ÿ‘ 8
erwinrooijakkers09:12:57

Wow indeed. No need to sort-by and then first ๐Ÿ™‚

pastafari20:12:01

#spoiler for some. I went old school to figure out the letters ๐Ÿ™‚ This is not necessarily a spoiler for everyone, there's a bunch of random inputs per the sub-reddit!

๐Ÿ˜„ 4
misha21:12:03

never even heard of min-key, and it was added in 1.0, wow