Fun with List Processing ™️
well i have a bug 😄
can't trace it for a while now
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day21.clj
I need to remember to use flatten more often...
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… 🙂
i found the bug, it was due to not reading the question properly
again.
🙂
https://github.com/ihabunek/aoc2017/blob/master/src/aoc2017/day21.clj
trash performance
@ihabunek just a tip. for
is pretty darn powerful for comprehensions you can do (for [x (range 10) y (range x)] [x y])
i know but i wanted nested lists so i nested fors
darn well that makes sense
😄
but i'm sure much of my code can be written in a nicer way
i'm still learning new functions every day
@ihabunek I would call distinct on variants
before using it
as "##/##" only has one variant
unless of course I'm missing something again
It's lazy though so distinct would make the whole thing eval and slow it down.
I think. 😀
distinct is lazy 🙂
Ah
Nice
I was just looking for what was slowing you down
i don't think that's going to help much
Day 21: https://github.com/mfikes/advent-of-code/blob/master/src/advent_2017/day_21.cljc
Very clean solution @bhauman
@mfikes our solutions are practically identical
Yes, I started thinking that when I saw (concat rotations (map flip rotations))
your split-xf
function is different from my break-into
which is interesting
oh it doesn't matter if they are rotated/transposed at this point
I was maintaining fidelity when I didn't have to
I definitely really like how you are composing everything into one big transducer function
Yeah, I don't think I succeeded completely. Or, at least I can say, Planck still consumes a few GB when solving it.
now I get it, I really like your split-xf
approach
Dunno if this is just lazy cleanup of garbage or if it is true head-holding type stuff.
way more straight forward
I would guess its the garbage
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.)
there's this https://www.reddit.com/r/adventofcode/comments/7l78eb/2017_day_21_solutions/drk8j2m/
discussion HINT
since depth isn't a problem a recursive solution seems like it could perform well
because we don't have to transform back to the original and if done right we could memoize whole portions of the tree
and the return type is just a string or a number
Sorry, I hijacked your discussion… I’ll remove
no worries
I tried an answer that I seriously computed, but then it said: this is the answer for someone else. LOL
ugh
but one bug I had: I didn’t consider ordering of the rules. Obviously that’s important
cheater! 😄
i had that the other day too
the one with two parallel programs
i gave the answer for the wrong program
holy crap the memoized recursive solution runs in 5ms
the recursive solution has to bridge past the divisible by 2 divisible by 3 ambiguity
I now have a 5ms solution for part 2
DOH, I thought for rotate, rotating the outer nodes of the square around the center one.. what was I thinking, looool
Oooh. Does the rule order matter? I didn't incorporate that into my solution.
I thought it was my mistake, but now I realize my rotations are totally bogus
surprise it did work for the example
My rotations were wrong initially as well and my code worked for the example
the logic order (mod 2) comes before (mod 3)
Yes, that order is crucial for, say 6 or 12
yeah, got that
I’m creating an extended rule book that already includes the rotations/flips
so you can just lookup by whatever you have
but then you have to take care of the order
yeah thats what we did
you do???
I don't think so
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
but ok
just make sure your (count (distinct (vals rules))
is equal to the original rulles length
yeah, added an assertion for that. I’m using more assertions since you helped me out 🙂
Phew, part 1 solved now.
Part 2 also.
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
But maybe they were orthogonal or however you may put this
exclusive
My code. Nothing fancy, but glad it works now. https://github.com/borkdude/aoc2017/blob/master/src/day21.clj