adventofcode

Happy Advent 2020! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
Average-user 2019-12-08T00:28:22.417200Z

I did something very similar. Just quite messier

Danny 2019-12-08T01:14:41.417600Z

I also did something similar, but I didn't use a go-loop... then had to deal with blocking IO. Argh! Should definitely have used a go-loop! Great job

mpcjanssen 2019-12-08T01:46:56.418700Z

My messy iterative solution https://github.com/mpcjanssen/aoc2019/blob/master/day07.ipynb

Average-user 2019-12-08T02:50:04.419800Z

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-user 2019-12-08T02:50:28.420300Z

Would something like that possible in Clojure?

uneman 2019-12-08T02:56:40.420500Z

wow, great idea!

2019-12-08T02:58:50.420900Z

@lucaspolymeris you have a link to the full program?

Average-user 2019-12-08T02:59:37.421400Z

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

2019-12-08T03:12:34.422100Z

thatโ€™s super cool

fellshard 2019-12-08T05:16:53.422500Z

Today's is downright trivial in Clojure. :)

Average-user 2019-12-08T05:20:28.422800Z

yup

Average-user 2019-12-08T05:21:14.423200Z

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

fellshard 2019-12-08T05:23:06.423800Z

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

fellshard 2019-12-08T05:23:31.424100Z

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

fellshard 2019-12-08T05:24:35.425900Z

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

erwinrooijakkers 2019-12-08T12:21:38.445300Z

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

fellshard 2019-12-08T13:21:52.450100Z

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

Average-user 2019-12-08T05:24:37.426Z

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

fellshard 2019-12-08T05:24:42.426300Z

Ohhh

fellshard 2019-12-08T05:24:57.426700Z

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

misha 2019-12-08T06:03:36.427800Z

this pissed me off really hard in day5 for day7:

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

misha 2019-12-08T06:04:38.428600Z

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

mpcjanssen 2019-12-08T06:14:44.429300Z

Today was some welcome relief indeed

๐Ÿ˜„ 1
mchampine 2019-12-08T06:33:18.430700Z

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.

fellshard 2019-12-08T06:35:01.431300Z

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

mchampine 2019-12-08T06:38:28.432100Z

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

2019-12-08T06:44:01.433200Z

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

pesterhazy 2019-12-08T09:42:23.444700Z

yes I was relieved too ๐Ÿ™‚

erwinrooijakkers 2019-12-08T12:37:21.448800Z

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

lilactown 2019-12-08T06:45:48.433700Z

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

mpcjanssen 2019-12-08T06:57:16.435Z

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

fellshard 2019-12-08T07:16:43.435200Z

Correct. ๐Ÿ™‚

fellshard 2019-12-08T07:17:05.435600Z

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

fingertoe 2019-12-08T08:04:33.438300Z

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.

mpcjanssen 2019-12-08T08:04:43.438500Z

The protocol elf should have a stern talk

gbouvier 2019-12-08T08:10:54.439400Z

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 ๐Ÿ™‚

misha 2019-12-08T08:41:22.439700Z

(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})

misha 2019-12-08T08:42:07.439900Z

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

misha 2019-12-08T08:43:42.440200Z

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

misha 2019-12-08T08:45:36.440400Z

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)))

misha 2019-12-08T08:47:57.441400Z

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

2019-12-08T08:49:10.441900Z

I kept submitting the list of 0's and 1's as answer, haha ๐Ÿ˜… https://gitlab.com/dmarjenburgh/adventofcode/blob/master/src/adventofcode/year_2019.clj#L183-198

misha 2019-12-08T08:51:08.442100Z

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

misha 2019-12-08T08:52:32.442300Z

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

misha 2019-12-08T08:58:15.442700Z

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.

misha 2019-12-08T09:01:43.442900Z

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

misha 2019-12-08T09:03:51.443100Z

this can be faster with

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

misha 2019-12-08T09:08:02.443400Z

(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))

pesterhazy 2019-12-08T09:42:04.444600Z

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

gbouvier 2019-12-08T10:00:52.444900Z

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?

misha 2019-12-08T11:04:38.445100Z

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

erwinrooijakkers 2019-12-08T12:36:39.448600Z

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]) )?

misha 2019-12-08T12:49:00.450Z

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

๐Ÿ˜ฎ 2
erwinrooijakkers 2019-12-08T13:48:24.450400Z

Thanks indeed ๐Ÿ™‚

2019-12-08T19:42:39.451600Z

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

๐Ÿ‘ 2
โ˜๏ธ 2
erwinrooijakkers 2019-12-09T09:02:57.470900Z

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

erwinrooijakkers 2019-12-09T09:03:22.471100Z

Better name would be max-by and min-by as mentioned in https://www.spacjer.com/blog/2016/01/12/lesser-known-clojure-max-key-and-min-key/

erwinrooijakkers 2019-12-09T09:06:34.471400Z

2019-12-08T20:49:01.453Z

#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!

๐Ÿ˜„ 1
misha 2019-12-08T21:53:03.454200Z

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