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-12T00:02:01.418Z

There's some really beautiful symmetry in creating the summed area table:

(defn summed-area-table [colls]
  (->> colls
       (map #(reductions + %))
       (reductions #(map + %1 %2))))

2
Average-user 2018-12-12T02:26:50.418900Z

what would it colls be here?

2018-12-12T02:30:58.419100Z

(for [y ys]
  (for [x xs]
    (f x y)))
Rows nested in columns, basically.

2018-12-12T02:31:48.419300Z

On mobile right now so apologies for any errors in that code.

2018-12-12T05:06:58.419900Z

shit.. forgot this was going on hahaha

2018-12-12T05:07:08.420100Z

having fun everyone?

mattly 2018-12-12T05:48:22.420600Z

anyone have a strategy for part 2? 😄

mattly 2018-12-12T05:49:43.420900Z

crap, there are people who've done it already

mattly 2018-12-12T05:49:54.421200Z

there must be some super-efficient algorithm for this

mattly 2018-12-12T05:58:58.421500Z

ah, apparently the pattern stabilizes

taylor 2018-12-12T06:09:17.422100Z

just started on this one and I don’t understand how to handle the negative range?

mattly 2018-12-12T06:09:25.422400Z

heh

mattly 2018-12-12T06:09:26.422700Z

that

taylor 2018-12-12T06:09:28.422900Z

does it go on forever?

mattly 2018-12-12T06:09:32.423Z

got me really good

mattly 2018-12-12T06:09:33.423200Z

yes

mattly 2018-12-12T06:09:51.423600Z

at least in theory

taylor 2018-12-12T06:10:47.424600Z

so in both directions, you have to find when the pattern stops producing new plants or something?

mattly 2018-12-12T06:10:56.424800Z

yep

taylor 2018-12-12T06:11:14.425Z

not very well described problem

mattly 2018-12-12T06:11:35.425200Z

it could have been clearer

fellshard 2018-12-12T06:18:03.425900Z

It's weirder than 'stops producing new plants...' at least with my input

mattly 2018-12-12T06:18:54.426700Z

so, part 2 asks you to solve for 50 billion iterations

mattly 2018-12-12T06:19:17.427100Z

i'm "cheating" for the first time and checking reddit

mattly 2018-12-12T06:19:17.427300Z

and

mattly 2018-12-12T06:19:25.427600Z

most people aren't simulating it

Average-user 2018-12-12T06:21:06.428Z

last year there was a similar problem, where the solution was to find a cycle

mattly 2018-12-12T06:22:47.428200Z

yeah

mattly 2018-12-12T06:29:52.428600Z

yeah, indeed

2018-12-12T06:31:44.429200Z

ugghh.. done.. I disliked this problem a lott

Average-user 2018-12-12T06:32:20.429400Z

how did you do it?

2018-12-12T06:35:23.432600Z

.. in a very non-robust manner. At first I storing the prior states looking for a repeat. No exact state repeated, but it when I normalized (removed the leading/trailing dots) it repeated with a cycle length of one.

fellshard 2018-12-12T06:36:45.434500Z

Thanks for the tip, mattly ^^

2018-12-12T06:36:47.434600Z

So, then under the assumption that I had this end condition, once I duplicated the state, I was able to advance immediately to the final 50b state (just shifting the pattern out)

fellshard 2018-12-12T06:37:23.434700Z

This one pretty much depends on reaching a fixed point, yeah. The offset changes, but the pattern fixes.

fellshard 2018-12-12T06:38:02.434900Z

That's often the case when they throw giant numbers at you; usually that's a hint you're missing an optimization in how you approach the problem.

2018-12-12T06:42:46.435200Z

I don’t consider this an optimization. It feels more like side-stepping the problem to efficiently solve only the given input. Is there a guarantee we’ll always hit a cycle? Maybe - I dunno. Will it always manifest like this? I suppose with some deep thought I could answer that? In the end, I don’t feel like I wrote useful code - I just used some code to help me solve a single instance of a puzzle. That’s not very satisfying to me. (but I realize that’s how most of the top leaderboard operates overall)

2018-12-12T06:48:39.437900Z

Oh, and just for amusement, before I searched for a pattern repeat, I searched for a score (sum of plant positions) repeat. I got several nonsensical repeats, and it took me a few minute to realize that there were many un-related patterns that could produce the same score. So then moved on to tracking the patterns

mattly 2018-12-12T07:08:25.438800Z

I ended up looking for a repeat of the difference in sums

taylor 2018-12-12T07:16:37.438900Z

this is what I’m currently trying but I must be missing something b/c I don’t see a repeat

taylor 2018-12-12T07:45:42.440200Z

hmm yeah just solved part 2 by finding the repeated pattern (started @ ~100 generations for me) and extrapolating the repetitive score difference to 50B

☝️ 1
fellshard 2018-12-12T07:47:01.440300Z

Pretty sure you'd be waiting a loooong time running each generation by hand. It's expected the inputs are designed to reach some fixed point like this, just because any that diverge would be infeasible to solve for a challenge like this.

ihabunek 2018-12-12T13:02:12.441500Z

just spent half an hour debugging the program and then discovering i was running on sample input instead of my input 😢

ihabunek 2018-12-12T13:02:33.442100Z

today was familiar to anyone who played last year, pattern searching

1
ihabunek 2018-12-12T13:11:56.442700Z

Part 1 "Elapsed time: 20.185556 msecs"
Part 2 "Elapsed time: 102.438381 msecs"

misha 2018-12-12T14:28:41.443100Z

.

p1 "Elapsed time: 5.678204 msecs"
p2 "Elapsed time: 43.402724 msecs"

misha 2018-12-12T14:49:34.443700Z

@taylor same

taylor 2018-12-12T14:50:25.444400Z

curious to see what data structures people used to represent the pots. I used a map where the keys where the pot numbers and it made the logic pretty easy

misha 2018-12-12T14:56:25.445100Z

(->> generations (drop 102) :kappa:

taylor 2018-12-12T14:56:45.445300Z

:man-shrugging:

taylor 2018-12-12T14:57:56.445700Z

REPL-driven development

ihabunek 2018-12-12T14:59:05.446700Z

@taylor I used a sorted set containing indexes of full pots

ihabunek 2018-12-12T14:59:30.447300Z

it made detecting patterns very easy

ihabunek 2018-12-12T14:59:49.448Z

just (map - next-gen current-gen)

misha 2018-12-12T14:59:53.448200Z

transient {pot-idx <"#"|".">} e.g. {-1 "." 0 "#" ...}

ihabunek 2018-12-12T15:00:03.448400Z

what is that 😄

benoit 2018-12-12T15:02:12.448900Z

Today was painful 🙂 https://github.com/benfle/advent-of-code-2018/blob/master/day12.clj

misha 2018-12-12T15:02:39.449600Z

transient map + sort keys turned out to be faster than sorted-map

ihabunek 2018-12-12T15:02:50.449800Z

ah, right

Average-user 2018-12-12T15:15:31.451400Z

I used something like (map rules (partition 5 1 pots) ) to get new generations

misha 2018-12-12T15:22:02.452400Z

I started with it, but after 1st wrong answer, I realized I need to track pot indexes :kappa:

Average-user 2018-12-12T15:23:17.453300Z

misha 2018-12-12T15:23:18.453600Z

also, if you don't shrink, and equilibrium is few 100k iterations away - you are in trouble

Average-user 2018-12-12T15:24:05.454300Z

I do track them:

(defn next-generation [pots rules]
  (-&gt;&gt; pots
       (partition 5 1)
       (map #(let [r (rules (map second %))
                   i (first (nth % 2))]
               (if (nil? r) [i \.] [i r])))))

misha 2018-12-12T15:24:28.454500Z

but what is pots?

misha 2018-12-12T15:24:47.455300Z

sorted-map? sorted-set?

Average-user 2018-12-12T15:25:03.455600Z

(map-indexed vector "....#...###...##")

misha 2018-12-12T15:28:14.456100Z

does this assume pots don't expand below 0?

misha 2018-12-12T15:29:28.456800Z

either code is to dense or I am :kappa:

Average-user 2018-12-12T15:29:30.457Z

No, I add some \. to the start and the end on each generation

Average-user 2018-12-12T15:29:41.457400Z

I didn't post that, sorry

misha 2018-12-12T15:29:59.457800Z

and you dont clean up those paddings?

misha 2018-12-12T15:30:45.458600Z

first, I added pads w/o shrinking, and boiled my CPU :opieop:

Average-user 2018-12-12T15:31:11.459100Z

Yeah, not sure how to shrink

misha 2018-12-12T15:32:34.459700Z

m! is {-1 "." 0 "#" ...}

misha 2018-12-12T15:33:23.460200Z

I am sure it has some off-by-1 error in there, but meh ¯\(ツ)

Average-user 2018-12-12T15:35:46.460300Z

Mine is something like

(defn shrink [pots]
  (if (= '(\. \. \.) (map second (take 3 pots)))
    (recur (rest pots))
    pots))

misha 2018-12-12T15:37:19.460500Z

I used indexes because I already had them in client fn, and did not want to pay reverse for shrink-right

Average-user 2018-12-12T15:38:19.460800Z

makes sense

misha 2018-12-12T15:39:01.461100Z

and I had them because I did not want to pay sort for map before each iteration

misha 2018-12-12T15:41:02.462500Z

but all of this does not really matter If equilibrium is just few hundred iterations away :opieop:

Average-user 2018-12-12T15:46:32.462700Z

(time (vector (part-1) (part-2)))
"Elapsed time: 161.300258 msecs"
[3890 4800000001087]

Average-user 2018-12-12T15:46:47.463100Z

Ended up with that, fair timo to be using just lists

Average-user 2018-12-12T15:46:53.463300Z

time*

Average-user 2018-12-12T15:49:32.465500Z

Has someone prove that there always will be an equilibrium?

misha 2018-12-12T15:50:23.466300Z

I printed like 1000 of steps, it never changes, just drifts to the right (for me)

☝️ 1
misha 2018-12-12T15:51:34.466900Z

I thought it would fluctuate, like gliders in game of life

misha 2018-12-12T15:52:23.467900Z

and started with a loop to track anything seen to detect loops, but then printed it, and saw there is just a shift, no loops

➕ 1
1️⃣ 1
uneman 2018-12-12T16:41:10.471400Z

https://github.com/namenu/advent-of-code-2018/blob/master/src/year2018/day12.clj I've encoded rules into binary digits (e.g. .#.#. -> 10), and looped through pots with five bits window.

2018-12-12T17:08:40.471800Z

Yepp, it’s useful to look at your data

borkdude 2018-12-12T21:11:01.473700Z

Advent of CLJC will now store times from comitted days and print an overview of times of solutions for committed days: E.g: https://circleci.com/gh/borkdude/advent-of-cljc/375

==== Scores:
  year | day | time | username | environment |  test  
------+-----+------+----------+-------------+--------
 2018 |   1 |    0 | borkdude | jvm         | part-1
 2018 |   1 |   31 | borkdude | node        | part-1
 2018 |   1 |  156 | borkdude | jvm         | part-2
 2018 |   1 |  329 | borkdude | node        | part-2

2
fellshard 2018-12-12T21:31:05.474300Z

That's not unlikely, as specific automata can have such proven properties, I think.

borkdude 2018-12-12T21:53:06.475400Z

@ben.grabow I see there is an issue with my ssh command when building a PR. I’ll fix that now and let you know

2018-12-12T21:54:26.475500Z

No worries. Tell me if you need me to do anything on my end.

borkdude 2018-12-12T21:57:49.475700Z

Fixed. Can you rebase or merge with master and then update the PR?

borkdude 2018-12-12T22:00:38.475900Z

Seems to work now?

2018-12-12T22:01:15.476100Z

Yeah, looks great. I don't see a table summarizing the times though. Should I?

borkdude 2018-12-12T22:01:49.476300Z

No, not in PRs, since the private key of my server is needed for that and PRs can’t access that

borkdude 2018-12-12T22:01:57.476500Z

but once I have merged it to master, you will

borkdude 2018-12-12T22:02:01.476700Z

so shall I?

2018-12-12T22:02:07.476900Z

Sure go ahead!

borkdude 2018-12-12T22:04:10.477100Z

crap, there’s still an error, I will fix

borkdude 2018-12-12T22:12:13.477300Z

fixed

🎄 1
2018-12-12T22:15:05.479Z

the pots were two infinite lazy lists for me - one representing postive numbered pots, one representing negative numbered pots. The negative pots were in "reverse" order, -1, -2, -3, -4, -5

2018-12-12T22:15:49.479700Z

however negative points weren't really needed, my pattern moved rightwards, apart from a few exceptions at the start.

☝️ 1
2018-12-12T22:16:57.480200Z

I considered doing something like that but shuddered at the thought of coding the step function near the origin. How did you handle it?

2018-12-12T22:19:06.480600Z

actually not too tricky:

2018-12-12T22:19:11.480900Z

(defn evolve-lhs [[lhs rhs]] (map (comp rule reverse) (partition 5 1 (cons (second rhs) (cons (first rhs) lhs))))) (defn evolve-rhs [[lhs rhs]] (map rule (partition 5 1 (cons (second lhs) (cons (first lhs) rhs)))))

2018-12-12T22:19:25.481100Z

just take a little of the other side

2018-12-12T22:19:32.481300Z

and add it to the front of this side.

fellshard 2018-12-12T22:23:32.481900Z

I think they were mostly needed to ensure pot 0 had known empty pots to its left at the beginning. You say it did dip below 0 briefly?

2018-12-12T22:27:46.483100Z

I guess you keep a little padding at the ends of each list so the partition 5 picks up the entire range?

fellshard 2018-12-12T22:30:49.483500Z

I pad the ends at the beginning and trim the ends at the end, keeping track of the new initial index. It seems to have worked reasonably well, though may be overkill; it really is just there to make the partition work.

taylor 2018-12-12T22:31:01.483900Z

this is why I used a map with indices as keys and did get with default value of \. for simplicity

➕ 1
taylor 2018-12-12T22:32:03.484Z

mine definitely went negative for a few generations but after that went straight positive

2018-12-12T22:33:33.484600Z

the lists are infinite, so no manual padding required.

2018-12-12T22:34:23.485400Z

If this has piqued anyones interest then Wolfram Alpha can show you your pot plants graphically, and millions of other pot plant reproduction schemes also!

2018-12-12T22:34:35.486Z

That's my rule working on random initial conditions

2018-12-12T22:35:19.486300Z

(def start-row [(repeat \.) (lazy-cat (seq input) (repeat \.))])

2018-12-12T22:35:47.486500Z

The first item in the vector is the left hand side, all dots, the second is the right hand side, i.e. my input followed by dots.

2018-12-12T22:38:00.487Z

This scheme ran out of stack space before I got to 500 iterations though 🙂

😄 1
2018-12-12T22:44:58.487900Z

oh nice new table 🙂

borkdude 2018-12-12T22:46:08.488100Z

yeah, it’s instead of running all solutions now, which seemed not feasible anymore given the accumulation of state in namespaces

2018-12-12T22:51:02.488300Z

yeah, I saw this when looking at the ci job 🙂. Pretty cool!

borkdude 2018-12-12T22:57:44.488800Z

https://github.com/borkdude/advent-of-cljc#scores