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
fellshard 2017-12-21T08:45:24.000150Z

Fun with List Processing ™️

ihabunek 2017-12-21T14:55:17.000028Z

well i have a bug 😄

ihabunek 2017-12-21T14:55:23.000713Z

can't trace it for a while now

fellshard 2017-12-21T16:14:16.000468Z

I need to remember to use flatten more often...

borkdude 2017-12-21T16:17:38.000425Z

I’m still in progress, so not looking, but I’ve already used flattened. I thought I could avoid assembling the whole grid from the parts, but then realized 3x4 is divisble by 2, sigh… 🙂

ihabunek 2017-12-21T16:39:48.000748Z

i found the bug, it was due to not reading the question properly

ihabunek 2017-12-21T16:39:50.000443Z

again.

ihabunek 2017-12-21T16:39:51.000502Z

🙂

ihabunek 2017-12-21T16:40:28.001007Z

trash performance

bhauman 2017-12-21T17:04:29.000014Z

@ihabunek just a tip. for is pretty darn powerful for comprehensions you can do (for [x (range 10) y (range x)] [x y])

ihabunek 2017-12-21T17:05:14.000640Z

i know but i wanted nested lists so i nested fors

bhauman 2017-12-21T17:05:32.000487Z

darn well that makes sense

ihabunek 2017-12-21T17:05:36.000669Z

😄

ihabunek 2017-12-21T17:05:58.000576Z

but i'm sure much of my code can be written in a nicer way

ihabunek 2017-12-21T17:06:12.000164Z

i'm still learning new functions every day

bhauman 2017-12-21T17:07:34.000385Z

@ihabunek I would call distinct on variants before using it

bhauman 2017-12-21T17:08:02.000089Z

as "##/##" only has one variant

bhauman 2017-12-21T17:08:34.000287Z

unless of course I'm missing something again

ihabunek 2017-12-21T17:09:04.000527Z

It's lazy though so distinct would make the whole thing eval and slow it down.

ihabunek 2017-12-21T17:09:40.000178Z

I think. 😀

bhauman 2017-12-21T17:09:42.000004Z

distinct is lazy 🙂

ihabunek 2017-12-21T17:09:45.000446Z

Ah

ihabunek 2017-12-21T17:09:50.000209Z

Nice

bhauman 2017-12-21T17:11:00.000721Z

I was just looking for what was slowing you down

bhauman 2017-12-21T17:11:54.000299Z

i don't think that's going to help much

mfikes 2017-12-21T17:32:01.000199Z

Very clean solution @bhauman

bhauman 2017-12-21T17:34:40.000026Z

@mfikes our solutions are practically identical

mfikes 2017-12-21T17:35:29.000099Z

Yes, I started thinking that when I saw (concat rotations (map flip rotations))

bhauman 2017-12-21T17:37:21.000223Z

your split-xf function is different from my break-into which is interesting

bhauman 2017-12-21T17:39:51.000685Z

oh it doesn't matter if they are rotated/transposed at this point

bhauman 2017-12-21T17:42:15.000055Z

I was maintaining fidelity when I didn't have to

bhauman 2017-12-21T17:48:07.000663Z

I definitely really like how you are composing everything into one big transducer function

mfikes 2017-12-21T17:50:39.000250Z

Yeah, I don't think I succeeded completely. Or, at least I can say, Planck still consumes a few GB when solving it.

bhauman 2017-12-21T17:50:51.000333Z

now I get it, I really like your split-xf approach

mfikes 2017-12-21T17:51:07.000150Z

Dunno if this is just lazy cleanup of garbage or if it is true head-holding type stuff.

bhauman 2017-12-21T17:51:09.000049Z

way more straight forward

bhauman 2017-12-21T17:54:05.000332Z

I would guess its the garbage

mfikes 2017-12-21T18:27:59.000005Z

I’m curious if there is any self-referential pattern for part 2 that would allow you to avoid brute force. (I haven’t bothered to check.)

bhauman 2017-12-21T19:54:00.000270Z

discussion HINT

bhauman 2017-12-21T19:54:30.000384Z

since depth isn't a problem a recursive solution seems like it could perform well

bhauman 2017-12-21T19:55:59.000476Z

because we don't have to transform back to the original and if done right we could memoize whole portions of the tree

bhauman 2017-12-21T19:56:22.000161Z

and the return type is just a string or a number

borkdude 2017-12-21T20:14:17.000281Z

Sorry, I hijacked your discussion… I’ll remove

bhauman 2017-12-21T20:15:09.000221Z

no worries

borkdude 2017-12-21T20:59:58.000229Z

I tried an answer that I seriously computed, but then it said: this is the answer for someone else. LOL

bhauman 2017-12-21T21:00:23.000576Z

ugh

borkdude 2017-12-21T21:02:08.000259Z

but one bug I had: I didn’t consider ordering of the rules. Obviously that’s important

ihabunek 2017-12-21T21:03:49.000325Z

cheater! 😄

ihabunek 2017-12-21T21:03:54.000107Z

i had that the other day too

ihabunek 2017-12-21T21:04:06.000242Z

the one with two parallel programs

ihabunek 2017-12-21T21:04:21.000249Z

i gave the answer for the wrong program

bhauman 2017-12-21T21:15:00.000038Z

holy crap the memoized recursive solution runs in 5ms

bhauman 2017-12-21T21:29:24.000334Z

the recursive solution has to bridge past the divisible by 2 divisible by 3 ambiguity

bhauman 2017-12-21T21:34:43.000006Z

I now have a 5ms solution for part 2

⚡ 1
borkdude 2017-12-21T21:50:38.000218Z

DOH, I thought for rotate, rotating the outer nodes of the square around the center one.. what was I thinking, looool

👍 1
mfikes 2017-12-21T21:53:02.000033Z

Oooh. Does the rule order matter? I didn't incorporate that into my solution.

borkdude 2017-12-21T21:53:28.000071Z

I thought it was my mistake, but now I realize my rotations are totally bogus

borkdude 2017-12-21T21:56:05.000355Z

surprise it did work for the example

mfikes 2017-12-21T21:56:43.000281Z

My rotations were wrong initially as well and my code worked for the example

bhauman 2017-12-21T21:57:02.000139Z

the logic order (mod 2) comes before (mod 3)

mfikes 2017-12-21T21:57:22.000299Z

Yes, that order is crucial for, say 6 or 12

borkdude 2017-12-21T21:57:30.000260Z

yeah, got that

borkdude 2017-12-21T21:57:46.000171Z

I’m creating an extended rule book that already includes the rotations/flips

borkdude 2017-12-21T21:57:51.000213Z

so you can just lookup by whatever you have

borkdude 2017-12-21T21:58:00.000105Z

but then you have to take care of the order

bhauman 2017-12-21T21:58:00.000155Z

yeah thats what we did

bhauman 2017-12-21T21:58:07.000008Z

you do???

bhauman 2017-12-21T21:58:12.000532Z

I don't think so

borkdude 2017-12-21T21:59:24.000078Z

ok well I thought it was my mistake that there would be some rotation literally in the rule book and I would be overriding it

borkdude 2017-12-21T21:59:32.000545Z

but ok

bhauman 2017-12-21T22:00:31.000076Z

just make sure your (count (distinct (vals rules)) is equal to the original rulles length

borkdude 2017-12-21T22:00:52.000045Z

yeah, added an assertion for that. I’m using more assertions since you helped me out 🙂

borkdude 2017-12-21T22:03:51.000322Z

Phew, part 1 solved now.

borkdude 2017-12-21T22:04:49.000171Z

Part 2 also.

borkdude 2017-12-21T22:06:11.000353Z

My assumption was that the rules could not be orthogonal with respect to rotations. E.g. if there would be a rule A => that had rotations A’, A’‘, but there would also be a rule B => , with B equal to A’ sorting the rules like A, B, A’ would mess things up

borkdude 2017-12-21T22:07:33.000014Z

But maybe they were orthogonal or however you may put this

borkdude 2017-12-21T22:07:37.000275Z

exclusive

borkdude 2017-12-21T22:23:35.000154Z

My code. Nothing fancy, but glad it works now. https://github.com/borkdude/aoc2017/blob/master/src/day21.clj