He's definitely not doing the most elegant, fancy, super smart solution and you can tell he Clojure isn't his strongest language, but he does go through most of his process step by step in a pretty entertaining way, so I definitely like seeing how he thinks through stuff.
9/10 recommendation because of the didactic part for more people that are newer to clojure
Yeah, Martin has a long history of OO and Java. I think his move to clojure is relatively recent. But heโs made some quite strong statements about its good qualities.
I think I will take the slow path and use insta-image, to learn a few new things.
heheh, I took a shortcut for part 1 which is useless for part 2...
now I have all work ahead of me
stats so far
20 91 1620 **
I am still on part1, thatโs difficult.
I've managed part 1, but also used a math shortcut and now have to start over for part 2.
Day 20 answers thread - Post your answers here
One ugly but practical way to solve it is by counting the heads visible in your input, get the images (without borders) to count total number of #
and do:
(def char-count-sea-monster
15)
(def sea-monster-count-guess
23)
(- total-hashes (* char-count-sea-monster sea-monster-count-guess))
;; => 1576
Finally got part 2 done. Damn. https://github.com/rjray/advent-2020-clojure/blob/master/src/advent_of_code/day20.clj
Took a few days off โ quite a ways into part one of day 20.. Itching to use some datalog..
https://github.com/green-coder/advent-of-code-2020/blob/master/src/aoc/day_20.clj
If you can do it using Datalog, I will definitely learn something new.
Todayโs puzzle is an endurance test.
I donโt see a lot of activity and I wonder if people are still trying to solve the puzzle or if they took a break.
Weekends be like that
In my particular case I'm a bit far behind, and I'm saving a few to warm up for upcoming interviews
I'm being interrupted a lot, but still soldiering on :)
I've managed to do only part 1 in the morning, will try to finish second part in the evening
Part 1 was """easy""". But when the part 2 seems having 3 parts, it's a bit terrific.
It seems like every border can have at most 1 possible partner. I guess that simplifies the problem to 'find the match to this edge' from 'find all possible matches for this edge, then find the only possible solution considering all possible combinations'
Youโd better not see my code today :)))
Here they go
Please share ~ itโs fine
I need to clean it up first.
OK, got the map resolved and stitched, now to look for monsters ๐
All the images have either 2, 3 or 4 matching sides. Part 1: Corners are the ones with only 2 matching sides. Part 2: Couldn't find any tricks beside the fact there is only one possible solution. Surprised that the result came out really quickly though.
found monsters in both the demo and real input, and my dash calculation works for the demo input, but somehow is too high for the real input ๐
finally!
https://github.com/euccastro/advent-of-code-2020/blob/master/src/advent/day20.clj
runs in 91 msecs, could probably get it much lower since at some point I stopped bothering with optimizations
I'm skipping this one. It already took me too much time.
I'll do the rest of the puzzles on the holidays since I can't afford to spend this much time on workdays
Tomorrow's problem could also be short - we don't know yet.
https://github.com/peterhhchan/aoc2020/blob/main/src/aoc2020/day20.clj under 400ms. could probably speed up the solution by considering only edges and solving inwards, but thats too much work
tip: in https://github.com/peterhhchan/aoc2020/blob/main/src/aoc2020/day20.clj#L123 you don't need to (remove nil)
if you use :when
in the for bindings instead of when
in the body
could be... but puzzles get revealed at 6AM my time, and I need to catch up on sleep too ๐
my solution2
function is really monstrous, keeping with the challenge theme, but https://github.com/Saikyun/miracle.save made it relatively easy to debug. It lets you work as if the definitions in the local let
were module-level (so you can just evaluate forms inside the function).
https://github.com/vvvvalvalval/scope-capture is a more powerful alternative, but I find it harder to remember how to use it
@vincent.cantin why do you have only 4+4 card variants? are you flipping only vertically? I got 16:
(defn flip [s] (-> s reverse str/join))
(defn flip-hor [[t r b l]] [(flip t) l (flip b) r])
(defn flip-ver [[t r b l]] [b (flip r) t (flip l)])
(defn turn-lef [[t r b l]] [r b l t])
(defn turn-rig [[t r b l]] [l t r b])
(def mops
(->>
[flip-hor flip-ver turn-lef turn-rig]
(map memoize)
(apply juxt)))
(defn transformations [edges]
(->> #{edges}
(iterate (fn [variants]
(->> variants
(map mops)
(reduce into variants))))
(partition 2)
(drop-while #(apply not= %))
(ffirst)))
(def edges ["...#.#.#.#" "#..#......" ".#....####" "#.##...##."])
(->> edges transformations)
=>
#{["#.#.#.#..." "......#..#" "####....#." ".##...##.#"]
[".#....####" "#.##...##." "...#.#.#.#" "#..#......"]
["#.#.#.#..." "#.##...##." "####....#." "#..#......"]
["......#..#" "...#.#.#.#" ".##...##.#" ".#....####"]
["#.##...##." "...#.#.#.#" "#..#......" ".#....####"]
["####....#." "#..#......" "#.#.#.#..." "#.##...##."]
["####....#." ".##...##.#" "#.#.#.#..." "......#..#"]
["...#.#.#.#" ".##...##.#" ".#....####" "......#..#"]
[".#....####" "......#..#" "...#.#.#.#" ".##...##.#"]
["#..#......" ".#....####" "#.##...##." "...#.#.#.#"]
["......#..#" "####....#." ".##...##.#" "#.#.#.#..."]
["...#.#.#.#" "#..#......" ".#....####" "#.##...##."]
["#.##...##." "####....#." "#..#......" "#.#.#.#..."]
["#..#......" "#.#.#.#..." "#.##...##." "####....#."]
[".##...##.#" ".#....####" "......#..#" "...#.#.#.#"]
[".##...##.#" "#.#.#.#..." "......#..#" "####....#."]}
thatโs enough to check
First you rotate a piece (4 times), itโs not matched, you flip it and do rotation again (+ 4). Thatโs all possible combinations.
slow and long https://github.com/nbardiuk/adventofcode/blob/master/2020/src/day20.clj
Doesnโt matter how you flip it vertically or horizontally.
all possible are shown above: 16, no?
(admittedly, those are after multiple manipulations)
unless rotated and flipped to a random orientation.
means "rotated once then flipped once", and not "rotated, flipped, rotated again, flipped again.. etc"
Did a visualization of part 2
Did one also, except I solved this one with Kotlin ๐
(def tile [[1 2 3]
[3 4 5]
[6 7 9]])
(take 4 (iterate rotate tile))
([[1 2 3]
[3 4 5]
[6 7 9]]
[[6 3 1]
[7 4 2]
[9 5 3]]
[[9 7 6]
[5 4 3]
[3 2 1]]
[[3 5 9]
[2 4 7]
[1 3 6]])
(take 4 (iterate rotate (flip tile)))
([[6 7 9]
[3 4 5]
[1 2 3]]
[[1 3 6]
[2 4 7]
[3 5 9]]
[[3 2 1]
[5 4 3]
[9 7 6]]
[[9 5 3]
[7 4 2]
[6 3 1]])
You can pick up a piece of paper and see there are only 8 orientations
Even better you can pick up a real puzzle piece
I also had doubts, but then called a set
an all flips and rotations and it was just 8
my set has 16 :d:
anyway, it seems like 1 flip + 1 rotation
Wow, I think I hit the wall on this one. End of the AOC adventure for me this year ๐
@misha unlikely itโs your problem, but I also had 16 at firstโฆ I was adding back the original, unmodified grid at the end, and forgot to wrap it in []
when concatting with the list of rotation/flips, which added each individual row (rookie mistake I know)
today was really work for 2 different days. Assembling jigsaw puzzle and pattern matching are different problems. I wrote 2x code compared to the longest previous day
also, I think taking the set of rotations/flips will result in a variable number, since sometimes there is symmetry in the input. For example flipping:
[["*" " " " "]
["*" "*" "*"]
["*" " " " "]]
the top-bottom rotations will be the same.
If you have the 8 basic symmetries of a square (4x rotational, 4x reflection), then any combination of these of the operations can be simplified to any of the basic 8.
found it:
(defn flip-hor [[t r b l]] [(flip t) l (flip b) r])
(defn flip-ver [[t r b l]] [b (flip r) t (flip l)])
(defn turn-lef [[t r b l]] [r b l t])
(defn turn-rig [[t r b l]] [l t r b])
->>
(defn flip-hor [[t r b l]] [(flip t) l (flip b) r])
(defn flip-ver [[t r b l]] [b (flip r) t (flip l)])
(defn turn-lef [[t r b l]] [r (flip b) l (flip t)])
(defn turn-rig [[t r b l]] [(flip l) t (flip r) b])
:harold:With some magic numbers, hope I will refactor it later https://github.com/zelark/AoC-2020/blob/master/src/zelark/aoc_2020/day_20.clj
For me, assembling the puzzle alone was work for 2 days. once that was done, scanning for monsters felt relatively straightforward
madness dot png
here I was trying to convince myself that I could do with just flips and transposes (i.e., no need for explicit rotations). I was silly/underslept enough to clutter the drawing with arrows in both directions even though all basic ops are their own inverses
some of my breakthroughs happened during those interruptions, so I can't complain
@markw there is no symmetry in the puzzle tiles; all borders are unique, even allowing for reversals
Yeah after much banging my head against the wall I came to the same conclusion.. and now Iโm stuck
every square unique, every perimeter unique, every convolved perimeter unique.. .ugh
and 8^144 choices ๐
no core.logic solutions yet?