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
Mno 2020-12-20T00:07:45.461800Z

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.

Mno 2020-12-20T00:09:01.462Z

9/10 recommendation because of the didactic part for more people that are newer to clojure

Joe 2020-12-20T00:21:29.465500Z

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.

2020-12-20T05:02:31.467700Z

I think I will take the slow path and use insta-image, to learn a few new things.

๐Ÿ‘ 2
๐Ÿ˜ฎ 1
euccastro 2020-12-20T05:54:57.469200Z

heheh, I took a shortcut for part 1 which is useless for part 2...

โž• 1
euccastro 2020-12-20T05:55:15.469500Z

now I have all work ahead of me

2020-12-20T06:12:28.469900Z

stats so far

20      91   1620  **

๐Ÿ‘ 4
๐Ÿคฏ 2
2020-12-20T06:22:48.470300Z

I am still on part1, thatโ€™s difficult.

โž• 1
rjray 2020-12-20T06:54:58.471500Z

I've managed part 1, but also used a math shortcut and now have to start over for part 2.

โž• 3
2020-12-20T08:15:56.474500Z

Day 20 answers thread - Post your answers here

erwinrooijakkers 2020-12-21T21:23:54.043700Z

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

rjray 2020-12-22T00:34:50.043900Z

Finally got part 2 done. Damn. https://github.com/rjray/advent-2020-clojure/blob/master/src/advent_of_code/day20.clj

๐Ÿ‘ 2
fingertoe 2020-12-20T08:35:25.475500Z

Took a few days off โ€” quite a ways into part one of day 20.. Itching to use some datalog..

๐Ÿ˜ฑ 1
2020-12-20T08:37:19.476100Z

If you can do it using Datalog, I will definitely learn something new.

2020-12-20T08:49:59.476500Z

Todayโ€™s puzzle is an endurance test.

๐Ÿ‘ 2
2020-12-20T10:28:40.477600Z

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.

Mno 2020-12-20T10:31:38.477900Z

Weekends be like that

Mno 2020-12-20T10:32:23.479200Z

In my particular case I'm a bit far behind, and I'm saving a few to warm up for upcoming interviews

euccastro 2020-12-20T10:34:45.479700Z

I'm being interrupted a lot, but still soldiering on :)

2
nbardiuk 2020-12-20T11:08:59.482400Z

I've managed to do only part 1 in the morning, will try to finish second part in the evening

2020-12-20T11:40:39.485200Z

Part 1 was """easy""". But when the part 2 seems having 3 parts, it's a bit terrific.

โž• 2
Joe 2020-12-20T12:21:43.485400Z

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'

2020-12-20T13:32:37.485600Z

Youโ€™d better not see my code today :)))

๐ŸŽ‰ 2
2020-12-20T13:34:12.485900Z

Here they go

๐Ÿ˜‚ 1
๐Ÿ 3
2020-12-20T13:35:00.486200Z

Please share ~ itโ€™s fine

2020-12-20T13:36:43.486500Z

I need to clean it up first.

euccastro 2020-12-20T13:40:27.487400Z

OK, got the map resolved and stitched, now to look for monsters ๐Ÿ˜›

๐ŸŠ 1
๐Ÿ‰ 1
๐Ÿฆ• 1
๐Ÿ 1
๐Ÿ‘พ 2
peterc 2020-12-20T14:34:22.488200Z

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.

euccastro 2020-12-20T14:49:51.489200Z

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 ๐Ÿ˜•

euccastro 2020-12-20T15:11:20.489900Z

finally!

euccastro 2020-12-20T15:15:22.490300Z

runs in 91 msecs, could probably get it much lower since at some point I stopped bothering with optimizations

benoit 2020-12-20T15:18:10.492600Z

I'm skipping this one. It already took me too much time.

euccastro 2020-12-20T15:21:24.493800Z

I'll do the rest of the puzzles on the holidays since I can't afford to spend this much time on workdays

2020-12-20T15:26:29.494400Z

Tomorrow's problem could also be short - we don't know yet.

peterc 2020-12-20T16:11:55.494900Z

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

๐Ÿ‘ 4
euccastro 2020-12-20T16:23:53.495300Z

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

โœ”๏ธ 2
euccastro 2020-12-20T16:29:10.495800Z

could be... but puzzles get revealed at 6AM my time, and I need to catch up on sleep too ๐Ÿ™‚

euccastro 2020-12-20T16:33:03.496500Z

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

misha 2020-12-20T16:47:28.497900Z

@vincent.cantin why do you have only 4+4 card variants? are you flipping only vertically? I got 16:

misha 2020-12-20T16:48:50.498Z

(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)
=>
#{["#.#.#.#..." "......#..#" "####....#." ".##...##.#"]
  [".#....####" "#.##...##." "...#.#.#.#" "#..#......"]
  ["#.#.#.#..." "#.##...##." "####....#." "#..#......"]
  ["......#..#" "...#.#.#.#" ".##...##.#" ".#....####"]
  ["#.##...##." "...#.#.#.#" "#..#......" ".#....####"]
  ["####....#." "#..#......" "#.#.#.#..." "#.##...##."]
  ["####....#." ".##...##.#" "#.#.#.#..." "......#..#"]
  ["...#.#.#.#" ".##...##.#" ".#....####" "......#..#"]
  [".#....####" "......#..#" "...#.#.#.#" ".##...##.#"]
  ["#..#......" ".#....####" "#.##...##." "...#.#.#.#"]
  ["......#..#" "####....#." ".##...##.#" "#.#.#.#..."]
  ["...#.#.#.#" "#..#......" ".#....####" "#.##...##."]
  ["#.##...##." "####....#." "#..#......" "#.#.#.#..."]
  ["#..#......" "#.#.#.#..." "#.##...##." "####....#."]
  [".##...##.#" ".#....####" "......#..#" "...#.#.#.#"]
  [".##...##.#" "#.#.#.#..." "......#..#" "####....#."]}

2020-12-20T16:58:45.498400Z

thatโ€™s enough to check

2020-12-20T17:00:52.498600Z

First you rotate a piece (4 times), itโ€™s not matched, you flip it and do rotation again (+ 4). Thatโ€™s all possible combinations.

nbardiuk 2020-12-20T17:01:36.498900Z

slow and long https://github.com/nbardiuk/adventofcode/blob/master/2020/src/day20.clj

๐Ÿ‘ 2
2020-12-20T17:02:12.499500Z

Doesnโ€™t matter how you flip it vertically or horizontally.

misha 2020-12-20T17:32:10.000100Z

all possible are shown above: 16, no?

misha 2020-12-20T17:32:53.000300Z

(admittedly, those are after multiple manipulations)

misha 2020-12-20T17:34:30.000500Z

unless rotated and flipped to a random orientation. means "rotated once then flipped once", and not "rotated, flipped, rotated again, flipped again.. etc"

2020-12-20T17:45:19.001600Z

Did a visualization of part 2

๐ŸŽจ 9
โค๏ธ 1
๐Ÿฆ• 1
Alexandre Grison 2020-12-21T10:28:53.025300Z

Did one also, except I solved this one with Kotlin ๐Ÿ˜„

๐Ÿ˜ 1
2020-12-20T17:51:46.001900Z

(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]])

peterc 2020-12-20T17:52:13.002100Z

You can pick up a piece of paper and see there are only 8 orientations

๐Ÿ‘ 1
2020-12-20T17:53:13.002600Z

Even better you can pick up a real puzzle piece

nbardiuk 2020-12-20T18:02:18.003Z

I also had doubts, but then called a set an all flips and rotations and it was just 8

misha 2020-12-20T18:21:11.003300Z

my set has 16 :d:

misha 2020-12-20T18:21:36.003500Z

anyway, it seems like 1 flip + 1 rotation

Joe 2020-12-20T18:32:19.004900Z

Wow, I think I hit the wall on this one. End of the AOC adventure for me this year ๐Ÿ˜ž

2
โค๏ธ 5
๐Ÿ™Œ 1
markw 2020-12-20T18:38:46.005Z

@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)

nbardiuk 2020-12-20T18:41:21.006500Z

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

markw 2020-12-20T18:55:51.007300Z

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.

Joe 2020-12-20T18:56:41.007500Z

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.

misha 2020-12-20T19:02:22.007900Z

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:

๐Ÿ’ฅ 1
๐Ÿพ 1
2020-12-20T19:32:30.009Z

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

๐Ÿ‘ 2
euccastro 2020-12-20T22:23:51.009700Z

For me, assembling the puzzle alone was work for 2 days. once that was done, scanning for monsters felt relatively straightforward

euccastro 2020-12-20T22:28:05.010200Z

2
euccastro 2020-12-20T22:29:03.010600Z

madness dot png

euccastro 2020-12-20T22:33:04.010800Z

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

euccastro 2020-12-20T22:37:06.011300Z

some of my breakthroughs happened during those interruptions, so I can't complain

euccastro 2020-12-20T22:41:39.011500Z

@markw there is no symmetry in the puzzle tiles; all borders are unique, even allowing for reversals

markw 2020-12-20T22:42:32.011700Z

Yeah after much banging my head against the wall I came to the same conclusion.. and now Iโ€™m stuck

markw 2020-12-20T22:42:49.011900Z

every square unique, every perimeter unique, every convolved perimeter unique.. .ugh

markw 2020-12-20T22:43:12.012100Z

and 8^144 choices ๐Ÿ˜•

misha 2020-12-20T23:19:49.012500Z

no core.logic solutions yet?