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
2018-12-18T01:51:05.728200Z

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.

2018-12-18T01:51:44.728700Z

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

2018-12-18T05:03:36.732Z

@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.

2018-12-18T06:03:21.732600Z

I was surprised at the cycle time for 18

baritonehands 2018-12-18T06:08:19.733Z

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

gklijs 2018-12-18T06:13:50.733100Z

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

baritonehands 2018-12-18T06:15:28.733400Z

like 100/sec

2018-12-18T10:54:20.740200Z

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

2018-12-18T10:54:44.740900Z

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

pesterhazy 2018-12-18T13:08:04.744100Z

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

gklijs 2018-12-18T07:49:14.734400Z

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

fellshard 2018-12-18T08:08:56.734800Z

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

pesterhazy 2018-12-18T09:13:19.737900Z

loved this one - beautiful patterns

ihabunek 2018-12-18T11:32:41.741100Z

i animated mine in ascii

ihabunek 2018-12-18T11:32:41.741300Z

https://imgur.com/a/L3VZbO8

gklijs 2018-12-18T07:55:19.734500Z

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

pesterhazy 2018-12-18T09:08:44.736100Z

and my day 18 https://github.com/pesterhazy/advent2018/blob/master/src/advent/puzzle18.clj

pesterhazy 2018-12-18T09:09:31.737100Z

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

pesterhazy 2018-12-18T09:10:34.737800Z

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

ihabunek 2018-12-18T10:23:15.739100Z

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

mfikes 2018-12-18T12:48:26.742200Z

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.

pesterhazy 2018-12-18T13:06:15.743300Z

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

pesterhazy 2018-12-18T13:07:19.744Z

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

mfikes 2018-12-18T13:11:02.746800Z

@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.

pesterhazy 2018-12-18T14:58:39.747900Z

@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

pesterhazy 2018-12-18T14:59:22.748700Z

kept me up all evening πŸ™‚

ihabunek 2018-12-18T15:06:37.750400Z

@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?

ihabunek 2018-12-18T15:07:09.751Z

i tend to break things into smaller functions and write some docs, for myself if noone else πŸ™‚

ihabunek 2018-12-18T15:07:27.751200Z

btw, my solution: https://git.sr.ht/%7Eihabunek/aoc2018/tree/master/clojure/src/aoc2018/day17.clj

mfikes 2018-12-18T15:08:41.751700Z

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

ihabunek 2018-12-18T15:09:23.752400Z

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

ihabunek 2018-12-18T15:09:49.752900Z

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

mfikes 2018-12-18T15:12:04.755400Z

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.

πŸ‘Œ 3
mfikes 2018-12-18T15:12:41.755800Z

Same thing happens with English (or any other writing)

ihabunek 2018-12-18T15:14:09.757500Z

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

ihabunek 2018-12-18T15:14:25.757700Z

(if used consistently)

mfikes 2018-12-18T15:14:43.758300Z

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

mfikes 2018-12-18T15:15:22.759100Z

A well chosen name is better than a long comment explaining something πŸ™‚

ihabunek 2018-12-18T15:15:37.759300Z

yes, very true

ihabunek 2018-12-18T15:15:45.759600Z

and also very difficult πŸ™‚

mfikes 2018-12-18T15:15:50.759800Z

But I agree, my day 17 is quite opaque right now πŸ™‚

ihabunek 2018-12-18T15:16:42.760400Z

there's only so much time available in a day

2018-12-18T16:32:25.763900Z

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

markw 2018-12-18T18:07:48.765600Z

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

ihabunek 2018-12-18T18:12:53.766500Z

Cool, I'll have a look

pesterhazy 2018-12-18T18:31:01.767800Z

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

pesterhazy 2018-12-18T18:31:21.768300Z

Which of course you don’t always have

markw 2018-12-18T18:35:15.769400Z

@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.

markw 2018-12-18T18:35:33.769900Z

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

πŸ‘ 1
Average-user 2018-12-18T19:53:18.771Z

My day17 solution is too slow

Average-user 2018-12-18T20:40:16.771900Z

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

Average-user 2018-12-18T20:40:27.772200Z

How long it takes yours?

2018-12-18T22:08:32.773600Z

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.

2018-12-18T22:09:04.774300Z

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.