Fork me on GitHub
#adventofcode
<
2018-12-18
>
Ben Grabow01:12:05

It took me the better part of the afternoon to notice that some of my outlets were getting duplicated, leading to O(2^n) runtime as the depth increased. I never tracked down the exact source of the duplicates, but I suspect it was related to multiple outlets feeding into the same pond. I took the lazy way out and turned my outlets data structure into a set.

gklijs06:12:50

I 'killed' outlets when they would end up in a pool.

Ben Grabow01:12:44

I think this is where my stack overflow came from, when I tried to concat some monstrously large lists of outlets.

norman05:12:36

@pesterhazy It’s probably a bit late, and maybe hard to implement with all that mutability, but if you can dump out your world state visually, it ought to be (relatively) clear where the problem is. Almost all my problems came from incorrectly deciding flow/rest, and it was usually easy to see exactly which squares were being decided incorrectly.

norman06:12:21

I was surprised at the cycle time for 18

baritonehands06:12:19

Mine runs really slowly, not sure the best way to speed it up

meikemertsch10:12:20

If mine runs for 13s to give me the 100 entries after dropping 1000, ist that then slower than yours?

meikemertsch10:12:44

I am a beginner and want to know how slow I am :thinking_face:

pesterhazy13:12:04

sounds about the same as my (completely, proudly non-optimized) solution

gklijs07:12:14

It's game-of-life like, it will stay at a repeating pattern pretty soon probably.

gklijs07:12:19

Spoiler from the kotlin slack, repeating pattern can take some time. https://streamable.com/2ud78

fellshard08:12:56

Mine was at ~500 steps, it pays off not to make assumptions about how early the cycle starts 😞

pesterhazy09:12:19

loved this one - beautiful patterns

ihabunek11:12:41

i animated mine in ascii

pesterhazy09:12:31

Day 18 was a breeze, but 17 I felt was horrible to implement in anything resembling idiomatic Clojure

pesterhazy09:12:34

I ended up porting a Python based solution to Clojure (that is, Java with Clojure syntax)

ihabunek10:12:15

finally a relatively easy one. 🙂 went with elixir today, but if anyone wants to take a peek: https://git.sr.ht/~ihabunek/aoc2018/tree/master/elixir/lib/day18.exs

mfikes12:12:26

A little late, but Day 17: https://github.com/mfikes/advent-of-code/blob/master/src/advent_2018/day_17.cljc Note, to run this, I had to increase the stack size in the JVM.

pesterhazy13:12:15

@mfikes nice, you managed a purely functional solution for a problem lending itself to imperative solutions

pesterhazy13:12:19

on the jvm btw the imperative (but still recursive) solution I posted doesn't blow the stack

mfikes13:12:02

@pesterhazy Yes. If curious, I initially had it doing the spill left and right and putting both of those results into a map. That wasn't working on the real problem because it would branch out recursively too much (much like a naive Fibonacci), and wouldn't complete even if let run over night. The fix in this case was to take the results of spilling left and pass them into the function that spills right, eliminating the 2-way recursive aspect.

pesterhazy14:12:39

@mfikes yes this is very interesting to me given that I tried, and failed, for a few hours yesterday, before going with a super imperative approach

pesterhazy14:12:22

kept me up all evening 🙂

ihabunek15:12:37

@mfikes I'm finding your solution a little difficult to follow, since it's quite dense with logic, how well are you able to parse your own code e.g. an year from now?

ihabunek15:12:09

i tend to break things into smaller functions and write some docs, for myself if noone else 🙂

mfikes15:12:41

Yeah, I agree; I didn’t have a chance to clean up day 17 to make it super readable.

ihabunek15:12:23

ah, it's always a matter of available time, and AoC is not too high priority for most people

ihabunek15:12:49

i enjoy reading your solutions, since i usually pick up some tricks i haven't thought of

mfikes15:12:04

My opinion: The initial code you write is often not quickly grokkable because it is simply messy. Once you clean up the mess, it is still not quickly grokkable because it is using way to many words to say what it is saying. If you then golf it a little, you can improve understanding by using fewer bigger words to convey your idea. The balance is to not golf it too much were it becomes opaque. There is some sweet spot between overly verbose and overly golfed where I find code most readily consuable.

👌 12
mfikes15:12:41

Same thing happens with English (or any other writing)

ihabunek15:12:09

for more complicated problems i almost want to start the solution with a dictionary - explain what words mean in the context of the problem, for this one, i used "spring", "water", "flow" which are not exact but could be defined, and that would make the program easier to read

ihabunek15:12:25

(if used consistently)

mfikes15:12:43

Yes, the right choice of names makes the code much more readily understanable.

mfikes15:12:22

A well chosen name is better than a long comment explaining something 🙂

ihabunek15:12:37

yes, very true

ihabunek15:12:45

and also very difficult 🙂

mfikes15:12:50

But I agree, my day 17 is quite opaque right now 🙂

ihabunek15:12:42

there's only so much time available in a day

potetm16:12:25

Gonna have to cancel today’s stream. I should be back tomorrow.

markw18:12:48

@ihabunek Peter Norvig always does that in his solutions (his PAIP book, Ipython notebooks etc) - always starts with "vocabulary" for the problem.

ihabunek18:12:53

Cool, I'll have a look

pesterhazy18:12:01

Finding a vocabulary at the beginning requires a pretty good understanding of the problem space though

pesterhazy18:12:21

Which of course you don’t always have

markw18:12:15

@pesterhazy Yeah that's a fair point - I think that's part of why it helps though... You have a chance to loosely sketch out the problem before starting to code it, and in some cases that can save you some trouble down the line.

markw18:12:33

Everyone is different though, for me I can't start typing until I have my idea initially thought out, usually on paper

👍 4
Average-user19:12:18

My day17 solution is too slow

Average-user20:12:16

adventofcode-clj-2018.day18> (time (part-2))
"Elapsed time: 29776.153121 msecs"
165376

Average-user20:12:27

How long it takes yours?

misha03:12:02

2015 macbook pro, 2.2 i7

misha03:12:05

oh, I see you probably meant 18:

Loading src/adventofcode/2018/day18.clj... 
"Elapsed time: 197.051339 msecs"
"Elapsed time: 6098.122681 msecs"
Loaded

magic_bloat22:12:32

Just finished 17 - took ages, had to make too attempts. Annoyingly my first attempt was looking very close to being right, so I stuck with it for ages before bailing out and trying a new approach.

magic_bloat22:12:04

Definitely recommend taking the time to do a visualisation for these sorts of things. There's no way I would have spotted my bugs without drawing the pictures.