Fork me on GitHub
#adventofcode
<
2023-12-03
>
norman06:12:07

Day 03 - Solutions

russmatney06:12:01

crazy one! definitely feel like they're starting harder this year, tho i believe they try to assign harder problems on weekends vs weekdays https://github.com/russmatney/advent-of-code/blob/master/src/_2023/_03/core.clj

👍 1
1
wevrem06:12:50

I might still do some tweaking to this, I sort of “over-built” my data maps and can probably streamline them a little bit. https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2023/day_03.clj

👍 1
1
wevrem07:12:31

I added some commentary to my two hairiest functions.

borkdude10:12:18

Already feel tired of seeing an "adjacent coordinate" puzzle in AoC again, so I'm just going to steal some of your solutions to test-drive squint :)

😁 2
Jan Tore Stolsvik10:12:20

I stored the gear coordinates by concatenating x and y coordinates. Ofc there was an overlapping index then, so had to add a “-” in between

Piotr Kaznowski11:12:16

Apparently the grid is created with some assumptions that made the logic simpler, so was able to solve both parts with same algo basically: https://github.com/caseneuve/aoc2023/blob/master/day03/solution.clj

1
alekszelark11:12:18

Hi all! I am a bit bored by parsing this year. Didn’t want initially post my solutions, but here we go. Maybe it’ll help someone https://github.com/zelark/AoC/blob/master/src/zelark/aoc_2023/day_03.clj

Alex Alemi11:12:12

Wrote a recursive parser that handled conjoining the nums from the start, so both parts were just fancy transductions: https://github.com/alexalemi/advent/blob/main/2023/clojure/p03.clj doesn't feel the cleanest.

borkdude12:12:30

@UGNFWPPGF https://squint-cljs.github.io/cherry/?boilerplate=https%3A%2F%2Fgist.githubusercontent.com%2Fborkdude%2Fcf94b492d948f7f418aa81ba54f428ff%2Fraw%2F3e871513ab6f2462841f75fc99668f841f33dabb%2Faoc_ui.cljs&amp;repl=true&amp;src=OzsgSGVscGVyIGZ1bmN0aW9uczoKOzsgKGZldGNoLWlucHV0IHllYXIgZGF5KSAtIGdldCBBT0MgaW5wdXQKOzsgKGFwcGVuZCBzdHIpIC0gYXBwZW5kIHN0ciB0byBET00KOzsgKHNweSB4KSAtIGxvZyB4IHRvIGNvbnNvbGUgYW5kIHJldHVybiB4CgooZGVmIGlucHV0ICgtPj4gKGpzLWF3YWl0IChmZXRjaC1pbnB1dCAyMDIzIDMpKQogICAgICAgICAgICAgc3RyL3NwbGl0LWxpbmVzKSkKCihkZWZuIGRpZ2l0PyBbeF0KICAoI3tcMSBcMiBcMyBcNCBcNSBcNiBcNyBcOCBcOSBcMH0geCkpCgooZGVmbiAtPmdyaWQKICAoW3Jhd10gKC0%2BZ3JpZCBuaWwgcmF3KSkKICAoW3ByZWQgcmF3XQogICAoLT4%2BIHJhdwogICAgICAgIChtYXAtaW5kZXhlZAogICAgICAgICAgKGZuIFt5IHJvd10KICAgICAgICAgICAgKC0%2BPiByb3cgKG1hcC1pbmRleGVkCiAgICAgICAgICAgICAgICAgICAgICAgKGZuIFt4IGNoYXJdCiAgICAgICAgICAgICAgICAgICAgICAgICAoaWYgcHJlZAogICAgICAgICAgICAgICAgICAgICAgICAgICAod2hlbiAocHJlZCBjaGFyKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgIFtbeCB5XSBjaGFyXSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgW1t4IHldIGNoYXJdKSkpCiAgICAgICAgICAgICAgICAgKGZpbHRlciBzZXEpCiAgICAgICAgICAgICAgICAgKGludG8gW10pKSkpCiAgICAgICAgKGZpbHRlciBzZXEpCiAgICAgICAgKGludG8gW10pCiAgICAgICAgKGFwcGx5IGNvbmNhdCkKICAgICAgICAoaW50byB7fSkpKSkKCihkZWZuIHBhcnQ%2FIFtjaGFyXQogIChub3QgKG9yICg9IFwuIGNoYXIpIChkaWdpdD8gY2hhcikpKSkKCihkZWZuIC0%2BcGFydC1sb2NzIFtyYXddCiAgKC0%2BZ3JpZCBwYXJ0PyByYXcpKQoKKGNvbW1lbnQKICAoLT5wYXJ0LWxvY3MgaW5wdXQpCiAgKC0%2BZ3JpZCBpbnB1dCkKCiAgKC0%2BPiAiNDUuLiouNCIgKG1hcCAoZm4gW2NoYXJdIChkaWdpdD8gY2hhcikpKSkpCgooZGVmbiBuZWlnaGJvcnMgW1t4IHldXQogICN7W3ggKGluYyB5KV0KICAgIFt4IChkZWMgeSldCiAgICBbKGluYyB4KSB5XQogICAgWyhkZWMgeCkgeV0KICAgIFsoaW5jIHgpIChpbmMgeSldCiAgICBbKGRlYyB4KSAoZGVjIHkpXQogICAgWyhkZWMgeCkgKGluYyB5KV0KICAgIFsoaW5jIHgpIChkZWMgeSldfSkKCihkZWZuIHgtbnVtLW5laWdoYm9ycyBbZ3JpZCBbeCB5XV0KICAobGV0IFstPngtbmJycwogICAgICAgIChmbiBbLT54XQogICAgICAgICAgKGxvb3AgW25ldy1jb29yZCBbKC0%2BeCB4KSB5XSBuYnJzIFtdXQogICAgICAgICAgICAoY29uZAogICAgICAgICAgICAgIChuaWw%2FIChncmlkIG5ldy1jb29yZCkpIG5icnMKICAgICAgICAgICAgICAoZGlnaXQ%2FIChncmlkIG5ldy1jb29yZCkpCiAgICAgICAgICAgICAgKHJlY3VyIFsoLT4gKGZpcnN0IG5ldy1jb29yZCkgLT54KSB5XSAoY29uY2F0IG5icnMgW25ldy1jb29yZF0pKQogICAgICAgICAgICAgIDplbHNlICAgICAgICAgICAgICAgICAgIG5icnMpKSkKICAgICAgICBsZWZ0LW5icnMgICgtPngtbmJycyBkZWMpCiAgICAgICAgcmlnaHQtbmJycyAoLT54LW5icnMgaW5jKV0KICAgIChjb25jYXQgKHJldmVyc2UgbGVmdC1uYnJzKSBbW3ggeV1dIHJpZ2h0LW5icnMpKSkKCihjb21tZW50CiAgKHgtbnVtLW5laWdoYm9ycyAoLT5ncmlkIGlucHV0KSBbMyAyXSkKICAoeC1udW0tbmVpZ2hib3JzICgtPmdyaWQgaW5wdXQpIFsyIDJdKQogICh4LW51bS1uZWlnaGJvcnMgKC0%2BZ3JpZCBpbnB1dCkgWzAgMF0pCiAgKQoKKGRlZm4gY29vcmQtPm51bWJlciBbZ3JpZCBjb29yZF0KICAobGV0IFtudW0tY29vcmRzICh4LW51bS1uZWlnaGJvcnMgZ3JpZCBjb29yZCldCiAgICBbKGZpcnN0IG51bS1jb29yZHMpCiAgICAgKC0%2BPiBudW0tY29vcmRzCiAgICAgICAgICAobWFwIGdyaWQpCiAgICAgICAgICAoYXBwbHkgc3RyKQogICAgICAgICAgKHBhcnNlLWxvbmcpKV0pKQoKKGNvbW1lbnQKICAoY29vcmQtPm51bWJlciAoLT5ncmlkIGlucHV0KSBbMiAyXSkKICAoY29vcmQtPm51bWJlciAoLT5ncmlkIGlucHV0KSBbMCAwXSkKICApCgoKKGRlZm4gcGFydC1udW1iZXJzCiAgKFtyYXddIChwYXJ0LW51bWJlcnMgbmlsIHJhdykpCiAgKFtvcHRzIHJhd10KICAgKGxldCBbZ3JpZCAgICAgICgtPmdyaWQgcmF3KQogICAgICAgICBwYXJ0LWxvY3MgKC0%2BcGFydC1sb2NzIHJhdyldCiAgICAgOzsgc3ltYm9scy0%2BbmVpZ2hib3ItZGlnaXRzCiAgICAgKGNvbmQtPj4gcGFydC1sb2NzCiAgICAgICB0cnVlCiAgICAgICAobWFwIChmbiBbW2Nvb3JkIHN5bV1dCiAgICAgICAgICAgICAgW3N5bQogICAgICAgICAgICAgICAobGV0IFtuYnJzIChuZWlnaGJvcnMgY29vcmQpXQogICAgICAgICAgICAgICAgICgtPj4gbmJycwogICAgICAgICAgICAgICAgICAgICAgKGZpbHRlciAoZm4gW25icl0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAobGV0IFtjaGFyIChncmlkIG5icildCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoZGlnaXQ%2FIGNoYXIpKSkpCiAgICAgICAgICAgICAgICAgICAgICAobWFwIChmbiBbbmJyXSBbbmJyIChncmlkIG5icildKSkpKV0pKQoKICAgICAgICg6c3ltYm9sIG9wdHMpIChmaWx0ZXIgKGZuIFtbc3ltIF9uYnJzXV0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoI3soOnN5bWJvbCBvcHRzKX0gc3ltKSkpCgogICAgICAgdHJ1ZQogICAgICAgKG1hcCAoZm4gW1tfc3ltIG5icnNdXQogICAgICAgICAgICAgICgtPj4gbmJycwogICAgICAgICAgICAgICAgICAgKG1hcCAoZm4gW1tjb29yZCBfZGlnaXRdXQogICAgICAgICAgICAgICAgICAgICAgICAgIChjb29yZC0%2BbnVtYmVyIGdyaWQgY29vcmQpKSkKICAgICAgICAgICAgICAgICAgIChpbnRvIHt9KSkpKQoKICAgICAgICg6cGFydC1jb3VudCBvcHRzKQogICAgICAgKGZpbHRlciAoZm4gW3hzXQogICAgICAgICAgICAgICAgICg9ICg6cGFydC1jb3VudCBvcHRzKSAoY291bnQgeHMpKSkpKSkpKQoKKGNvbW1lbnQKICA7OyBwYXJ0IDEKICAoLT4%2BCiAgICAocGFydC1udW1iZXJzIGlucHV0KQogICAgKG1hcCB2YWxzKQogICAgKGFwcGx5IGNvbmNhdCkKICAgIChyZWR1Y2UgKykpCgogIDs7IHBhcnQgMgogICgtPj4KICAgIGlucHV0CiAgICAocGFydC1udW1iZXJzCiAgICAgIHs6c3ltYm9sICAgICBcKgogICAgICAgOnBhcnQtY291bnQgMn0pCiAgICAobWFwIHZhbHMpCiAgICAobWFwICMoYXBwbHkgKiAlKSkKICAgIChyZWR1Y2UgKykpICAKICAp

Arnaud Geiser13:12:16

Code much more complicated than it should be, but everything passed on the first try (rather rare on my side!) : https://github.com/arnaudgeiser/advent-of-code/blob/master/2023/clojure/src/advent_of_code/day3.clj

genmeblog13:12:15

Always happy to use (almost) the same code and processed data for both parts. https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2023/day03.clj

alpox10:12:06

Not sure if I used the best datastructure but it worked out quite well

pez10:12:21

I struggled a bit with scanning the input. Seeing where I went overboard when looking at your solution, @U6JS7B99S

alpox10:12:31

@U0ETXRFEW I struggled too. I rewrote the parsing multiple times 😄

imre17:12:15

A bit late to the party but I'm pretty happy with how this turned out. Calculation done in a single pass transduction, and it's my first time using iteration too. https://github.com/imrekoszo/advent-of-clj/blob/master/src/imrekoszo/advent/y23/day3.clj

mynomoto20:12:24

https://squint-cljs.github.io/squint/?boilerplate=https%3A%2F%2Fgist.githubusercontent.com%2Fborkdude%2Fcf94b492d948f7f418aa81ba54f428ff%2Fraw%2F3e871513ab6f2462841f75fc99668f841f33dabb%2Faoc_ui.cljs&amp;repl=true&amp;src=OzsgSGVscGVyIGZ1bmN0aW9uczoKOzsgKGZldGNoLWlucHV0IHllYXIgZGF5KSAtIGdldCBBT0MgaW5wdXQKOzsgKGFwcGVuZCBzdHIpIC0gYXBwZW5kIHN0ciB0byBET00KOzsgKHNweSB4KSAtIGxvZyB4IHRvIGNvbnNvbGUgYW5kIHJldHVybiB4CgooZGVmIGlucHV0ICgtPj4gKGpzLWF3YWl0IChmZXRjaC1pbnB1dCAyMDIzIDMpKSkpCgooZGVmIHNhbXBsZSAoc3RyL3RyaW0gIgo0NjcuLjExNC4uCi4uLiouLi4uLi4KLi4zNS4uNjMzLgogICAgICAgICAgICAgIAouLi4uLi4jLi4uCjYxNyouLi4uLi4KLi4uLi4rLjU4LgouLjU5Mi4uLi4uCi4uLi4uLjc1NS4KLi4uJC4qLi4uLgouNjY0LjU5OC4uIikpCgooZGVmbiBpcy1zeW1ib2w%2FCiAgW3NdCiAgKG5vdCAoY29udGFpbnM%2FICN7IjAiICIxIiAiMiIgIjMiICI0IiAiNSIgIjYiICI3IiAiOCIgIjkiICIuIn0gcykpKQoKKGRlZm4gbmVpZ2hib3VycwogIFtbeCB5XV0KICBbCiAgIFsoZGVjIHgpIChkZWMgeSldCiAgIFsoZGVjIHgpIHldCiAgIFsoZGVjIHgpIChpbmMgeSldCiAgIFt4IChkZWMgeSldCiAgIFt4IChpbmMgeSldCiAgIFsoaW5jIHgpIChkZWMgeSldCiAgIFsoaW5jIHgpIHldCiAgIFsoaW5jIHgpIChpbmMgeSldCiAgIF0pCgooZGVmbiBpcy1wYXJ0LW51bWJlcj8KICBbc3ltYm9scyBbdmFsdWUgY29vcmRzXV0KICAod2hlbiAoc29tZSAjKGdldCBzeW1ib2xzICUpCiAgICAgICAgICAobWFwY2F0IG5laWdoYm91cnMgY29vcmRzKQogICAgICAgICAgc2V0KQogICAgdmFsdWUpKQoKKGRlZm4gcGFydC0xCiAgW2ldCiAgKGxldCBbc3ltYm9scyAoLT4%2BIGkKICAgICAgICAgICAgICAgICAgKHN0ci9zcGxpdC1saW5lcykKICAgICAgICAgICAgICAgICAgKG1hcC1pbmRleGVkIChmbiBbaWR4IGxpbmVdCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChtYXAtaW5kZXhlZCAoZm4gW2MtaWR4IGNdCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICh3aGVuIChpcy1zeW1ib2w%2FIGMpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgW2lkeCBjLWlkeF0pKSBsaW5lKSkpCiAgICAgICAgICAgICAgICAgIChhcHBseSBjb25jYXQpCiAgICAgICAgICAgICAgICAgIChyZW1vdmUgbmlsPykKICAgICAgICAgICAgICAgICAgKHJlZHVjZSAoZm4gW2FjYyBpXSAoYXNzb2MgYWNjIGkgaSkpIHt9KSkKICAgICAgICBudW1iZXJzICgtPj4gaQogICAgICAgICAgICAgICAgICAoc3RyL3NwbGl0LWxpbmVzKQogICAgICAgICAgICAgICAgICAobWFwLWluZGV4ZWQgKGZuIFtsLWlkeCBsaW5lXQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAobGV0IFtyZSAoanMvUmVnRXhwLiAoLi1zb3VyY2UgIyJcZCsiKSAiZyIpXQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChsb29wIFtyZXN1bHQgW11dCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoaWYtc29tZSBbbSAoLmV4ZWMgcmUgbGluZSldCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChyZWN1ciAoY29uaiByZXN1bHQgWyhmaXJzdCBtKSAodmVjIChmb3IgW2MtaWR4IChyYW5nZSAoLi1pbmRleCBtKSAoKyAoLi1pbmRleCBtKSAoY291bnQgKGZpcnN0IG0pKSkpXQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFtsLWlkeCBjLWlkeF0pKV0pKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQpKSkpKQogICAgICAgICAgICAgICAgICAoYXBwbHkgY29uY2F0KSldCiAgICAoLT4%2BIChmaWx0ZXIgIyhpcy1wYXJ0LW51bWJlcj8gc3ltYm9scyAlKSBudW1iZXJzKQogICAgICAobWFwdiBmaXJzdCkKICAgICAgKG1hcHYgcGFyc2UtbG9uZykKICAgICAgKGFwcGx5ICspKSkpCgooZGVmbiBnZWFyLWNhbmRpZGF0ZT8KICBbc10KICAoPSAiKiIgcykpCgooZGVmbiBpcy1nZWFyPwogIFtbXyBnZWFyLWNhbmRpZGF0ZV0gbnVtYmVyc10KICAobGV0IFtuIChuZWlnaGJvdXJzIGdlYXItY2FuZGlkYXRlKQogICAgICAgIG5tYXAgKHJlZHVjZSAoZm4gW2FjYyBpXSAoYXNzb2MgYWNjIGkgaSkpIHt9IG4pCiAgICAgICAgZ2Vhci1jYW5kaWRhdGUtbmVpZ2hib3VycyAoZmlsdGVydiAoZm4gW1tuIGNvb3Jkc11dCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChzb21lICMoZ2V0IG5tYXAgJSkgY29vcmRzKSkgbnVtYmVycyldCiAgICAod2hlbiAoPSAyCiAgICAgICAgICAgIChjb3VudCBnZWFyLWNhbmRpZGF0ZS1uZWlnaGJvdXJzKSkKICAgICAgZ2Vhci1jYW5kaWRhdGUtbmVpZ2hib3VycykpKQoKKGRlZm4gcGFydC0yCiAgW2ldCiAgKGxldCBbZ2Vhci1jYW5kaWRhdGVzICgtPj4gaQogICAgICAgICAgICAgICAgICAgICAgICAgIChzdHIvc3BsaXQtbGluZXMpCiAgICAgICAgICAgICAgICAgICAgICAgICAgKG1hcC1pbmRleGVkIChmbiBbaWR4IGxpbmVdCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKG1hcC1pbmRleGVkIChmbiBbYy1pZHggY10KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAod2hlbiAoZ2Vhci1jYW5kaWRhdGU%2FIGMpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBbaWR4IGMtaWR4XSkpIGxpbmUpKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAoYXBwbHkgY29uY2F0KQogICAgICAgICAgICAgICAgICAgICAgICAgIChyZW1vdmUgbmlsPykKICAgICAgICAgICAgICAgICAgICAgICAgICAocmVkdWNlIChmbiBbYWNjIGldIChhc3NvYyBhY2MgaSBpKSkge30pKQogICAgICAgIG51bWJlcnMgKC0%2BPiBpCiAgICAgICAgICAgICAgICAgIChzdHIvc3BsaXQtbGluZXMpCiAgICAgICAgICAgICAgICAgIChtYXAtaW5kZXhlZCAoZm4gW2wtaWR4IGxpbmVdCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChsZXQgW3JlIChqcy9SZWdFeHAuICguLXNvdXJjZSAjIlxkKyIpICJnIildCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGxvb3AgW3Jlc3VsdCBbXV0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChpZi1zb21lIFttICguZXhlYyByZSBsaW5lKV0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKHJlY3VyIChjb25qIHJlc3VsdCBbKGZpcnN0IG0pICh2ZWMgKGZvciBbYy1pZHggKHJhbmdlICguLWluZGV4IG0pICgrICguLWluZGV4IG0pIChjb3VudCAoZmlyc3QgbSkpKSldCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgW2wtaWR4IGMtaWR4XSkpXSkpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCkpKSkpCiAgICAgICAgICAgICAgICAgIChhcHBseSBjb25jYXQpKV0KICAgICgtPj4gZ2Vhci1jYW5kaWRhdGVzCiAgICAgIChtYXAgIyhpcy1nZWFyPyAlIG51bWJlcnMpKQogICAgICAocmVtb3ZlIG5pbD8pCiAgICAgIChtYXAgKGZuIFtbW24xIF9dIFtuMiBfXV1dCiAgICAgICAgICAgICAoKiAocGFyc2UtbG9uZyBuMSkgKHBhcnNlLWxvbmcgbjIpKSkpICAgICAKICAgICAgKGFwcGx5ICspKSkpCgoKKGFwcGVuZCAocGFydC0xIGlucHV0KSkgCihhcHBlbmQgKHBhcnQtMiBpbnB1dCkp

mynomoto21:12:02

I learned how to use flags on regexes in clojurescript, it was ok after that and @U04V15CAJ’s tips related to javascript object keys.

Ben Sless09:12:31

How can I solve this using regex :thinking_face:

metal 1
pez10:12:59

@UK0810AQ2 I think re-matcher might be of help for that.

Ben Sless10:12:19

I can stagger the lines then do something like

(let [m (re-matcher #"((...)?(.\d.)+(...)?)"
                    (str/join (map str/join (map vector
                                                 "..2......."
                                                 "467..114.."
                                                 "...*......"))))]
  [(re-find m)
   (re-find m)
   (re-find m)])
then in each group look for one containing a symbol which marks it as a part, and extract the numbers from every 3rd index starting from the second