Fork me on GitHub
#adventofcode
<
2023-12-13
>
genmeblog09:12:57

Day 13 - Solutions 🪞

borkdude10:12:10

I have @U1EP3BZ3Q’s solution working https://squint-cljs.github.io/cherry/?boilerplate=https%3A%2F%2Fgist.githubusercontent.com%2Fborkdude%2Fcf94b492d948f7f418aa81ba54f428ff%2Fraw%2Fa6e9992b079e20e21d753e8c75a7353c5908b225%2Faoc_ui.cljs&repl=true&src=OzsgSGVscGVyIGZ1bmN0aW9uczoKOzsgKGZldGNoLWlucHV0IHllYXIgZGF5KSAtIGdldCBBT0MgaW5wdXQKOzsgKGFwcGVuZCBzdHIpIC0gYXBwZW5kIHN0ciB0byBET00KOzsgKHNweSB4KSAtIGxvZyB4IHRvIGNvbnNvbGUgYW5kIHJldHVybiB4Cgo7OyBSZW1lbWJlciB0byB1cGRhdGUgdGhlIHllYXIgYW5kIGRheSBpbiB0aGUgZmV0Y2gtaW5wdXQgY2FsbC4KKGRlZiBpbnB1dCAoLT4%2BIChqcy1hd2FpdCAoZmV0Y2gtaW5wdXQgMjAyMyAxMykpCiAgICAgICAgICAgICBzdHIvc3BsaXQtbGluZXMpKQoKKGRlZiBkYXRhICh2ZWMgKC0%2BPiAocGFydGl0aW9uLWJ5ICMobm90PSAiIiAlKSBpbnB1dCkKICAgICAgICAgICAgICAgICAocmVtb3ZlICMoPSAiIiAoZmlyc3QgJSkpKSkpKQoKKGRlZm4gZXF1YWw%2FIFtbYSBiXV0gKD0gYSBiKSkKKGRlZm4gbWlycm9yZWQ%2FIFtwYWlyXSAoZXZlcnk%2FIGVxdWFsPyBwYWlyKSkKKGRlZm4gb3JwYWlyIFtbYSBiXV0gKG9yIGEgYikpCihkZWZuIHJldmVyc2UtYSBbW2EgYl1dIChtYXAgdmVjdG9yIChyZXZlcnNlIGEpIGIpKQoKKGRlZm4gZGlmZi1zdW0gW1thIGJdXQogICgtPj4gKG1hcCAoZm4gW2MxIGMyXSAoaWYgKD0gYzEgYzIpIDAgMSkpIGEgYikKICAgIChyZWR1Y2UgKykpKQoKKGRlZm4gbWlycm9yZWQtYnV0LW9uZT8gW3BhaXJdCiAgKGxldCBbYyAobWFwIChqdXh0IGVxdWFsPyBkaWZmLXN1bSkgcGFpcildCiAgICAoYW5kIChldmVyeT8gb3JwYWlyIGMpCiAgICAgICg9IDEgKHJlZHVjZSArIChtYXAgc2Vjb25kIGMpKSkpKSkKCihkZWZuIGlkLW9mIFtibG9jayBtPyByb3dzIGlkXQogICh3aGVuICgtPj4gYmxvY2sgKHNwbGl0LWF0IGlkKSByZXZlcnNlLWEgbT8pCiAgICAoKiByb3dzIGlkKSkpCgooZGVmbiBmaW5kLWlkIFtibG9jayBtPyByb3dzXQogICgtPj4gKGNvdW50IGJsb2NrKQogICAgKHJhbmdlIDEpCiAgICAoc29tZSAocGFydGlhbCBpZC1vZiBibG9jayBtPyByb3dzKSkpKQoKKGRlZm4gZmluZC1pZC1hbGwgW20%2FIGJsb2NrXQogIChvciAoZmluZC1pZCBibG9jayBtPyAxMDApCiAgICAoZmluZC1pZCAoYXBwbHkgbWFwIHZlY3RvciBibG9jaykgbT8gMSkpKQoKKGRlZm4gc29sdXRpb24gW2RhdGEgbT9dCiAgKC0%2BPiAobWFwIChwYXJ0aWFsIGZpbmQtaWQtYWxsIG0%2FKSBkYXRhKQogICAgKHJlZHVjZSArKSkpCgooY29tbWVudAogIDs7IHBhcnQgMQogIChzb2x1dGlvbiBkYXRhIG1pcnJvcmVkPykKICA7OyA9PiAzMTg3NwogIDs7IHBhcnQgMgogIChzb2x1dGlvbiBkYXRhIG1pcnJvcmVkLWJ1dC1vbmU%2FKQogICk%3D - now squint...

borkdude10:12:04

here's the https://squint-cljs.github.io/squint/?boilerplate=https%3A%2F%2Fgist.githubusercontent.com%2Fborkdude%2Fcf94b492d948f7f418aa81ba54f428ff%2Fraw%2Fa6e9992b079e20e21d753e8c75a7353c5908b225%2Faoc_ui.cljs&amp;repl=true&amp;src=OzsgSGVscGVyIGZ1bmN0aW9uczoKOzsgKGZ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gKC0%2BPiBibG9jayAoc3BsaXQtYXQgaWQpIHJldmVyc2UtYSBtPykKICAgICgqIHJvd3MgaWQpKSkKCihkZWZuIGZpbmQtaWQgW2Jsb2NrIG0%2FIHJvd3NdCiAgKC0%2BPiAoY291bnQgYmxvY2spCiAgICAocmFuZ2UgMSkKICAgIChzb21lIChwYXJ0aWFsIGlkLW9mIGJsb2NrIG0%2FIHJvd3MpKSkpCgooZGVmbiBmaW5kLWlkLWFsbCBbbT8gYmxvY2tdCiAgKG9yIChmaW5kLWlkIGJsb2NrIG0%2FIDEwMCkKICAgIChmaW5kLWlkIChhcHBseSBtYXAgKGNvbXAgc3RyL2pvaW4gdmVjdG9yKSBibG9jaykgbT8gMSkpKQoKKGRlZm4gc29sdXRpb24gW2RhdGEgbT9dCiAgKC0%2BPiAobWFwIChwYXJ0aWFsIGZpbmQtaWQtYWxsIG0%2FKSBkYXRhKQogICAgKHJlZHVjZSArKSkpCgooY29tbWVudAogIDs7IHBhcnQgMQogIChzb2x1dGlvbiBkYXRhIG1pcnJvcmVkPykKICA7OyA9PiAzMTg3NwogIDs7IHBhcnQgMgogIChzb2x1dGlvbiBkYXRhIG1pcnJvcmVkLWJ1dC1vbmU%2FKQogICk%3D - I needed to add a str/join in there since you can't straightly compare arrays with characters in JS :)

borkdude10:12:28

(defn find-id-all [m? block]
  (or (find-id block m? 100)
    (find-id (apply map (comp str/join vector) block) m? 1)))

genmeblog10:12:09

Btw, windows key + enter doesn't work for me on Edge.

borkdude10:12:30

can you try:

localStorage.setItem("editor.modifier", "Ctrl")
in the console and then refresh?

borkdude10:12:58

I should probably switch to Ctrl for the modifier key since Windows/Cmd gives problems on other OSes than mac

genmeblog10:12:24

Still the same...

borkdude10:12:09

Also after refresh? Damn, I should check at home in Windows

genmeblog10:12:46

yes, after refresh, prv

genmeblog10:12:38

wait! works on squint but not on cherry

borkdude10:12:07

Ah yes makes sense

borkdude10:12:38

I haven’t made this tweak in cherry but I’ll just change the default key on non-Mac

👍 1
erdos13:12:30

https://github.com/erdos/advent-of-code/blob/master/2023/day13.clj I could not yet figure out how to do without loop-recur.

👍 2
1
alekszelark17:12:58

@U2E1D7WUB impressed by your solution, so neat and nice!

rjray20:12:16

I'm stuck on part 2... my answer keeps coming up low.

rjray21:12:04

I'm def overthinking it... looking at other solutions, I'm using 3x (or more) code.

Ivana22:12:05

My solution, after some fixes, finally i may share without my shame

(defn errs [a b] (apply + (map #(if (= %1 %2) 0 1) a b)))

(defn refl [c es]
  (->> (range 1 (count c))
       (keep (fn [i] (let [[a b] (split-at i c)]
                       (when (= es (apply + (map errs (reverse a) b))) i))))
       first))

(defn transpose [m] (apply mapv vector m))

(defn task [s es]
  (let [m (str/split-lines s)]
    (or (some-> (refl m es) (* 100)) (refl (transpose m) es))))

(->> (str/split input #"\n\n")
     (map #(-> [(task % 0) (task % 1)]))
     (reduce (partial mapv +) [0 0]))

wevrem02:12:04

My https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2023/day_13_mirrors.clj. It’s rather bulky. I read the part 1 quickly before going off to a day of meetings and while thinking about it during the day I made a guess what part 2 would be. I was completely wrong. I tried to keep all the info as I went along, none of which I needed, it turned out, for part 2. Oh well. A few tweaks to my logic and both parts run with same code. @U2E1D7WUB I like your stack trick for finding the mirror pair.

bhauman05:12:28

My basic trick was

(let [[a b] (split-at n rows)]  (every? identity (map = (reverse a) b)))

1
👍 1
💡 1
Felix Dorner11:12:51

Here’s one from a clojure noob, 100% not clever, I feel lots of attention goes to figuring out the clojure stuff instead of thinking about the actual problem 😞 https://github.com/felixdo/aoc23/blob/main/src/aoc23/day13.clj

genmeblog10:12:41

Questions to all: • Maybe we should remove an url to the github from the channel topic? It's been dead for 3 years now • What do you think about new leaderboard just for this year (and maybe new every year)? Current one is almost full with more than half people are inactive.

👍 4
1
wevrem14:12:27

What does “almost full” mean? Is there a limit to the number of members in a channel?

elken14:12:51

Private leaderboards are limited to 200 yeah

elken14:12:58

(don't care about the ID I just made/wiped it)

pez14:12:53

Did you irrevocably obliterate it?

elken14:12:09

It is forever lost to the annals of time

Ivana17:12:28

Day 13 - can't understand the task description clearly I want to solve all the AOC by myself without reading suggestions, but can't clearly understand the task & examples. What means "perfect reflection" - should we check palindrome ONLY with (inc (quot cnt 2)) center (rows or cols) and may drop only line/col #1 (all the examples from description shows this case!) or we have to find all the palindromes? What to do if patters has more than 1 reflection - first example in description has also reflection between rows 3 and 4 (two pairs of rows) - what to do in this case? What to do if pattern has no reflections at all, even with 2 rows/columns?

genmeblog19:12:28

There should be such reflection which covers one side fully. Let c_n is a column. [c1 c2 c3 c3 c2 c1 c0] has a reflection, Full left side is reflected on the right side. Right side contains additional column which can be ignored in reflection.

genmeblog19:12:54

[c1 c2 c3 c3 c2 c0] has no reflection.

genmeblog19:12:41

There is no reflection in rows in the first example. Because of that (one side is not fully reflected in the other)

1
Ivana21:12:46

Ok, thanks, got it!