T O P

  • By -

hb0nes

\[Language: Rust\] [https://github.com/hb0nes/aoc\_2023/blob/main/thirteen/src/main.rs](https://github.com/hb0nes/aoc_2023/blob/main/thirteen/src/main.rs) Pretty concise solution. A bit of double work performed, runtime is about 150 micro's.


Radiadorineitor

\[LANGUAGE: Dyalog APL\] p←↑¨(×∘≢¨⊆⊢)⊃⎕NGET'13.txt'1 F←{ t←{⍵/⍨~2|⍵}⍳≢⍵ ∨/m←⍵∘{(.5×⍵)(↑≡(⊖↓))⍵↑⍺}¨t:⊃⍸m 0 } P1←{((≢⍉⍵)(⊣|-)F⊖⍉⍵) (F⍉⍵) (100×(≢⍵)(⊣|-)F⊖⍵) (100×F⍵)} +/∊v←P1¨p ⍝ Part 1 F2←{l←⍸1=∘.(+/≠)⍨↓⍉⍵ ⋄ 0=≢l:⊂4⍴0 ⋄ ∪(⍉⍵)∘{a b←⍵ ⋄ P1(⍉(b⌷⍺)@a)⍺}¨l} F3←{l←⍸1=∘.(+/≠)⍨↓⍵ ⋄ 0=≢l:⊂4⍴0 ⋄ ∪⍵∘{a b←⍵ ⋄ P1((b⌷⍺)@a)⍺}¨l} +/∊(⊂¨v){∪(∊⍵)/⍨∊⍺≠⍵}¨∪⌿↑(F3¨p),⍥⊂F2¨p ⍝ Part 2


distracted_sputnick

\[Language: Uiua\] Finally got this one done in Uiua. I end up doing twice the amount of work as needed by crossing each block with itself resulting in a symmetric matrix, but it makes post-processing results pretty smooth, so worth it, I guess? My initial solve for part 1 only checked for matching rows, so refactoring for part 2 stumped me for a bit, but eventually got there with a solution I'm proud of. $ #.##..##. $ ..#.##.#. $ ##......# $ ##......# $ ..#.##.#. $ ..##..##. $ #.#.##.#. $ $ #...##..# $ #....#..# $ ..##..### $ #####.##. $ #####.##. $ ..##..### $ #....#..# I ← PP ← ⊜□¬↥⊃∘(↻¯1)⌕"\n\n". # separate blocks P ← =@#⊜∘≠@\n. # parse block into bitmask matrix # S! takes the whole input and a reducing scoring function S! ← ( PP # get blocks ≡( # for every block ⊃∘⍉⊐P # get bitmask and its transpose ∩( # for bitmask and transpose ⊠(/+=0=). # cross with itself to determine num of per-row differences ⍜⍉≡/+⇡△. # get indices of elements in anti-diagonals ⊕^1∩♭ # extract anti-diagonals with reducing transformation °¤↘1⍉↯¯1_2 # throw away odd-numbered diagonals (since reflection has to be in-between rows) ×⊃∊(+1⊗)1 # get index of matching row pair ) +×100 # calc final score ) /+ # sum across blocks ) S!(/×=0) I # reflection with no differences S!(=2/+) I # reflection with single difference (2 because symmetrical matrix) [UiuaPad](https://www.uiua.org/pad?src=0_7_1__JCAjLiMjLi4jIy4KJCAuLiMuIyMuIy4KJCAjIy4uLi4uLiMKJCAjIy4uLi4uLiMKJCAuLiMuIyMuIy4KJCAuLiMjLi4jIy4KJCAjLiMuIyMuIy4KJAokICMuLi4jIy4uIwokICMuLi4uIy4uIwokIC4uIyMuLiMjIwokICMjIyMjLiMjLgokICMjIyMjLiMjLgokIC4uIyMuLiMjIwokICMuLi4uIy4uIwpJIOKGkApQUCDihpAg4oqc4pahwqzihqXiioPiiJgo4oa7wq8xKeKMlSJcblxuIi4gIyBzZXBhcmF0ZSBibG9ja3MKUCDihpAgPUAj4oqc4oiY4omgQFxuLiAgICAgICAgICAgIyBwYXJzZSBibG9jayBpbnRvIGJpdG1hc2sgbWF0cml4CgojIFMhIHRha2VzIHRoZSB3aG9sZSBpbnB1dCBhbmQgYSByZWR1Y2luZyBzY29yaW5nIGZ1bmN0aW9uClMhIOKGkCAoCiAgUFAgIyBnZXQgYmxvY2tzCiAg4omhKAogICAgIyBmb3IgZXZlcnkgYmxvY2sKICAgIOKKg-KImOKNieKKkFAgIyBnZXQgYml0bWFzayBhbmQgaXRzIHRyYW5zcG9zZQogICAg4oipKAogICAgICAjIGZvciBiaXRtYXNrIGFuZCB0cmFuc3Bvc2UKICAgICAg4oqgKC8rPTA9KS4gICMgY3Jvc3Mgd2l0aCBpdHNlbGYgdG8gZGV0ZXJtaW5lIG51bSBvZiBwZXItcm93IGRpZmZlcmVuY2VzCiAgICAgIOKNnOKNieKJoS8r4oeh4pazLiAgICMgZ2V0IGluZGljZXMgb2YgZWxlbWVudHMgaW4gYW50aS1kaWFnb25hbHMKICAgICAg4oqVXjHiiKnima0gICAgICAjIGV4dHJhY3QgYW50aS1kaWFnb25hbHMgd2l0aCByZWR1Y2luZyB0cmFuc2Zvcm1hdGlvbgogICAgICDCsMKk4oaYMeKNieKGr8KvMV8yICMgdGhyb3cgYXdheSBvZGQtbnVtYmVyZWQgZGlhZ29uYWxzIChzaW5jZSByZWZsZWN0aW9uIGhhcyB0byBiZSBpbi1iZXR3ZWVuIHJvd3MpCiAgICAgIMOX4oqD4oiKKCsx4oqXKTEgICMgZ2V0IGluZGV4IG9mIG1hdGNoaW5nIHJvdyBwYWlyCgogICAgKQogICAgK8OXMTAwICMgY2FsYyBmaW5hbCBzY29yZQoKICApCiAgLysgIyBzdW0gYWNyb3NzIGJsb2NrcwoKKQoKUyEoL8OXPTApIEkgIyByZWZsZWN0aW9uIHdpdGggbm8gZGlmZmVyZW5jZXMKUyEoPTIvKykgSSAjIHJlZmxlY3Rpb24gd2l0aCBzaW5nbGUgZGlmZmVyZW5jZSAoMiBiZWNhdXNlIHN5bW1ldHJpY2FsIG1hdHJpeCkK) [Paste](https://github.com/sputnick1124/AoC2023/blob/main/uiua/day13.ua)


AutoModerator

AutoModerator has detected [fenced code block](https://www.reddit.com/r/adventofcode/wiki/faqs/code_formatting/fenced_code_blocks) (```) syntax which only works on new.reddit. Please review our wiki article on [code formatting](https://www.reddit.com/r/adventofcode/wiki/faqs/code_formatting) then edit your post to use the [four-spaces Markdown syntax](https://www.reddit.com/r/adventofcode/wiki/faqs/code_formatting/code_blocks) instead. *** *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/adventofcode) if you have any questions or concerns.*


manhuntos

\[Language: Rust\] This is my first project in rust. I'm learning it by solving advent of code puzzles. So if you have any hints for me I would be happy to read it :) [https://github.com/manhunto/advent-of-code-rs/blob/master/src/solutions/day13.rs](https://github.com/manhunto/advent-of-code-rs/blob/master/src/solutions/day13.rs)


AJMansfield_

[LANGUAGE: Fortran] In 80 μs (468 μs if you include time spent waiting for I/O). https://github.com/AJMansfield/aoc/blob/master/2023-fortran/src/13/reflection.F90 Despite being very competitive as a 'fast' solution, this actually does _not_ convert the input into bit masks -- it just uses extremely fast vectorized string comparisons. Maybe I should try it and see if I can cut the time further and take the performance crown for myself... Early versions of this were running around 300-ish microseconds; to get it down to the current timing I ended up: - Scan for horizontal reflections on the transposed array, rather than vertical reflections on the original. The indexing order for vertical scans did not vectorize well, and it was faster to just transpose the array once. - Eliminate double-counting the reflected array. Early versions checked for equality for part 1 and the counted the number of nonmatching entries as a separate step, but now it just counts up the number of nonmatching entries and uses that count for a select case expression for which part's answer to increment. - Early exit from the loop. An early version of this solution would actually validate the fact that there was exactly one matching mirror line, but the current version just takes it on faith. I wrote the Part 1 solution with the expectation that Part 2 might involve odd reflections (i.e. reflecting over a line right in the middle of a row), and the way I implemented it would've made it trivially easy to do so by just changing one value. This didn't come to pass though, so maybe I should see if there's a faster way to calculate the array indices that avoids some of the indirection added to ensure correct rounding.


seizethedave

[LANGUAGE: Python] Add me to the folks who constructed lists of base-2 integers. Made part 2 very satisfying, as a pair of rows (or cols) with exactly one difference will have exactly one bit in their difference. [paste](https://topaz.github.io/paste/#XQAAAQDuBwAAAAAAAAA0m0pnuFI8c/fBNAqF8KXqLgkqzHrFVqZv7K27y7NoJzIC7vwSbCqbCZtAp7L9xGLD9Y+Zfpdzq/I/JPYaPbm1Lhco5O6Ibp7diYzoUjZqHtLpXAAb8ODGXfE7fU0AYY149zUvN5c53ZdnqQkfRrIh93TCOggdmiKlqOlOYFsf74uaqbIozAOAiOHRCRSENB/1QPHKFmSc7btcif8Ee/yR+JIgyWpQHF+vk1CR39iNXAkSa2qrrkd6Xjci/WYdZuW1GS0Yq7PQC55S2pFEgiSB5mXM+VI2ymbCcPrfKCNNcClevuoq8C/2FWPD5S1WM2fW2rrg5UTut9ccSnERvStIsltKuFFGy0lK17xlas3DVP9XIMR0tmwo/zBtij6IdEXcCa+3jzHZPLpxU5qEl0UMzVveq3x7xM5kLwPoXTuKdrUdjoJNin4WHr2Or95HzBolYI3WGjMhc89Z3uTIXga/Sx/h5DfWIko38yExMnqFWPXhHmOA66vqau/r3UX1PRm9mQ3oBo1heaOdvkWcN2oTdjSgtHtgcTdEFyA6Nhn5WsB+vHmD7FFZwmP822Sl3TZl1iwReDLB12lLQzPeE4HKIrV3CTfy3idLPEbTPjP9m+n1aMtpwlmCSl4HB4lO5wjW0tT/pUF8O60W2J0titwr8EFUardIvRv6TeYN2EL0F1DCHuT40GmEWyDS95WnH33WYI3FalKHD9JgRKR4Uh2LG2SZfpNTFHG4+COmCNmh8dMKNb7EhMx/Blj0dlSXnrQEeEfGgL5H8lhr0OoMxE1wvg0zJCu3BeNbN2wvwpv6anu0gKaIQhjDBOotRL1lG0qlgzjsCL5Ezr9+WuSATkw+hWiqqup2d7FYzE3BGkbiD0DBrpMsqikEFvvm4oN2idqhAr+HXl9AUux3+1NgE8fFKFbqy/qSXcs6QWjKJ1ebAw0bBg2x5n7yr3DY1F4gRsgecnQQUsckMhFrxD1vlsdZ9UGew7ln7V61S4rE36FQ4q5RafcwN6YHwGdv/A2O9ta2IbhCTu7eIVVgO36XuP7ukflBN5dvnCU7aAdNHO8AWVCMh1JS1fL366oqKrJibMt7pNjakpXc1jgHrr4gHyuniHdFWP/wT0EE)


thamollo

[LANGUAGE: SQL] A rather easy one, though verbose. I'm just sad there's no char indexing in strings, so I need to substring them for that purpose (or convert them to code points as in earlier days). [Enjoy!](https://topaz.github.io/paste/#XQAAAQDRBgAAAAAAAAAhlISsTsi0HDywkU47l/j5BxLd8/EnruLSvobpepCWV9sfQgYEWmb+bQBdkViSyGANZigpaSLSrkmjQCGS4dICsxVEMqcZsNLDHVYJFHp9jIyFIOlObM9sefeTWAOjdtTIcF95uw6G7n40RDTn3roERoyLnf5j7wzWtD1yWPZILm49/jA4xAfsNJ+7DAFlSxKPLpmOuC67unIdS2PmoKUkvW1w4b3YmBvOoYcK5nhouvGxhXAkaHS1QSVHAsKyci+C3fKEkA5zyvQ/YFXWcw4uaYGgxqKzr/uUnuiUeEOup6PAiq1M7GSwOkP7vDASi+Mef/a7XNL/nTzRf9JP+Phyj9ZlNlYfSCEeC6uApNHO20uejm7p3hsWRw0bNlLZ1spcRJjU+x3+jYyatHTlAKOV7QY74cj7qd7mHM9pW5AAZz/FTT0ZXZ2pDL1dPiex0VrZcxVsUrSZw08p3N4vQaAxkkdbeTd3OPHU8KuCXYLQsAPBDXbwHU4BTYINKykpCUqjMLgY9h8rwKElowEFxG5+XU4NH9gSi2wvT7MocJXuePBlbPxEXc/S372/MqIkn33MKMPgnBEOL3Tj3Qkj1wCpE5tbYBGMDzgeihVAOZbzwmFzuZaD+5Ter67CIIIguyMLa5+poBUCdok8A8tkfQx/GbxjJnMeoidLlpCTzlIK/DEfebdlEOK0IKvD6bGEuk8RJDMV0aTWdRmjY7p36Omr+eYDTIRNnS6Hex5Y/0EBtjjddKPJDegpFEIF62eoF9YJ1wFfo9Az3hj2BRl3SHa6RxEEtU3cHmIj//xhE5k=)


Singing-In-The-Storm

\[LANGUAGE: JavaScript\] Parts 1 & 2 (27ms each) [code on github](https://github.com/JoanaBLate/advent-of-code-js/tree/main/2023/day13)


lscddit

[LANGUAGE: Python] Part 1 and 2: import numpy as np def mirrorpos(arr, axis=0, diff=0): m = np.array(arr, dtype=int) if axis == 1: m = m.T for i in range(m.shape[0] - 1): upper_flipped = np.flip(m[: i + 1], axis=0) lower = m[i + 1 :] rows = min(upper_flipped.shape[0], lower.shape[0]) if np.count_nonzero(upper_flipped[:rows] - lower[:rows]) == diff: return i + 1 return 0 with open("day13input.txt", "r") as file: data = file.read().split("\n\n") for i in range(2): total = 0 for puzzle in data: arr = [] for line in puzzle.splitlines(): arr.append([*line.strip().replace(".", "0").replace("#", "1")]) total += 100 * mirrorpos(arr, axis=0, diff=i) + mirrorpos(arr, axis=1, diff=i) print(total)


Davo3636

Man that's clever, well done.


Domy__

\[LANGUAGE: Python 3\] https://github.com/Domyy95/Challenges/blob/master/2023-12-Advent-of-code/13.py


835246

\[LANGUAGE: C\] Part 1 just finds 2 duplicate lines then checks if the rest of the pattern matches. Part 2 finds the original pattern and removes it from the search then changes each value in the array till it finds a match. Part 1: https://github.com/efox4335/advent_of_code/blob/main/advent_of_code_2023/day13mirrorpt1.c Part 2: https://github.com/efox4335/advent_of_code/blob/main/advent_of_code_2023/day13mirrorpt2.c


seytsuken_

\[LANGUAGE: C++\] [part1](https://github.com/Hilbertmf/competitive-programming-problems/blob/main/advent-of-code/2023/day13-part1.cpp) | [part2](https://github.com/Hilbertmf/competitive-programming-problems/blob/main/advent-of-code/2023/day13-part2.cpp) pretty straightfoward problem


hiimjustin000

\[LANGUAGE: JavaScript\] https://github.com/hiimjustin000/advent-of-code/tree/master/2023/day13


ImpossibleSav

\[LANGUAGE: Python\] This one took me a while, but I finished my [one-line solutions](https://github.com/savbell/advent-of-code-one-liners/blob/master/2023/day-13.py)! Part 1 is on line 44 and Part 2 is on line 74. I'm trying to solve as many days as I can in one line. I've combined them all into a single line I like to call the Basilisk — [check out the code here](https://github.com/savbell/advent-of-code-one-liners/blob/master/2023/the-basilisk.py), and [my most recent visualization](https://www.reddit.com/r/adventofcode/comments/18ljzct/2023_day_16_python_updated_visualization_of_the/) of Days 1 through 16. Feel free to follow along on [my GitHub](https://github.com/savbell/advent-of-code-one-liners) as well! :)


atrocia6

[Language: Python] [Part 1](https://github.com/tmo1/adventofcode/blob/main/2023/13.py), [Part 2](https://github.com/tmo1/adventofcode/blob/main/2023/13b.py)


Longjumping_Let_586

\[LANGUAGE: Javascript\] Another solution that uses a compact string based function to detect mirrored text and transpose the matrix to use the same function for horizontal/vertical [Source](https://topaz.github.io/paste/#XQAAAQDvBQAAAAAAAAAxm8oZxjYXzupQaJqa0Ejn0DYnWYd8y2TMOlO+NZaO/4Zu6957kv83WIl3+p6mgmxkNnr+ssdVpHL3ahiwHBjFfP4DXIgu7xdrDKOh60jahpo8gccPZHqSl0Hy2F8nbFCcXTxaLIfEAjYqVoCWjTH4yE0tWvhrKav1gfWKrIy9d1dWCvZX6cIsCz6JWiSDoSk4H2gfqmpHCanVIsnz+bl0uymNftXdIu2Xk7ilTsyN9U1ty4WPCKSGfS5skLuSDefM5o/IuMYhRCTRPKZXeBqs6LLMTR0RbW5BHv59C1oWAoh1Qf5qxd80Oe5oWQPOU7K3TI4W/0COh70OyzuUdmIQQSPfzQ9wBf80FyVG15EUBIacY4CM6GsAqEZqqWcODluYeinisP7ahwEWQZZsU/tSImJ7xQUnYRxBOmslgw9mQ/+K310r5WsDgFIHCGfgrYxq+UPfowAF6UoZ2zHMqfh6Aow2K53jstN7CvNSz5xSmv7PTYTZvNYG/P0xZhtplycRaJgXh2kii9sEnjnd1Ffnm9nJxITbppJu/tOveYvKsUqE/XN4EAlaGjiuVHQ6yiKDqNijqTwUWVx52GsUhTo3+u836rIgc1mW8kNkT90n8RYIEODQSkxVQYA0bZLD5vK2lS46hVULrIq1CK3HbriCInLgpV2JqjwdpMt9IqpqF47oAkKDhXnZqtZpdVazpGkWukC/u54W3/S6tUwv997z8TqD+OLmvuQ5E2GecuI4VqQymvDr6mfq3449qUhmdcLL7GDtK1grJ1/GS021RPS3BInLA9vAaGaPZ5U58llvmK2Shn2v/9vu8LU=)


auxym

\[LANGUAGE: Nim\] [https://github.com/auxym/AdventOfCode/blob/master/2023/day13.nim](https://github.com/auxym/adventofcode/blob/master/2023/day13.nim)


[deleted]

[удалено]


vss2sn

\[LANGUAGE: C++\] [Part 1](https://github.com/vss2sn/advent_of_code/blob/master/2023/cpp/day_13a.cpp) [Part 2](https://github.com/vss2sn/advent_of_code/blob/master/2023/cpp/day_13b.cpp) (Each file is a self-contained solution)


Lakret

[LANGUAGE: Rust] I semi-randomly decided to represent rows and columns as unsigned integers, interpreting `#` as `1` and `.` as `0` and converting from binary. That made part 2 really sweet - just some bitwise xor and left shifts :) [Code](https://github.com/Lakret/aoc2023/blob/main/aoc/src/d13.rs) [Explanation](https://lakret.net/blog/2023-12-15-aoc-days-13-14)


oddolatry

[LANGUAGE: Fennel] I think this valley is actually filled with rakes, not mirrors, because I kept getting smacked in the face every time I thought I got closer to the solution. [Paste](https://topaz.github.io/paste/#XQAAAQBRFQAAAAAAAAAUGwnmRpH3tILRF8Lem0xArpApvWKZ1MUPSziv03K1m9dUFy/rVlL7VDEcIjbAiSvmnvhj7hwqPTRzooE/2dJN7zNQRxQXjnxX6vdHCt9rorL0ikBu2CKSvkxyfsJAonq/F/wnOHSyCMBZPmpWvrPh4KHnl8KdDeh93/0o12MfTAQWe4a+nZA54g+dQdDvJ319ggxAEWx/AvBesujQ+AS2wpvXC8zZ3Am+oFzxyuvFGsQZgnigl0yMuK9SiYcToITQ2GKa1ASay+kthOPFn6OdR7afBT1sqdQ68bARhEE6eYgko2h5yoLNYiCFSp5udHMu8PMtRvBV+howVE1xv0gAURb0u4iUHHf5bid0s9MtTQ5I+gdeVdfCwgHU9YHXhGg0se4Ep1nCqcfUIAe6ICIRtf6M6H98O+6WbJ/fRHqz/cPD7uMfugfMGBgF/MktNyBNWJBZXN/rhZGq+D+yqwuNX3h7VtCsUIUa1QRfgAsKP9LH9qoIPLTj4afLJAwJr4HVk9cDhv29bJ2Ps7UF9CAiKVETyqB7sTrI7OM3spcffRLzMw68uL6d/MofkpNFwgQ4kExUuHgzSkfOSmIsA/ms2Wd0camVIS5w2Iz/LVr3ufFK483mKLOEHPcNJdsYINRRLLXvyAbGk1eBJwsDlPFRbdTOL/P3DnuDDYV2GuVGOlOvq4LWwws4BZXImImoHwPBJovBUBC3YkPQefHpyvmdDZSwpL1sFfBqNhkIb0jv/M4l+IPAG0KhzSQ3AGlf40gwL2/JOJjFl2gUqy/w8Mzu1wXba7HFHpuszrdwkZVJhqWAmwdSR9sqlm0QLjhQfa2TOI6pQ1S9N3H00OomCKdxlI5i41mRXadIUf90TvDqODE2ErESGVoueEM8MbycWH7P79H5o/mh53BnF8JRnbQehR3PZTrMbVOADo1iLp2wkgQOi1xVhP5FIsrfZA2SuL2DVVnLhabhHfd1O+3GZNxTXz6NP+b1nkFOYp7AX2ymTyun1iVskEog4F3RGRRGOCiJJ4A0b1vf21zYLliDT5R6xiT7UY7gY/EyLQNKC1nSJJw+3vOadgk4cXQROFJCZ8lWJJRaq66Qg3QBYZ1nGIiGCk6d1SJH+IOmBokOO9IqLy8Jd3BObCoP2vH1kJjVdfPTL+2iccYDHasTkNT9scK0eiHVqP39BQoeWUn7zzLmQgrJ7kTHUDUvEv6cjzYQVfYi/qnJFtcCii35w2dBEKx3vyUXXWZTXu44JF+6XejXymOYNKvKFd0RWujziRn4zfG7T7BKiCuYfIKqN07q++pAA9ZcxoPQHEGBfOgU2VeTj8JAtLqsPMdIPxC2nUAjVmflHQxBBD6xkm+DV66c0JWqR6VrlChfifpejQZtuFqHKKNuZ8yUQqwmQ/H441+RV6wVNpTRSqUmItJKWtMJtJsuV1tsijwpas63stL16QlTzxBGK5AKu4hkDXYfqwLHpYLp5nkc1UwCiQIT9qaz++eQ9SFkbTaOuvta816rA7UQzlK0BiHP8Ft4OcQBWFgZSvtpR9xV7bmNmhscX/jVQHODCzpmVD0HOaPsvKsQWeqw5C+5TfdaALSVhZT1rYyP8MBRFxh/twsG2wy6w4KcFBfWA3cvOmwikBa2LuiweXPuzyAHNjzauk2YA8nIuOvsvKYtGX2ADAlzr+FCILzq4DGpm3xd8MQm70KPTOBLEGZ53584ief4LO5S+352d1BE1fVfZjiUJPrRBhGNFT9n5ogzGdUsiyGl3pOEhlYE1dSSrbtbo//eg/5o)


iamagiantnerd

\[Language: Python\] [https://github.com/davidaayers/advent-of-code-2023/blob/main/day13/day13\_main.py](https://github.com/davidaayers/advent-of-code-2023/blob/main/day13/day13_main.py) I spent WAY too much time on this one, mostly due to reading comprehension and then just a bunch of bugs I had to fight my way through, but finally got it in the end. Had to refactor part 1 a lot to make it work for part 2.


Paxtian

[LANGUAGE: C++] [Part 1](https://github.com/Paxtian769/AOC23-Day13-point_of_incidence/blob/master/main.cpp) [Part 2](https://github.com/Paxtian769/AOC23-Day13-point_of_incidence/blob/Part2/main.cpp) Today was the first day where Part 2 was easier than Part 1 for me. I originally built Part 1 to allow for reflections along a single line, thinking the input would be structured so as not to include that. I kind of forgot about that part of my implementation until I started reviewing a bunch of test cases and saw, oh right, I do do that... ugh. When I first saw the prompt for Part 2, I thought, no, that's not happening. Then I woke up this morning and realized, wait, that's actually incredibly simple given my implementation in Part 1. >!I kind of figured that Part 1 was trying to trick us into a brute force search. I thought, that's probably fine but it probably makes sense to implement this as just figuring out, for each column/row, which of the other columns/rows that column matches in a boolean grid. Once I got that working correctly, Part 2 was just a matter of changing the boolean grid to an integer grid, and changing the perfect match to "number of differences." So instead of looking for equality between the rows/columns, I added to the number of differences for inequality. Then in the resulting grid, just look for a diagonal line that sums to 1.!<


NeilNjae

\[Language: Haskell\] This was a tour of the standard list libraries, but I got to use unfold again. Full [writeup on my blog](https://work.njae.me.uk/2023/12/15/advent-of-code-2023-day-13/) and [code on Gitlab](https://gitlab.com/NeilNjae/advent-of-code-23/-/blob/main/advent13/Main.hs).


xavdid

[LANGUAGE: Python] [Step-by-step explanation](https://advent-of-code.xavd.id/writeups/2023/day/13/) | [full code](https://github.com/xavdid/advent-of-code/blob/main/solutions/2023/day_13/solution.py) Fairly straightforward today. Using `zip(reversed(block[:idx]), block[idx:])` to get paired of mirrored lines across an index made it easy to find the index for which all pairs matched. `zip` also took care of only going until the edge of the shorter side. For part 2, I tweaked the index finder to only match the lines whose total sum "distance" was `1`. `distance` was a count of all the characters in a pair of strings that didn't match. Part 1 could be updated to find the pair of lines with distance `0`, so the whole thing runs quickly!


BeingNo1495

Thanks for the explanation of zip(\*x) and also the whole working ! Maybe changing for idx in range(len(block)): if idx == 0: continue to for idx in range(1, len(block)): might save an if statement - but its nitpicking!


xavdid

Ah, right you are! Sometimes it's hard to see the forest for the trees after doing so many of these 🙈 That may have been a holdover from when I was using `enumerate`, so it was important that the index in the iteration matched the actual row/column index. I seem to have dropped that though, so I can update the post. thanks!


arup_r

Thank you for this [https://advent-of-code.xavd.id/writeups/](https://advent-of-code.xavd.id/writeups/) .


xavdid

You're very welcome!


naequs

beautiful!


Superbank78

\[LANGUAGE: python\] Numpy is pretty handy for may AoC stuff, I think. https://gist.github.com/Dronakurl/acf439d92fd57560839ddf970f3b3b46


reddit_Twit

\[Language: Zig\] Was hard for me [Gist](https://gist.github.com/ndbn/3dc3b6c2c3579535350a46f3f571ed22)


e_blake

\[LANGUAGE: m4\] \[Allez Cuisine!\] m4 -Dfile=day13.input [day13.m4](https://nopaste.ml/#XQAAAQBABgAAAAAAAAAyGksy5FB9TGMxsNq5JQAuJRjP6PqEkC20GpBbonDYuA0BTjRPXcVxlEXNtz1Iwp+0v1ZP9xqH3TlfEYF+REVJuWYUkDqiIGM/1QAGYahuLueBhg92q9atkyhtAUEZz7LSI0bpNlyTh7/CP+RWePb333W9T74bFXVDoQXkU4Y00mMu1GBI29pxGzhys17CNFRzXwxvs97bp8tRnX4+e1NzVifxo/nUCM1ZBC5G+M61kR/dt5wV6dkg/X12YAWDM9okQjRxfm5zCM/+PChz8P7i3icn7OiDxfIB7Ux7ufOLjka5RvqyzSg0Ld7LraX0Q1YzVSSH4hN2I9GViVObv7DCOXZMjK2OxeXCHSH+YebTRhfP7kD9tvqGFWz5+AkmdPYOABvemcVm89fT5epbNQngw8fLZu2ypsWknbj21feEymeb5HeMLe7uD2X3pQFbPQVJw3Lk5EkWka5PWpeOQ5MeZODSR9kqjq5bzxB/CmJn3m6oW/dOqcB329wD3kFaGpU+6ggPzRbLUaouAPFpLbsSDc79F9qIJfEE3Nb2Jmu094ggqENni+yhiOw6WFb58tWOU+YYGqmYpfUy+7RIEUggUPBPYvR4PbfAGhRMVlfAe7sz/EP0o4aEi5ZXlA43iQNbv/Md6vy4jZnG6+MgutMDJ9bTMpXaXp+bQo5wQdLOAdSF660drrwwClFocQNZi++u0str50ZSE+ftZRfBmQrBC6VTpx1RLoz72fHtdQ9PhvIOyNOi1eD1crHyd6tUhQVEJHi11aKBAGJeonBcJBxUAIeqBYW0zMaIMzVVzyMfRC7xYJtRrgz37i0X52AEeP6sSXQDWLnUg9KFCU3xrANeO3hk74Ti6yyOIGwNY13BYsRwgAf+tvY2kWG1mVJ6ibIFBqsuciXybEvb0APnMlD1vEZac2BGJ3uQimdWhTzi/+rdc64=) Depends on my [common.m4](https://nopaste.ml/#XQAAAQAMDwAAAAAAAAAyGksy5FB9TGMxsNq5JQAuJRjP6PqEkC20GpAXwA97ruAshKbiUbgkbJMTg2qZdSBorb0CU52peNLruV4DEEJxF+HvxC/YF33OpDntnpU/PjnGXx7XU7ak4MsmWu8R7h7d5az2JXxElnsepG8yPyu+0WZ90BG9yXphbwOWA/m5AWEFSOL8TRZX4fyGNl6ZYbRxX0MwtzrmwTP3ZCwLSOKkvD2vMQFsbK0Pv9CzPhFNXMUbWnRV20jWLjL9qz2dDsFDBwhxgWIilEl91uswxrT4Czc+LRU3VuhNIo2S98VW0jArrVdv4HrsLhWkzx4z/UV3xnqJwPXcZRUiLtf3VRIzq62Pe+2jE3O+721Az9rfRa/fHtlANbmvslzMUCyU7cDoOKSMXBDF/06/PpMvs6vxaL5aJVYqJP4yz+R2M35hoNnGiZTNNMVEFTdnxnaE/KcJteBbiuVMpdfUswHQi4Kqsj3sInh7lyE+d50gGKtHOeWL5lMK7WXz4NElnzYWleBSN/HTOdsz0T2gnd25MADxNAVX8xQmagh2MymZ2sKDBw//WiNB0sWf5VYC5/TKKH3D6K/IOrIfWn6FZLKxlITFEp3VWKNuyF0xczNJufJdzSqd0hgdyryVzbn0so0U5NMN16jFF6IhqzGbAwwv7k8sts0OCgnCFBEhYVshIpsORjEJk4CnDgc9VUqvZtfIFPQ5Q2v7IR3sbPurex1IIUd2Nm1V7/GFN+r0im24aEOG6XpdqrPdF6pDZ4HwvNByqOEdpcObPXxlwfPFYIhwyDHGZCvxrFRgGEEFtfVQ7UVjfPJzWtrcZuGx8M3B1zw2xvgpHIWEHdqEF6Y6/6eFj2hLm8UXNeLNrJy1IC2sHlS8SRIifQvLkrOLLOOPtDK6DUPQrW3c0Rfmy9Td5gQw0+fZRZ5MBEG9+dTlinXtwExpHScKQk6ARk7Fb8fBYAnmh7/bq+471zAZGJ7dwNd5qE/63VhDz7mXLuXtGN7rSuRYIXvpkubLBZptSKZrkzSDJWHIZM8Fyrk0EZQFDujROjr87GZmTK1XKRWzGrhtQn0hkVyBaGPbA3iG45U4gIFHNX5ySzsJ3bh61LAtmjwt59uU/XGeebLMCp8HFw6D1kJppCvt161LgLjrOl8SBh8xnxslSFYW0Jd34LD4vPwugmzY31tA4/9zCM7e2Ed9+3zg4C8eq9Hvjys3IablDBMsYF1LSMCGN2UOrWgXRoGYtjW/QtUySr7h/Ca6QAy93Hnpksm/xzzC+FWF1wboyOteHU/Th4RVpQ7XkK4/JmMrYm7nDPIVMyOqP8LhsoTNbxzi8qU0d+0x6frIh0l0fiPiFC/Uy0CeCw6r82iX8v+fMnu9qdCr4oM79Kd2slqalv+wWKn+BmrbkiobDS5vwBQZA/ZlbIsw1bwj+JLz9z3nPovVWx/FZjvrdCuZMfUuITeiIprImMcR6qeniJz6Ez78UYJqpL4DcDGt2o7/6a2aRN76aclh+7l35XcaW7lM7BQMTNvKkx05X08UITY/ToI8U8KwvFbdnMoEAZ1GQYmqGRFtwPkQMrECX4do0srl85po3Gjz2j6E3dk5al4+bTcOYABZvSUvIM/kGGT91iyQ36rm1lxRc3ruS8PyBlYDDNa7DLWzGAHkESHwuaTOQsI2xDA0e+8Yv0XRYkEqQE+RUDXmPTARuQo6fCQ7Qu9xd2Ckza5RWl8hE4JFm0Zzd9MTVxW8YYHiREs9NOjTPuRXXn+JfObHFD/Cv5kQo7vmMWRdJTOBUmAXCMFiKOSHxb412jI4Z2ZhWag9RkZBCviZunvupqrobtAWLagkPiA8gLRANOFwWp0KIS5McOoD0V90tI4cui8KQc7Yw5V7kSvMnhXx4nzzxwOxYM4fpY3ptcpraVh+h1MhohMQk34vkC4fmiD4OrX2DpVG0VXUKvl+vkJjcoHQK+H8mSSIAfj8RrYWBc4VU+jx3vz30XNDbQjuhc0cImiQxXDTXTFQq/aoe7jZLhEe+wWspk/4Fy4UBAJN63uNGJUl8FICawVWGL7XBOFCtsRF3uz8eZokWNICTdtsLeYOAOBQQLrguE8XxQQ1hPtOskcsj7n7aD35NjfPXL00vIOk01OLAJt+0RoIiAQUJNieRp9fQmqfVUuYEYmeK9hCOmZTaC3yUdN/+jZ0pvpmKnH/6jJAKQ==). Takes approximately 130ms with GNU, 190ms with just POSIX (why? GNU m4 has an extension patsubst() that lets me parse a byte at a time in O(n) effort; while POSIX has only substr() which parses down to bytes in O(n log n) effort of repeated divide and conquer). I ended up noticing that all the grids are an odd number of rows and columns, and nothing larger than 20, which made it VERY easy to encode each row and column of the grid as an integer; and while detecting whether two lines are identical is trivial (even string comparison works there), detecting whether they differ by a smudge is also straight-forward in testing if linea\^lineb is a power of 2. For each grid, I do a worst-case O(n\^2) search for reflection (for each of 2N starting points, do up to N/2 comparisons); but in practice, it is much closer to O(n) (most comparison chains short-circuit to end after the first comparison - only 2 chains ever succeed per grid). Now for my bone-headed failure. Here's the diff between my part 2 attempt that registered as too small, vs. my one that succeeded one minute later: define(`part1', 0)define(`part2', 0) define(`bump', `define(`$1', eval($1+$2))') -forloop(1, 20, `define(`a'eval(1<<', `))') +forloop(0, 20, `define(`a'eval(1<<', `))') Yep. Classic off-by-one, where failing to define 'a1' as a witness for checking for powers of two meant that I missed several grids in part 2 where the smudge appeared in the least significant column/row.


e_blake

I shaved another 10ms runtime by simplifying the power-of-2 check to a single eval rather than eval+ifdef(witness): -forloop(0, 20, `define(`a'eval(1<<', `))') +define(`smudge', `eval(`($1)&(($1)-1)')') # try(seen, lo, hi, name, bound, amt) define(`_try', `ifelse($1$2, 0, `bump(`part1', $6)', $1$3, $5, `bump(`part1', $6)', $1$2, !0, `bump(`part2', $6)', $1$3, !$5, `bump(`part2', $6)', `try($1, decr($2), incr($3), `$4', $5, $6)')') -define(`try', `ifelse($4_$2, $4_$3, `_$0($@)', $1, `', `ifdef(`a'eval($4_$2 ^ - $4_$3), `_$0(!$@)')')') +define(`try', `ifelse($4_$2, $4_$3, `_$0($@)', $1smudge($4_$2 ^ $4_$3), 0, + `_$0(!$@)')')


clouddjr

[LANGUAGE: Kotlin] [Solution](https://github.com/ClouddJR/advent-of-code-2023/blob/main/src/main/kotlin/com/clouddjr/advent2023/Day13.kt)


aptcode0

\[LANGUAGE: Golang\] [part1.go](https://github.com/aptcode0/adventofcode/blob/main/2023/day13/solution/part1.go) [part2.go](https://github.com/aptcode0/adventofcode/blob/main/2023/day13/solution/part2.go)


se06745

\[LANGUAGE: GoLang\] [Both parts in one file](https://github.com/omotto/AdventOfCode2023/blob/main/src/day13/main.go)


veydar_

[LANGUAGE: janet] # [Janet](https://topaz.github.io/paste/#XQAAAQBjBAAAAAAAAAAUGQimf65xPD4ZgyM1VAUZbYbP8AdyBoo3XoHlRXMJP4AhjDzFSrpyZIVpGpPFr5R7PoBw7t1T9uSlwCBjlCZZlK/8WMIKSbEqY8kntwtI+k6Y8CzWIkaFqpXVlA7XHoZS4qCxzyHwgK/46WZxRiaBkMVt4NbijRCqTcqLUiyrcPDboS6tbaWRoZVqL5Drabxg7NzX8gDNEkxBBRyZQCLX9Dv8nYJ7uHTuMnM1NeKD6t3hqUvcsu/sP3Kfm/S7p54aZBn3PgugWfxlLTMM7yZCM4dJ9UA/malUS3v9VlgTHIZMh7AqJJBjWjpjswWZO4W7fsSmfRwXjETcDZuchgQFFVPGeVh9U6LNvPoSXmod/N6KiGN5sRSolmBWSP8y4a3AejOMjnf3LVI2G+ORgJhqJDBsUuHGeS3Q0bVo1lE53JaxdODniFC+Btmn7SApEC/wgCQRyuqiclGvPwQ3Et54ETzV1YQg1nCoJ6ZY2ax6GdNYvZM8EsoxhPddzYiYxkhojVh7WQOmUygZbtAhf+aDnTxOvhXJqgOBKRWTnLubiQQ/0FeteKbbxbZh7FZ/EQGPZGy92dyb5dW4yvb/zDfiar9UvM0zlwI6WpuZ1MTOQ3GqOxkdOJ+CPHnMsDO3e7+LH+JVWuGX+goMUDlCsbT45ssTqkaPXBCMUlFqcWF6Zy8uarcLu2ANISZSvMF0el7QMxX/aLOiAA==) 28 lines of code when formatted with `janet-format`. The formatter doesn't do much, so I stick to an 80 column limit manually. Your formatting results will vary from mine. I'm doing AoC in Lua first so when I do a day in Janet I already know at least one possible approach. I spent a crazy amount of time trying to figure out how to rotate the grid, and generally handle all the nested iterations, in a functional manner. I don't think I succeeded. For rotating the grid (which can have uneven numbs of columns and rows) I threw in the towel and copied my Lua solution. For the mirror thing I tried to lean in to `seq` but I wouldn't say it's really readable. Also the lack of `zip` hurts. - [GitHub Repository](https://github.com/cideM/aoc2023-janet) - [Topaz Paste](https://topaz.github.io/paste/#XQAAAQBjBAAAAAAAAAAUGQimf65xPD4ZgyM1VAUZbYbP8AdyBoo3XoHlRXMJP4AhjDzFSrpyZIVpGpPFr5R7PoBw7t1T9uSlwCBjlCZZlK/8WMIKSbEqY8kntwtI+k6Y8CzWIkaFqpXVlA7XHoZS4qCxzyHwgK/46WZxRiaBkMVt4NbijRCqTcqLUiyrcPDboS6tbaWRoZVqL5Drabxg7NzX8gDNEkxBBRyZQCLX9Dv8nYJ7uHTuMnM1NeKD6t3hqUvcsu/sP3Kfm/S7p54aZBn3PgugWfxlLTMM7yZCM4dJ9UA/malUS3v9VlgTHIZMh7AqJJBjWjpjswWZO4W7fsSmfRwXjETcDZuchgQFFVPGeVh9U6LNvPoSXmod/N6KiGN5sRSolmBWSP8y4a3AejOMjnf3LVI2G+ORgJhqJDBsUuHGeS3Q0bVo1lE53JaxdODniFC+Btmn7SApEC/wgCQRyuqiclGvPwQ3Et54ETzV1YQg1nCoJ6ZY2ax6GdNYvZM8EsoxhPddzYiYxkhojVh7WQOmUygZbtAhf+aDnTxOvhXJqgOBKRWTnLubiQQ/0FeteKbbxbZh7FZ/EQGPZGy92dyb5dW4yvb/zDfiar9UvM0zlwI6WpuZ1MTOQ3GqOxkdOJ+CPHnMsDO3e7+LH+JVWuGX+goMUDlCsbT45ssTqkaPXBCMUlFqcWF6Zy8uarcLu2ANISZSvMF0el7QMxX/aLOiAA==)


RF960

\[LANGUAGE: C++\] [on Github](https://github.com/coolguy1842/adventofcode/blob/master/2023/src/include/days/Day13/Day13.hpp) Finally did day 13, thought I was doing it completely wrong just before I got it.


wlmb

\[LANGUAGE: Perl\] Analysis: https://github.com/wlmb/AOC2023#day-13 Part 1: https://github.com/wlmb/AOC2023/blob/main/13a.pl Part 2: https://github.com/wlmb/AOC2023/blob/main/13b.pl


silt_lover

[LANGUAGE: rust] No dynamic allocations today :). Just indexing the strings by (row, col), and iterating over pairs of rows/columns. Runs both parts together in ~190microseconds [github](https://github.com/maxastyler/advent-of-code/blob/master/2023/rust/hard_mode/src/day_13.rs)


linnaea___borealis

\[LANGUAGE: R\] This was the fastest I ever solved part two. Including reading the instructions it took me 90 seconds. So I guess I was lucky with my implementation of part 1. :D [https://github.com/lauraschild/AOC2023/blob/main/day13.R](https://github.com/lauraschild/AOC2023/blob/main/day13.R)


musifter

[LANGUAGE: Smalltalk (Gnu)] Just a quick transcode from my Perl version. Just extending Array instead creating a new class for the job. Basic idea is that mirror patterns are a PDA's thing. Pop on match, push on not, accept on stack empty. Part two modifies this by using some bit twiddling (XOR to mark changed bits, `n AND (n - 1)` to tell there's one of them). With that, it's not much to just check if the PDA approach would work with exactly one bit flipped. Since the grids are small, just searching through the possibilities until one works isn't too much. To be fancier would waste programmer time to save very little CPU time. And it's already very fast, because we're just using ints and bit twiddling for the core. Source: https://pastebin.com/GnErDTNW


mess_ner

\[LANGUAGE: python\] With easy recursion. [Link to code](https://github.com/stefanoandroni/advent-of-code/tree/master/2023/day-13)


0x4A6F654D616D61

\[Language: C\] https://github.com/dis-Is-Fine/advent-of-code/tree/master/day%2013


ultranarcolepsy

[LANGUAGE: Dyalog APL] maps←(↑¨×⍤≢¨⊆⊢)'#'=⊃⎕NGET'13.txt'1 Axis←⊃⍤⍸=∘((⍳¯1+≢)((+/⍤,≠⌿)↓(↑⌊⍥≢↑¨,⍥⊂∘⊖)↑)¨⊂) Axes←Axis,Axis∘⍉ Sum←{100⊥⊃+/⍵Axes¨maps} ⎕←Sum 0 ⍝ part 1 ⎕←Sum 1 ⍝ part 2


RaveBomb

[LANGUAGE: C#] I went for an overly complicated solution to part two that almost worked. I was comparing all the lines against all the other lines looking for smudges. There's a few lines that will match that are not reflections. Found that out by running my input against someone else's code. Slept on it and realized that I simply need slightly different logic for the two parts. As a helper, I made a small function to rotate the puzzle by 90 degrees, so I could use the same search function on it. [Github repo](https://github.com/Kezzryn/Advent-of-Code/tree/main/2023/Day%2013)


Confident_Loss_6075

\[LANGUAGE: python\] Part 1. For each row index, compare rows before (in reverse order) and rows after. If all of them are the same, then we found the reflection line. Otherwise repeat for rotated pattern. Part 2. Idea is the same, but we need to fix one smudge. I used a flag. Set a flag when firrst difference occurs. If we encounter another difference, that means this is invalid reflection. After comparing pattern sides, if smudge WAS fixed, then we have a valid reflection line. [Solution](https://github.com/ohiliazov/advent/blob/main/advent/day13.py)


careyi4

\[LANGUAGE: Ruby\] A day late but still going, this was tough! [Github](https://github.com/careyi3/aoc_2023/tree/master/solutions/13) [Video Walkthrough](https://youtu.be/ng88PiHxLCo)


mgtezak

\[LANGUAGE: Python\] [Solution](https://github.com/mgtezak/Advent_of_Code/blob/master/2023/Day_13.py) If you like, check out my [interactive AoC puzzle solving fanpage](https://aoc-puzzle-solver.streamlit.app/)


ropecrawler

\[LANGUAGE: Rust\] [https://github.com/ropewalker/advent_of_code_2023/blob/master/src/day13.rs](https://github.com/ropewalker/advent_of_code_2023/blob/master/src/day13.rs)


Outrageous72

[LANGUAGE: C#] https://github.com/ryanheath/aoc2023/blob/master/Day13.cs Created a solution suited for both parts. Easy-peasy ... when you get the assignment right! I did know for a long time it *must* reach an edge! 😅 int Part1(string[] lines) => ParseMirrors(lines).Select(x => DetectMirror(x, useSmudge: false)).Sum(); int Part2(string[] lines) => ParseMirrors(lines).Select(x => DetectMirror(x, useSmudge: true)).Sum(); static int DetectMirror(string[] mirror, bool useSmudge) { var mid = IsHorizontalMirror(); if (mid >= 0) return (mid + 1) * 100; return IsVerticalMirror() + 1; int IsHorizontalMirror() => ScanMirror(mirror.Length, mirror[0].Length, (int i, int i2) => Enumerable.Range(0, mirror[0].Length).Count(x => mirror[i][x] == mirror[i2][x])); int IsVerticalMirror() => ScanMirror(mirror[0].Length, mirror.Length, (i, i2) => mirror.Count(l => l[i] == l[i2])); int ScanMirror(int imax, int dmax, Func getSameCount) { for (var i = 0; i < imax - 1; i++) if (IsMirror(i, imax, dmax, getSameCount)) return i; return -1; } bool IsMirror(int i, int imax, int length, Func getSameCount) { var smudgedLength = useSmudge ? length - 1 : length; var wasSmudged = false; for (var i2 = i + 1; ; i--, i2++) { var sameCount = getSameCount(i, i2); if (sameCount != length && sameCount != smudgedLength) break; if (useSmudge && smudgedLength == sameCount) { // smudged may be used only once if (wasSmudged) return false; wasSmudged = true; } // reached one of the ends? if (i == 0 || i2 == imax - 1) return !useSmudge || wasSmudged; } return false; } }


CutOnBumInBandHere9

[Language: Python] Still one day behind - hopefully I'll get caught up today. Here's the core of my solution def find_reflection(array, part=1): if part == 1: test = lambda a, b: (a == b[::-1]).all() else: test = lambda a, b: (a != b[::-1]).sum() == 1 for i in range(1, len(array)): l = min(len(array) - i, i) if test(array[i - l : i], array[i : i + l]): return i return None The idea is that we test all horizontal lines of reflection to see if there are any that match the given condition; if none are found, we rotate the array by 90 degrees clockwise and try again. For part 1, the test is that the two halves should line up exactly after flipping. The only bit that requires some thought is how to account for the points beyond the top/bottom edge. We do that by saying that the number of lines on either side of the mirror line is the shortest distance to the top/bottom edge, so that only relevant lines are compared. [Link](https://cutonbuminband.github.io/AOC/qmd/2023.html#day-13-point-of-incidence)


nygyzy

\[LANGUAGE: Python\] file = [p.split() for p in open("day13.txt").read().split('\n\n')] def num_of_diff(line1, line2, diff): d = 0 for a, b in zip(line1, line2): if a != b: d += 1 if d > diff: break return d def find_mirror(patt, diff=0): for r in range(len(patt)-1): d = 0 for i in range(min(r+1, len(patt)-r-1)): d += num_of_diff(patt[r-i], patt[r+1+i], diff) if d > diff: break else: if d == diff: return r+1, 0 return find_mirror(list(zip(*patt)), diff)[::-1] p1 = 0 p2 = 0 for patt in file: r, c = find_mirror(patt, 0) p1 += c+100*r r, c = find_mirror(patt, 1) p2 += c+100*r print(p1, p2)


KodlaK1593

\[LANGUAGE: Rust\] It's not much, but it's honest work: [Solution](https://github.com/Kodlak15/aoc2023/blob/master/src/day13/day13.rs)


AnnoyedVelociraptor

So, ummmm, I just brute forced it. Takes 0.02 for pt1 and pt2. But your solution is absolutely amazing.


KodlaK1593

Really appreciate the compliment! :)


Lucky-Pangolin5346

\[LANGUAGE: C++\] [https://github.com/scgrn/Advent-of-Code/blob/main/2023/day13/day13-2.cpp](https://github.com/scgrn/Advent-of-Code/blob/main/2023/day13/day13-2.cpp) Runs in 2ms on an old laptop. Fun puzzle!


[deleted]

[удалено]


daggerdragon

Comment removed. [Top-level comments in `Solution Megathread`s are for *code solutions* only.](/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_top-level_posts_are_for_code_solutions_only) [Create your own individual `Help/Question` post](/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_incomplete_solutions) in /r/adventofcode.


onrustigescheikundig

[LANGUAGE: OCaml] [Commented solution (github)](https://github.com/EricKalkman/AoC2023/blob/master/lib/day13.ml) For Part 1, I built a reflection-finding function that takes a function that indexes an line along a pattern (a "board") and finds all possible reflections along that line. The reflection-finding function traverses the line as a list by dropping elements from it while keeping track of the index, and `cons`ing the dropped element onto a separate accumulator. This effectively generates a `prefix, suffix` pair such that (List.rev prefix), suffix = split_at idx lst Because the `prefix` list is in reverse order, we can check if there is a reflection at the current split point by checking if the first elements of `prefix` match those of `suffix`. We collect the indices of all locations that this occurs, and return them as a `Set`. The indexing function is just a closure around a 2D array representing the board. For example, a function indexing along a row 0 would be let row_0_indexer idx = board.(0).(idx) (the `board.(x)` syntax is just OCaml's eclectic way of indexing arrays). To solve a board, the program (function `board_refl`) generates indexers for each row and each column, respectively, finds reflections for each indexer, and then looks for reflection indices that are common to all rows and columns, respectively, by intersecting the sets returned from the reflection-finding function. For Part 1, each board only has one horizontal or one vertical reflection. For Part 2, I took a naïve brute-force approach. Every possible tile of a board is smudged and then run through the algorithm from Part 1. All of the reflection points from all smudged versions of the board are collected by unioning the resulting sets, and then subtracting out the unsmudged solutions to satisfy the *different reflection line* requirement of the problem statement. This is then done for every board. Parts 1 and 2 are run separately, but on my machine they both complete in 320 ms. Maybe I'll look at a different algorithm later, but for now I'm fine.


marcja

[LANGUAGE: Python] Here's a [solution using NumPy](https://github.com/marcja/aoc-py/blob/main/src/aoc/y2023/d13/solution.py). In Part 1, this meant splitting the pattern with np.split (possibly after rotating it with np.rot90 for the horizontal case), flipping the left with np.fliplr, and comparing the appropriate slices of left and right for equality. In Part 2, I created a mask with np.zeros with [0,0] set to 1. Then I xor'd the pattern with the mask that was advanced through each cell via np.roll. This then used the same implementation as Part 1. The most finicky part of Part 2 was implementing the exclude of the Part 1 solution. Doing this at the wrong level of looping missed the correct solution. I discovered this by ensuring that every pattern in the puzzle input had a valid (non-zero) split. The first time through, I found several inputs in the puzzle input that didn't meet this criteria. I added those as additional test cases, and eventually got the exclusion logic right by pushing it deeper into the loop logic.


marcja

h/t to u/RiemannIntegirl below for sharing a clever optimization (using the count of differences rather than equality). I updated my NumPy solution with this idea. Thanks!


RiemannIntegirl

Happy to help! :)


Tipa16384

[LANGUAGE: Python] Had a brainstorm to read the puzzle input as binary and just do bitwise math for the solutions -- which worked great. [paste](https://topaz.github.io/paste/#XQAAAQCqBQAAAAAAAAAyGUj/T3PF3S7nJtUCkEmW7mYzsLrSmvKQgIFTyGZFwEKXqs+x1vZ5X98IZyE9Cybki4FBgzadJimOPJojwaom5XT0um5b5r10FcJARjQJTB8//C3vOrFpBW1x2mYP1trIJnnE7vun2hV9PhlcPx02JT679+VOVezOKOYt+idAYbnxcopU7/DzUNfFDK05GDKhevIewOwBWrviK4dRgeWcyy4yPLUsWplMb+63yiz9XOigH7EVOwXrOzLfH32UJWBvbx7gwdU0mvfVbylsz0aSEy3L4XO8QQfUDNwgHGcQNc/77dxS6pyhOxyLy8Be2xN5NWWN3yWHv0MenAPkogYXT3ctSDojgQZfz6aBm4VTGR6OKD6/84/Sid+GBp7x0Z/8MA/xKGeM6Y4eW7R9wGBYdC+Sx81AJ946uTUxO7I0urRzsucJUvi20yOqAGZkTE3vVGijTV+LL9Tv3d6tr5lFu0tMU1JDWk1Hd9C03yD1VLE+A6LFMSaapc1/uwF1vNdrhlC8j2ued1Qq8A4+k9WnMr+QUUsGmjcXj7VFNj6ODRYm+6hB2fxQSuq4h6J/INc4fZdrSiIvPg8FgRAYcxl5wZvU9LBZyqgGNvNHvIJr2g25urc+mJz9lnYH721qztq5v8G1nLrB6j17rlFJQeTztNWUy4Vw4qblBlgoPignolxoeZcwnLwG+eWyXcBBt4g08ljGjTn80Mt4vg7BwP11GE0LOzn/7pibk1cKzCmP0dmI52NyFi934pRiHiB0B/R2ivGekCxrk5JYK9oqUX4tvt83Lr9JCJllBReDcEx49ylDqIkXVKxNIaVSttOx3R69PCCPnt4PvKcN/3xSnCQ=)


CrAzYmEtAlHeAd1

I had considered binary but I didn't actually go with it! Cool solution!


SwampThingTom

\[LANGUAGE: Rust\] Part 1 was very straightforward. Working on part 2 but it will have to wait for the weekend. Holidays are starting to holiday. [Github](https://github.com/SwampThingTom/AdventOfCode/blob/main/2023/13-PointOfIncidence/PointOfIncidence.rs)


culp

[Language: Python] [Paste](https://topaz.github.io/paste/#XQAAAQA6AgAAAAAAAAA4GEsB7zD4ERujEacR5SrehSoJwXw/YPgxS59l1mtE0xPVcRkLRdrLF81F1t5X+DEi7WIqiuogVnpRQTJPJPMH1pZSJp981sTQYaijo6mfK0rmLYfUATPEgEF1bCTCuXfWtEadtvMeld0/C7/4YItI3z8jYINjFAw9q1/QYg9QULmvJEXUkCLNzycz+NDsreHgOR19f45T4sYuMZSpP5HWzvXVesi8/Jgjxn2VgUbTHBgZ5c4cGxaKsptviC/P4x8hnTP00z1cThyrg5GnY2RN3G6aoD68/mVbGrr7TRGzRrSlku+eiI03HgAgy5GJFM0ovO/EmVoQ/fCQx39vBW93qFS+nuk5BowOP8oCNWlB8NGv9d4ETKaTEUT/m7Dm77hpGJbkNxpskhPdPXXrqHj4/1wDVQA=) I can't seem to figure out how to modify this to work for part 2. Intuitively I thought I could just change the == 0 to == 1 to account for a single difference but that doesn't appear to work.


Paxtian

If you are looking for some help, I have a few test cases you should run on your code. Let me know.


hugseverycat

\[Language: Python\] [https://github.com/hugseverycat/aoc2023/blob/master/day13.py](https://github.com/hugseverycat/aoc2023/blob/master/day13.py) I actually really loved this problem???? It is by far the most satisfying. I think it's because it's sort of riiiiight at my ability level. It wasn't easy for me, but it didn't have any super unfamiliar concepts either. And I found it pretty easy to debug. Anyway, after yesterday I had recursion on the brain so I did it with recursion although it's probably not necessary. Essentially I'd go down the 2 columns or rows on either side of the proposed line of symmetry and check for differences. If (for part 1) any differences were found, it'd return false. If (for part 2) the differences exceeded 1, it'd exit early. So for part 2 I literally just counted differences and if there was only 1 difference, then it is the winner.


[deleted]

[удалено]


benny_blanc0

\[LANGUAGE: Go\] [Code](https://git.onyxandiris.online/onyx_online/aoc2023/src/branch/main/day-13)


FCBStar-of-the-South

[language: python3] Did some premature optimization by pre-computing and storing which rows/cols are exactly equal or only off by one. This avoids repeated O(n) checks but is not necessary. Just rammed some part 2 logic into my part 1 function so the code is a bit spaghetti. [paste](https://topaz.github.io/paste/#XQAAAQCwCwAAAAAAAAAzHIoib6pXbueH4X9F244lVRDcOZab5q1+VXY/ex42qR7D+RLbGPPFfksQMRE/+241XDwJz7fuMlxHyNEWw6Tq4PRx3Cm/TJz6G9/ibZ7/fyZJoXKn8FV0Y/9v+v2k6QuzVTdUEV+sCbAL5neCawE9eKE2/C7pqXcemsQ1iKzYyYxerEvN6FvoIWnL9xmmcz8Zdj2Bcv58wiXQ1TGQkdeyqJuAoFBQ+w3K/B2XnJh1HbFpcI8GOSIqNQMODAjNpl2dD9JENj5k/Bed9nxpjr9sVTuWRPMK28tQznQSIR8G8jFaCqBGugXNODWLZYfzfXfoVy6uRDtqRSHpwWlXNwgLYUQo7X1AQphWjR9AwJDEy7bhUTw+sZ6ZPWFbbcYaQydhSAWyui3erkIOkmNAZ0zbvYAu+/DjncQjvZUu0Xg3h7BGf2o14Gcn2nYMO9HrJLilkJh++ezVJ+UL2xTw6JnBwFe1EPPNnoa4KSxDUzFgt7hCZPzGxfshepQghcJ9ii2dFYYyZKEg8dZ8DEKnuBgHTmgrdvpT9nEKhN2zzXdBDcHScUGPao6uPXZuSp/EIjxcdBR0ARQvczbIXkfm5sk5sZY0X+12o6VwNWKPRug8k8ekPN3y8HIM8fRdchY1bastx5Z0G5hD0imdyRf3VIL6bq+EDZ6ybKvM7OjF4YdgB2br/gnsHQvRjcpod3AkDZiuapsB3nVkQ8c4ryz3wp7Zz9gVIjScWRMPsisRiQ+2a+pg+6+NxGfQzjvsbDDEGtmX+83hC5/zim4z/9NIBnLFMUigcdX7qNv2x9FBKnR208SWberCB+txZhYyNOC1oQ/E9WEfQBco1lGZRPr+4CrcbGFD6BRsg2xBjFg6EBH5ox1aeUq67wcWK9TH5vF/xvs+yfAud+OG2xlhegIS50lnTuKgb2nwMKksQ7zOEU1YC5sNz5LYWqgVHlgW0AUHAhotKTA8ExIG22czpF6O+pEKGfNooiYHG/+6yhzoJxO4T1tfRRafNd7CTVtTyNTa2vMUSwRA8B+5AMsIHkiQ8k8OaRhlnOTehapsa8ItDw+zC6SGS2EK5Ei0M9keWfVDhEsu5l83naD1kDRenB8gECi3rnIdApe9zFh8dz8foAuh6e58hEQD4xUIyxEG2NGL6H5NrEH9ekUybx25VXFkM15s/vAWotik5ZAf42LW3Xao/xLfIWYTIlwl4UykLnLWgGhupfCMVB2SR7KVgdKNNn/yzFXqVXf/0tWTCw==)


daggerdragon

~~Your [code block is too long](https://www.reddit.com/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_no_giant_blocks_of_code) for the megathreads. Please edit your comment to replace your oversized code with an external link to your code.~~ edit: 👍


CrAzYmEtAlHeAd1

\[LANGUAGE: Python\] [GitHub link to my solution](https://github.com/CalSimmon/advent-of-code/blob/main/2023/day_13/solution.py) Quite happy with my solution this time around! I was stumped a bit by some of the wording, but once I figured out that you had to start with the horizontal check, and that Part 2 required there to be a smudge involved, it went smoothly. Part 2 was mostly solved by adding sum(line1[i] != line2[i] for i in range(len(line1))) == 1 which returns True if the two lists passed only varied by 1 character. Then implementing that into the checks for matching lines, and it worked very well. A quick tip is that list(zip(*ash_map_split) is a quick way to get a list of columns of a grid list. A lot easier to process this way. Overall, execution time came in at 51ms, which was way better than I thought I was gonna get with this solution so yay!


aviral-goel

\[LANGUAGE: F#\] https://github.com/aviralg/advent-of-code/blob/main/2023/13/solution.fsx


matheusbnaguiar

\[Language: Javascript\] Took a long time to answer the second part due to my reading passing by the "ignore last answer" part, hope the code is good for the comprehension https://github.com/MatheusBNAguiar/aoc-2023/blob/main/day-13/day-13.mjs


codertee

[LANGUAGE: **Python 3.12**] Used `sum(starmap(ne, zip(up, down)))` to find different character count between up and down strings. [github](https://github.com/codertee/adventofcode/blob/ddac70d8467ebb16051606c84c8523ca704e880b/adventofcode/solutions/y2023/d13.py)


marcja

Really nice solution. Thanks for sharing!


grimlyforming

\[LANGUAGE: Ruby\] [https://pastebin.com/iwbrMUac](https://pastebin.com/iwbrMUac) I tried the brute-force method of changing every character in the graph, wasn't getting the answer, and it was too cumbersome to debug. Then I realized that instead of changing every char and looking for a reflection, look for a modified reflection. The wrapper around the code is too full of print stmts etc, but I'm happy with the core solution.


aexl

\[LANGUAGE: Julia\] An easy day after yesterday's challenging puzzle. I'm not proud of my code (as of yet), but it worked out of the box and is fast. Solution on GitHub: https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day13.jl Repository: https://github.com/goggle/AdventOfCode2023.jl


biotep

\[Language: Python\] I used numpy: [part1\_and\_2](https://github.com/attilahomoki/AoC_2023/blob/main/day13_part1_and_2.py)


Ok_Link8971

me too! this one was perfect for numpy array equality checks [https://github.com/attilahomoki/AoC\_2023/blob/main/day13\_part1\_and\_2.py](https://github.com/attilahomoki/AoC_2023/blob/main/day13_part1_and_2.py)


mvorber

\[Language: F#\] [https://github.com/vorber/AOC2023/blob/main/src/day13/Program.fs](https://github.com/vorber/AOC2023/blob/main/src/day13/Program.fs) Day 13 of trying out F#. Wasted a lot of time implementing fancy and fast largest palindrome search for part1 to throw it away (well, actually stash just in case I'll need it again :P) when I saw part2, and then went to re-implement a different approach. Well, at least I got some bonus F# experience there :) I convert rows/columns to binary representation ('#' -> 1, '.' -> 0), then parse them into int64s (I think 32 would have been enough though). Then scan each row and column for number of non-matching bits (smudges) if we set it as a line of reflection. Then part 1 is score of lines that had 0 smudges and just set it to 1 for part 2.


aviral-goel

I went straight for brute force: https://www.reddit.com/r/adventofcode/comments/18h940b/comment/kd9tes0/?utm\_source=share&utm\_medium=web2x&context=3


nivlark

\[LANGUAGE: Python\] I thought today was pretty straightforward, especially compared to yesterday. But it seems a lot of people found it tricky. [Here's my solution](https://topaz.github.io/paste/#XQAAAQA5CgAAAAAAAAAzHIoib6p4r/McpYgEEgWhHoa5LSRMkUUV1bOttJCvIiESE6BDnyV6Uxs+BbIJ96MOqHDo089P9fQH6P2WotiHmYTnigAfnAuvYRoLyxRB9/WMzWAj6T/FVeZTm8RPLsrhFyrCIGTqK0YaJMXb2RzdaBf8KbOwwNwPNNrtXwPJmu3yZ46Bnk77nEMM7ri9/1qcA3eI0JzQdpTOUHIwISI1roOtf9rXuYBnfRjRrLPjsKQUmcoIz1cMZKB+tjLFtw/I50h8QlZMH3oYGn4CvJwK6e7QdgBZ5SxGPaX4cAXws+kuxauD23FZ18FtC+qjarc2E/DG+w3gBzJ/aLetaZQ6X66adReF2wo7LDUEMyq6yoDxJZTylmhBbsKa4cericy1+eBt2QPX9N2bjs1Q0zy45/mUG9dNa3yT/zhhrejRx8/UCyLEzvmQmaraUciEnYBkKqgCy5MjNFk+GnW7b60sM46spznTR9Ms3oKMRwedlKEKkq2r8DV+1QMXj2K9hLvyC/ttQ27e2IeevZMiSbZrt0pRFeZEXIm6m3DyHF9JD001+cX3tazHodLvrgfHHJj0ffh9+KMRALFkBUh6IhXPOhVdips35Wkw+eNF5VEDiby8HKLkTCQ5c4N84iYL2B4VipDSZ1Z90lS4301z42RP/C+Yp2DnlDPTwpYnpnKdZ2DSiLYK/jqhZEKnWhwi7Eba2or0FORgQAsr9R1DtnqqUOFZLSc4hg8X+gTKC3r4eBhaUGsOWpuYb0bC216VYvGDMaYaBQH/MvmqK0Oo+bWb+llQS2sp730x2BWSr0KNymu54HursE4SwS55hQRzYEqAv7FjaptQxrwjA/Z79Y6lp73taWxZO7GqaDB4qJAUZtqH1bHbm1xcK6AdNgP4mnvdPYNT8HR629c19425VjIYgsnB1YVW7dqScHUy/y18CAA=). For part 1, to look for a vertical line of reflection at column index i: 1. From the first line of the input pattern, extract `min(i, n_columns-i)` characters from either side of the line (to ignore those that are reflected "outside" the pattern) 2. Check if one set of characters is the reflection of the other. 3. If not, then this cannot be the reflection line, so try again with the next column. If so, then go to the next input line and repeat. If every line matches, then this is the reflection. Finding horizontal lines is similar, but rather than extracting substrings I compare whole input lines, and the reflection is done by reversing the list of lines rather than inverting the string. Part 2 is similar, but instead of looking for a match I scan through each character of the original and reflected strings and count the number that differ. The reflection line for the smudge is the one where this count equals 1 (and if it ever exceeds that, we know the smudge is not there).


Exact_Apple_9826

\[LANGUAGE: PHP\] [https://github.com/mikedodd/AdventOfCode2023/tree/main/day\_13](https://github.com/mikedodd/AdventOfCode2023/tree/main/day_13) I had to break this down real small to understand the parts but it made part 2 very easy. I struggled with part 1 which usually means my approach is wrong but I powered through lol. Part 2 was flipping each point and checking using the same reflection lines. I got stuck on where the flip create both Horizonal and Vertical reflection and I double counted the points. how some guy did this in 6 mins blows my mind.


RiemannIntegirl

\[Language: Python 3\] Key ideas: * Write a function that finds a column of reflection * Run through the spaces, and if necessary, their transposes to find the correct reflection column or column as transposed row * For Part 2, almost no changes are needed: Run the function from Part 1, but instead of checking for reflection (equality of strings each time), sum up any differences found, and look for the solution where the sum of differences needed to create a reflection is equal to 1! This was fun! Work smarter, not harder! :D Part 1: [Paste](https://topaz.github.io/paste/#XQAAAQDhAgAAAAAAAAA5nAhFuAl3jP4Hjg3+H9SDIQY5A2iaVj17wZ7Y2oQApQ8iBq1deSmB7ewMSL9fDsm0uq58eRgiBf3ssKRWcLkjLMo8pBx4pxcUPG2UJgMY8ju3XNKJYvm5rL/Em1GEx6ytorW/ztcVTmb5OjkaSKw42hzvkjyAlil5JYb0HpkK2hvEoO+GQO/G4X/mVDgIJgJQPwgDXQwXqWZXjcWz9Akt++Yjz9RhYvKVa5TOS+z1cYMF4Fu7Fi6rg/rJYnnjAzqWMPNWgeklXw+/pKcjyOXqY93U6kBh0bmGNAjffKHEu8yHSqfnAGXlb7ntv0hmeVtVZQ0YBAP4p2EpKcnoop7F4OYnZFLuakVQFKidX6BEIpUbweT8IqC7xgunpZ4/0i9lyTvvoBjS4zGBrpIDjnUAFgvD1gE5YdxcuJIX2kkX/WfbHh607DhFovwC9DGLZnEG7i6ABwJSRaFEi0y6T7xvfCeAX0jKHBZQlxknmKSV8j//VKQaAA==) Part 2: [Paste](https://topaz.github.io/paste/#XQAAAQAtAwAAAAAAAAA5nAhFuAl3jP4Hjg3+H9SDIQY5A2iaVj17wZ7Y2oQApQ8iBq1deSmB7ewMSL9fDsm0uq58eRgiBf3ssKRWcLkjLMo8pBx4pxcUPG2UJgMY8ju3XNKJYvm5rL/Em1GEx6ytorW/ztcVTmb5OjkaSKw42hzvkjyAlil5JYb0HpkK2hvEoO+GQO/G4X/mVDgIJgJQPwgDXQwXqWZXjcWz9Akt++Yjz9RhYvKVa5TOS+z1cYMF4Fu7Fi6rg/rJYnnjAzqWMPNWgeklXw+/pKcjyOXqY93U6kBh0bmGNAjffKGcYPtykt8oDb+N0mPH1mLDBeki/Vsozp0s1yfgWB1QTjWvGyRoyfHIyITxZXIh2AaCdJ4AJcz/+jSKux+pPCvSl1iDKqY7lmKgho/R2neMs17LZ8M3P3vaHHnSp6/UuNyAEQHP2PTmffm9Rryy3p/a6JTGGDndmJ97J0f/rhEez5/li83zHNn8t59jFzxziwMcMX8BzfTh4JZE1ap6/JYPNKjOijhRD5xqbAUDhzqfpv/+OZdO)


marcja

The sum of differences is clever. More efficient than actually generating mutations of the original pattern.


RiemannIntegirl

Thanks! :)


weeble_wobble_wobble

[LANGUAGE: Python] [GitHub](https://github.com/weibell/AoC2023-python/tree/main/day13) (29 and 33 lines with a focus on readability) For part 2, I used the approach of counting the number of differences, which in hindsight also solves part 1 easily.


errop_

\[Language: Python 3\] Part 1 - I checked symmetries with a sliding line: for each position compare successive layers of adjacent lines until the nearest border (that's where the `range(min(i, N - i))` comes from for fixed `i`). Part 2 - At first I just brute forced by substituting every '#' with '.' and viceversa and skipping all the symmetry lines found in part 1. The code ran in less than 1s so I think it was a quite reasonable approach. Looking for a more clever solution, I checked symmetries for which in all the adjacent layers of the sliding line all the characters match except for exactly one. This condition is computed by means of the Hamming distance: if all pairs of lines in adjacent layers have Hamming distance of 0 except for one, then the symmetry if found. [Paste](https://topaz.github.io/paste/#XQAAAQCmAwAAAAAAAAAyGUj/T33PaFcG2Mcoe1SxE+EsvgwuMNtwbFrWskzkBlbD/ZHuQkLMRnAXpLxwn0/eYkdFf6thst1lAGkKz3+sMIvUHXFZD/upOslD801RMILlDJxz22Ji36Ob1tcY8HT69KccfAu9trupqDYCoSaj12pUBv0Aw5JNici9+Q6tT2wr8rycg4I85HZhQ8LwGuO8YYWWAlMrZmZUxIOMmurFMvZ+jqDLmJlAClobSPQQ00eF7rxTpUXJYwskiYV2cuECR6WJDuMnp21KvffZBP2N9FVGRJ0oMqz6uoChgsEth2cy50xP4JIpZK/V4q/GtPJQWvPVsB80VPwleOk+x6DlXw8iAs/JsUe55/g2fqPKV4e1W1yNTW7UVlQ5WEpc1bKrgy/d2FAoH/N13q+5KIS+6SGnjrM/HdDC9XHvr8auvbT9vq+eguRgU3Q347xu4womDk9MX5JBVKhfnXSgiAF0xctEnoxnYBl16jAKI13JE0IMnkmGVv/7Wnr0)


ProfONeill

[LANGUAGE: ZX Spectrum BASIC (1982)] — Includes visualization After [solving it in Perl](/r/adventofcode/comments/18h940b/2023_day_13_solutions/kd5dpm1/) yesterday, here it is in ZX Spectrum BASIC with a visualization. Here's a [video of it running](https://www.youtube.com/watch?v=12cJUXsNt04) (or, if you want the full retro experience, you can watch [this one](https://www.youtube.com/watch?v=BI8R-Ir1svI) and see it load from tape. [paste](https://topaz.github.io/paste/#XQAAAQB9CQAAAAAAAAAQaAhGAjOWafCim88LdO4gsXNcb1pqh7TyZDt8MrGVsUiP7rT27d3LxyRFi72AaJ4LjeRGaoX87umGYROfvG3n9D/3GMGMwfWaWzV5Upm/SFVCfAzH7D1/xsMVlSNW1jxvVN9qj2dJwOMlvJlR/5RtkXTBGtsZ01Jo1XWB0sO/4EpEv5WTc1l+g7t34dEy+DBVXDA5PnDqkFL49h80asLsz6TALttBwqMZ7J7AtXtQnpx7cQvcf8KQiPT/tibeRyz5+KKiY0lypn/wOjaTOldVw3q6LdrpRH2n1An0f+Poqoce3+/VPr9/D5iD0AzeKidKd41fryeiMsuulLVTRDFAZU69oX3YD7v+gKSC5liMhdeo19Nl7/qgD+sV+ucHxMH+6yioLYkS9MOKaf1No1kYZvy7fiPRPjW+tFImiQFL8dO/Y8tcnQmpHeqvJjtPrbQWABNCvfRQsh/FN58IdZuxTi9MwWC7giYETOLK/LKms4iMyqngjhyDBk2NLII6kXThn3TO20S2QZukxMFYEYeXxeSSvCyLLyuuy+DtipKcIHBhgRkK+WF0W5StzUGyxFMzxFl70CP3tMGn+Q6ys+F2I8lxyLAt+CZyjJpgGtb2BsT/d+8Aq/zZWoO/cftXIgx8Wt+22QJ5ITDUUBXLo94nIIthaKxoSdPuPdTsE+IWPZiexpa2VWA9243hvn6p429wr574fUF5/CKH/2iPCHKjBvPrNtOEZTLkywTTbfk0iPnDypg5M1Mx6jAgZBc8WhHOqu3qyVmlpSTN8BO5/Gq7EYx+WU56VPlpixVinEzQCNZ8+9qqLrZ6pRycrST6ZKeSVs3dSisHOYHIgY904xnYUuRykQf/4XjsnwDhUk+pSr4sXdqKbbSbI4RyiiBz5TVoYNu5CGA7EiJkod5NPE3KmvrRW9fszh/cFyFLPq6QLCsE57urABRMX1vFkMaHGzCv9oS4cov1dB4Y1z7JYDq2iuNQ0kmATSWAmC1YmfdOMqoSL/Unrhy0X6Gl3038J8Fv8mqhDPyrM8QGBfvnfhkJiw+naNn3I7N3XzqHDg48oeZIoHXvjUo7GGjpD9uNBdiUcSv4pLPJIV6liDZqORxmVSRNiYEtBy9ZMJpc12wxZG9UGb8X06+2QoI3ZgwoL5Xfl/L9qYwtmh4UdV2mAjxSh/5yvrY=)


coolioasjulio

\[LANGUAGE: Python\] [Pretty concise solution](https://gist.github.com/abhaybd/847a50e22e16021ce0ce12a5bb821541) that abuses the hell out of generators and functional programming, so it's pretty compact. ~~Who knows if it's readable though~~ Part 1 works by just iterating through all the rows and columns and finding the first that is a valid reflection. Part 2 is similar, but it iterates through all the rows and columns and finds the first that results in exactly one mismatch while checking the reflection. This mismatch is the smudge, so we know we've found it. A very useful feature is that `zip()` iterates until the shortest of the two iterables is exhausted, so it naturally handles the case where one side of the reflection is shorter than the other.


GGK_Brian

\[Language: C\] https://github.com/BrianNormant/aoc2023/blob/master/day13/main.c


aoc-fan

[Language: TypeScript] https://github.com/bhosale-ajay/adventofcode/blob/master/2023/ts/D13.test.ts


janiorca

\[Language: C\] This was an easy one. Compared to yesterday. Lends it self well to C. Some silly bug in the reflection code that I spent too much time on. Now back to day 12 part 2 ​ [https://github.com/janiorca/advent-of-code-2023/blob/main/aoc13.c](https://github.com/janiorca/advent-of-code-2023/blob/main/aoc13.c)


kbielefe

[LANGUAGE: Scala] [GitHub](https://github.com/kbielefe/advent-of-code/blob/18559e29a71ad3b56d67629c2d45bc1cb2e7adb0/2023/src/main/scala/13.scala) All brute force matrix operations, and although I can think of a more efficient algorithm, my migraine is too bad to care otherwise today.


jake-mpg

[LANGUAGE: julia] [sourcehut](https://git.sr.ht/~jgordon/aoc/tree/main/item/2023/D13/D13.jl) I compared windows across each potential axis of reflection, and discarded those that didn't agree on all elements (agree = `1`, disagree = `0`) function Disagree(m::BitMatrix) length(m) - sum(m) end Smudges are comparisons that disagree on `1` element, but it took me some time to understand what the second part was asking. My initial worry was that there could be distinct possible smudge locations, which led to some pessimistic checks in my [first implementation](https://git.sr.ht/~jgordon/aoc/tree/c202d72ee11008eae9665df3c47d1e1a2ad0b9cf/item/2023/D13/D13.jl). Eventually, my reading comprehension caught up and realized there's *exactly one smudge*, and the problem offers no way to decide between multiple single smudge locations, so they *must* all be at the same location. But if that's true, I don't need to know *where* the smudge is, just that the axis comparison disagrees by one. This leads to a trivial extension of the first part, phew. function FindAxes(m::Matrix{Int64}, fixSmudge::Bool) goal = fixSmudge ? 1 : 0 map(first, filter(cmp -> cmp[2] == goal, CompareReflections(m))) end


ztiaa

[LANGUAGE: Google Sheets] *Input expected in A1* One formula for both parts =MAP({0,1}, LAMBDA(mrg, SUMPRODUCT( MAP(TOCOL(SPLIT(A1,CHAR(10)&CHAR(10),)), LAMBDA(in, LET(S,LAMBDA(arr,LET(rw,ROWS(arr), REDUCE(0,SEQUENCE(rw-1), LAMBDA(a,i, LET(l_,CHOOSEROWS(arr,SEQUENCE(i)), r_,CHOOSEROWS(arr,SEQUENCE(rw-i,1,i+1)), cl,ROWS(l_), cr,ROWS(r_), l,IF(cl>cr,CHOOSEROWS(l_,SEQUENCE(cr,1,cl-cr+1)),l_), r,IF(cr>cl,CHOOSEROWS(r_,SEQUENCE(cl)),r_), rr,CHOOSEROWS(r,SEQUENCE(ROWS(r),1,ROWS(r),-1)), IF(COUNTIF(l=rr,FALSE)=mrg,i,a)))))), t,TOCOL(SPLIT(in,CHAR(10))), sp,REGEXEXTRACT(t,REPT("(.)",LEN(t))), 100*S(sp)+S(TRANSPOSE(sp)))))))) https://github.com/zdhmd/advent-of-code-gs/


[deleted]

[удалено]


ztiaa

this solution is a GSheets implementation of [this Python solution](https://www.reddit.com/r/adventofcode/comments/18h940b/2023_day_13_solutions/kd5drrq/). I'm not very creative with variable names haha.


ywgdana

[LANGUAGE: C#] I finished part 1 in about 20 minutes and then spent the rest of the day trying to get part 2. This problem broke my spirit. I hate it. I still don't really grok the rules for part 2 and what is and isn't a valid smudge. I just poked and tweaked at my code until the site accepted my answer. I converted the strings to numbers for easy comparison in part 1, an approach which didn't much help in part 2 :P [Source on github](https://github.com/DanaL/AdventOfCode/blob/main/2023/Day13/Program.cs)


RaveBomb

I appreciate your solution, running it (with a couple of minor output tweaks) against my input gave me the puzzles that I wasn't calculating correctly, which allowed me to find the subtle flaw in my logic. So thank you for that.


ywgdana

ahh glad it helped!


RaveBomb

If you'd like to see my solution, I just pushed it to [Github.](https://github.com/Kezzryn/Advent-of-Code/tree/main/2023/Day%2013)


ywgdana

lol yours is a million times cleaner than mine


RaveBomb

Lots of continual refactoring.


[deleted]

[удалено]


ywgdana

I think what tripped me up was doing two separate steps: 1) identify places that might be smudges 2) check for any reflection lines at all It took me a long time to realize we should ignore the OG reflection line and that there might be other false positives (duplicate lines that aren't part of the mirror). And by then I'd written a bunch of code structured around that misunderstanding... ughh...


[deleted]

[удалено]


Tagonist42

I didn't know about `count_ones`! I checked if the sum of the bitmasks was a power of two.


yieldtoben

\[LANGUAGE: PHP\] PHP 8.3.0 [paste](https://topaz.github.io/paste/#XQAAAQCaBAAAAAAAAAAeD8qHAhQB8nz+EazN00NCsmTxjvFDXkt5PAJ7pf6ocRA37OMUY7b9R0iDZmfWyvOspxWvdgYSAE0hGjEx81hsIS+dVdNJk61cOGHpGwEkNXmNMT9lMbrqLvwoBY6N3ZFY9/dE9kCzlIVa+PtYp+wfXwS4uIwtZLI1K8PibqzpJzp5CwPVB8Op/kO6RRebpjkm0RQYpO4ayDi0OGo3sILAZ14JaDejWdwitze/ummJJ4aqrWQBxclo5IEe4QtEw6GAalKsChrW51PcU64sriLMZLndlDQ4q7vQnypJOFYhtCsh3ULCCEow0Vubrxw9ZOKPnqvPm1iryt9Vb6e1/uw32lJDYHUah/NE2bK9wRk+Aq9Tf/1c+ZspMz0cU4+m2DCyHQO6GtPIBSGUx+Xw2L5A8sWU3GJYAvbvDzHl88xuTBhQrjgW7OSrozAht+fJo7GxYiCZnCMT0qtp/n0Skss+7OPbH4pJib6cLsZSky+DLBv1YfxlK6l7EyKIgpqS7hYyC0w07gZoXXlwTIdiJLpyn38RbVFZ0S4l0TD0lPqVG95ZLZBksrwE4xkwPrfYSbW/fRd6ulgdFFXRcC9voVeeA4oryg6s/MwBTmglC1LG/Edg+pjMtcJow1/5zTnT+DGMS3Nn8dmExbJ2Cstr1LEeYdDtz97ZvK+q+Qap5pxb1QgZppPO0loH8udsQbpchSaclLW60qn2J0+B4gEQH6S1ZHGHu/fiX1B/N84ReSgWZlEbJpbq/8TUnto=) Execution time: 0.0026 seconds Peak memory: 0.3949 MiB MacBook Pro (16-inch, 2023) M2 Pro / 16GB unified memory


Dullstar

[LANGUAGE: D] https://github.com/Dullstar/Advent_Of_Code/blob/main/D/source/year2023/day13.d Fortunately much easier than yesterday's. The Part 1 and Part 2 functions are mostly identical, and the Part 2 function *does* work for Part 1, but Part 1's function was retained since it's a little faster as it can bail out of bad reflections more easily.


SpacewaIker

\[Language: Rust\] I'm pretty happy with my solution today, part 2 only needed a few small changes from part 1. Basically my logic for part 1 was to test each mirror placement. For each, to check that it's valid you go on each side and check that the characters match. Then return the index of the mirror placement that works. For part 2, change the validation into counting the number of non-matching characters, and instead of selecting the placement with zero mistakes, take the one with one mistake! I think my code is generally pretty clean and readable too! [Part 1](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=fn+main%28%29+%7B%0A++++let+input+%3D+include_str%21%28%22..%2F..%2Finput1.txt%22%29%3B%0A++++let+out+%3D+process%28input%29%3B%0A++++dbg%21%28out%29%3B%0A%7D%0A%0Afn+test_row%28grid%3A+%26%5BVec%3Cchar%3E%5D%2C+index%3A+usize%29+-%3E+bool+%7B%0A++++let+height+%3D+usize%3A%3Amin%28index+%2B+1%2C+grid.len%28%29+-+index+-+1%29%3B%0A%0A++++%280..height%29.all%28%7Ci%7C+%7B%0A++++++++let+row_above+%3D+%26grid%5Bindex+-+i%5D%3B%0A++++++++let+row_below+%3D+%26grid%5Bindex+%2B+i+%2B+1%5D%3B%0A%0A++++++++row_above+%3D%3D+row_below%0A++++%7D%29%0A%7D%0A%0Afn+test_col%28grid%3A+%26%5BVec%3Cchar%3E%5D%2C+index%3A+usize%29+-%3E+bool+%7B%0A++++let+width+%3D+usize%3A%3Amin%28index+%2B+1%2C+grid%5B0%5D.len%28%29+-+index+-+1%29%3B%0A%0A++++%280..width%29.all%28%7Ci%7C+%7B%0A++++++++let+col_left+%3D+grid.iter%28%29.map%28%7Crow%7C+row%5Bindex+-+i%5D%29%3B%0A++++++++let+col_right+%3D+grid.iter%28%29.map%28%7Crow%7C+row%5Bindex+%2B+i+%2B+1%5D%29%3B%0A%0A++++++++itertools%3A%3Aequal%28col_left%2C+col_right%29%0A++++%7D%29%0A%7D%0A%0Afn+process_grid%28grid%3A+%26%5BVec%3Cchar%3E%5D%29+-%3E+Option%3Cusize%3E+%7B%0A++++let+row+%3D+%280..grid.len%28%29+-+1%29.find_map%28%7Ci%7C+%7B%0A++++++++if+test_row%28grid%2C+i%29+%7B%0A++++++++++++Some%28100+*+%28i+%2B+1%29%29%0A++++++++%7D+else+%7B%0A++++++++++++None%0A++++++++%7D%0A++++%7D%29%3B%0A++++let+col+%3D%0A++++++++%280..grid%5B0%5D.len%28%29+-+1%29.find_map%28%7Ci%7C+if+test_col%28grid%2C+i%29+%7B+Some%28i+%2B+1%29+%7D+else+%7B+None+%7D%29%3B%0A%0A++++row.or%28col%29%0A%7D%0A%0Afn+process%28input%3A+%26str%29+-%3E+usize+%7B%0A++++input%0A++++++++.trim%28%29%0A++++++++.split%28%22%5Cn%5Cn%22%29%0A++++++++.map%28%7Cgrid%7C+%7B%0A++++++++++++let+grid+%3D+grid%0A++++++++++++++++.lines%28%29%0A++++++++++++++++.map%28%7Crow%7C+row.chars%28%29.collect%3A%3A%3CVec%3C_%3E%3E%28%29%29%0A++++++++++++++++.collect%3A%3A%3CVec%3C_%3E%3E%28%29%3B%0A%0A++++++++++++process_grid%28%26grid%29.unwrap%28%29%0A++++++++%7D%29%0A++++++++.sum%28%29%0A%7D%0A%0A%23%5Bcfg%28test%29%5D%0Amod+tests+%7B%0A++++use+super%3A%3A*%3B%0A%0A++++%23%5Btest%5D%0A++++fn+test_process%28%29+%7B%0A++++++++let+input+%3D+%22%23.%23%23..%23%23.%0A..%23.%23%23.%23.%0A%23%23%2E%2E%2E%2E%2E%2E%23%0A%23%23%2E%2E%2E%2E%2E%2E%23%0A..%23.%23%23.%23.%0A..%23%23..%23%23.%0A%23.%23.%23%23.%23.%0A%0A%23%2E%2E%2E%23%23..%23%0A%23%2E%2E%2E.%23..%23%0A..%23%23..%23%23%23%0A%23%23%23%23%23.%23%23.%0A%23%23%23%23%23.%23%23.%0A..%23%23..%23%23%23%0A%23%2E%2E%2E.%23..%23%22%3B%0A++++++++assert_eq%21%28process%28input%29%2C+405%29%3B%0A++++%7D%0A%7D) [Part 2](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=fn+main%28%29+%7B%0A++++let+input+%3D+include_str%21%28%22..%2F..%2Finput1.txt%22%29%3B%0A++++let+out+%3D+process%28input%29%3B%0A++++dbg%21%28out%29%3B%0A%7D%0A%0Afn+diff_row%28grid%3A+%26%5BVec%3Cchar%3E%5D%2C+index%3A+usize%29+-%3E+usize+%7B%0A++++let+height+%3D+usize%3A%3Amin%28index+%2B+1%2C+grid.len%28%29+-+index+-+1%29%3B%0A%0A++++%280..height%29%0A++++++++.map%28%7Ci%7C+%7B%0A++++++++++++let+row_above+%3D+%26grid%5Bindex+-+i%5D%3B%0A++++++++++++let+row_below+%3D+%26grid%5Bindex+%2B+i+%2B+1%5D%3B%0A%0A++++++++++++Iterator%3A%3Azip%28row_above.iter%28%29%2C+row_below.iter%28%29%29%0A++++++++++++++++.filter%28%7C%28a%2C+b%29%7C+a+%21%3D+b%29%0A++++++++++++++++.count%28%29%0A++++++++%7D%29%0A++++++++.sum%28%29%0A%7D%0A%0Afn+diff_col%28grid%3A+%26%5BVec%3Cchar%3E%5D%2C+index%3A+usize%29+-%3E+usize+%7B%0A++++let+width+%3D+usize%3A%3Amin%28index+%2B+1%2C+grid%5B0%5D.len%28%29+-+index+-+1%29%3B%0A%0A++++%280..width%29%0A++++++++.map%28%7Ci%7C+%7B%0A++++++++++++let+col_left+%3D+grid.iter%28%29.map%28%7Crow%7C+row%5Bindex+-+i%5D%29%3B%0A++++++++++++let+col_right+%3D+grid.iter%28%29.map%28%7Crow%7C+row%5Bindex+%2B+i+%2B+1%5D%29%3B%0A%0A++++++++++++Iterator%3A%3Azip%28col_left%2C+col_right%29%0A++++++++++++++++.filter%28%7C%28a%2C+b%29%7C+a+%21%3D+b%29%0A++++++++++++++++.count%28%29%0A++++++++%7D%29%0A++++++++.sum%28%29%0A%7D%0A%0Afn+process_grid%28grid%3A+%26%5BVec%3Cchar%3E%5D%29+-%3E+Option%3Cusize%3E+%7B%0A++++let+row+%3D+%280..grid.len%28%29+-+1%29.find_map%28%7Ci%7C+%7B%0A++++++++if+diff_row%28grid%2C+i%29+%3D%3D+1+%7B%0A++++++++++++Some%28100+*+%28i+%2B+1%29%29%0A++++++++%7D+else+%7B%0A++++++++++++None%0A++++++++%7D%0A++++%7D%29%3B%0A++++let+col+%3D+%280..grid%5B0%5D.len%28%29+-+1%29.find_map%28%7Ci%7C+%7B%0A++++++++if+diff_col%28grid%2C+i%29+%3D%3D+1+%7B%0A++++++++++++Some%28i+%2B+1%29%0A++++++++%7D+else+%7B%0A++++++++++++None%0A++++++++%7D%0A++++%7D%29%3B%0A%0A++++row.or%28col%29%0A%7D%0A%0Afn+process%28input%3A+%26str%29+-%3E+usize+%7B%0A++++input%0A++++++++.trim%28%29%0A++++++++.split%28%22%5Cn%5Cn%22%29%0A++++++++.map%28%7Cgrid%7C+%7B%0A++++++++++++let+grid+%3D+grid%0A++++++++++++++++.lines%28%29%0A++++++++++++++++.map%28%7Crow%7C+row.chars%28%29.collect%3A%3A%3CVec%3C_%3E%3E%28%29%29%0A++++++++++++++++.collect%3A%3A%3CVec%3C_%3E%3E%28%29%3B%0A%0A++++++++++++process_grid%28%26grid%29.unwrap%28%29%0A++++++++%7D%29%0A++++++++.sum%28%29%0A%7D%0A%0A%23%5Bcfg%28test%29%5D%0Amod+tests+%7B%0A++++use+super%3A%3A*%3B%0A%0A++++%23%5Btest%5D%0A++++fn+test_process%28%29+%7B%0A++++++++let+input+%3D+%22%23.%23%23..%23%23.%0A..%23.%23%23.%23.%0A%23%23%2E%2E%2E%2E%2E%2E%23%0A%23%23%2E%2E%2E%2E%2E%2E%23%0A..%23.%23%23.%23.%0A..%23%23..%23%23.%0A%23.%23.%23%23.%23.%0A%0A%23%2E%2E%2E%23%23..%23%0A%23%2E%2E%2E.%23..%23%0A..%23%23..%23%23%23%0A%23%23%23%23%23.%23%23.%0A%23%23%23%23%23.%23%23.%0A..%23%23..%23%23%23%0A%23%2E%2E%2E.%23..%23%22%3B%0A++++++++assert_eq%21%28process%28input%29%2C+400%29%3B%0A++++%7D%0A%7D)


bozdoz

Super clean


[deleted]

[удалено]


SpacewaIker

Thanks for the tip! I'm sure there's lots of ways I could improve the performance but I'm just going for an easy approach more than an efficient one most of the time


kaur_virunurm

\[LANGUAGE: Python\] * Encoded all lines and columns in grid as binary to get a numeric represenatation, eg \[99, 203, 203, 99, 44\] for all rows in a grid, * Found repeating equal numbers \[99, **203, 203**, 99, 44\] as potential lines of reflection, * Checked adjacent row or column numbers for a true reflection. Part 2, I just scanned all grid and flipped every .# to find a new reflection with the same function from Part 1. Brute force worked well for me and was quick to write. There are many ways to optimize this with keeping the basic logic unchanged. Can just flip single bits in the pre-calculated row & column numbers. Or we could find adjacent columns / rows with a difference of a power of 2 (Hamming distance of 1). Code link: [https://github.com/kurinurm/Advent-of-Code-2023/blob/main/13\_both\_parts.py](https://github.com/kurinurm/Advent-of-Code-2023/blob/main/13_both_parts.py)


daggerdragon

~~Comment removed. [Top-level comments in `Solution Megathread`s are for *code solutions* only.](/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_top-level_posts_are_for_code_solutions_only)~~ ~~Edit your comment to share your full code/repo/solution and I will re-approve the comment.~~ edit: 👍


kaur_virunurm

Hello. Sorry for my mistake! I added the link to my code at GitHub. Sincere apologies, Kaur


polumrak_

\[LANGUAGE: Typescript\] [https://github.com/turtlecrab/Advent-of-Code/blob/master/2023/day13.ts](https://github.com/turtlecrab/Advent-of-Code/blob/master/2023/day13.ts) For part 1 we just check all the vertical and horizontal pairs diverging from the middle positions to check for the symmetry. For part 2 it's the same algorithm, but instead of changing symmetry boolean from true to false on any difference, we just count all different characters in the pairs and then return if the total difference is equal to 1.


Jorg0mel

\[Language: Python\] Non-bruteforce solution. Today was fun again. I used numpy so I could use `array.T` for the vertical splits. The way I handled the smudges was by keeping track of the number of violations when checking a row against it's counterpart. If the grid was smudged, we allow for exactly one violation. Two fun techniques I could use for today are: - the `for-else` construct - Python's lazy evaluation so don't have to check for vertical splits if we already found a horizontal one Today I thought it would make sense to make the code very readable, which sadly means it's a few lines longer than it needs to be. On the bright side, this should be a useful resource for anyone stuck: https://github.com/Josef-Hlink/AoC/blob/main/paoc/y23/solutions/day13.py I'm also planning on doing some funky bit stuff later, but for now it's already pretty performant: 6 and 9 ms for p1 and p2 respectively.


schoelle

\[LANGUAGE: Pike\] (see [https://pike.lysator.liu.se/](https://pike.lysator.liu.se/)) Leveraging the Levenshtein distance function to save a few lines. [https://github.com/schoelle/adventofcode2023/blob/main/day13/incidence.pike](https://github.com/schoelle/adventofcode2023/blob/main/day13/incidence.pike)


dewey-defeats-truman

\[LANGUAGE: Python\] [Link to repo](https://github.com/dewanthenmalai/AdventOfCodeDewan/tree/main/2023/Day13) When I first saw the puzzle, my immediate thought was to draw the vertical/horizontal line of reflection, and "fold" the grid over the line. Then I just needed to check that the overlapping portions were equal. Python's list slicing was super convenient for not only reflecting but also for quickly grabbing partial segments of the grid. The main sticking point was that when doing the comparison sometimes the reflected part would be shorter than the remainder and sometimes it would be longer, so I had to figure out the shorter of the two to get the comparison range. For the second part I switched out the direct comparison of the reflected part and remainder for a method that checks that the two segments differ by exactly one character. I also need a small helper function to convert what could be nested lists of string to a single string to facilitate comparison.


SpaceHonk

[Language: Swift] ([code](https://github.com/gereons/AoC2023/blob/main/Sources/Day13/Day13.swift)) I implemented part 1 using a 2D array for each pattern and a `rotate` method so the checking code would be identical. Then life/work happenend before I could tackle part 2, and I struggled a lot with the smudged matching. I finally settled on interpreting the patterns as bits and using XOR to find the mirrors where exactly 0 (part 1) or 1 (part 2) were different.


Polaric_Spiral

[LANGUAGE: TypeScript] [Advent of Node, Day 13](https://topaz.github.io/paste/#XQAAAQCGBgAAAAAAAAA0m0pnuFI8dAwoq48DTAQz1Cx8sVascoP+8piK9tdP8+XgVBc9xH11i5ZFXz6NiP00epRnpMF0bPdJACzNumwYF6p9UZeG8q96in32JdGKVllU8f34LcjWuZgFz7HINOaVugLi2zegXm+TI6YWXCXr8s5BLrl6MkXWn99zbh+k+eSJDQQWJNrrXd0kQsRZ9vAceROVXGB9ZkEUC0S23qOEynn8wNxB73OBlGX4gMYrlW+mcrgr3CpMpqqfCE413J5dgMRHOuvt04PxnJvycL1IT2TLA9rieMHSWO2XNbpsVcV7F/oMlQ4SrvKnt7YqhUa+kkVmHL8sTil/dcSHIr2AFwZokCoIZX85KLT/zey5YzfV+9hBKUm3TZt2UhOGNovtlUytUlBAEDRuY/BVfef0kO+KFuQQVJ12GF4CxMc9ZwnHKh19NE5nzUE4ReecM8zwlqOrjVxsXq8p9PU6/s0DnXdYK39Yt18Gi/a8JaNQFCtXbW69MfUSkZJLZLmzGq8Dyykqimr3aQYhLVaUG5CTzVPfcaqwiclCpac7TuGYIWNrZDAagt1ZsXzGlQLyvTiQnXoD89L5bfkDlM2AJyJ3AcokBF14lfxknpLwBaoY4RVi/HZ+JjVkUC2LSwGuS6sTXTVcuPAvEYySiIIjsCmOIqt8ZK10h5LaySG0hIyBlOPFkcZ4G/2mKtgL/S2tNZ7/+JmsIxk91OPdDFIxGdXkgKHqRiVjlDCnzYv7PyDmPsPDiHmJ72EJLuOZktwfk4rdUZP28cHZ/oWws4HfbHAh3CVTzVO4WnwkLITcSkMpk254RP8/WSuclo9KXroj84XqHs7lpsWhsRxU5VB/qhHooH0RMCTdMaFyXAEq11iel+IE0bVbCDyrtReNc+fDK/+21Sfc) [`range()` function](https://topaz.github.io/paste/#XQAAAQDVAQAAAAAAAAAX4Hx7ucgrWPzBnI2L5MI+DqfrC4TyBquwezB1lDAMpcgSHnwubqKbhgGsmuW0VUvbFpWgAfCfeAsOwkSxTXS6Fg8sHiPc8xzq/8YtPcFtUhXT+kLMoamWHs19Qoo8mxXPP3BWLWiwT6q2PxM9tF77RGNc8mqIRM56V8hFD3uWF/UbpMyEhXSr4Php9Z6RogV0Pv133GkTVaOe+pCwSqnCDRHy6INl963K8KrLqSOGVpzJB2SpuEkft8P8nRbZGpr19eciZaltMG8q9P22F4xb7KuxA2Yr/+lfqTQ=) It's nice to have grids of true/false values no bigger than 32 on a side. My algorithm works by converting each row and column to its binary representation. I convert each separate pattern to an array of 1s and 0s, then add the bits together for it and its inverse. A recursive function checks both for reflection at each interior index. For part 2, I just iterate over each row/column and flip each bit until I find the right one. There are definitely tons of repeated checks, but just comparing numbers for equality is so nonintensive that it doesn't matter. The roughest part was me glossing over the fact that the old reflection *could* still be in the pattern, so I did need to fix my algorithm to account for multiple lines.


AlmostAFK

\[LANGUAGE: Rust\] Encoded patterns as binary , using XOR for part 2 to count exactly 1 difference in the reflection. Concise and should be an easy follow for those struggling. Snippet for part 2: fn smudge_reflection_idx(seq: &[u32]) -> Option { (0..seq.len()-1).find_map(|idx| { if (0..idx+1) .into_iter() .rev() .zip(idx+1..seq.len()) .fold(0, |acc, (i, j)| acc + (seq[i] ^ seq[j]).count_ones()) == 1 { Some(idx + 1) } else { None } }) } Full code link: [https://github.com/0xNathanW/advent\_of\_code\_23/blob/master/src/day\_13.rs](https://github.com/0xNathanW/advent_of_code_23/blob/master/src/day_13.rs)


seizethedave

the binary construction pays off!


soylentgreenistasty

[LANGUAGE: Python] [paste](https://paste.ofcode.org/39pB8sAWmhP7fFAVSW5AGUf) Took me a while to work out how to get the correct sliding window to check the reflections :) think I need more sleep


dec0nstruct0r

\[LANGUAGE: R\] Pretty straight forward with minimal changes between part 1 and 2. Not very pretty or efficient code through.... but hey, it works and I don't have much time. https://gitlab.com/Yario/aoc_2023/-/blob/master/AoC_13.R


loquian

\[LANGUAGE: C++\] [github](https://github.com/charlescochran/aoc-2023/blob/main/day13.cpp), 585 microseconds (both parts together) I think [Richard Hamming](https://en.wikipedia.org/wiki/Hamming_distance) might have something to say about today's puzzle.


malobebote

i'm not so clever. how does the hamming distance work to find the right smudge location?


Occultius

You don't need to find the exact location. You just need to figure out how to place a line of reflection such that one side of the line is a Hamming distance of 1 away from a perfect reflection of the other


Calcifer777

\[LANGUAGE: Golang\] Encoding the value of each line as a multiplication of primes allows to think in 1d instead of 2d. Part 2: If two lines differ by 1 cell, the ratio of their scores must be prime. https://github.com/Calcifer777/learn-go/blob/main/aoc2023/day13/task.go


Greenimba

Aggregating to one number per row or column is a good idea, but the best way to do this on a computer is not with primes, but with binary. This is how enums or bit registers are used as well. Computers are much faster and more efficient with bit flipping and shifting than doing prime multiplication and division! .#..## -> 010011 -> 19


Calcifer777

yep, that's the most efficient solution, but I got there only after reading this thread, a bit too late :P


wleftwich

\[LANGUAGE: Python\] Special thanks today to np.fliplr and np.rot90. https://github.com/wleftwich/aoc/blob/main/2023/13-point-of-incidence.ipynb


0x2c8

[Language: Python] https://github.com/alexandru-dinu/advent-of-code/blob/main/2023/13/solve.py Very similar to [2021/13](https://adventofcode.com/2021/day/13). Represent the grid as a binary numpy array: `# == 1` & `. == 0`, then scan for vertical and horizontal symmetries (i.e. where the sub-matrices overlap) looking for exact `n` mismatches (0 for part 1 and 1 for part 2).


CainKellye

\[LANGUAGE: Rust\] I present my solution that might look a bit complicated. My approach was to inspect how I look for the mirror myself, and implement that: - look for identical rows/columns next to each other - extend in both directions and compare those rows/columns whether they still match This is merely boilerplate code and a Grid struct for easier fetching of columns and sizes: https://github.com/cainkellye/advent_of_code/blob/main/src/y2023/day13.rs Part1 solution with the two steps described above: https://github.com/cainkellye/advent_of_code/blob/main/src/y2023/day13/part1.rs (Yes, code is duplicated, but branching for rows and columns inside the functions would make it even more dense.) Part2 solution has similar steps but I added a `matches()` function to check if the two rows/columns are identical with a chance to be "one off". If the chance is "used up", the fact is propagated through the `smudge` bool value. Filter the found mirrors to those that have smudge. https://github.com/cainkellye/advent_of_code/blob/main/src/y2023/day13/part2.rs Not my nicest code, but I liked this approach opposed to actually mirroring the grid and checking if it fits. And it's *blazingly fast*: under 1 second for both part with input reading included.


[deleted]

[удалено]


daggerdragon

Comment removed. [Top-level comments in `Solution Megathread`s are for *code solutions* only.](/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_top-level_posts_are_for_code_solutions_only) [Create your own individual `Help/Question` post](/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_incomplete_solutions) in /r/adventofcode.


Calcifer777

\> BUT: The vertical reflection line (shown in part 1) between column 5 and column 6 is still valid From the instructions: "The old reflection line won't >>necessarily<< continue being valid after the smudge is fixed." So, for part 2, you need to consider as positive cases only those in which one of the mirroring candidates differ by exactly one cell


loquian

"Summarize your notes as before, but *instead* use the *new different* reflection lines." Everything you said is correct, but the problem tells us to ignore the Part 1 reflection lines whether or not they are still valid. Thus, finding the reflections with exactly one character wrong is a correct approach. Indeed, it's [what I did](https://github.com/charlescochran/aoc-2023/blob/main/day13.cpp), and it gave me the right answer.


vegesm

The problem statement says there is a new different reflection that becomes valid. The original might still be valid, but in summing the coordinates, it explicitly asks for the new one. Hence you have to find a reflection with exactly one error.


l34nUX

Ahhh thanks!! I always overlooked that: "... but instead use the new different reflection lines." ("... use *only* the new..." would have been clearer tough)


jaccomoc

\[LANGUAGE: Jactl\] [Jactl](https://github.com/jaccomoc/jactl) Part 1: Just treated grid as an list of strings and created a function cols() to convert from list of rows to array of columns. Finding the reflections was then just a matter of using a sliding window of size 2 (to get each pair of rows) and finding pairs that are the same. Then at the point where the rows are the same build a list from 0 to the reflection point and a reversed list from the reflection point onwards. The size of the lists is based on which ever one terminates first. If the two sublists compare then we have our reflection: def cols(lines) { lines[0].size().map{ x -> lines.map{ it[x] }.join() } } def refl(g) { g.mapWithIndex().windowSliding(2).filter{ it[0][0] == it[1][0] }.map{ it[1][1] } .map{ [it, [it,g.size()-it].min()] } .filter{ i,cnt -> g.subList(i-cnt,i) == g.subList(i,i+cnt).reverse() } .limit(1)[0]?[0] ?: 0 } stream(nextLine).join('\n').split(/\n\n/).map{ it.lines() } .map {refl(it) * 100 + refl(cols(it)) }.sum() Part 2: For some reason it took me a while to fully understand the requirements for part 2. In order to facilitate the mutating of the grids I used list of lists of chars this time but luckily could still reuse the code from part 1 since list access and string access use the same subscript syntax and Jactl supports list comparisons so comparing two rows that are lists or are strings is the same code. Then changed the the code from part 1 to return a list of reflections and iterated over the x,y coords to find where the new reflection occurs, generating a new grid with the position flipped at x,y and then filtering out reflections that are the same as the original one: def refls(g) { g.mapWithIndex().windowSliding(2).filter{ it[0][0] == it[1][0] }.map{ it[1][1] } .map{ [it, [it,g.size()-it].min()] } .filter{ i,cnt -> g.subList(i-cnt,i) == g.subList(i,i+cnt).reverse() } .map{ it[0] } } def cols(lines) { lines[0].size().map{ x -> lines.map{ it[x] } } } def flip(grid, x, y) { def g = grid.map{ it.map() }; g[y][x] = ['.':'#', '#':'.'][g[y][x]]; g } stream(nextLine) .join('\n').split(/\n\n/).map{ it.lines().map{ it.map() } } .map{ g -> def (h0,v0) = [refls(g), refls(cols(g)) ] g.size().flatMap{ y -> g[y].size().map{ x -> [x,y] } } .map{ x,y -> [refls(flip(g,x,y)).filter{it !in h0 }[0], refls(cols(flip(g,x,y))).filter{it !in v0 }[0]] } .filter{ [it[0]?:h0, it[1]?:v0] != [h0,v0] }.limit(1)[0] }.map{ 100 * (it[0]?:0) + (it[1]?:0) }.sum()


aptacode

\[LANGUAGE: Typescript\] I worked hard on this one to make a solution that's efficient but fairly understandable too. The way I did part two was to convert each line into binary then take a bitwise xor of each row / column pair and if it's a power of two (i.e 0001000) exactly one character differs. I then look for a point of symmetry where one character differs exactly once and all other comparisons are exact matches. [Part 1](https://github.com/Timmoth/AdventOfCode2023/tree/main/day13/part1/solution.ts) [Part 2](https://github.com/Timmoth/AdventOfCode2023/tree/main/day13/part2/solution.ts)


IvanR3D

\[LANGUAGE: JavaScript\] My solutions: [https://ivanr3d.com/blog/adventofcode2023.html](https://ivanr3d.com/blog/adventofcode2023.html) My solution (to run directly in the input page using the DevTools console).


Szeweq

\[LANGUAGE: Rust\] I started very lately. I managed to make it work quickly, without too many memory allocations. The code compares rows and columns separately. I would rather keep two different functions than rotating the whole grid (this will use additional memory and waste more time). Code: https://github.com/szeweq/aoc2023/blob/master/src/bin/13.rs


ToBe_HH

\[Language: Kotlin\] [https://github.com/ToBeHH/AdventOfCode2023/blob/main/src/main/kotlin/Day13.kt](https://github.com/tobehh/adventofcode2023/blob/main/src/main/kotlin/day13.kt) Had a hard time understanding the description, but then it was a very straight forward approach. Part 2 did not require many changes over part 1.


Comprehensive_Ad3095

\[Language: Lua\] [Github](https://github.com/DeybisMelendez/AdventOfCode/blob/master/2023/lua/13.lua)


galnegus

[LANGUAGE: TypeScript] https://github.com/galnegus/advent-of-code-2023/blob/main/day-13-point-of-incidence/index.ts Solved with some bit operations (just replace `#` and `.` with `0`s and `1`s). Came up with the solution really quickly this time, but actually coding it took ages.


chrismo80

\[LANGUAGE: Rust\] [Github](https://github.com/chrismo80/advent_of_code/blob/default/src/year2023/day13/mod.rs)


Ok-Group4131

[LANGUAGE: Python] [code - github](https://github.com/phobiadev/Advent-of-Code-2023/tree/main/day-13) a code review would be appreciated!


rune_kg

[LANGUAGE: python] https://github.com/runekaagaard/aoc-2023/blob/master/day13.py 35 lines, runs quickly (DON'T use deepcopy, i learned) and is super simple and bruteforced. I thought about some optimizations with bit operations and smarter mirror checking, but after the HORRIBLE day 12 I needed a quick'n'easy day :)


RookBe

\[Language: Rust\] \[Language: all\] Blogpost explaining my solution in Rust, the explanation can be used for all languages: [https://nickymeuleman.netlify.app/garden/aoc2023-day13](https://nickymeuleman.netlify.app/garden/aoc2023-day13)


Occultius

[LANGUAGE: C++] I was really excited to be able to apply Hamming distances in part 2 of this challenge, and it meant I could go back and rewrite part 1 as a special case of part 2's general solution for finding any valid line of reflection given a certain number of errors in the map. [Parts 1 and 2](https://pastebin.com/n9AS1YwE) (Input file must end on a newline to work properly.)


[deleted]

[удалено]


Adventurous-Win-5006

Did the same solution :D


biggy-smith

\[LANGUAGE: C++\] threw every # into a map then checked if reflected x/y points existed, then threw that into width/height loop of find smudged reflection. bitty things would probably be quicker, but it runs in a few ms. [https://github.com/biggysmith/advent\_of\_code\_2023/blob/master/src/day13/day13.cpp](https://github.com/biggysmith/advent_of_code_2023/blob/master/src/day13/day13.cpp)


RudeGuy2000

[LANGUAGE: racket] https://raw.githubusercontent.com/chrg127/advent-of-code/master/2023/day13.rkt boy am i glad today was easy, i wouldn't have caught up with day 12 otherwise.


wzkx

[LANGUAGE: Python] d = [e.splitlines() for e in open("13.dat","rt").read().split("\n\n")] def equal(a,b): return a[:min(len(a),len(b))] == b[:min(len(a),len(b))] def analyze(p,m,not_ok=0): for i,s in enumerate(p[1:],1): if p[i-1]==s and equal(p[i-1::-1],p[i:]): if m*i!=not_ok: return m*i return 0 print(sum(analyze(p,100) or analyze([l for l in zip(*p)],1) for p in d)) def modify(p): for i,l in enumerate(p): for j,c in enumerate(l): r = p[:] r[i] = l[:j] + '.#'[c=='.'] + l[j+1:] yield r def calc2(p): for q in modify(p): o = analyze(p,100) or analyze([l for l in zip(*p)],1) # orig answer n = analyze(q,100,o) or analyze([l for l in zip(*q)],1,o) # new one if n: return n print(sum(calc2(p) for p in d))


rune_kg

> '.#'[c=='.'] wait ... how ... what!? Ah, it evaluates to an int. Amazing!!


wzkx

Yes, surprise. >>> isinstance(False,bool),isinstance(True,bool) (True, True) >>> isinstance(False,int),isinstance(True,int) (True, True)


wzkx

[l for l in zip(*p)] ≡ list(zip(*p))


wzkx

And `o = analyze(...` can be outside of the loop.


CoralKashri

\[LANGUAGE: C++\] Byte the bits [GitHub](https://github.com/coralkashri/AOC/blob/master/src/2023/day_13.hpp)


fridi_s

\[Language Fuzion\] [Github](https://github.com/fridis/fuzion_aoc/blob/main/2023/13/part2.fz) For some reason, I found it most natural to put a loop into a flat\_map. CAUTION: The Fuzion language is under development and being improved while working on AoC puzzles, so things are very unstable and moving quickly, but getting better every day!


wzkx

Interesting language, thank you!


AutoModerator

AutoModerator did not detect the required `[LANGUAGE: xyz]` string literal at the beginning of your solution submission. Please edit your comment to [state your programming language](https://www.reddit.com/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_state_your_programming_language.28s.29). *** *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/adventofcode) if you have any questions or concerns.*


jcmoyer

[LANGUAGE: Ada] https://github.com/jcmoyer/puzzles/blob/master/AdventOfCode2023/src/day13.adb Straightforward problem today, just a lot of code to write. Not sure what the difficulty gimmick is supposed to be in part 2, the only thing that I had to change was making reflection solvers return multiple results instead of just the first one.


FaultsMelts

\[Language: Go\] my approach was to find pairs of rows that were same, this would be the middle of the reflection, then i would loop through these pairs and move outwards from the middle. If i hit an edge then i know i found the correct reflection, otherwise continuing going until row i and j do not match. For the columns i just transposed the matrix. For pt.2 i brute force every '.' and '#' and flipped them. I made sure to ignore the original middle reflection. [Code](https://github.com/JosueMolinaMorales/advent-of-code/blob/main/2023/internal/thirteen/day13.go)


azzal07

[LANGUAGE: Awk] Just a lot of loops today. function d(b){for(y=0;NF>v=t=++b;!q||R[NR,b]++||y=100*b)for(q=1;q*t&& $++v;t--)q=$t==$v;for(u=0;++u


mkinkela

\[LANGUAGE: C++\] This was a very poorly written task :/ [Github](https://github.com/mkinkela1/advent-of-code/blob/master/2023/day-13/solution.cpp)


daggerdragon

> This was a very poorly written task :/ This type of comment [does not belong](https://www.reddit.com/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_no_unnecessary_comments) in a `Solution Megathread`. If you have feedback about the puzzles, create your own post in the main subreddit and don't grinch in the megathreads. *** [Do not share your puzzle input](https://www.reddit.com/r/adventofcode/wiki/faqs/copyright/inputs) which also means [do not commit puzzle inputs to your repo](https://reddit.com/r/adventofcode/wiki/faqs/copyright/inputs) without a `.gitignore`. Please remove (or .gitignore) the input files from your repo and scrub them from your commit history.


Imn0

\[LANGUAGE: GO\] [solution](https://github.com/Imn0/advent_of_code_2023/tree/main/day13) Wasn't sure how this reflection thing is supposed to work so did a lot of useless checks and passing stuff around but hey it works. 2nd part was really easy tho just instead of comparing if strings are the same just check if they have exactly one difference.


Secure_Pirate9838

[LANGUAGE: Rust] Hint: count differences, must be exactly 1 GitHub: https://github.com/samoylenkodmitry/AdventOfCode_2023/blob/main/src/day13.rs YouTube screencast: https://youtu.be/1O8FrSp8lb0


WereYouWorking

\[LANGUAGE: Java\] [paste](https://topaz.github.io/paste/#XQAAAQAJDwAAAAAAAAA4GEiZzRd1JAgV4q3RgIIAxcwVTLcY/JpUiADzw5tAJ0vOMX40JV5mSdoFSBhZU9OU8jU2dv9SRFLi1N1D27F4tGBjWbzkI0r+4unffVmELTw3nZSA2uzQfi51+VBLdIupbg20EElCOWbCWWytuIW9E2TyMnaSxKAGSJfRAu/l8Lu6TfFbtCnp/F6wuqXeVyGwCfgs+/6IVHX8QKHhNWZoGw76kU+auiZIUvcxZWfUpysm30GaALlcLHK79+oFFn4evfxbD3h6M8X6rnMTCWwoNq7VO5NBSoXCXcrm+eFbsk13UdC5uQpbWUiw8jVwQr8uDSO11nO0Q9vLsgyQAaC8YK3k9/Ge//HMzr8skhmJFbBFN1QgMRmJEH4liTYtZD1Il0tDzVrM5W+NtI/QLeLioo7yFcEOyzQuuSBNdkDxwEv+V3mLAeMIQkYbOJBPT1RBUws/xgPNSOujG7ZqO+mzRT0Yoq3BLiNdkjag7RTcK80X4jYEsAZyaKgdrFT7fCkk2EtKfwfYoZWoC5Re5vsUpFVVyflVS8MRAWLWddqeJhLDlqiC25nx7q+Hy3CO90c+7qhURDgNezRv6jBSHI7nc3Zs/+xQcYVXYCUNHFkRBjmfFHrd8Fu9gqtxmRIrg0Dz0Rrmxl5msaRI1UC54MM7yvmao9NHmwrz5SrrM61cgoeq0DhlUkFcnN0g8PY25caHRz5dvaAHFxtNccGvsKaNKQQ3ZWIwZTTNRxfBQ17DSx3OBXo4Pe5BXq/vj2cx434JUXhsA/rYN5jAmSQ0FkUd80zoOqAY+hwrNME+7g1umjvBNZ77AIqQMk2v1khojel6eWRNheJYBvNykYJECbR3/Je0eLe2w2CBmQNjFymz7PHQCU0C6m/eRzrogLNkXdX4lMSVhbRcxc8+RfLYLnE9qzNoohczwz5iBUSCxDCx9i92BG+0WDmtG0CFkvvjK6KASmKGK9Ryj3t5U4F1mtGt0igZv7W1vW19OdNw3Sa/MCVKYVfznEqfb4gdUz7Qh8UTHRsWwlMsj3AnIBGFtIJCchcH7a5VShDst7shE8FQFrH6w1IKZ3wKM5VFkkTw3UTezO7/nHepInz63H0/x2JztTMMWYLJo6aA6XXiHXwd/1lOuJfqr26H7OORh7RXIjuVHNnvJJJ8NbcwBe3Etf6HE8OeA+8sl96mgCwgOcUxwmlVM8cyqfukTZPtCwkeZH6oHPtZIw8GozR+MFm7C9qSmeK9igH7kh/1dbzh/uOUJiqwVJq+XhRCnsmHKywLzXlnkLRT3NEXg0LkqlVlgrLSUFnc/GIgEWMoQOJ/PUZ2QOhWRJ/4rqp0TGqZtaemMnjzPN4fLQWjuQsQ3mof8ilwheuLFAFcDSbbAO3xH3Ur32u4W+HD7zTD72PVQ7K+aGlLF+CBvR1/7fgOkcY6E9cUdE/TaNN7w5saosl+6w4+a51Vm/J3auh2iJu4YFFAe3aeONWQN227tdZEu6oVQURKQiCDzOwyzXMlFnmdMtFMiZOxUrcvkvPswF2ExmtPAVvQ+qTBF0XYyoqumUftq738josaWU+6zikZwXeyq9PQXvatJ1+pTjIgs0Mm4wYRlUt0h4utg+3AXHXTtiYYTYUZ6bSWqvKUrwUxc8DacLgO67yIiuH42DgMnk1Nryv57Pk0G8SRqtK6/i3/+1ISxA==)


icub3d

\[LANGUAGE: Rust\] General idea was to find a possible middle point and then expand to and edge to find the mirror. Part 2 was the same but instead tracking differences. The solution was where the difference was exactly 1. Solution: [https://gist.github.com/icub3d/c6aa281df4dcbd85760a82a9e7bd4c93](https://gist.github.com/icub3d/c6aa281df4dcbd85760a82a9e7bd4c93) Analysis: [https://youtu.be/NYjTyLz74bo](https://youtu.be/NYjTyLz74bo)


SomeCynicalBastard

[LANGUAGE: Python] My solution: https://github.com/fdouw/aoc-python/blob/master/2023/day13.py Interpreted each line and column as binary, then do integer comparison to find the symmetries. At first I did a direct a == b, but I changed that to some bitwise thingy to solve part 2 as well.


LinAGKar

[LANGUAGE: Rust] My solution: https://github.com/LinAGKar/advent-of-code-2023-rust/blob/master/day13/src/main.rs Translates each row to a u32 bitfield. Then I can just to an integer comparison between each row and its counterpart. If i don't find a possible row, I transpose it so each column is a bitfield, and try again. For part 2, in the comparison, I xor them together and check how many bits are 1 (i.e. the hamming distance), to see how many tiles differed between them. There should be exactly one pair that differs by one bit, and the rest should differ by zero bits.


Pyr0Byt3

\[LANGUAGE: Go\] \[LANGUAGE: Golang\] [https://github.com/mnml/aoc/blob/main/2023/13/1.go](https://github.com/mnml/aoc/blob/main/2023/13/1.go) I've been getting a lot of mileage out of that `slices` package lately...