adventofcode

2021-12-15T17:29:03.135Z

Can someone who has solved Day 14 help me debug an issue, issue in thread

2021-12-15T17:29:49.135100Z

Using the test data "NNCB" After 10 cycles of reactions, I get

{"CH" 21, "HH" 32, "BH" 81, "BN" 735, "NH" 27, "NB" 796, "HB" 26, "BC" 120, "CN" 102, "CC" 60, "BB" 812, "CB" 115, "HN" 27, "HC" 76, "NC" 42}
Can someone who has solved it tell me what the pair counts are after 10 iterations?

2021-12-15T17:30:13.135300Z

When I try to solve, I'm counting the number of character and halving it. BUt I'm off by one on some

R.A. Porter 2021-12-15T17:30:59.135600Z

The last character in the template string.

2021-12-15T17:32:59.135800Z

oh yeah, its the first and last char that is off by one

2021-12-15T17:34:31.136100Z

thanks, that helps

R.A. Porter 2021-12-15T17:35:38.136300Z

šŸ‘

genmeblog 2021-12-15T19:26:17.142900Z

You have to add first and last characters too before dividing by 2.

Sam Adams 2021-12-15T17:38:42.137Z

SPOILER ALERT — day 15 hint request šŸŖ”šŸ™

Sam Adams 2021-12-15T17:39:28.137100Z

Maybe just a sanity check: contrary to the examples, the min-risk path CAN include leftward and upward movements, right?

euccastro 2021-12-15T17:40:23.138700Z

theoretically yes, I haven't checked whether they happen in my real input

AC 2021-12-15T17:40:25.138900Z

yes. people were posting example grids in the reddit thread that break the assumption that it’s only down and to the right. for example: <tel:1911191111|1911191111> <tel:1119111991|1119111991> <tel:9999999111|9999999111> <tel:9999911199|9999911199> <tel:9999119999|9999119999> <tel:9999199999|9999199999> <tel:9111199999|9111199999> <tel:9199999111|9199999111> <tel:9111911191|9111911191> <tel:9991119991|9991119991>

Sam Adams 2021-12-15T17:54:08.140300Z

Gahh, okay, thanks!

Sam Adams 2021-12-15T18:45:16.140700Z

I’m stumped… were people able to write recursive memoized solutions? Or is a stateful cache necessary…?

AC 2021-12-15T19:15:41.142100Z

my main logic is a loop and a priority-map. have you gotten any hints/spoilers about what algorithm others are using? (I don’t want to give too many hints unless you want them)

Sam Adams 2021-12-15T19:19:11.142300Z

Have had no hints yet, but I’d appreciate any that come to mind šŸ™‚ (at this point just hoping to avoid punting or reading the solution thread)

Sam Adams 2021-12-15T19:20:08.142500Z

ā€œpriority-mapā€ confuses me so I suspect my basically brute-force approach (to which I’m trying to add memoization and pruning) is very wrong…

AC 2021-12-15T19:24:03.142700Z

most people are using Dijkstra’s algorithm (or A* though it didn’t help speed mine up at all)

šŸ™Œ 1
Sam Adams 2021-12-15T19:30:29.143200Z

That’s a very helpful hint and just what I was after, thanks!

genmeblog 2021-12-15T19:34:17.144Z

my two hints for dijkstra: you don't need to track a path and you should stop after reaching the end

šŸ™Œ 1
samedhi 2021-12-23T03:57:11.271900Z

Wow, finally https://github.com/samedhi/advent-of-code-2021/blob/main/30.clj. Took me a long time to reason that I could use a sorted map as a heapq like thing.

samedhi 2021-12-23T04:00:44.272300Z

I would love to see other peoples solution to this day.

2021-12-15T19:09:41.142Z

Day 14 is annoying me majorly. It works for the test data, gets the correct answer of 1588 after 10 cycles Wrong answer for real data. I re-write with a different approach. It works for the test data, gets the correct answer of 1588 after 10 cycles. Exactly the same wrong answer for the real data! Argh!

genmeblog 2021-12-15T19:31:05.143400Z

how do you count character count?

genmeblog 2021-12-15T19:32:03.143600Z

my string has the same character at the beginning and the end and it broke my first attempt

2021-12-15T19:33:05.143800Z

I end up with two chars that have an odd number of counts. One char is the same as the first char in the string, so I add 1 to that. Same with the last char in the string. THen I find the max and min, do max-min, and half that result.

genmeblog 2021-12-15T19:35:15.144200Z

what is the result after, say 20 cycles?

2021-12-15T19:35:15.144400Z

My algo is, I only keep track of the number of each pairs, then on each react cycle I swap out the key with that pair (repeated n times, where n is the original keys value).

genmeblog 2021-12-15T19:36:38.144600Z

I remove everything before next cycle. I mean I build counts from the scratch every time.

2021-12-15T19:38:55.144900Z

Yeah, that's waht I'm doing too. My react method

(defn react [reactions v]
  (reduce (fn [acc [k v]]
            (let [freq (frequencies (flatten (repeat v (reactions k))))]
              (merge-with + acc freq)))
          {}
          v))
where reactions is a map of reactions
{"CH" ["CB" "BH"], "HH" ["HN" "NH"], "BH" ["BH" "HH"] ...}
And v is a map of the current pair counts
{"NN" 1
 "NC" 1
 "CB" 1}

genmeblog 2021-12-15T19:39:14.145100Z

to verify: after 20 cycles my result is: 2264701 and for example [\N \O] is 77113

2021-12-15T19:39:33.145300Z

is that for the test data ?

genmeblog 2021-12-15T19:39:48.145600Z

yes

2021-12-15T19:40:12.145800Z

oooh, for the test data I get 1961318 after 20 cycles.

2021-12-15T19:40:52.146Z

so there is something that happens after 10 cycles, that doesnt happen in the first 10 cycles for me!

genmeblog 2021-12-15T19:40:52.146200Z

yep, sometimes some bug appears later than sooner (was there šŸ™‚ )

2021-12-15T19:41:04.146400Z

thanks

genmeblog 2021-12-15T19:44:49.146600Z

check also "NO" count

genmeblog 2021-12-15T19:45:34.146800Z

if it's the same it could mean that your final counting is wrong not pair counting

2021-12-15T19:47:33.147Z

It's my react function, I guess as I don't end up with any "NO" key at all after 20

genmeblog 2021-12-15T19:47:54.147200Z

it looks valid at the first glance...

genmeblog 2021-12-15T19:50:14.147400Z

shit... sorry

2021-12-15T19:50:27.147600Z

After 20 my map looks like

{"CH" 10614, "HH" 10002, "BH" 20606, "BN" 965778, "NH" 6775, "NB" 983801, "HB" 13841, "BC" 36044, "CN" 31220, "CC" 18022, "BB" 986886, "CB" 24787, "HN" 6775, "HC" 17379, "NC" 13198}

genmeblog 2021-12-15T19:51:38.147800Z

sorry, I have the same result as you... I used the same var for my data and test data and acciedentally shadow one by another

genmeblog 2021-12-15T19:51:57.148Z

The result on test data is 1961318

genmeblog 2021-12-15T19:52:16.148200Z

{[\C \H] 10614, [\H \C] 17379, [\N \C] 13198, [\N \H] 6775, [\C \N] 31220, [\N \B] 983801, [\B \C] 36044, [\B \B] 986886, [\B \H] 20606, [\C \C] 18022, [\H \N] 6775, [\C \B] 24787, [\H \B] 13841, [\B \N] 965778, [\H \H] 10002}

genmeblog 2021-12-15T19:52:31.148400Z

sorry for confusion, my fault

2021-12-15T19:54:00.148600Z

so my problem is, something happens in real data that doesnt happen in test data!

genmeblog 2021-12-15T19:55:11.148800Z

you can try on my test data: https://github.com/genmeblog/advent-of-code/blob/master/resources/advent_of_code_2021/day14.txt

genmeblog 2021-12-15T19:56:25.149200Z

for 10 I got 2194

genmeblog 2021-12-15T19:56:59.149400Z

for 40: 2360298895777

2021-12-15T19:57:29.149600Z

oh, thats helpful, i deffo have a problem as after 10 I'm getting 4151/2

2021-12-15T20:00:47.149800Z

Is this a valid way of doing 10 cycles

(->> (partial react reactions)
     (repeat 10)
     (apply comp))
Then just call that with my starting map ?

genmeblog 2021-12-15T20:01:23.150Z

it's better to use iterate

genmeblog 2021-12-15T20:02:07.150200Z

(nth (iterate (partial react reactions)) 10)

šŸ‘ 1
genmeblog 2021-12-15T20:03:24.150500Z

however comp of 10 the same functions should be ok as well

tschady 2021-12-15T20:48:33.150800Z

there is a key difference between real and test data, want a hint?

2021-12-15T20:48:42.151Z

yes please

tschady 2021-12-15T20:49:02.151200Z

teh example data only has at most 1 of each pair. real data has multiple.

2021-12-15T20:49:03.151400Z

is it that you can get duplicate results from the pairs

2021-12-15T20:49:21.151600Z

šŸ˜„

2021-12-15T20:49:27.151800Z

thanks for confirming that

tschady 2021-12-15T20:50:03.152Z

that one bit a friend

2021-12-15T22:14:11.156800Z

got it! Thanks for the help guys šŸ˜„

2
sebastian 2021-12-15T22:29:20.159300Z

General question: has anyone tried used Clerk to do some visualizations on their AoC problems? I would like to see some use-cases.

lread 2021-12-15T23:27:55.161800Z

Someone said it starts to get harder on day 15. Well, I think I see watcha meant there!

2021-12-15T23:56:25.162200Z

i'm trying to wrangle my existing clojure maze solver into a solution for this, but i dont think i can use it

Aleks 2021-12-15T04:52:36.127800Z

🧵Day 0xF answers thread: post your answers here

lread 2022-01-05T19:59:51.325700Z

I kept track of paths too so that I could easily print out a visualization.

2022-01-05T02:21:35.325500Z

I implemented Dijkstra first the naive way (no priority queue, 41+ secs on real input for part 1, no part2 result); then used clojure.data.priority-map (370 msecs for part1), then used a Fibonacci Heap (252 msecs for part1, 10+ secs for part2). I kept track of all the paths throughout.

Aleks 2021-12-15T09:36:06.129700Z

The same result could be gotten with #(inc (mod % 9))

Aleks 2021-12-15T09:37:20.129900Z

I slept not much today, so my brain’s working badly 🤯

erwinrooijakkers 2021-12-15T10:13:34.130200Z

Wat does (Character/digit n 10) do?

MiÄ·elis Vindavs 2021-12-15T10:17:13.130600Z

parses a char into an integer

MiÄ·elis Vindavs 2021-12-15T10:18:08.130800Z

user=> (Character/digit \9 10)
9
user=> (type \9)
java.lang.Character
user=> (type (Character/digit \9 10))
java.lang.Integer

tschady 2021-12-15T12:58:24.131200Z

280ms / 9s, used ubergraph doc: https://github.com/tschady/advent-of-code/blob/main/doc/2021.adoc#aoc-2021-d15 code: https://github.com/tschady/advent-of-code/blob/main/src/aoc/2021/d15.clj I did Djikstra once, ain’t nobody got time to type that out all day. I also assume input is a square, easy enough to change for rects.

2021-12-15T13:20:01.131900Z

Djikstra indeed! I’ve used https://github.com/clojure/data.priority-map which is a pretty nice way of using a priority queue in Clojure (~ 100ms / 2500ms)

šŸ‘ 1
genmeblog 2021-12-15T13:29:09.132600Z

Dijkstra here (with slow second part, 13s)! https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2021/day15.clj

euccastro 2021-12-15T17:37:18.136700Z

I no longer have the time to try and factor nicely across parts, so ugly redefs will have to do: https://github.com/euccastro/advent-of-code-2021/blob/main/day15.clj

šŸ‘ 1
euccastro 2021-12-15T17:39:33.137300Z

uses A*

euccastro 2021-12-15T17:44:17.139200Z

... but it actually implements it in the code, instead of using it from a library (nothing wrong with that, I just felt like using the opportunity to have a refresher)

euccastro 2021-12-15T17:46:47.139400Z

and this also allowed me not to compute the paths, just the cost of the result

euccastro 2021-12-15T17:47:04.139600Z

so it runs in <4s

Callum Oakley 2021-12-15T17:51:01.139900Z

had a dijkstra function ready to go from previous years. 72ms/1.7s https://github.com/callum-oakley/advent-of-code/blob/main/src/aoc/2021/15.clj there goes my sub 1s total runtume (for the year) šŸ˜ž was fun while it lasted. 2.5s total now, 740ms before today

šŸ‘ 1
Antonio Bibiano 2021-12-15T20:56:52.152900Z

Wow my dijkstra takes 98 seconds on the second grid :(

sarcilav 2021-12-15T21:02:58.153100Z

@antbbn? how? maybe wrong data structure implementation?

AC 2021-12-15T21:04:40.153300Z

@antbbn are you keeping track of all the paths you’re trying? I did that to help with debugging, but then ripped it out. Mine sped up from 17s to 4s.

Antonio Bibiano 2021-12-15T21:10:19.154400Z

Mhh maybe my implementation is very inefficient, it takes about 1 second on part 1

Antonio Bibiano 2021-12-15T21:10:40.154900Z

I'll try to clean it up and post it in a bit

2021-12-15T21:12:01.155100Z

I used A* (which isn't the best pick for topleft to bottom right, but okay), but it runs in ~1.2S for part1 and doesn't finish for part 2 :') 102ms for part 1 and <4s for part 2. That wraps it up 😬

Callum Oakley 2021-12-15T21:30:48.155300Z

@antbbn if I had to guess… are you considering positions more than once? If you return to a position you’ve already seen, then you’re necessarily returning to it via a longer path than the first time, so you can ignore it.

2021-12-15T21:43:12.155600Z

I sped up my algorithm by a factor of 10 by just using a proper priority map šŸ˜…

šŸ’Æ 1
Antonio Bibiano 2021-12-15T21:43:16.155800Z

this is my implementation

Antonio Bibiano 2021-12-15T21:43:55.156Z

Antonio Bibiano 2021-12-15T21:44:57.156400Z

my first guess would be that sorting becomes expensive as tds becomes bigger and bigger

Antonio Bibiano 2021-12-15T22:40:04.159500Z

i changed (first (sort-by val tds)) to (apply min-key val tds) and got down to 15 s

sarcilav 2021-12-15T22:51:41.160Z

ah yeah, that helps, sort is O(n log n) and min is O(n)

šŸ’Ŗ 1
Sam Adams 2021-12-15T23:07:11.160600Z

I spent way too long trying to invent an algorithm for this… thanks to @agile-cactus for pointing me to Dijkstra’s. Toxic code: https://samadams.dev/2021/12/15/advent-of-code-day-15.html

kevinc 2021-12-16T00:02:55.162300Z

Brute force, and probably not doing lazy sequences right because I can't fit part 2 in a heapsize under 50MB… 0.2s and 1.0s though! https://github.com/kconner/advent-of-code/blob/master/2021/15a.clj,Ā https://github.com/kconner/advent-of-code/blob/master/2021/15b.clj

kevinc 2021-12-16T01:17:01.164800Z

No, I have to take that back. I spaced on checking my second answer after I got the correct answer for the sample input. There are paths I don't consider at all.

lread 2021-12-17T03:28:41.186100Z

Blech! Finally finished day 15 using dijkstra alg. My code is a mess, but I’m not gonna clean this one up anytime soon! Clever fellow that dijkstra!

2022-01-07T03:09:21.011500Z

As an aside, I couldn’t find a Clojure implementation of a Fibonacci Heap, so I fetched a (mutable) Java impl. and hacked a wrapper around it. Does anyone know of a Clojure and/or persistent FibHeap impl?

AC 2021-12-15T06:50:05.128300Z

I have a lot of code clean-up and optimization to do.. 17s for part 2.

Aleks 2021-12-15T07:43:19.128500Z

> However, risk levels aboveĀ `9`Ā wrap back around toĀ `1`. @norman why do you wrap it back when n is equal to 9, not above? (if (= n 9) 1 (inc n)))

peterc 2021-12-15T07:45:11.128700Z

I think its because the function is increasing n (`n` hasn't been increased yet)

Aleks 2021-12-15T07:47:01.129Z

Oh, thank you, I see