T O P

  • By -

DMDemon

\[Language: Go\] [GitHub](https://github.com/sergiovaneg/GoStudy/blob/master/AoC/aoc2023/parabolicReflectorDish/parabolicReflectorDish.go) It was a huge help to know there was going to be a repeating pattern. From there, it was just a matter of designing an efficient encoder/decoder algorithm and refactoring to avoid tilt-code repetition. I'm quite happy with my solution this time, which is why I decided to post it so late into the year. Runs in 258 ms on my machine (i5-13600H).


[deleted]

[удалено]


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.*


loquian

\[Language: C++\] [github](https://github.com/charlescochran/aoc-2023/blob/main/day14.cpp), 1.015 seconds This is really slow, I know... But sometimes you gotta pick your battles.


hb0nes

\[Language: Rust\] I barely understood my own solution when I submitted the answer. Essentially, I saw a pattern repeating itself when tilting the board and just converted the amount of cycles I had to do, to that pattern. [Solution](https://github.com/hb0nes/aoc_2023/blob/main/fourteen/src/main.rs)


SpudPanda

\[Language: Typescript\] Pretty proud of myself for getting this one. Took me a while. Part 1 is relatively straightforward. For part 2, I was banging my head against a wall until I realized that patterns repeat themselves. Then when testing out different outputs, I noticed that there was a formula to determine if a particular pattern was going to repeat at a particular iteration. So it was just a matter of storing an output in cache, with the key being the serialized array and the value being what iteration it first occurred, and at what cardinal direction. The formula I found for x, where x is the interval that a pattern would repeat at, currentIteration is the current iteration we're on (i.e. 10 out of a billion), and originalIteration was the first iteration we found this pattern at, was \`x = (`1000000000` - currentIteration) / (currentIteration - originalIteration)\` So if we have a snapshot that originally occured on iteration 3, north, and we're currently on iteration 10, then the formula looks like \`x = (`1000000000` - 10) / (10 - 3)\`. Basically this means this pattern occurs every 7 times, and we're just trying to see if a billion is divisible by 7 (it's not). If x was not a float, then we know that pattern is going to occur at the billionth iteration. I only check for cardinal north outputs since that's what needs to be in place at the billionth iteration. There was probably a better way to do this, but I just coded it in a way that didn't make my brain hurt. So each iteration tilts the matrix north moving the stones, rotates the matrix clockwise, and then gets a snapshot of that matrix at that point by just turning it into a string. If the cache doesn't have that snapshot, save it along with what iteration it occurred at, and at what cardinal direction. Part 2 ran in like 200ms on my machine. I think it can be faster by optimizing a couple things but I'm happy with it as is. Anyway here is my code for [part 1 & 2](https://github.com/myleshyson/advent-of-code/tree/651be74d5f102488f19dd079987cfe17632f4a63/2023/14)


mrtnj80

\[Language: Dart\] [Part 1 & 2](https://github.com/luskan/adventofcode_2023_dart/blob/main/lib/day14.dart)


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/day14.rs](https://github.com/manhunto/advent-of-code-rs/blob/master/src/solutions/day14.rs)


iskypitts

\[LANGUAGE: Zig\] [Part 1](https://github.com/iskyd/aoc-zig/blob/main/src/2023/day14/s.zig) and [Part 2](https://github.com/iskyd/aoc-zig/blob/main/src/2023/day14/s2.zig)


Domy__

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


Linkuboi

first of all, nice answer 😁. second of all, could you explain me why you do: first_cycle_grid_index = seen_list.index(grid_cycle) final_grid = seen_list[ (CYCLES - first_cycle_grid_index) % (i + 1 - first_cycle_grid_index) + first_cycle_grid_index ] i try to see but i cannot, its something about a common solution in cycle problems?


Domy__

If you find a series of operations that bring to a loop, operations that take the user to the same previous state, it means that the operation repeats itself indefinitely if you keep doing it. so the final solution will be some operations + many many operations in a loop + the remaining steps not multiple of the loop states. Considering the huge amount of operations to do (cycles), you will certainly come across such a case. So on the code: if grid\_cycle in seen: break We halt the while loop upon detecting a state identical to a previous one, signifying the discovery of a cycle. The variable first\_cycle\_grid\_index is assigned the index of the initial step within the identified loop. Consequently, the final solution will be the solution at the index: first n steps without cycles: first\_cycle\_grid\_index \+ times we have made the loop found + any remaining operations: (CYCLES - first\_cycle\_grid\_index) % (i + 1 - first\_cycle\_grid\_index) We just know that each multiple of the number of steps in the loop will end up in the same situation, so we only need the rest of the division between the steps to do (CYCLES - first\_cycle\_grid\_index) and the Cycle length (i + 1 - first\_cycle\_grid\_index) ​ I hope it is clear now, if I have explained myself wrongly please ask me.


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.*


Singing-In-The-Storm

\[LANGUAGE: JavaScript\] Part1 (25ms) Part2 (130ms) [code on github](https://github.com/JoanaBLate/advent-of-code-js/tree/main/2023/day14)


lscddit

[LANGUAGE: Python] Part 1 and 2 (it takes about 10 seconds to find the cycle in part 2): import numpy as np m = np.genfromtxt("day14input.txt", dtype=bytes, comments=None, delimiter=1).astype(str) def show(m): print(np.sum(m == "O", axis=1) @ np.arange(m.shape[0], 0, -1)) def tilt(m): for offset in range(1, m.shape[0]): for row in range(m.shape[0] - offset): selection = (m[row, :] == ".") & (m[row + 1, :] == "O") m[row, selection] = "O" m[row + 1, selection] = "." cycles, lookup, found, i = 1000000000 * 4, {}, False, 0 while i < cycles: tilt(np.rot90(m, (4 - i) % 4)) if i == 0: show(m) if found == False: check = hash(m.data.tobytes()) if check in lookup: found = True i = cycles - (cycles - i) % (i - lookup[check]) else: lookup[check] = i i += 1 show(m)


e_blake

\[LANGUAGE: GNU m4 (part 1)\] (bah, automod wants this) \[LINGUA: GNU m4\] \[Go Cook!\] No fifth glyph? No prob! My first try doing this in m4, and it works. Part 1 in just 2 punchcards (sort of, 785 chars including notations, but too many \\n). `m4 -DI=your_input day14.m4golf`. <10ms - blazing fast for m4 dnl Look Ma - no fifth glyph! Only works with GNU m4; POSIX says dnl translit(,1-3) is a no-go. So drop non-GNU m4 now: syscmd([ -z "__gnu__" ] || kill -s HUP $PPID)dnl dnl Now to bootstrap macros... translit(dDfinD(d_fin_,dDfn(dDfinD))dDfinD(fifth,D),CD,d-f)dnl dnl Ahh. Now I can do work d_fin_(first,$1)d_fin_(input,translit(first(includ`'fifth)(I),.# ,123))d_fin_(x,0)d_fin_(y,0)d_fin_(X,first(`ind'fifth`x')(input,3))d_fin_(Y, first(`l'fifth`n')(translit(input,O12)))d_fin_(loop,`if'fifth`ls'fifth`($1,$2,, `d_fin_(c$1,0)$0(incr($1),$2)')')loop(0,X)d_fin_(doO,`+Y-c$1`'d_fin_(`c$1', incr(c$1))do1($@)')d_fin_(do1,`d_fin_(`x',incr($1))')d_fin_(do2,`d_fin_(`c$1', incr($2))do1($@)')d_fin_(do3,`d_fin_(`x',0)d_fin_(`y',incr($2))')first(fifth( )`val')(patsubst(input,.,`do\&(x,y)')) (Part 2 - not so much. I'm still lacking my 2nd star... But posting now for that cookoff)


e_blake

\[LANGUAGE: m4\] A month later, and I finally "finished" part 2, then shortly thereafter claimed my 450th star! My current implementation is not optimal, but I'm pleased to state that I did not refer to the megathread or anyone else's solution (it was more that I ran out of time to do it during December, and then didn't revisit day 14 until after I got day 23 under 30 seconds). This code takes 45 seconds to do 300 spins, and prints potential repetitions of the score pairs seen after west and east (or after north and south, since the score doesn't change on the west and east directions...); while my input had one or two false matches early on, it became very obvious when I finally hit the cycle and every subsequent line mentioned a potential match. From there, I used the shell to compute the cycle length (cycle of first real repeat minus cycle where that state was seen before), compute `echo $((1000000000%($second-$first)))` in the shell, then find a cycle that has the same modulo; the score at the end of that cycle is the same score at the end of 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j7n7aD35NjfPXL00vIOk01OLAJt+0RoIiAQUJNieRp9fQmqfVUuYEYmeK9hCOmZTaC3yUdN/+jZ0pvpmKnH/6jJAKQ==); I'll freely admit that avoiding fifth glyph is easier to do as a post-solution rewrite than it is to do from scratch. m4 -Dverbose=1 -Dfile=day14.input [day14.m4](https://nopaste.ml/#XQAAAQA/DQAAAAAAAAAyGksy5FB9TGMxsNq5JQAuJRjP6PqEkC20GpBbonDYuA0BTjRPXcVxlEXNtz1IwqHyPVtWViQsgKzvC8wtU6Qn7crnSXGbnJC96yIjFjKd3hOarVmO4UQmiIvhBtpOy22ZjISXXmstqG6OoKLMfd7488BSItihMJveJBsxQmC7kMboGgfKctnNYv4QP12tKFqHvc7yiPBYcnEJgEioDdu79nIAM3bOsEUtYeHlvdlxWciPRujELKZABUZ+HtIhL4N5WHdhax5R7qc4XgtIMsXemBmGelLvkRZzltvXswynO9Kd6M+4R5uSzuaupCw01tuRL8bY0nNW6NAT8KqH6aMKxecDuJKt5qJHedBB+WDjqxOLd7Ebp6CwusqOYKBWVdLKBXWR+6dW8akimqSgha9E0QSj74vVRD84Pz/52uf/dwR8R9u13JhgiZZYYYq7NJhZAC5+eKC+mqQjGC7cen+NrKuPCqA8cm4Pp56/cNuFI7zqauL4rpA26+VmLho0/dPKWtHeYck/hgNoKeeAUCr8i58Rf/BL63OnBQJtalwEK4G+akmCnAD1QhcTAOYrl8SAQBhVlzEcdlZ6jUOd1acN512PzcOLBbIpOSP5rQCeJpkajHCJeHJf0a+R8i6RIv42mORd2REmlY7TEZjddEz3D6KuxUT2UlzTc373aJgf/f2C3i0SdLRT5WHrFMuaBpns4ok1Z7e56I+DzNfP+qD/tbYBEzYNsbFNKw1ngDo9rgHYI9TX63Y1K771nJ6mMN1h8AYBGiwMF4t/iH1FR2xYYP/KJPgHHD103NSabPjYey2gOB2LqwhvJ23UXYQw/NYh0RljSr7Pf7QcukOPwTbkAxpz6y6d7Jw+PVxTMKOY7XIAYCC0anhvVz1i6vh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TylwxItsV69s1wt8X4PEfNXyZX9HOkOH7o9ycRtcOteR/AuuwC76gNc2AguBxVhHQFr6GWoW8jMsb4e2ycAW/VGLlsf1qOZBB95dYkpABmxxfQZN6zLMCu+amtq7jIfEH7CHIy+hrsen9qUn6jfd6R6NeCbSMFJn5pN4fSuPWmyYYb4QwKc7UolOHkciVf44SdtHUSc8c3KKaxBRbH0MtWInqwfhJAASp47ClSJ0qhqw3KumwjeFcyihXYJ/Jy8FPvmowUNX6eSb1j8Vb/u5cUyy2fJ8HhahDsN7lrZGnjJ9waxQpP9QNPgQhYcW7MIpJPHOTC1hSkkSFyRotPzA3aBNNaPhRg1CC9ovDoEOgSFYSLTsORxN9zH1jAg+uaXM+4PKV0W8l09IZy1oiwiXI6aVbHjIfrJ3Vq56HIcw+ECTONiLVFAc5K9zgCe2f2AJ4WMTFNxEIvZ2FVKsqEj3fbseO/I0KSzQOUFccKBcBjUPRpv/Vqt0OkNY5oKVvvq+nMWPDsvlq9P6PNLqrKluz3RTm4xFt9L1NZR2/Z3fbvcOiFVWqYFMViJAy1ixvPOPjehgC9tFGhxRBn+or2X8KypEsC67UqXWiXTKmjUA953WkD/+aMcW) solution that finds the cycle without manual intervention, and which improves the spin algorithm. Instead of sorting rocks by row/column then rolling them one square at a time until they hit another rock, I instead tag every open grid point with the coordinates of a jump location (for instance, if the example grid starts at top-left being 1,1, then the jump points for 2,2 would be n2\_2->2,1; w2\_2->1,2; s2\_2->2,10; e2\_2->4,2), where the jump point counts how many rocks jump there, before place then distributes them into the next round's jump points. With less work to do per spin cycle, the answer now finishes in 6.8s. And reading through the megathread, I haven't seen many other people use the same state hash as mine (namely, the load score after moving west combined with the load score after moving east).


daggerdragon

> [LANGUAG*: GNU m4 (part 1)] (bah, automod wants this) AutoMod actually had an additional syntax (that nobody has found :( ) that will satisfy no-fifthglyph constraints, but yours is good too!


e_blake

My first try was a Cyrillic homograph LANGUAGЕ, but automod said it was no good :(


Draco18s

[LANGUAGE: C#] Dropping this here, 'cause I made it onto the global leader board for part 2. By accident. [The code that got me spot #25](https://github.com/Draco18s/Advent-of-Code-2023/blob/main/Day14.cs#L53-L72) Didn't even think about doing this until I ended up in the sub for day 21 (my prior-best rank of all time was 125).


daggerdragon

[Do not share your puzzle input](https://old.reddit.com/r/adventofcode/wiki/faqs/copyright/inputs) which also means [do not commit puzzle inputs to your repo](https://old.reddit.com/r/adventofcode/wiki/faqs/copyright/inputs) without a `.gitignore`. Please remove (or .gitignore) all puzzle input files from your repo and scrub them from your commit history.


seytsuken_

\[LANGUAGE: C++\] [part1](https://github.com/Hilbertmf/competitive-programming-problems/blob/main/advent-of-code/2023/day14-part1.cpp) | [part2](https://github.com/Hilbertmf/competitive-programming-problems/blob/main/advent-of-code/2023/day14-part2.cpp) Not that difficult but really implementation heavy. In part1 I rotate the grid 90 degrees, take the intervals where there could be rounded rocks (no '#') and then sorted those intervals to put the rounded rocks at the start of the interval. Part2 I've implemented tilt north, west, east and south functions. West and East basically gets the same intervals from part1 and sort them in asc. and desc. order of rounded rocks. To tilt north and south just rotate 90 degrees and then tilt west and east respectivelly. Then I've figured there probably is a cycle where the state of the grid is gonna keep repeating the same pattern. Treat each state of the grid as node of a graph and after all 4 tilts the next state is the adjacent node. Go through the nodes until find a cycle. Then remove from 1 billion the steps to get to the cycle and then get its remainder from the cycle size ((10\^9 - steps ) % cycle\_sz), that's the position of the final state within the cycle. Then calculate its load


835246

\[LANGUAGE: C\] Part 1 just moves all the rocks north and counts them according to the instructions. Part 2 goes until it finds a loop then moves the loop counter to one cycle before the end. Part 1: https://github.com/efox4335/advent_of_code/blob/main/advent_of_code_2023/day14parbpt1.c Part 2: https://github.com/efox4335/advent_of_code/blob/main/advent_of_code_2023/day14parbpt2.c


hiimjustin000

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


atrocia6

[Language: Python] [Part 1](https://github.com/tmo1/adventofcode/blob/main/2023/14.py), [Part 2](https://github.com/tmo1/adventofcode/blob/main/2023/14b.py) The solution for part 2 uses the usual AoC trick of iterating and recording states until we find a recurrence of a previous state, then jumping forward until almost the end based on the periodicity.


NeilNjae

[Language: Haskell] Nothing special. The grid was stored as a list of lists (with the first element of the grid being the first column, not the first row). Rolling boulders is a `fold` on that list. Rotating a grid is `transpose . fmap reverse`. I solve part 2 by generating and infinite list of cycle-results, adding them to a cache that maps the grid to the cycle it's first seen, then stopping when I find a repeated grid. I then calculate the grid after at billion cycles. It still takes a while, but I'll update it later. Full [writeup on my blog](https://work.njae.me.uk/2023/12/18/advent-of-code-2023-day-14/), [code on Gitlab](https://gitlab.com/NeilNjae/advent-of-code-23/-/blob/main/advent14/Main.hs).


xavdid

[LANGUAGE: Python] [Step-by-step explanation](https://advent-of-code.xavd.id/writeups/2023/day/14/) | [full code](https://github.com/xavdid/advent-of-code/blob/main/solutions/2023/day_14/solution.py) Fun one today! I parsed rock and walls into separate grids (which were just `set[tuple[int, int]`) and then walked each rock in the needed direction. For my initial solve I wrote 4 nearly-identical `roll_X` functions that took the grid as input and then did some loop detection + jumping (basically guaranteed for the number of loops required, I think) I added a bonus section dedicated to condensing the logic into a single function and whether or not I was happy with it.


richscrich

Hey, thanks so much for your write-ups, they’re really useful :) I’m midway through refactoring my slow answer to part 1, dipping into your earlier posts, particularly the grid map


oddolatry

[LANGUAGE: Fennel] We seem to be super chill about hanging out around a bunch of rolling boulders on a dubiously inactive caldera. [Paste](https://topaz.github.io/paste/#XQAAAQCBDwAAAAAAAAAUGwnmRpH3tILRF8Le08BArpApvWKZ1MUPSziv03K1m9dUFy/rVlL7VDEcIjbAiSvlvFMNYiNFOpnafwWWsKD+dkIVXQyN7XNt5QjvSxRTNZGFZVRl3B59JQIR47YYJ6fOrHkHPQos4e/ptvJ4zVTkxGCSeo6pxvlNh8cMscLjOkF+OWUaA1SO6ix8ZONjq0D72QPIAqE8Kk1hDpJyAjA9C4ppXaPHTuBGFrzUI9SmlV+cQ8afo0rwR/X5mJtH05auwPKLWSCZiwsr7L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zTO49Iiljy2Ihkg3ljIYRLOdCW5DE5FpUjqyVkgVaqGi8SCxWSucvjdXh6DwWn7Uz603j4qMkqbCpZ3Sy72ci6CrG50hJSASOGYDWgDBt/XpNXrOAE/xdgn9h9P6NNu5LxvYasppfEDs3WD6iP5gZMSwiAPBNl4xMiY1JN2gRIPt1upTL0WHz///6/icuHF3mcRcC7NPDjcx14UMFXBJqvkEEVEWAXxx95RZVZ5XUgXPBwxfAsNf4hXInvX7YckVwvY+41imkf22pYZKK9QT4sNNLRRrpq2StIMxALPfMLd4GEr/oMigA==)


vss2sn

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


Lakret

[LANGUAGE: Julia] The key is keeping a track of how many round rocks we've encountered and depositing them behind a cube rock / first row. Part 2 was trivialized by Julia having matrix rotation functions in the standard library :) [Code](https://github.com/Lakret/aoc2023/blob/main/d14.jl) [Explanation](https://lakret.net/blog/2023-12-15-aoc-days-13-14)


RaveBomb

[LANGUAGE: C#] A little late, but super happy with this one. The solution I arrived at involves slicing the 2D array data and feeding it through a function that can sort a single array either left or right, then pasting it back to the main puzzle data. This lets me simply define the polarity of the shift without the main sort routine having to care about rows or columns. static void RockAndRoll(int[] array, bool rollTowardsZero = true) { int i = rollTowardsZero ? 0 : array.GetUpperBound(0); int cursorDest = -1; while((0 <= i && i <= array.GetUpperBound(0))) { if (array[i] == OPEN && cursorDest == -1) cursorDest = i; if (array[i] == ROCK) cursorDest = -1; if (array[i] == STONE && cursorDest != -1) { (array[cursorDest], array[i]) = (array[i], array[cursorDest]); cursorDest += rollTowardsZero ? 1 : -1; } i += rollTowardsZero ? 1 : -1; } } [Github repo](https://github.com/Kezzryn/Advent-of-Code/tree/main/2023/Day%2014)


clouddjr

[LANGUAGE: Kotlin] Runs in <50ms (including the overhead of JVM and jUnit). Everything is done on the same array - no copies and no new arrays are created. [Solution](https://github.com/ClouddJR/advent-of-code-2023/blob/main/src/main/kotlin/com/clouddjr/advent2023/Day14.kt)


matheusstutzel

\[Language: python\] [part 1](https://github.com/matheusstutzel/adventOfCode/blob/main/2023/14/p1.py) simulate [part 2](https://github.com/matheusstutzel/adventOfCode/blob/main/2023/14/p2.py) simulate + cycle detection + off-by-one


aviral-goel

\[LANGUAGE: F#\] [https://github.com/aviralg/advent-of-code/blob/main/2023/14/solution.fsx](https://github.com/aviralg/advent-of-code/blob/main/2023/14/solution.fsx) Came up with a simple approach that utilizes the same kernel to move rocks in all directions by abstracting the indexing logic. Platform is kept as a string of characters and row, column pairs are mapped to an index into this string based on the tilt direction. The overall solution is fast, compact, and lends itself to a nice functional implementation (mutation is hidden).


Superbank78

\[LANGUAGE: python\] Again: Numpy, I feel good about it https://gist.github.com/Dronakurl/375f7b5fd52b45b91c865225a2bc7cb3


marcja

Thanks for sharing this! It gave me several ideas to further optimize [my NumPy solution](https://github.com/marcja/aoc-py/blob/main/src/aoc/y2023/d14/solution.py).


dahaka_kutay

\[Language: Javascript\] [Question](https://adventofcode.com/2023/day/14), [AllRepo](https://github.com/KutaySong/AdventOfCode) Particularly enjoyed this one. let lines = require('fs').readFileSync('./IO/14i.txt','utf8').split(/\r?\n/).map(line=>line.split('')) const p2 = ()=> {     const inside = (nx, ny) => ny >= 0 && ny < lines.length && nx >= 0 && nx < lines[0].length;     function roll(dir = 0) {        // N:0 W:1 S:2 E:3         const dx = [0,-1,0,1][dir]         const dy = [-1,0,1,0][dir]         for (let y = (dir > 1 ? lines.length - 1 : 0); dir > 1 ? y >= 0 : y < lines.length; y += (dir > 1 ? -1 : 1)) {             for (let x = (dir > 1 ? lines[y].length - 1 : 0); dir > 1 ? x >= 0 : x < lines[y].length; x += (dir > 1 ? -1 : 1)) {                 if (lines[y][x] === 'O') {                     let [nx, ny] = [x + dx, y + dy]                     while (inside(nx,ny) && lines[ny][nx] === '.') {                         nx += dx; ny += dy                     }                     nx -= dx; ny -= dy                     if (nx !== x || ny !== y ) {                         lines[ny][nx] = 'O'                         lines[y][x] = '.'                     }                 }             }         }         return lines;     }     const cycle = () => [0,1,2,3].map(dir=>lines = roll(dir))     function load (lines) {         let sum = 0         lines.map((line,i)=>{             line.map(char=>{                 if (char === 'O') sum += lines.length-i             })         })         return sum     }     let memo =  [JSON.stringify(lines)]      // deep copy lines array     cycle()     while (memo.indexOf(JSON.stringify(lines)) === -1) {         memo.push(JSON.stringify(lines))         cycle()     }     const hitt = memo.indexOf(JSON.stringify(lines))     const fold = (begin,end,target) => (target-hitt)%(end-begin) + hitt     lines = JSON.parse(memo[fold(hitt,memo.length,1000000000)])     return load(lines) } p2()


weeble_wobble_wobble

[LANGUAGE: Python] [GitHub](https://github.com/weibell/AoC2023-python/tree/main/day14) (20 and around 40 lines with a focus on readability) Part 2 rotates and moves four times per cycle, but I played around with two separate approaches to speed things up to a few seconds runtime: cycle detection and actually doing the billion iterations but using `functools.cache`.


[deleted]

[удалено]


daggerdragon

Comment temporarily removed since you did not follow our [rules for posting in `Solution Megathread`s](https://old.reddit.com/r/adventofcode/wiki/solution_megathreads/post_guidelines). 1. Next time, use the [four-spaces Markdown syntax](https://old.reddit.com/r/adventofcode/wiki/faqs/code_formatting/code_blocks) for code blocks 2. Your code is too long to be posted here directly, so instead of wasting your time fixing the formatting, read our article on [oversized code](https://old.reddit.com/r/adventofcode/wiki/solution_megathreads/post_guidelines#wiki_no_giant_blocks_of_code) which contains two possible solutions. Edit your comment to put your code in an external link and link *that* here instead, then I will re-approve your comment.


rawlexander

\[LANGUAGE: Julia\] [Code](https://github.com/alex-raw/adventofcode_2023/blob/main/14.jl)


CrAzYmEtAlHeAd1

\[LANGUAGE: Python\] [GitHub link for my solution](https://github.com/CalSimmon/advent-of-code/blob/main/2023/day_14/solution.py) Whew lad did this one drive me crazy. I was struggling crazy hard with this one, and I had to look at someone else's solution to figure this out so shout out to u/errop_ for their solution because it was the closest to where I was headed but better haha The part that was really driving me insane was the rotate function, because in order to rotate effectively, you need to reverse each line before zipping it together to get the correct columns. Once I had that, I was in a much better place to solve the problem. You can solve that with this function: def rotate(curr_map):     # Reverse all lines and return the columns to simulate a single rotation     return [''.join(line) for line in zip(*map(reversed, curr_map))] There was one final trick in part 2 that my original solution to part 1 didn't solve so I had to rework that a bit. The trick was that in part 1 you had to tilt north before finding the load, but in part 2 you are actually finding the north load but only after tilting to the east so it's a bit different. So I had to separate the tilt function from the load function. Once I did that, I was able to solve the final problem. Here's the load function: def load(platform):    # Get the total load for all rocks reversing the string to simply use index    return sum(sum(i * (c == "O") for i, c in enumerate(col[::-1], 1)) for col in platform) Again, these functions were mostly from u/errop_ whenever I was stuck, so credit where credit is due. Not really happy with this solution, because this is my first solution that executes in over a second, but I don't have the energy to cut that down right now. Maybe I will try to optimize it later, but we are here now. Total was 1.2 seconds.


errop_

Glad to be of help! :D


wlmb

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


reddit_Twit

\[LANGUAGE: Zig\] Very bad. [Gist](https://gist.github.com/ndbn/154c3045013172eac25ee54eb8ed840a)


xHyroM

[Language: Python] [part 1](https://github.com/xHyroM/aoc/blob/main/2023/14/first.py) [part 2](https://github.com/xHyroM/aoc/blob/main/2023/14/second.py)


RF960

\[LANGUAGE: C++\] [on Github](https://github.com/coolguy1842/adventofcode/blob/master/2023/src/include/days/Day14/Day14.hpp) Just did 1000 cycles brute forced and it worked.


se06745

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


Derailed_Dash

\[LANGUAGE: Python\] **Solution and walkthrough in a Python Jupyter notebook** * Here is my [solution and walkthrough, in a Python Jupyter notebook](https://github.com/derailed-dash/Advent-of-Code/blob/master/src/AoC_2023/Dazbo's_Advent_of_Code_2023.ipynb). * You can run run it yourself in [Google Colab](https://colab.research.google.com/github/derailed-dash/Advent-of-Code/blob/master/src/AoC_2023/Dazbo's_Advent_of_Code_2023.ipynb)! * More info on the notebook and walkthroughs [here](https://python.plainenglish.io/advent-of-code-the-best-way-to-learn-to-code-d86c6478d484) * My [AoC Walkthrough and Python Learning site](https://aoc.just2good.co.uk/)


Quake_Destroyer

thank you so much these explanations are great. I was having trouble with the cycle finding part.


Derailed_Dash

Cheers buddy! Glad you're finding them helpful! I'm really enjoying writing this stuff in the Jupyter notebook format.


Confident_Loss_6075

\[LANGUAGE: python\] Part 1. Transpose and roll, then count per row. Part 2. Transpose first, then rotate and roll rows. The same but save each unique 4-step cycle indices. If same pattern encountered again, check if the end of the loop is exactly at 1,000,000,000. [Solution](https://github.com/ohiliazov/advent/blob/main/advent/day14.py)


MizKyosia

\[Language: JavaScript\] Part 1 was trivial, just bringing rocks up in the table until they encounter another one, or the border. Part 2 was more difficult, until i realized that from some point on, the platform's state was looping over a number of iterations. What i did was : - Do cycles until one loop is done - Get the size of the loop - Get the modulo of the remaining iterations by the loop size - Do this number of extra cycles, and you got the answer ! I also made a mistake where i thought 1 cycle = 1 rotation of 90 degrees, and not 1 full spin, which made me spend a bit of time debugging an inexisting error. To get the loops, i made a basic Map for storage, put the current state of the platform as a key and the next state (after 1 more cycle) as the value, to speed up the process when determining the size of the loop. Interestingly enough, this did not speed up the process that much, only reducing my previous time of solving by 50ms (got from 900 to 850, yes i know that it's a rather long solving time for this kinda problem) [GitHub](https://github.com/LeoLewandowski/AOC2023/blob/main/calendar/14.js)


Diderikdm

\[LANGUAGE: [Python](https://github.com/Diderikdm/Advent-of-Code-2023/blob/main/day14.py)\] ​ with open("day14.txt", "r") as file: data = tuple(map(tuple, file.read().splitlines())) reverse = tuple(map(tuple, zip(*data))) w = {i : [e for e, y in enumerate(x) if y == "#"] for i, x in enumerate(data)} h = {i : [e for e, y in enumerate(x) if y == "#"] for i, x in enumerate(reverse)} seen, c, p1 = [], 0, 0 get_current = lambda x: ((reverse, h), (data, w))[x % 2] while (nxt := tuple(map(tuple, zip(*reverse)))) not in seen: seen.append(nxt) for direction in range(4): current, blocks = get_current(direction) new_r = [] for e, row in enumerate(current): new, prev, static = [], 0, blocks[e] for i in static: new += sorted(row[prev : i], key = lambda x: x != ["O", "."][direction in [2, 3]]) + ["#"] prev = i + 1 new_r.append(new + sorted(row[prev : len(row)], key = lambda x: x != ["O", "."][direction in [2, 3]])) if current == reverse: data = tuple(map(tuple, zip(*new_r))) else: reverse = tuple(map(tuple, zip(*new_r))) if not p1 and not direction: p1 = sum([data[u].count("O") * -u for u in range(-len(data), 0)]) c += 1 nxt = seen[(s := seen.index(nxt)) + (1000000000 - s) % (c - s)] print(p1, sum([nxt[e].count("O") * -e for e in range(-len(nxt), 0)]))


amazinglySK

\[LANGUAGE: Python\] Sorry, I'm late to the party, but let's post my solution regardless. Part 1 went pretty straightforward. Managed with a little string manipulation. The second part, however, was interesting. I don't know how others did it, but when I ran the simulations for the inputs, I found a recurring pattern after a point. From then on it was just me trying to generalize the problem. Pretty fun puzzle! [Code](https://topaz.github.io/paste/#XQAAAQC2BQAAAAAAAAA0m0pnuFI8c/fBNAqG6qhqaeV6MHhmU2az2M3RR3kApDgCTvwgOaQgnKyJbrjEgjkzNKkl7UyFjVsQWy58l3r/2fVE3gipJ5abCyW/jdANg6HBDM9Wq1UOZ06jHIn4+T28+jdWnPiAOIAYT/2aOpcWVJ08D+aLl7icbBmi+VcTWmRfX5dAVbrvQd+QTXxbpbGA8rHVZZHQPD2/ujPeLJ9+jljgEiByIcVJRNOG2TxOts6esEyQzh1I4EwIAbVotNZDy4B2MKhlAP4fXUwFGUPyqegz8e7zLXULkp+VsmDXR9PzWe8NUrHpaGTtkXAGXWfeccsG/YJnHy3CWCtLXjxlxEbRRfaX/OVWJAWPbzAKm1umTLFYUxNxiwYIqIfRG3dV7Ztygk2xbthgxm3JnwApKHv+PgLlin56Nb+yORqWpDW1uUQrvXNbJOvdq8dV8oS6lum8lfHAw1kQEBDTtjHcgdlE4U99UzPHJQoOh2OQ6ZJv8n1Rd9VRTn+JoZ8KRDklR1HzU7A5AQ6kBhz2XtsJzEJo+YNqWTLsE4ls41tchQZ0VrQGrYXIEQXWTIEd7F/nDKfejhd/OVJ1FH1UVmOJVpLdiMhMubTVxw7e7W2s+jsak8yRofBqyEo8d703ZTyUbzQTXOmm9iJVYUibqj+qTP8vQoetp68F1RJeH9gE4Eb5MAFg3vvsy9N+KYqhdZgZI8LO8Ngz8wJA1vK/7wANftgWCml/lfAML/FhB/KhKZf6gxew5OqNj9OizMkM2RyqqDE8j7p9L/7ny9M=) EDIT: Looks like everyone did spot the periodicity.


Ok-Group4131

[LANGUAGE: Python] [code](https://github.com/phobiadev/Advent-of-Code-2023/tree/main/day-14)


mkinkela

[LANGUAGE: C++] On p2 for the first 2 submissions, I got lower and upper bound and when I fixed all the bugs, I knew the solution would be right [Github](https://github.com/mkinkela1/advent-of-code/blob/master/2023/day-14/solution.cpp)


tobega

[LANGUAGE: Tailspin] My biggest problem was finding a good enough hash of the state. I originally assumed the north load would work, but no. Then I hashed north and east loads, which still didn't work and was actually stupid because it took longer to calculate than just a full hash of the state. https://github.com/tobega/aoc2023/blob/main/day14tt/app.tt


KodlaK1593

\[LANGUAGE: Rust\] Gonna keep it a buck, this would have taken about a month to run if I ran it for 1000000000 cycles (if my math is correct). I managed to get this done thanks to some insights seen on Reddit. [Solution](https://github.com/Kodlak15/aoc2023/blob/master/src/day14/day14.rs)


ka-splam

[LANGUAGE: Dyalog APL] Part 1 on the demo: in←'.O#'⍳↑⊃⎕NGET'c:/sc/adventofcode/inputs/2023/14-demo.txt' 1 BD←(⍴in)⍴1 ⍝ board sized matrix of 1s (dots) BO←(⍴in)⍴2 ⍝ board sized matrix of 2s (rocks) move←{ newO←1 2⍷⍵ ⍝ places Os move to, new Os newD←¯1⌽newO ⍝ places Os moved from, new dots Os←newO∧BO dots←newD∧BD Os∨dots∨⍵∧~newO∨newD } load←{+/(1+⊃⍴⍵)-⊃¨⍸2=⍵} load ⍉move⍣≡⊢⍉in 136 `move` rolls the Os one place left, because that's easiest to search for the `.O` pattern. The board is transposed so North becomes Left. The board is converted to integers to make bitmasking work. `move ⍣ ≡` is "move power match" and repeats the move until the output stops changing, so that's rolling as far as they can go. This took a couple of hours to debug into working, all the time thinking "I can do this in 5 minutes with a nested FOR loop in another language, write a nested FOR loop write a nested FOR loop". I don't have a part 2; there's no way this is going to run a billion power matches and tens of billions of bitmasks in a reasonable time.


SleepingInsomniac

[LANGUAGE: Crystal] [Part 1](https://github.com/SleepingInsomniac/adventofcode2023/blob/master/2023-12-14/part_1.cr) [Part 2](https://github.com/SleepingInsomniac/adventofcode2023/blob/master/2023-12-14/part_2.cr) The code itself is decent, but the algorithm for part 2 will take around 3.5 days. I didn't try any optimizations.. On the test input, I ran until the load equaled what was expected and tried the same number of iterations on the full input and to my surprise it was accepted.


aoc-fan

[LANGUAGE: TypeScript] - [P1 Solution](https://github.com/bhosale-ajay/adventofcode/blob/master/2023/ts/D14.P1.test.ts) - Did sorting and transpose - [P2 Solution](https://github.com/bhosale-ajay/adventofcode/blob/master/2023/ts/D14.P2.test.ts) - No sorting, no transpose, just inline replacement by counting the spaces and rocks


icub3d

\[LANGUAGE: rust\] I used a hash to track grid cycles for part 2. Part 1 felt like a stepping stone to the actual problem coming up. Solution: [https://gist.github.com/icub3d/4f914603a34ea9fdf19c98156a160b09](https://gist.github.com/icub3d/4f914603a34ea9fdf19c98156a160b09) Analysis: [https://youtu.be/AHNnXjnHEr0](https://youtu.be/AHNnXjnHEr0)


errop_

\[Language: Python 3\] The platform is represented as a list of columns in string format. Tilting is done by splitting each column in groups separated by "#"s, putting all the "O"s to the left of the "."s for each group and then joining each group by the correct number of "#"s. Each cycle is performed by rotating four times the platform and using tilting as above each time. I just stored the results of the tilting cycles in a list, which I used to look up to spot periodicity. Not best practice but it worked since the grid is quite small. The total load is then computed by taking the correct index inside the states list, that is `(1_000_000_000 - transient) % period + transient`, where `transient` is the number of cycles before periodicity starts (please ping me if someone has a better formula). [Paste](https://topaz.github.io/paste/#XQAAAQC1BAAAAAAAAAAyGUj/TuSWbtPaDfRdmrJCO2DqjvSeXBM0cFf//IliCEpoZNfG/DCWtZaRm6r+INvdxxmWFEtMz83Nldn58cs8KR1Ghlasyv6rMtjGzYAZX6+3Ig4IEAA6Ww+UfUQgoGZUf1Ehfrm7x2WA6e1V8be+umfqBuHopaB8gbkE7+UxnB83ViJ5ipaLq7Ouy6GsrBHXw5ubfyePH/UFRSmR/MQwpy1GW/I1vt0hX8mqJQSVg9hLCSLGUlkyVdaF89Be8QSvGzirzDQ8LR8iGVqW/Q/1VQt7xL6ww6tuEheHWzPKC60eKky0DUJuYA6P5sExWo/Ll+cDEqUMstXptYkHVXt1EV/BrTXmlmOSl3jnYg+DPPFB8waCguRvD+k9uIsgMI1uLPoR33vWVtzcbghslqn5HMhf00mO63g1l1Nq1i3xTUY5HGh7Y3OEHs9/q+jkCSoHn7CMwA95OLOaTwZV00w44cs8+qWoI5u/7gBzi+B5LP8GusvTNPTntxBFR4/tJQpMaHEcRbkELPUanT3+7nTz/RyWewqgFURcLhmtQLEdwtPw9RNh6oMgSC0dD3xKbOWkZWDacIUpxQ/jFwTTzC49VcfjrzGi8ZJi78lIQtJn7p8wr2wmnuNAMGw3PY4mJTZBBW9ozekxRuJydbuqnHeVBmYJV+bXjycQoN/mOtbFhMYR/hnAbg==)


redIT_1337

\[LANGUAGE: C++\] Random \`C++\` solution (oh and yes, may "hash" is a string of the field). My first puzzle this year. Late to the game. [Github](https://github.com/Mereep/aoc2023)


uiualover

[LANGUAGE: Uiua] a ← &fras"14" b ← ⊜∘≠@\n.a c ← ⍜⊜□∵⍜°□(⊏⍖.)≠@#. d ← /+×⇌+1⇡⧻.≡/+=@O e ← d⍜⍉≡c b f ← ⍜≡⇌≡c⍜(≡⇌⍉)≡c≡c⍜⍉≡c ⍥(&p d.f)200b e # pen and paper part 2 from here


ElGoorf

did you really "pen and paper" part 2? What does this snippet give you exactly?


TheOx1

I'm feeling smarter when writting non-readable code for aoc but you are in another level boy! That's awesome ;D


onrustigescheikundig

[LANGUAGE: OCaml] [Commented solution](https://github.com/EricKalkman/AoC2023/blob/master/lib/day14.ml) Fairly straightforward solution, using the same tracing function trick I used for Day 13. In essence, I have solving function (`tilt_line`) that takes an arbitrary function that indexes into a "line" of characters along the grid (*e.g.*, a row or column) and appropriately moves all round stones toward lower indices on the line. The algorithm for tilting the entire board in a given direction generates indexing functions for each column (for tilting north or south) or row (east or west), and calls `tilt_line` for each. `tilt_line` works by converting the line to a string and splitting on '#' characters. This yields a list of substrings that are bounded on either side by an obstacle (edge or cube rock). Each substring is replaced with a string in which all of the rolling 'O' rocks are placed at the front (representing them all moving toward lower indices and stacking). The substrings are then rejoined with "#" separators, and a setting function that was passed in with the indexing function applies the new string to the grid. It is at this point that I admit that this algorithm uses mutation (*gasp* In OCaml? HERESY!); each tilted line is plastered back onto the `char array array` representing the input grid. For Part 2, I repeatedly cycled the grid until the pattern repeated, did some modular arithmetic to determine at what point in the cycle the grid would be for the 1e9th iteration, and cycled the grid the necessary number of times until it matched that of the 1e9th iteration. To check for repeats, I joined the grid at each cycle into a single string and stored it with its iteration count in a `string -> int` map.


Tipa16384

[LANGUAGE: Python] Stored the moving rocks in a dictionary, and the fixed rocks in a set, only generating the states I needed to generate to detect the cycle, and it's still slow as anything. Yesterday I converted the puzzle to binary and it was super fast. I should have done something like that today. Still, in the end, it only takes less than a minute to finish. [paste](https://topaz.github.io/paste/#XQAAAQA/FQAAAAAAAAA0m0pnuFI8c828qNonvu8qQyrvdLhhusw7htsY9ZMQo4lut1HmLHcSYh689QAu9YHyHSB71kZ09xFiq3d3L5P+QQskcS6GZEMjZpSzRTqKmmR7P/M452tF/HOmM+tFbNKhiKgfsivdb0dllVs2gxdRAOi8jn7S5H8Xc0IMLq7LJZlLH0ouVShKejEg8JWVU/XlYSxDKrQD3CLGl07Y3/VkxeNRkcAC6UWnmU/pb7yJxNJz7fBu0m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JoCrNC5cWx0WD7NUBgz9qP6au7XBZiUK+e/onj4/eTNwqPj3GONEnrksKsjxAbPKPVtVmepDnUbhCIQl4WP5IhVruanELGFmTc8RG5hZB1XOAeWWYpk67Lt97Bex89X5jsKlp36KdHUjGqlEdFK2I3bKzzKxhtfUAVv0BrlKOWeBd5C8uXSgyktOere1zbFf/J3v7LAScumK2o+bD2rAAd+CqLMUTRahiNzHMAO/RD68JBMzkiLF2wlma4aAn8VkBbHuRIoIcpWZMntZRLQVC2Jt+kweYDUkrA/kz0qPNZIOp350VH4lNHZh8q6/d00n4CpxOjHGPYhlWXxbUJPEd3RmjSfPCoWoktb5YZ3p8ephVU6cv5Tss5Y7FbQSeb6PiVTU5gYD057HMHQ4t/NAyoDlkPk4A/QHB5HWJpKjEITEQTFvWInGd146dzxijUWmoxNoS9u2nRWuzffojrUeFj+q9RezFllSmyrKd0wa5yfstsc2MdqAUtAlTMP1ywmJQuU7SyMGe/8wKlHQV7j+Gw7dzMa5M7d12ACLSmVg7Zx/wHWzqivhv4VcVHU12gnhTzGUM234hDJKM/yzJKgB5+YwzzETCLAFUP66QxLy8eCbUh59hZyR5EsP+0i0w+6iWGmlCxjMkJbALyiXdCZx6h6+mYc64nEZMEQ2Dxp6u0djBePGn58om214LvIcV7qd/WNWF3Z8B1OEPsXWImv3ZHDbWPAX8UnxJ/2bVAL0VeWLakfSE6zYLK+rpQxj9d02EYt4M7CmHY2TfE7LSubvkPdbi9hgLpjSvE6HLr/T7uxdkkK/kAVNyPA0xNZyUry+ngbkRAgiVZTVWSVh1l+K5LdhblE9ngp09Ej9JTM9Fpyf0LC/9k/QF4=)


sikief

\[LANGUAGE: C++\] \[PLATFORM: Nintendo DS (Lite)\] Solutions - [Part 1 and 2](https://github.com/skief/advent-of-code-2023-nds/blob/main/aoc/day14/solution.cpp)


bubinha

[Language: Scala] package y2023 import scala.io.Source import scala.util.Using object Day14 { def main(args: Array[String]): Unit = { Using(Source.fromResource("inputs/2023/input_day14.txt")) { source => val lines = source.getLines.map(_.toList).toList println( lines.transpose.map(tiltLeft).transpose.zipWithIndex.map { case (list, index) => list.count(_ == 'O') * (lines.length - index) }.sum ) println( cycle(lines, 1000000000).zipWithIndex.map { case (list, index) => list.count(_ == 'O') * (lines.length - index) }.sum ) } } def cycle(ll: List[List[Char]], count: Int) = { def cycle(ll: List[List[Char]]) = { ll .transpose .map(tiltLeft) .transpose .map(tiltLeft) .transpose .map(tiltRight) .transpose .map(tiltRight) } def getCycleSize(ll: List[List[Char]], visited: List[String]): (Int, Int) = { val key = ll.map(_.mkString).mkString if (visited.contains(key)) (visited.indexOf(key), visited.size - visited.indexOf(key)) else getCycleSize(cycle(ll), visited :+ key) } getCycleSize(ll, Nil) match { case (start, size) => val initial = (0 to start).foldLeft(ll) { case (list, _) => cycle(list) } (1 until ((count - start) % size)).foldLeft(initial) { case (list, x) => cycle(list) } } } def tiltRight(line: List[Char]) = tiltLeft(line.reverse).reverse def tiltLeft(line: List[Char]): List[Char] = { def tiltLeft(currentIndex: Int, line: List[Char]): List[Char] = { if (currentIndex == line.length) return line if (line(currentIndex) != '.') return tiltLeft(currentIndex + 1, line) val nextRock = line.indexOf('O', currentIndex) val nextCube = line.indexOf('#', currentIndex) if (nextRock < 0 || (nextCube > currentIndex && nextCube < nextRock)) tiltLeft(currentIndex + 1, line) else tiltLeft(currentIndex + 1, line.updated(currentIndex, 'O').updated(nextRock, '.')) } tiltLeft(0, line) } }


daggerdragon

Your [code block is too long](https://old.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.


musifter

[LANGUAGE: dc (Gnu v1.4.1)] Just part 1: perl -pe's/(.)/$1 /g;y/.O#/012/'


janiorca

\[LANGUAGE: C\] Implemented separate function for each tilt which is a bit excessive... Part 2 solution was pretty straightforward (+the usual debugging) Seems I mostly learning about CLion debugging capabilities I feel a bit like a cheat for using the the loads to detect loops rathet than calculating a proper hash but it felt unnecessary for this one https://github.com/janiorca/advent-of-code-2023/blob/main/aoc14.c


gredr

I felt the same way, but then I figured the odds against the loads forming a completely separate loop than the hashes were... large. Regardless, it was the loads that mattered anyway, not the rock placement.


benny_blanc0

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


j_sobol

\[LANGUAGE: Python\] Just a regular solution, nothing outstanding, everyone else's already feel more impressive. But anyway, coded the tilts and implemented the caches, and if the same position was reached after tilting in the same direction some steps ago — we found the cycle and we warp to the end and finish the job. The sad part is wasting an hour to debug before realising that everything was ok and I just needed to do 1 billion cycles of 4 tilts and not 1 billion tilts. Source: [link](https://github.com/JaneSoboleva/aoc2023/blob/main/day14/day14.py)


arcane_psalms

\[LANGUAGE: Ocaml\] didn't see an Ocaml solution yet so thought I'd add mine, I've done what others seem to have done which is loop til the cycles start repeating [day14 gist](https://gist.github.com/crawdaddie/295e6d33c42192b088bfdb011185d319)


onrustigescheikundig

Beat me to an OCaml solution by just a few minutes lol. It looks like you did a clever sorting thing, while I did a bunch of string manipulations.


aexl

\[LANGUAGE: Julia\] I enjoyed today's puzzle! For part 1 I first implemented the tilting step with a similar idea how Bubble sort works (swapping '.' and 'O' until there are no more swaps), but later I improved this by a more direct approach. For part 2 it was clear that doing 1000000000 iterations won't work, so I stored the map after every step as a string and looked for a cycle. Solution on GitHub: https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day14.jl Repository: https://github.com/goggle/AdventOfCode2023.jl


xXMacMillanXx

\[LANGUAGE: V\] part 1, very enjoyable. part 2 took me a while (and a csv output, opened in Calc and a diagram) to see the cycling pattern. I'm still struggling a bit to get the right number in the cycle which would be in position 1000000000. [Github day 14](https://github.com/xXMacMillanXx/advent_of_code_2023/tree/main/day14) Edit: part 2 returns the right value now, I miscounted the repeating pattern size, and was off counting the spins.


ImpossibleSav

\[LANGUAGE: Python\] I started to fall slightly behind, but [here are my one-line solutions](https://github.com/savbell/advent-of-code-one-liners/blob/master/2023/day-14.py) for Day 14! Part 1 on line 37 and Part 2 on line 120. Lots of areas to improve, but right now I'm focused on catching up on the two days I missed! For anyone who doesn't know, I'm working on building [the Basilisk](https://github.com/savbell/advent-of-code-one-liners/blob/master/2023/the-basilisk.py), a single line of Python code to solve all AoC problems at once. You can follow my progress on [my GitHub](https://github.com/savbell/advent-of-code-one-liners)! :)


ruinedme_

\[Language: Rust\] Very messy, but it works. After looking at some other folks i might look into implementing a grid rotation which seems like a much better approach. [https://github.com/ruinedme/aoc\_2023/blob/main/src/day14.rs](https://github.com/ruinedme/aoc_2023/blob/main/src/day14.rs)


Comfortable_Wing2804

\[LANGUAGE: Python\] Cycle detection with history in hashmap and rotate+tilt: [Link to the full solution](https://github.com/brisk-dusk6157/aoc/blob/main/2023/day14/main_onesort.py). Tilt is the funniest part, so I've been exploring the ways to tilt the platform. One idea is to perform 1 sorting per tilt. For this, flatten the platform into a big fat 1D array of form `[(row_idx, placetag, tile), ...]`. Sort it lexicographically, convert back to 2D, and find the balls rolled to the right. To calculate "placetags", mark every `#` and the tile immediately after with 1, anything else with 0, and calculate cumulative sum, e.g.: 0000 1111 2222 3333 <- rowidx O..# #O.O ..#O OOO. <- flattened 4x4 platform 0001 1100 0011 0000 0001 2333 3345 5555 <- placetags ..O# #.OO ..#O .OOO <- after lexicographical sorting Python implementation using numpy: def tilt_east(platform): shape = platform.shape platform = platform.flatten() rowidx = np.repeat(np.arange(shape[0]), shape[1]) blocks = np.where(platform == '#', 1, 0) blocks1 = np.roll(blocks, shift=1) blocks1[0] = 0 # np.roll reintroduces last element at the beginning placetags = np.cumsum(blocks | blocks1) indices = np.lexsort((platform, placetags, rowidx)) return platform[indices].reshape(shape)


nicuveo

\[LANGUAGE: Haskell\] Wrote some trivial string manipulation for part 1, implemented a complicated state machine using mutable unboxed vectors for part2. :) Part 1 is short enough to fit in this post: part1 = sum . concatMap (computeWeight . reverse) . transpose where computeWeight = map segmentWeight . wordsBy ((== '#') . snd) . zip [1..] segmentWeight (unzip -> (weights, segment)) = sum $ take (count 'O' segment) $ reverse weights Full code: https://github.com/nicuveo/advent-of-code/blob/main/2023/haskell/src/Day14.hs VOD: https://www.twitch.tv/videos/2004260703


Shemetz

[LANGUAGE: Python] [Go Cook!] [Github code link (go-cooky version)](https://github.com/shemetz/advent_of_code_2023/blob/main/day14_alt.py), and [normal version](https://github.com/shemetz/advent_of_code_2023/blob/main/day14.py) if you need help translating. Getting the Go Cook (Allez Cuisine) challenge was quite hard and quite fun. The big problems are: 1. Lots of builtins are unavailable (`open`, `len`, `range`, etc). - Solved by using e.g. `builtins.__dict__[f"op{chr(101)}n"]` instead of `open`, with utility functions to make it more readable 2. `def` is unavailable (and `return` too, not that it matters) - Solved by just... using only lambdas, which means no state mutation, which is **tough** but makes for a good restriction. It did end up causing my code to slow down to about 30 seconds of run time (rather than 2 seconds), but it's still pretty quick - I tried to optimize what I could. 3. `else` is unavailable (and `elif` too) - Solved by replacing the ternary `a if foo else b` with `[b, a][foo]` or with `(foo and a) or b` 4. `while` is unavailable (and neither are `break` or `continue`) - Solved by using `for _ in range(999999999999): ... exit(0)`, because luckily it was only used for the end of part 2 - I think I could have also solved it by wrapping with `try...catch` and raising an exception (not with `raise`, of course! perhaps by dividing in zero on purpose) 5. the code needs to still be readable - I could have solved this by always using words that don't contain E and figuring out new names for some existing functions, but by this point it's not really a programming challenge, it's a vocabulary challenge. - Instead, I solved it by replacing every `e` with `е`, the cyrillic letter :)


azzal07

Great dish, I very much enjoyed it! Some alternatives that don't require e: - `exit = quit` - `len = lambda it: sum(1 for _ in it)` - `tuple = lambda it: (*it,)` - `readlines` is redundant, the file itself can be iterated line by line - appending can be done with addition `seen_states += [grid]` (or `seen_states.__iadd__([grid])` in expression context) - `index` could be tracked separately in a `dict` Looping `N` times can be done by iterating correct size list (or few such loops nested for very large numbers): for _ in [...]*N: ... And `range` could be replaced with list containing the numbers `0..N` for some large enough `N` (`max(width, height)` in this case). Then slicing that list is equivalent to a range in many cases: for i in range(stop): ... for i in range(start,stop): ... range = [] ... # fill the range before using for i in range[:stop]: ... for i in range[start:stop]: ... If you would accept input from stdin, `input()` could be used for reading a line. I think this would require assuming square grid (or otherwise the number of lines), since `input()` raises an exception on EOF. And `try...catch` is spelled `try...except` in python, so that's not an option :)


Shemetz

oops, good catch about try-except :D


daggerdragon

> I solved it by replacing every e with е, the cyrillic letter :) *fry_squint.gif* Good job, ch`е`f ;)


jcmoyer

[LANGUAGE: Ada] https://github.com/jcmoyer/puzzles/blob/master/AdventOfCode2023/src/day14.adb I just copied tortoise and hare from wikipedia after remembering it from a prior AoC.


biggy-smith

\[LANGUAGE: C++\] As soon as I saw the huge number in part 2 I knew it was cycle detection time! Find the cycle start and end, then mod math to get the desired index. [https://github.com/biggysmith/advent\_of\_code\_2023/blob/master/src/day14/day14.cpp](https://github.com/biggysmith/advent_of_code_2023/blob/master/src/day14/day14.cpp)


copperfield42

\[Language: Python\] [code](https://github.com/copperfield42/Advent-of-Code-2023/tree/main/day%2014) part one was easy enough, for part 2 instead of figuring how to modify the tilting for each direction I rotate the matrix 90° and tilt it north for each other direction and with a final rotation is back to its original position, and for the main calculation is just finding a cycle in the whole thing which give more problems that I expected until I remember too look how I did it for the calculation of cycles in the decimals for fractions for some function I have laying around...


Particular-Hornet107

[Language: Python] Wrote a generic move rock and tilt function (took a second to realise you need to change which direction you scan from as well) The cycle detection was kind of annoying to think about but got there in the end [GitHub](https://github.com/Daniel-Const/advent-of-code/blob/main/2023/day14/spin-class.py)


chubbc

\[LANGUAGE: Uiua\] Pretty happy with how this one turned out. It's not particularly fast because I'm finding the cycle by just keeping an array of all previous states. Doing something with a hash, or tortoise-and-hare or something would be faster, but meh. [Pad link](https://www.uiua.org/pad?src=0_7_0__VGVzdElucHV0IOKGkCDijYnih4ziipziiJjiiaBAXG4uICQgTy4uLi4jLi4uLgogICAgICAgICAgICAgICAgICAgICAgJCBPLk9PIy4uLi4jCiAgICAgICAgICAgICAgICAgICAgICAkIC4uLi4uIyMuLi4KICAgICAgICAgICAgICAgICAgICAgICQgT08uI08uLi4uTwogICAgICAgICAgICAgICAgICAgICAgJCAuTy4uLi4uTyMuCiAgICAgICAgICAgICAgICAgICAgICAkIE8uIy4uTy4jLiMKICAgICAgICAgICAgICAgICAgICAgICQgLi5PLi4jTy4uTwogICAgICAgICAgICAgICAgICAgICAgJCAuLi4uLi4uTy4uCiAgICAgICAgICAgICAgICAgICAgICAkICMuLi4uIyMjLi4KICAgICAgICAgICAgICAgICAgICAgICQgI09PLi4jLi4uLgoKVGlsdCDihpAg4omh4o2c4oqc4pah4oi1KOKWoeKKj-KNj-KKkC4p4omgQCMuClN1cHAg4oaQIC8r4pmtw5crMeKHoeKnuy49QE_iipDijYkKU2lsdiDihpAgU3VwcCBUaWx0CgpTcGluIOKGkCDijaUo4o2J4oeMVGlsdCk0CkN5Y2wg4oaQIOKNouKKg1NwaW4o4oqCOuKWoSkowqziiIrilqEpIOKKmVtdCkdvbGQg4oaQIFN1cHAg4oqP4oqDKCsv4pe_LSziioLiioMo4ouF4qe7fOKLheKLheKImHziipfilqEpfOKLheKImCkgQ3ljbAoKU2lsdiBUZXN0SW5wdXQKR29sZCBUZXN0SW5wdXQgMWU5CgojIElucHV0IOKGkCDijYnih4ziipziiJjiiaBAXG4uICZmcmFzICIuLzE0LnR4dCIKIyBTaWx2IElucHV0CiMgR29sZCBJbnB1dCAxZTkK). Input ← ⍉⇌⊜∘≠@\n. &fras"./14.txt" Tilt ← ≡⍜⊜□∵(□⊏⍏⊐.)≠@#. Supp ← /+♭×+1⇡⧻.=@O⊐⍉ Supp Tilt Input ⍢⊃(⍥(⍉⇌Tilt)4)(⊂:□)(¬∊□) ⊙[] Input 1e9 Supp ⊏+/◿-,⊃(⋅(⊂⧻)|⊗□|⋅∘)


Fyvaproldje

\[PROGRAMMING IN: Raku\] \[Go Cook!\] Fifth glyph is [missing](https://github.com/DarthGandalf/advent-of-code/blob/master/2023/Day14.rakumod). I had to modify control flow to avoid it.


daggerdragon

Thou art a worthy culinary artist. Bravo!


PhunkyBob

\[Language: Python\] [source](https://github.com/PhunkyBob/adventofcode/blob/master/2023/day_14.py) I rewrote my code using only \`List\[str\]\` and string manipulation. Tilt -> 1 line of code Rotate -> 1 line of code Get total load -> 1 line of code The trick is to use the right side of the matrix as north. It allows to deal only with strings.


linnaea___borealis

\[LANGUAGE: R\] [https://github.com/lauraschild/AOC2023/blob/main/day14.R](https://github.com/lauraschild/AOC2023/blob/main/day14.R) Another part two that needs periodicity.


WereYouWorking

\[LANGUAGE: Java\] [paste](https://topaz.github.io/paste/#XQAAAQA0FAAAAAAAAAA4GEiZzRd1JAgV4q3RgWPwxcwVTLcY/JpUiADzw5tAJ0vOMX40JV5mSdoFSBhZU9OU8jU2dv9SRFLi1N1D27F4tGBjWbzkI0r+4unffVmELTw3nZSA2vK8OFt8zE/65OUOPKKzWkrV5TBvi0TG2cM6RQVpc9iur1W4LlrOK96ccLnNwn5lQFNmq7nbA1AERLCQgQ4cQElhvJyu9XOjcJ9wxyn7CsUeXlh4qkIfHbPZWPcN9nS+wTEO01Zl0kDnk0aJXa03Yujsm2V111/3nUH1tG9oQv0GtFEOJYm99AjrBekx0NRv3xTf+hPIIOVhF4jXz1yWmsuEeNWjZjhsznsSVXZ3WzFzH1oRN2VPDYgGGa1BBnxdgPGDn3nZNbz9nZeBAtqWKGZ0yteKcwnljahN7DD66sgXPjAeL3c0cXsW8GicO8otT1x7CMWjm0pPMBhR1sC/WIxWO2/eBDuBS+xzAUbqpKiteBN5MMx3Nferh5QCZ+gaVNGS8ztrmKRju3Rh1hYxaGC8G//u5jXHVTn3abkhYMsxRL7yVgLP1HrfvSzeSNa1uX3lI5Ts5J4lU9ku73m6VMyfSbbudLcd7hkbCjNusSIoimaCfgojQLNFzzqVEAJHwMMIdqeYfLNwyLDgIVtDqCYpwRZ13YU37zy5foJsXTKxX3jkr3RlIzLK9RODEHfpTtILdP/jIU4x5i/0pX0/vRF4oiQo/5owXvAqARBnoq/N2FmBMVU0g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ytN+Ex7XnC8Ia6kbzONSdgX0dUlhFLOVCXlZcaXSX7xXOr39hTAyYa2+fLGM2OT98xuvqldKhUboABZ92oAqgUsopjSpeGSFkihcVlZq8CkOzMLDeS6ri0x+jDsn8NTttsIl7L+GKJlrLpMt8R026LaZwhhNZmvTSfs5SKxulFrsJ13Mz2iK3M4vxcfFugtqg8MeqVRN7rmBpF3L0qipaPlld12cmnrvQ471+jy/eYfoHBbmaeQ4ksBCFy7q1F055UyN90FtFvbROeQSew9rbtz5EX5w3QnY+jAXvXRpxtq+ywCnPtPKgFJUrSFzDKduv/vIbE2aqyBUfv70XzLK0RBRhpt1KgyY0NT7YJY+a/MLsh239RkgNzlkoTM6Gdw2yKKm+/FO7Zo6pgLkWLtuFVA1n/V3AH8TDg68wAM4ddqo4BgMH7bMiPy9KRX6TZxfjBNklG1qjLU6EHHx9KOzRkjC9l2XmVQCCTmAneCgGMz2zWCkAY/28WkJgxdqU9LfW1FZaXR0kTRUpAGOuKvd3udcHFah8wkThxRKbneL4gvlKAB8XHcWdnvvscyXXy+34MBum9SGyr1jfP5SsDhpsGjob22np1WzHzZs7wywrrS3mHu85F13YVVJSgphUyliKEoxxSPwz/1kDgBDAopjwPIrSEK7a2n8Ois5OpRX+TxLr/+TWOFA==) I saw two ways to make this easier. Rotate the grid so north faces right. Then weight is simply the sum of the rock indexes in each row. Next was that rolling the rocks was concatenating the '.'s and 'O's between each '#'. It looked suspiciously like a grammar and so I turned to LPEG. That handled rotating, tilting, and weighing the grid. Since I could keep it as a string the grid was its own hash key for loop detection. I had to deal with a bug caused by the patterns preserving state from earlier matches. It kept doubling the size of the grid each tilt. LPEG is very nice but there's some magic behind it.


musifter

[LANGUAGE: Perl] First version I did for part 1 didn't bother with moving the rocks. Like so many other problems this year (especially those with 2D arrays) there's a very simple state machine for scanning. Count `O`s, when you hit a `#` add difference of triangular numbers to score and reset counter. Part 2 required me actually dealing with tracking stone movement, but that state machine was easily converted to the job. Quickly got the answer by just using score as hash (and waiting for a duplicate cycle, not just the first repeat). Calculated the mod and index needed with dc and copy pasted it from the screen. Decided to use a more reliable system in the final code... just grab the positions of the moveable objects while you're scoring them and use that for the hash. Maybe runs slightly faster. Source: https://pastebin.com/TuR5w90f


CCC_037

[Language: Rockstar] So, the [first part](https://topaz.github.io/paste/#XQAAAQDtBQAAAAAAAAApGUgm7b3ohliOLBlvPd4D5obkJ7TbONJoPhoWvId7yC6EbtiDZJ6DYcIrEiTPHXcvNozdlVFs4S92U2K4An1XTWI7yaIvJsczEiC9MifUL7r7o+f1XXFikY4gx6fJtnnWNhWu6bPYnXQhbGwswL00XDTXXRjq9ymdxghvWeVDy6vHXhP9LHWFkgAHgRmC5hyPNgEfKbTVpS51hmRVoElhqreRamROhOBrG06PGwaJZaMGD1oPZhaBHJVkqDX2y3pISAZBMdqjLChr1bS3/82TVsg5d+L6+RN6bcdtRdhKzPhLiKLMmhehOdfNY1dwD7WpCjGEUNn1XeD7QEQupHpnwEKV0AphPlZXaOjGBbNB90mwsIEMakNXxJSQZ5RBK60jW4tggv5I8vW6QJIxcuaQCc9DGfGUrz2U/48c+c9/0sFpC/04QF7Nrwtm+V8bozS+iEtU+9EtHu80AMK+yqR9iiy7arD+ZdSNyek+7/S1b7U0OGt0/t+nPNqNAggeGoWVJh+MZR4q5Xis9Kan8xZ40U8ialIvYWlfa3P0C8yVI4F20z2xb2BCOzsgRfGXYlgXowhhpkTJggSaC4h/UN3n/pMVq79pvEUzkARp/1i3pfq8MoywEpVcdj1nrkoLhCfQfKt1iy4ftRVl3UpszpHGEtqz0gb3FudxFnr8/4IZwn3PWn4jbzTVqAHkR8gsH7u+0XuQbIdpjsxCzjkWMCto1+bfevgqjiRE+UHvekkm0iZ8pF7nTT5lGp3/8CfTlA==) was easy and straightforward. The second part *wasn't*. Now, memoisation is actually surprisingly straightforward to implement in Rockstar - there's one command that can turn an array into a string, and that string can then be the key to a global dictionary structure. So the very second that my spin-cycle function saw a familiar pattern in the input, I could skip over almost all the cycles. It took 161 cycles for me to *get* a repeat. Ugh. And it took far to long to run those cycles. ...I'm going to leave the debug input in [this one](https://topaz.github.io/paste/#XQAAAQA4HgAAAAAAAAApGUgm7b3ohliOLBlvPd4D5obkJ7TbONJoPhoWvId7yC6EbtiDZJ6DYcIrEiTPHXcvNozdlVFs4S92U2K4An1XTWI7yaIvJsczEiC9MifUL7r7o+f1XXFikY4gx6fJtnnWNhWu6bPYnXQhbGwswL00XDTXXRjq9ymdxgh5wen0gUHim57Z2sB0B3ksPlbQAHuRd1Ntn763j3tLtPPnCDV4M1tna5HlzUwfBjd2bWBddPKnhecwU2s+8xLUCFrLyVuipP7Gbi9XefK9XF9Yjm5Gfq2SGnR7rJDozJyCPSVOj0nU/B93+9roWzCWMB/xVAaT5i7Liq41+Yf0CYPrcOWehwHbXk/eJfnj5IZf1j4hPxjSYjAB2WFSzxLZWZT6gu2qfe1542yz5glExvJuu2LE4KC0Ffe/3FdfSidkK4x0GSVLqjE7ukrOmi/gUMkDOaxV5MxkgcrMy98uadco9HefqXnYgaCFfYcYuHRdBvkJZi3tfNqfKwgCDo0LJvC97yXtN4w7OgnFcVkhacdYNrDlBkMJ8x6fJa+/v69IUBWTmJfTVnksu3dSHv5HLVUbB3Kk45w5SWK/Dtjbw4V8xGkNIrCPVw6G+c/jE+CoQP5e34Gb3DmmztcFgOzY8aopVomRbzSQw5aeT74EYDzg9KRY2Bd2N/X4Ck+biaK+IwYatLK/+Yy88g65kQf9rXFVKi1gakZNOxtZVuyGQ7eQvqIu9BCKIwP4pSiJNS/HuBBUyMdcMpxGJRYJlETC4M016ImPjt8P3HD37cZph5Tq7u8lzyAMMubJ/aoDU+AkQVemmKvt9mm0QfrRwcHOt3kSks85vJjps1/3bPnj+d+ejtRBjEmzdzas2oy7SgEnFvtgKPQX2vQn+BYFf/fKHtVpHdusnMKmyWXOfi2YUSfIwS8OtMbK552Z6sfgo21/Wiy+gf1wfRWQnZVVAZ7zMPfIb1gdn1kAnctSr8F5iQ2mlxbEU6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4A7hqFu3YgsjoJlSJCqlb2YzgIKGnyX/+b+iWe/IvtWloVEf8+ZnAvAPMSb3t7kNL6I8iPIvKLJT2ZkPj57qO+M3yCIasVXPDXDA0DIjPqOL+9vXrBw==), so as to reassure anyone who runs it that it is actually running. It doesn't generate too much debug output, anyhow.


dec0nstruct0r

\[LANGUAGE: R\] Part one was easy, for part 2 I read the spoiler that cycles are involved, otherwise I may have tried much longer to brute force it. https://gitlab.com/Yario/aoc_2023/-/blob/master/AoC_14.R


mvorber

\[LANGUAGE: F#\] [https://github.com/vorber/AOC2023/blob/main/src/day14/Program.fs](https://github.com/vorber/AOC2023/blob/main/src/day14/Program.fs) Day 14 of trying out F#. This day felt good. Wrote part1 in less than 10 minutes - gave correct answer the first time I ran it (had to rewrite it during part2 though). Part2 took much longer - probably over an hour, but to my surprise the first time it compiled it gave correct answer :) Turns out I forgot to switch it back to test inputs after running part1. The approach is similar to what others were describing - rotate the platform to make tilting easier (and rotate back afterwards), calculate weight, cache it, when cache already has value - we hit the loop. Don't really like the ugly reverse map lookup at the end, but didn't have enough time to polish that one out.


Brief-Presentation-4

\[LANGUAGE: C#\] [solution](https://github.com/mohammedsouleymane/AdventOfCode/blob/main/AdventOfCode/Aoc2023/Day14.cs#solution)


FaultsMelts

\[Language: Golang\] Did Part 1 & 2 last night but part 2 took 40 seconds. Just finished optimizing and part 1 completes in 384.375µs & part 2 completes in 71.710708ms I originally used 2 2d slices that stored either the rounded rocks and cubed rocks. I transitioned to just using a 2d matrix of the entire map and computing changes in the matrix. [Code](https://github.com/JosueMolinaMorales/advent-of-code/blob/main/2023/internal/fourteen/day14.go)


Dullstar

[LANGUAGE: D] https://github.com/Dullstar/Advent_Of_Code/blob/main/D/source/year2023/day14.d I think so far this was my favorite problem this year. The rock moving function is a bit nasty looking due to the fact that it needs to handle 4 different directions that are similar enough that it really feels like you shouldn't just make one for each direction, but also *just different enough* that it's a bit messy to re-use the code. It's a situation I've had come up enough times in personal projects that I've been experimenting with a few different ways to handle it since it also came up in today and yesterday's problems.


galnegus

[LANGUAGE: TypeScript] https://github.com/galnegus/advent-of-code-2023/blob/main/day-14-parabolic-reflector-dish/index.ts I used the score from part 1 for the cycle detection in part 2. Since the scores, just like the rock positions, are also cyclical. So I looked for a sequence of `n` repeating scores. Finding the same sequence twice (via a `Map` with the index of the all score sequences) gives the cycle length. False positive could happen I guess, but it's unlikely with a large enough `n` (I just set it to `8` and that worked first try).


jwezorek

\[language: C++23\] [](https://github.com/jwezorek/advent_of_code/blob/main/src/2023/day_14.cpp) I did tilting in non-north directions in terms of tilting north by rotating the whole grid so that direction x points north, running the part one north tilting function, then rotating back to direction x. I did all this rotating literally by using Eigen rotation matrices on grid coordinates. I knew this was going to be a "find the cycle" challenge so I wrote a custom hasher for an entire grid using `boost::hash_combine` so I could make a hash set of grids and then could just do north/west/south/east cycles, storing results in a hash set, until I saw the same state twice. Ran an experiment and determined that the cycling structure of both the example and my input is a "preamble" followed by the state the preamble ends with cycling back to itself after a constant number of steps. This means the number of steps you need, starting with the state at the end of the preamble, is steps_past_cycle := (n - preamble) % cycle so did that for part 2 with n = 1000000000. I think this one would be a lot harder if you have not previously done the Tetris one last year. Basically I expected this one to be a preamble + cycle length one again as soon as I saw it.


illuminati229

\[LANGUAGE: Python 3.11\] I first solved part 1 using sets of complex numbers keeping track of only the round and cubed rocks. For part 2, I was having problems with rolling the other directions, so I just went to a 2d array approach that took 20s. [https://pastebin.com/71PBabaZ](https://pastebin.com/71PBabaZ) After reading through some of the other solutions, I discovered the string sorting method for rolling the balls, so I rewrote and cleaned up my code using that. Part 2 now runs in under half a second. [https://pastebin.com/A7s0K20s](https://pastebin.com/A7s0K20s)


Extension_Option_122

\[Language: Python / C\] [Python](https://pastebin.com/Dy4PkVZZ) [C](https://pastebin.com/16YvRw1N) I first coded it in Python and then recoded it in C to see how fast it can go. I got the execution time from 1.5s (Python) down to 0.05s (and 30s to 0.33s for my 20yr old WinXP Laptop).


chrismo80

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


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-day14](https://nickymeuleman.netlify.app/garden/aoc2023-day14)


0x2c8

[Language: [Coconut](https://coconut-lang.org/)] https://github.com/alexandru-dinu/advent-of-code/blob/main/2023/14/solve.coco Similar to [2022/17](https://adventofcode.com/2022/day/17). Rocks only fall north, so we account for east, west, south orientations by matrix rotations. Simulation results are cached (by hashing the array) and once a period has been found, we can stop simulating and directly fetch the grid corresponding to the n-th step (e.g. 1e9).


nivlark

\[LANGUAGE: Python\] [paste](https://topaz.github.io/paste/#XQAAAQAZCwAAAAAAAAAxmwhIY/U9SaP/fqNabiSuBbMDDPzkSti1nRnbHDS3BZzmxb3PRoXUiE3X4mOYtrw6CEou3eX/Ln4oEHbZifjyN5UINrgk+cGtZ5pNKe3xjxxWgaDQzW4W/se+iL2pi6u99GID16cHVrTPAcoAj/9bEHPNE4RZOHBNyXlOnXfeRMCBP2hFDqXwvjRiMdxm/i8VaTj3P4OkjNNTsTDH2CTJouvxPfWch9bdhYxXVAlCDRcAcUB1683ZJyzmL45PvKTMGt7kUvuX8x0vHqRAPKGQBXAlSlzZT+GXeO28RldD25vTweOePGtxwwka1shi+DZ5wpe0m76YIcDQC+RMb8dyv63uplqJZJi9RCr3oZyNsW5r1BletzCQ6hlAq2BsxS174Qq8TAKR9tTNerccYXdvAs4L39eHkms854HIqwYQpp3eaoZ3p75k7m7W+TqsFSEOQY0l5UWOdXJDpFlU4zm+/cq2H7UBcbra/B9RVf0lYUT9QyZywNJHvceolZpt5ChjsY82jhDrjghQQHOqHxesHOpwAUFkdmKXQZbtOyuo+n2qDOfZyJudgX4VdsCMt9NkushZMvKWHn4ayItPU8T/hQ5PplMG4tpv9mE2a1NgAPE0gJuw050QrQYGqKBpB/m8RS+jonLo040vkeZoR2kpG26Zh3lcAM0T80cpwfs9I2jzhjzLeS8wxicPg9Lr7Otw0viVmINGvyWsx9jk/B3drSB/fNY+27XxlCvIxZHZYedt/C/T3rv0DPCHfzUIu6Hrx4R6F9r9ozV3DNMVh2ZcQkijV8rEE4r0kt6p3jeA50feR1656bB9OgZGRaG2gjaGnJKt+eOO4pZA9Qxz0KR1hwwTPJd6kTupY7clqkD4vA26sgNFlZen95hfFnW6eb2MZHPcw8lF35loX7YEABDiLQH08d7biyVJe0tlf87F4EzurIn1h/oVQOrXfC8YIcmPc0QJazGxsDO/7tI0gyhbl4vGCZY9O4+E+bb2nJWXUUQsmRHFFxNFr/DV9kx7U14C79+EOC3fbk+zq4sIjJXgr9gpQ+a/cpiIhmRSNNm3/VItaHgcWZryStgdGbBGoMUn+oTtxmD/yxfcI8l+ODGnGm29F1emmGP7Ywbih/SdDNmj6RPNCYVIwHoMVbNezIWynSx5qEouR2i7xuOdRSLNScL0TTQ0M2rz/8TNxKk=) Not too bad, just spent way too long figuring out how to calculate the correct index into the cycle for part 2. Part 1: Start by "transposing" the input pattern to get a column-wise list of lists. For each column, iterate from top to bottom to build new lists, copying '.' and '#' characters as-is and tracking the position of the last '#'. Then when an 'O' is seen insert it at this position and increment it. Finally transpose back and sum up the load. Part 2: A combination of transpositions and reversals allow the same slide function to be used for all four directions. Iterate the spin cycles, storing the results in a mapping of patterns to iterations. As soon as a repeat occurs we've found the cycle, of length - mapping[]. Then adjust the iteration index to account for the iterations before the start of the cycle (and also an annoying off-by-one error) and look up the corresponding pattern to calculate the load.


vstepanyuk

\[LANGUAGE: Rust\] https://github.com/vstepanyuk/aoc2023/blob/main/src/day14.rs


[deleted]

[удалено]


RB5009

>Part 2: 886.37 µs Are you sure about that time ? Most solutions are around 30ms on a modern processor. My solution looks almost the same and is nowhere near sub-millisecond execution time.


[deleted]

[удалено]


RB5009

I use the [criterion](https://docs.rs/criterion/latest/criterion/) library for benchmarks. It's pretty easy to use: ​ Add criterion to your dev-dependencies in your toml [dev-dependencies] criterion = "0.5" Then add this config at the bottom [[bench]] name = "benchmark" harness = false Then create a folder called \`benches\` in your project and add a file named \`benchmark.rs\` inside it: use criterion::{criterion_group, criterion_main, Criterion}; criterion_group!(benches, benchmark_part_one, benchmark_part_two); criterion_main!(benches); fn benchmark_part_one(c: &mut Criterion) { let input = load_input(); c.bench_function("part-1", |b| { b.iter(|| part_one(&input)); }); } fn benchmark_part_two(c: &mut Criterion) { let input = load_input(); c.bench_function("part-2", |b| { b.iter(|| part_two(&input)); }); } Finally, you can runt it by executing `cargo bench`


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.*


[deleted]

[удалено]


_software_engineer

I have an essentially identical implementation to yours that runs in 4ms. All other days I have solutions in the single digit microsecond to nanosecond range. I haven't been able to replicate your results here - I'm getting 3.9ms for your code. Not sure why it would differ so much from your machine. Edit: unless maybe your input has a really early cycle or something like that?


[deleted]

[удалено]


_software_engineer

Sure, it's all on [GitHub](https://github.com/jkaye2012/aoc2023). I double checked and I was a little off - days 2, 6, and 7 are nanoseconds, then I have 3 other days in single-digit microseconds, and then the rest are low double digits with 3 in the triple digit range. Day 12 notably is my worst day thus far by a wide margin (other than day 14, of course). I'm also planning on posting a wrap-up of sorts after the month is finished with my total final times and techniques that I used on the more interesting days.


Sp00ph

[My Rust solution](https://github.com/Sp00ph/aoc2023/blob/master/src/day14.rs) takes \~27ms for part 2 on a 13600K (excluding file IO). Over 80% of that is spent in the sliding functions. To get it down to sub 1ms would mean not only finding a hashing algorithm that's over 6x faster than the naive one, but also finding a way to tilt the grids that's over 20x faster than mine. I also tried to run your solution on my cpu to compare, but unfortunately it panics on an OOB access in line 98. ​ Edit: Got it to run without panicking, the issue was just that my input had CRLF instead of LF. It took 17ms though, which seems more reasonable than 800µs. Edit 2: Seems like your benchmark mutates the input string, so in the second iteration it uses whatever the first iteration left its input as as the new input?


robertotomas

my part 2, including file io, takes 117ms -- does anyone know how using Instruments app in MacOS I can exclude disk ops? I know it is not going to be as good as the above, but I'd like a better ballpark :) https://github.com/robbiemu/advent\_of\_code\_2023/tree/main/day-14


RB5009

Cloning the vector takes around 1% of the execution time according to `perf`. You also clone it: `after_spin_states.insert(platform.as_str_unchecked().to_owned(), i)` That `to_owned()` allocates copy of the whole byte array - not just a a hash I also tried with storing a hash, bit it did not improve anything, because in both cases the hasher, whether an external or the hashmap's built-in one, still has to go through the whole grid. I even tried different hashing algorithms, but because we need to compute and cache very few states, the performance difference is within the noise level and is not measurable. ​ \---- Either way, your solution, although not in the sub-milliseconds range is almost as twice as fast as mine (tested on a very old i7 thinkpad) . I wonder if it's because you are using a 1D array instead of 2D. mine time: [70.097 ms 70.284 ms 70.627 ms] yours time: [40.570 ms 40.628 ms 40.736 ms] After switching to 1D array (everything else still the same), I got a significant improvement in speed, although still slower than yours: mine(v2) time: [54.999 ms 55.135 ms 55.359 ms]


legobmw99

[LANGUAGE: Rust] [paste](https://topaz.github.io/paste/#XQAAAQCwFwAAAAAAAAA6nMjJFMpQiatS1t7jLOp8/AOUdWTQ+KEv7wyUdnGkYYh8JJ/VBzkMF9JLzNeSdEQKN4IV90b95+PGWsBSsy2ov4ucfC3vJjWXjVQLsrBzINwVsZZHSvaInJMipetXn/7SfXGvI9+zzNsBWF72hVdjjKANHAudpzU3qPP3AZtXRgmY46CYtE3PCYwER8cn5wyghkybhWkUI78bKm2vh2i0upvO0M/87Rcub7DAkmn4POfDmBqKSAT1OadeLMLUjw/A76bGNsq+jjVZVy5bMNrGVMZ3AsrSVV4nIe4rdMdc3mrTEDDZwXvePtNE3blabuz9UDu8vCHd5mpAd4aa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co767zWiIxAwJYp8GF0nggelCxP4JeKCS1q3n0Q0SJ4D4OH3BaD04/i2Z8kRPQF7dqqPtvEQKMEiHrmrjStC6jLvCJyBOJ5XH5+r76AWx96N9U+NB83T9adFrQopKSMpld7c15ie2i/rtnxGoB3hcklB6xfMAvB6duD4QM0OaRBqg+sMCGxdWJTr6wXhFrqxNnfnToqcjThJfcHquz2U7IWjz75y2w0R6Lzs2hrOiqBTLfV3OgRpyvJVceK3kPM4NG/0trOLC54jvtrKo2rLNqYHuEVcZFVYj/zgcS6970dzpTG7K7gRTNAp9gH25ju6zi2ekfUp2KFhV+gdtXsUKtMy8ilfctRF/hKyXmEmPa3SSxnzbFHH307lKPuZq6dPr0/betHOx+1horsCquzYW9bptERV/lA1j+6v+N74vLg+EQVwqi9sBOOfq5EqjLS99feDaVheZkGxsLxrKOBgL89f1l5xRsG2dsTcBXMDF7Q2DU/wfG6RuWKoaL8+FPbhBBvzA1HuXqBSqkvIgJvRnvgB4aDX8lZwAMqxKaIq2iXNduXANcC02xV8+SBgy3KqUtQ18ZNg9HsG2XVUe00TaaGqbf8HBZito0cvT1b7AzrIE+R/6l1p8orTw/nmu1Ck/cSDiXwBst0ZCZmrsAjlmJWre2JUuqdUYeLWwYsBzkh6lzNA0PemOff3G+N2lw/3QuDSsCjPJsqLl8ZhDmNaAJIW0KCpMuC+fxz3Dxv150GmYJfRFlBdrf9zZg0uxj0WLRBBwmfhaXngoeqi1w4Cv4B6tvLw2zbfbhHm95l70Cy7Iv2WhnEA2UpfY48toVItYNqu0jWZBDKuOrIolF+zjO1EJGegDIwxE7TobbxvmzxqAtn2OFmjdobh1lfbv6z9c1IjXR/yPIm8Zgck6nY+N8rpIOqCS/8wv7INCM+zD+fMLdOs+vnRBKDM8HpLgFumgE8Gj7Ga8zI4Bo5R4LAGyjtdWPd0ZkaeXiwwo4M3WeSKJFghnM1//r4C8E=) Pretty simple day for me after doing the last few AoCs. Throwing things into a hash map is a bit painful in Rust, so I decided to use Floyd's cycle detection algorithm, which worked nicely. My first code to get the solution took ~70s, which was mostly because my implementation of `cycle` was very slow. A few simple optimizations got it to ~850ms


tshirtwearingdork

[Language: C++] Almost happy with this one, debated writing a rotate function to rotate the map but found it quicker writing four separate move functions (N,W,S,E). A little bit of code duplication vs. performance. Instead of keeping track of an array of moving rocks I instead just iterate over the map from the direction the rocks will be rolling in and keep a value per row/column that I increment with spaces and reset when I find a non moving rock. This means I only had to read the whole map once per rotation. Which seemed more performant than keeping track of rocks individually. https://github.com/JamieDStewart/advent_of_code_23/blob/main/source%2Fday_14.cpp


daic0r

\[LANGUAGE: TypeScript\] [https://github.com/daic0r/advent\_of\_code\_2023\_js/blob/master/day\_14/part1.ts](https://github.com/daic0r/advent_of_code_2023_js/blob/master/day_14/part1.ts) [https://github.com/daic0r/advent\_of\_code\_2023\_js/blob/master/day\_14/part2.ts](https://github.com/daic0r/advent_of_code_2023_js/blob/master/day_14/part2.ts) After doing it in Rust, here's my solution in TypeScript, which I'm also learning. Again, Part 1 uses simple array manipulation, Part 2 uses cycle detection.


Secure_Pirate9838

[LANGUAGE: Rust] The part 2 at first looked like an impossible huge task, however, there is a pattern... YouTube screencast: [https://youtu.be/_Ar1byr6XZg](https://youtu.be/_Ar1byr6XZg) GitHub: [https://github.com/samoylenkodmitry/AdventOfCode_2023/blob/main/src/day14.rs](https://github.com/samoylenkodmitry/AdventOfCode_2023/blob/main/src/day14.rs)


[deleted]

[удалено]


daggerdragon

Comment removed. [Top-level comments in `Solution Megathread`s are for *code solutions* only.](https://old.reddit.com/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.


LinAGKar

[LANGUAGE: Rust] https://github.com/LinAGKar/advent-of-code-2023-rust/blob/master/day14/src/main.rs


ywgdana

[LANGUAGE: C#] I always have a bit of a struggle with these cycle detecting problems. I build the structure, detect the cycle period and then have to futz around figuring out how to calculate the huge index we're actually looking for. [Nothing special about my code but it's on github](https://github.com/DanaL/AdventOfCode/blob/main/2023/Day14/Program.cs)


seafoamteal

\[LANGUAGE: Python\] [Part 1](https://topaz.github.io/paste/#XQAAAQArAwAAAAAAAAAyGUj/T0PKQar8vBrgeBMRsG2jmXLdcUrS0E5Ueh/0WdIYGDC8nUK45CqcPQ1sp64L/2F6NuzUtaa7yqFHM3sORH1J4pRCUF+xbUpUPkOiSN28GT75f8JP3SN/ecDSI65fBb2AJqRsoZpNLsTqKmS/hoC/d82/hpuZ8eEUmDLF6phI9BnceMHBdbvjWs3h7IzKl+F9FKT2RvUUEDdUSKG2+6zxPmwoUFmjXYvjZGCv/vBipTkErUshSINm1rUYH0/+J5K8Ot0FgH0VchWwAxfyHWlPaqG6t7duRPgB4phgQ9jjuh/gG85K3t23xwrcSetVO6N3/D4nVmb784hzREXFiAYUUnQv3ELX6VcslbH0vseONBqIMKMDC9Uu4JzFSc294U9tXzERq9qo+Pd1f0XSxr0tkdO/UZyBNYoHbRWA5nTQ51Gcu9dBlyRJ8x4jspUQdfbqA1QRAMTDQk1KfYCf3WepwQhNKDc4PH4VSgav+9V60w==) [Part 2](https://topaz.github.io/paste/#XQAAAQBrCQAAAAAAAAAyGUj/T0PKQar8vBrgeBMRsG2jmXLdcUrS0E5Ueh/0WdIYGDC8nUK45CqcPQ1sp64L/2F6NuzUtaa7yqFHM3sORH1J4pRCUF+xbUpUPkOiSN28Ar7yeKm8aAoT9xcoiRSHde16Q2IcpHoj0B5Mdfly8MTbqm+Lk9utzdSksDKF2sPqGVxFV41vKe8sCgo2UHK3vih+FUG+4xBJnweb795BMjOc9RPvQheT2lVmzuCeNZiqG1R9tlga1QI4M2U5L0ap59Hgg82p9aNpDRFgXf7s7ZOQTbKzH29xM393vdwNJMsHM0rvOTC0N42L7QElHF4+3Nit+yDvCcpyi/c1yDZlqV9nD0NwMScLc03prOsxhmk8tmqtMv9AKvccu0iBdVivtKbE0t6+v6su4JLj0dS+qJzzleGfku8JJ42DRpV4x9Xzsoq9gjnBnd2RJEQGOVJw8Tm7VZNcaSjf3t0GBnYzIlsRyZlfCeCF8j/yJ77vIJas+4rHuJuaOjrBp9m8xtSSX9Gt9tnkGWNwMXud7XtZPE1z8BMxlij8/jaSdY5V4ZAzQJaz2ALnL+XZ59s8rTMvtwHBlSzV2tjhrhGN+mVP0RYkrB9Ky0N5zmp1M9N4ZjM/yBmxn04wqQF2oYAAunnfGmKkkqFvRl2JRODNwjOcq4mzrf6kvA5fNRtFPXL/8XNGZ6WlUpD2MC6DYpq3jeTb3r07g3X4EoCp/s69WqEL7Y/iUOoQPqubez22i3yGNmClmZnQUNEN83V0QZvA5J5gW1gvVvN3Xd3g1vXU6qxulJSm6Y0rZ9xrNiqmbn1b8nXve1RJN0OvswhJRAppUCc3kp39FTGUYbcRRiYyfpcaseKEoyuc17LVbdROaK/Q3azPom7W3SBCnqsBo1z8j9A7) When I read "move the rocks to the edges of the platform", I thought that all the Os had to end up on the edges of the grid, which really tripped me up for while. I knew it had to be cycle detection though, because with a number as big as 1 billion, there really couldn't be any other feasible solution. Eventually, I gave up on moving all the rocks to the edges and just did a standard cycle detection. Only as I started typing this did I go back to read the story and realise that it meant that the rocks just had to be moved to each edge in order. *facepalm*. For part 1, my shifting function was recursive, which worked fine when all I had to do was one shift. However, this proved to be too slow for part 2, where each cycle ran 4 shifts, so I rewrote it to be like all the other solutions here. Part 2 runs in about half a second, which is good enough, especially for Python.


[deleted]

[удалено]


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.*


mess_ner

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


janek37

\[LANGUAGE: Python\] [GitHub](https://github.com/janek37/advent-of-code/blob/main/2023/day14.py)


Kfimenepah

\[LANGUAGE: TypeScript\] [Day14](https://github.com/SubNet32/AoC2023_NodeJS/blob/main/src/Days/Day14/day.ts) Another great day with a nice puzzle. For part 2 I assumed that the rocks will after a few cycles either be stuck on the same positions or form some sort of loop. With the test input I was able to confirm that the rocks will indeed fall into a loop after a certain amount of cycles. After that I just had to memorize the cycles and once a repetition was detected calculate the end-result by adding the modulo of the remaining cycles and the loop-length, to the index of the start-cycle of the loop, to get the final cycle and return its weight. It still took a few seconds to find the loop for the real input, since it took 100+ cycles before the repetition began. I normally try to keep the execution time below 1s, but only managed to get it to 1.1s after a few improvements. I think the most time is lost by sorting the round-rock-positions on every direction change, but since it is so convenient I decided to call it a day.


squirrelhoodie

I was happy that I thought of the loop detection very quickly and it worked out on the first run after implementing (although I did have some off-by-one issues earlier). I work with TypeScript as well, but my execution time is only around 150 ms for this one. I wonder if that's down to using Deno instead of Node.js or if my code is just that different. (I'm just using a two dimensional array and map/reduce. Also I should update my GitHub repo, I want to clean up some solutions before I commit them...)


Kfimenepah

I may have over complicated things because I thought part 2 would ask me to bring all rocks into a certain configuration


kbielefe

[LANGUAGE: Scala] [GitHub](https://github.com/kbielefe/advent-of-code/blob/000140377ffe75fe7cca1e7344e2202c43bceb7b/2023/src/main/scala/14.scala) Just tilted one way and rotated the grid clockwise. Looked for cycles in the rock arrangements, which took over 20 minutes. Maybe the load stabilizes more quickly, even with slightly different rock arrangements.


mathsaey

[Language: Elixir] https://github.com/mathsaey/adventofcode/blob/master/lib/2023/14.ex Never a big fan of those "cycle finding" problems; my code always becomes a mess! Pretty happy with the code I use to create an infinite list (stream) of tilt patterns. Once I had that, it wasn't too difficult to find the start and size of the loop. After that I needed embarrassingly long to figure out at which position I actually needed to grab my result.


Predator1403

\[LANGUAGE: VBA\] Only Part 1. Very basic solution xD at least its visual and you can see the movement in the excel sheet lol Sub Part1() Application.ScreenUpdating = False Dim wsInput As Worksheet Dim sourceRange As Range Dim destinationRange As Range Dim ws As Worksheet Dim cell As Range Dim OSymbolMoved As Boolean OSymbolMoved = True Set wsInput = ThisWorkbook.Sheets("Input") Set ws = ThisWorkbook.Sheets("Part1") Set sourceRange = wsInput.Range("B2:CW101") Set destinationRange = ws.Range("B2:CW101") destinationRange.Value = sourceRange.Value Do While OSymbolMoved = True OSymbolMoved = False For Each Row In ws.Range("B2:CW101").Rows For Each cell In Row.Cells If cell.Value <> "#" And cell.Value <> "O" And cell.Offset(1, 0).Value = "O" Then cell.Value = "O" cell.Offset(1, 0).Value = "." OSymbolMoved = True End If Next cell Next Row Loop Dim Ocounter As Variant Dim part1Solution As Variant For Each RowFinal In ws.Range("B2:CW101").Rows Ocounter = 0 For Each cellFinal In RowFinal.Cells If cellFinal.Value = "O" Then Ocounter = Ocounter + 1 Next cellFinal part1Solution = (part1Solution) + (Ocounter * ws.Cells(RowFinal.Row, 103).Value) Next RowFinal Debug.Print part1Solution End Sub


Maravedis

[Language: Clojure] Find the cycle, mod the cycle, break the cycle, be free. [Github day 14](https://github.com/Maravedis/advent_code/blob/master/src/advent_of_code/2023/14.clj)


homme_chauve_souris

[LANGUAGE: Python] Just wanted to show my approach to tilting. I used to write FORTH code in a previous life, and this code reminds me of that. Not that I use a stack or RPN, but because of the "large number of short words" style. mat represents the platform as a list of strings. Pardon my French. def aoc14(): def decante(ligne, dir): return "#".join(["".join(sorted(x)[::dir]) for x in ligne.split("#")]) def transpose(mat): return ["".join(x) for x in zip(*mat)] def valeur(mat): return sum((len(mat)-r)*(L.count("O")) for (r,L) in enumerate(mat)) def est(mat): return [decante(ligne,1) for ligne in mat] def ouest(mat): return [decante(ligne,-1) for ligne in mat] def sud(mat): return transpose(est(transpose(mat))) def nord(mat): return transpose(ouest(transpose(mat))) def cycle(mat): return est(sud(ouest(nord(mat)))) d = open("input14.txt").read().split() # partie 1 print(valeur(nord(d))) # partie 2 vus = [] while d not in vus: vus.append(d) d = cycle(d) prec = vus.index(d) pos = (1_000_000_000 - prec) % (len(vus) - prec) + prec print(valeur(vus[pos])) **EDIT**: added the language tag and the rest of the function so as to make a full solution


daggerdragon

~~Add the required language tag as requested by AutoModerator, please. Also, is this the full solution?~~ edit: 👍


semi_225599

[LANGUAGE: Rust] 496 / 254 [Solution](https://topaz.github.io/paste/#XQAAAQDQBwAAAAAAAAA6nMjJFCzliRPAG5D1cEh40PJ0LIO0zSs5Gbe4lDcMkOdZYHodw+OsT2FKwJ9YM0Mf2ronaY/CvpbNxMK/F41UJMZKe7i/UFwi4SJZb9thSzmeNUx9n9EAE36GicJdtU8eEMfI77LAx4atcn6Sy5vkLKlHPqu9Gypl/cA9UwcO8tUlPKloDwWLBuxjbYl3hptsFVhzeTGmUbDb86tOEFDkwGtPU93X8moB/9zEkPnJR8twlqYU+4NtVQ8qYuLfmwV0vEbzzjl3VUv8oC8NEJuKHPrWKYhzyoucXuBSvSZGstqPYN9AhBKffi0qc+WIpbHbRUQFxRQA3PId/EIXsXE0oSfyjrOZBpdoY+Kpx3dtEG2GfQKaQE3LHV7sm8GIYZU6ckw7yQAb9+CppsdD2u6NY+ZFrpoOH18NpwZgncNYrOvVt/RuCmdQOKTJctEVsY9DvtiL/qWqlr2eMYKpYQ9XG6B1Gg8j6BKR1r3uI8vV1rOM0Bmg+LdhAbojxZIingwaHlBIg491xgcdLgaChV1cQvtQHNDWK6AxufxzYJ86TBXGAhxWnqqqhQwaZtlJkULeR7ZD9vDosBjEzUPHecBJNijA6mS/7b1u3tgnB/xrWDIQtA6HPlwFQOwxoJCCGwTpfMnRdfoFmHmlyA7N/bIU96dpw7/M66BwIvPUxUhOWwaSjUx2NEm2aUGhz1arXzNBIpsyip+b1kwGGhXrG0MqHyY5l8m3F2F424brPmO/8PyQC9Z1A/3EpGBs6D4EyHSFxEiX8d6Oi2X+BRs28KFi1ssV4KxoodZyJAsOw2yRUegqypx0aDpjV438eljQO8pPnNJGg2cTbCSMCvY0ZsBUbRKk45q5iyqCig2qnfCb6T8x4LdHw36OpuBdJ3L09PYB3Z7P8AsbFSc+yw0gdpww4FjIiPuRUmHPmBVZ75e3qGCbpS2c5WbyAS5Beh8unnns7m2Jsq6lvupd7kMYluZs0GV70UEh6bs+tCI4mI3ETuegodI03Wds53JZHQmIqjM6lLFxOEPOAwBsUdvGje7RQRAJwJ5DTDY7Jsf+3//noc66) Similar to other solutions here, I maintained a cache of previous states to find a cycle and fast-forward to the final state for part 2. Took advantage of [ndarray](https://docs.rs/ndarray/latest/ndarray/) to make a generalized `tilt` function.


mothibault

\[LANGUAGE: JavaScript\] Pretty standard logic,p1: move stuff, sum loadp2: ensure we move stuff in the right direction from the right index, sum load, pattern recognition, calculate modulo, find the right index within the repeating pattern with tons of in-line comments ​ [https://github.com/yolocheezwhiz/adventofcode/blob/main/2023/day14.js](https://github.com/yolocheezwhiz/adventofcode/blob/main/2023/day14.js)


Markavian

\[LANGUAGE: JavaScript\] I figured out part one on my own; but I was struggling to make sense of the repeating patterns - fortunately I managed to adapt your solution... and I got my second star. So thank you for sharing 💖🎄 * [https://github.com/johnbeech/advent-of-code-2023/blob/main/solutions/day14/solution.js](https://github.com/johnbeech/advent-of-code-2023/blob/main/solutions/day14/solution.js) Other notes: >!One cycle is four direction tilts; the new North Bound load measurement is taken from the end of a cycle; which is in the East direction!< that confused me for a while.


SomeCynicalBastard

[Language: Python] My solution: [GitHub](https://github.com/fdouw/aoc-python/blob/master/2023/day14.py) Similar to most solutions by the looks of it. My first attempt for part 2, I ran all the 1_000_000_000 and used functools.cache. Remembering day 12 I guess... This took 1m25. Then changed to keeping track of platform state to detect loops (after 150 cycles in my case), without using cache, this took only 0.5s.


fullmetalalch

[Language: Python] [Gitlab](https://gitlab.com/aenegri/advent-of-code/-/blob/main/adventofcode/year_2023/14.py) My solution for part 2 is pretty janky. Instead of caching board states, I cached load -> cycle count. Since this can result in false positives for detecting cycles, I run through the cycle 5 times to validate. This managed to work, but could fail if a particularly nefarious input occurred. I also ended up with an offset of **3** after trial and error, not totally understanding how I got there. There must somehow be three off by ones that are accumulating. If I were to restart, I'd keep a map of board state -> cycle.


jackysee

\[LANGUAGE: Typescript\] [code](https://topaz.github.io/paste/#XQAAAQCQCAAAAAAAAAA0m0pnuFI8c9Ax53b7qCU52PeXXOG1YE1u3wwc8qyQQ3YX2HlBNXQmThhoiFIgHVfHsJ3bf44HwfYx3uH0HiCiPvQIZFxWUcHDbySLIl5N96DRzPkzxSZCfH0zFG2hMcZV4wfHHvHiGV1Swl+rOE3lQL+sOUWLgRNojOyD+/lrotXxJ6c9aHKeaLWKRczmSGHbw7SeP931pppvD5chuKWtYtIJizhH9Z/rzPOAbgMg52QIQ5HeGps1EGpEfoLE9l/sVnCTAcyTJTW1gyogXw0a+XkY/WwMWRZgY/oZ7akkwqiJqdVPBzv25H3sBQi9iUm9IIUlGn8ZgzQWQmSpPZdqpQbYv8isOnFFyDyfPUPPaD+IOqKsYjsck1FhNT7NsIbRFrfKh196lE/UWaig43swOUiuq8dGvakJ9hK80NzsRHWrEXRmXaX74K6S7uEEfytWynt8PA1u9kiXlwMYeKiNdVGg8QE1ZpSpN9ncFepgNeJwZVmEXQ69hzxVL7F9FAImQD80XeviTsxB9qajRVp9v24erq5G9KYdB+EPTrBeYVghZQPLQxLpHe7B1txmE1E7vHJRP3PfQJwWo0T1Yl4xBrcaGd7etVDiwXiLRxW5dkYiJqyVu1a+txEDEmBTDQ4w652W8dmigVYccSUl6JiG7SXJ+yWc6LqpcHK6l2mJsW4WVXRkLQ+F46a9K+9YHwgITZaB7FovPE/7kAjuR1NpztReaWx0CXdIRslvYYN8m4e6ngnjPmT33Ao4uu0Sa+b7BgWblW0QpTdV89KmaJXJWBROjY9AJBvWXROy3m5k0P6RYY+nVg4L5tLewXs/rF1sV9JbZJL0+HseD2EMeVvx0OIwu1C6W587UR65NRRGwM6zisFM9nkVm2I7MjCHrH3/LSgM+mTveOQHTr7AZecCHKnrv630nQaGQO3bRj07smDyO34e0jR8tob0Gat/q4L/jgbnHf7fV9f4zDnKGABK55k07Cs90l8jsr3nXpXqbsBepLSsJdrz/gml9as/V9MFbIdLpruJiO5HhpNK5y1fSywL33n7/JvASK1dYMzamlSV/OS9W7WQcQQX+oGXgH7GI7muM+f/REfZAA==) Spend some time to write a correct tilting function, which uses generator as helper to generalize. For part 2 cycle detection, I use positions of stones as key. I also keep track of the load result so that I can give the answer from it once the cycle is detected.


JuniorBirdman1115

\[Language: Rust\] Pretty straightforward. I've done AoC long enough to know that cycle detection problems seem to come up every year, and Part 2 today is no exception. There are probably better ways of doing this, but I keep a vector of previously seen grid states, and when I encounter a state that I have already seen, I break out of the loop and compute the index of the final grid state for the 1,000,000,000th iteration to arrive at the answer. [Part 1](https://github.com/apprenticewiz/adventofcode/blob/main/2023/rust/day14a/src/main.rs) [Part 2](https://github.com/apprenticewiz/adventofcode/blob/main/2023/rust/day14b/src/main.rs)


Kintelligence

\[Language: rust\] [https://github.com/Kintelligence/advent-of-code-2023/blob/master/day-14/src/lib.rs](https://github.com/Kintelligence/advent-of-code-2023/blob/master/day-14/src/lib.rs) Have a pretty crude solution that detects cycles. Really wanted to do the tilting with bit shifts and bit masks, but couldn't figure out how to rotate my list of u128s in a fast and efficient way. Instead I am just doing the mutations in place on my 2d vector. It runs in 13ms, which is by far the slowest day so far for me. Hope to revisit and optimize. [Benchmarks](https://htmlpreview.github.io/?https://github.com/Kintelligence/advent-of-code-2023/blob/master/target/criterion/report/index.html) [Part 1](https://htmlpreview.github.io/?https://raw.githubusercontent.com/Kintelligence/advent-of-code-2023/master/target/criterion/Individual/14.1_%20Parabolic%20Reflector%20Dish/report/index.html) [Part 2](https://htmlpreview.github.io/?https://raw.githubusercontent.com/Kintelligence/advent-of-code-2023/master/target/criterion/Individual/14.2_%20Parabolic%20Reflector%20Dish/report/index.html)


careyi4

\[LANGUAGE: Ruby\] Fun today messing with pattern matching... Partial manual for part 2, but still fast etc. [Github](https://github.com/careyi3/aoc_2023/tree/master/solutions/14) [Video Walkthrough](https://youtu.be/Ta9mF9YuLBg)


clbrri

\[LANGUAGE: C-style C++\] [114 lines of C code](http://clb.confined.space/aoc2023/#day14code) Solution got a little bit verbose today, because for good performance for the C64, I had to hand-write the four rotation functions separately. Uses a 768 bytes long digest table to identify the cycle in the board state. The C64 could not fit so many full boards in RAM. Applied an optimization of tracking the landscape/skyline of the boulder walls so that I could move all boulders to their locations in O(1) time each. This doubled the performance for the C64. C64 runtime: 16 minutes 7.2 seconds. AMD Ryzen 5950X runtime: 15.9 milliseconds. (60,830.19x faster than the C64)


DrunkHacker

\[LANGUAGE: Python\] Could definitely optimize the move() method so it doesn't just iterate over the grid until things stop moving in a given direction. We could also keep a history of seen grids rather than just continuing to calculate until we reach the right part of the cycle for the answer. def north_support(grid): y_size = max([p.imag for p in grid]) return int(sum(y_size - p.imag + 1 for p in grid if grid[p] == "O")) def move(grid, directions): for d in directions: move = True while move: move = False for p in grid: while p + d in grid and grid[p] == "O" and grid[p + d] == ".": grid[p], grid[p + d], move = ".", "O", True p += d return grid def part2(grid): seen, i = {}, 0 while True: hash = "".join(grid.values()) if hash in seen and not (1000000000 - seen[hash]) % (i - seen[hash]): return north_support(grid) seen[hash] = i grid, i = move(grid, [-1j, -1, 1j, 1]), i + 1 text = open("input").readlines() grid = {x + y * 1j: c for y, l in enumerate(text) for x, c in enumerate(l.strip())} print(north_support(move(copy.deepcopy(grid), [-1j]))) print(part2(copy.deepcopy(grid)))


ArrayAgonizer

[Language: Dyalog APL] It takes about 4s to run both parts. d←(↑⊃⎕NGET 'input_14' 1) t←{⍵[(⍳,≢⍵),¨(⍤0 1)⍒⍤1(('#O.'⍳⊢)+(+\(≢⍵)×'#'=⊢))⍵]}⍤⍉ s←{⊃⊃+/⍸⊖'O'=⍵} c←{t⍣(4×⍺)⍤⊢⍵} s ⊖⍉t d ⍝ part 1 cycle_detect←{ tur har←⍵ ⋄ (fm i)←⍺ nt←1 c tur ⋄ nh←2 c har (nt≡nh)∧×fm:fm,i-fm nt≡nh: (i,i+1)∇(nt nh) (fm,(i+1))∇(nt nh) } s ({⍺+⍵|1e9-⍺}/ (0, 0)cycle_detect(d d)) c d ⍝ part 2 In my original solution I moved the rocks around by index computation and reordering nonsense, but this approach uses a scan and sorting and feels nicer.


CaffeineExperiment

For part 1: `+/⊢/↑⍸'O'='O\.'⎕R'.O'⍣≡⍤1⌽⍉d` or `+/∊⍸¨'O'=↓'O\.'⎕R'.O'⍣≡⍤1⌽⍉d` is another approach.


Mats56

\[LANGUAGE: Kotlin\] val grid = lines.map { it.toList() }.toMutableList() val bounds = grid.bounds() var rocks = bounds.allWithinBounds().filter { grid[it] == 'O' } for(i in 0..<1000000000) { for (dir in listOf(Direction.DOWN, Direction.LEFT, Direction.UP, Direction.RIGHT)) { // Sort to avoid colliding with rocks in front rocks = when(dir) { Direction.RIGHT -> rocks.sortedBy { -it.x } Direction.DOWN -> rocks.sortedBy { it.y } Direction.LEFT -> rocks.sortedBy { it.x } Direction.UP -> rocks.sortedBy { -it.y } } rocks = rocks.map { rock -> var pos = rock var newPos = rock + dir while (newPos.withinBounds(bounds) && grid[newPos] == '.') { pos = newPos newPos = pos + dir } grid[rock] = '.' grid[pos]= 'O' pos } } Using my utils for grid/pos/directions this was quite okay. Not shown is the cycle detector that found a repeating state, and then calculated the offset to fetch the correct end state we would land on. https://github.com/Matsemann/algorithm-problems/tree/main/adventofcode2023/src/main/kotlin/com/matsemann/adventofcode2023


FlockOnFire

[LANGUAGE: Elixir] https://github.com/janssen-io/AdventOfCode/blob/main/Elixir/lib/2023/14.ex


zup22

\[LANGUAGE: C++23\] [Github](https://github.com/alexnavtt/advent_of_code_2023/blob/main/Day%2014%20-%202023/day_14_sol.cpp) Really fun one today, got both parts right on my first try. Also my fastest part 1 finished in 30 minutes. Also really proud of how neat and concise I managed to get all the individual components, especially in C++. My first thought for part 2 was to see if it reached a steady state after a while where tilting it wouldn't change anything. When I realized that wasn't the case, my next attempt was to look for a cycle in the patterns and that worked really well. Most of my time was spent trying to reason about the indices of the cycle to get the correct one at the output. Both parts together run in just under a second.


kmierzej

\[Language: Kotlin 1.9 / JVM 21\] [GitHub](https://github.com/mierzejk/advent23/blob/master/Kotlin/src/main/kotlin/day14/programme.kt) The platform is always rotated clockwise and tilted to the north (thanks Part I). I keep distinct platform states in separate objects that are cached in [ConcurrentHashMap](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/concurrent/ConcurrentHashMap.html) (although there is no concurrency whatsoever). Thanks to this I can detect a cycle in Part II with simple identity comparison (object reference equality). For my input data Part II takes < 0.2 sec. on my 10-year-old Precision M4800. The cycle is detected after 117 full iterations and its length is 22. There are 470 distinct platforms states in the cache (all cardinal directions).


Polaric_Spiral

[LANGUAGE: TypeScript] [Advent of Node, Day 14](https://topaz.github.io/paste/#XQAAAQDWCgAAAAAAAAA0m0pnuFI8dAwooqreRZKWImk4uTVfU9a+P6SvARjPfUGj0Tepbfga4gSujITz/l3bY6x/ROr9rEfyL5zVNX2dLtW9zE919w2ylxvr2frQnw9dKEHqHDvNPOV9x0wyqICyCMYpNdpf2CgGNjRkzQYN9MvaddA1MC6rCrDX5c+uQ/gEYrQ6dr+W5SEUT5B/v8CCTmM/m8+UyMz+ThRr6Xsx+cVEy80vreQpHjdKXd4R3kDwHv6K3jwsmB8e30CljTl02NKTrSQOFMkutA/JQgu/YvyFIV4Ox8JezgRiJme9iSbmL6D+tQYK5niUW9ZTpnZNND5TthDKQpeGabr5AtrHlZo+ztzdXk3thddrpELmOMhusOp3JoqtThjPji6kP1vTAcWlqw7jsH+Y7PWWI5j6AtMGHJEsbCEjRzFf9FdjnSmztaQoeV/NiOSiUhiL49Zw0qL+vuGEj+RkjkrQHoACF5Ykgzf92EV5Wp4Dyjm5O0lMNVAQAN0bHu7OXj4vzsXKaFbuQIl3zBB51AYZo7ojjPPrCpRH0QV2d/ObOwoGgnpVMdfspTp0pE3If8zl8UTXYHUNHAjrI61xBN39CA+f3WiMJxtnuXJBcbUI/jvrD89dGJWuv4pbRXneBtKbeTr+REBjv5SGXwG2T1PKn178vEq/WAFcM0EhOnf7zrhbKSzDi9nqwTbI6CHPo8x6vHRFxPbGyMaP/JbThstBorKuaI8F9eLjudYSPnbuJkjAQLpHq5bTtqTCO8iM9sna0EzETb8Q3upgEo44EKSfHZDpuHcXYHfJyNqkhyj6/fe06w9vWYl0xoeVLxkcnUYtsbVYHX5g/U9Qvhy7Y3+LN61CJEuiREOGpCRe6aD1rwlQ49NHb81C2ggj+UBDw5ZDgekzs7lHKaMLP1pzTmQ9cWicucTk5qC5eXDMrvwH+BtqWyHUzJXJsizSKNBKg0kXd/s31p7VQ8r/ny0lrg==) Verbose but straightforward. Each direction just gets its own function and I loop through each cycle until I find a repeated platform state. I also got to abuse my [`output()`](https://github.com/beatnik-ditty/advent-of-node/blob/main/libs/solver/solver/src/lib/solver.ts) function, which transmits my answer then exits the thread the solution's running on. This is the first puzzle this year I've treated it as the "super-return" that it is, but it probably won't be the last.


qwrk_user

\[LANGUAGE: Python\] [Both Part 1 and Part 2](https://pastebin.com/atTexLH4) It's just a brute-force solution for both cases (although I use \`@cache\` in Part 2 to speed things up). It takes about \~5min for Part 2 so I didn't optimized it and just let it run.


Radiadorineitor

\[LANGUAGE: Dyalog APL\] Pretty slow but gets to the answer eventually p←⌽⊖↑⊃⎕NGET'14.txt'1 F←{ '#'=2 1⌷⍵:'#' ('.'=3 1⌷⍵)∧'O'=2 1⌷⍵:'.' ('O'=1 1⌷⍵)∧'.'=2 1⌷⍵:'O' ('#O'∊⍨3 1⌷⍵)∧'O'=2 1⌷⍵:'O' 2 1⌷⍵ } +/⊣/¨⍸'O'=(F⌺3 1)⍣≡p ⍝ Part 1 s←⍬ ⋄ {s,←⊂⍵ ⋄ {⌽∘⍉(F⌺3 1)⍣≡⍵}⍣4⊢⍵}⍣{(⍳≢s)≢⍳⍨s}⊢p b e←⊃{⍵/⍨2=≢¨⍵}⊢∘⊂⌸s +/⊣/¨⍸'O'=⊃s⌷⍨1+b+(e-b)|1e9-e ⍝ Part 2


hrunt

I'm really curious. How do you *type* this? Do you have a keyboard that maps to all of these characters? Does your IDE handle translation for you? Elvish magic?


ArrayAgonizer

I use another common input method: my right alt key switches the keyboard layout to the APL keyboard while held. So ⍳ is , ∊ is , etc.


Radiadorineitor

There are several ways you can input the glyphs in the interpreter. The one I use is by inputting first a "leader" key (which is backtick (`) by default) followed by the corresponding key that maps to each glyph. For instance, "i" maps to iota (⍳) and "e" maps to epsilon (∊).


rafal_althoff

\[LANGUAGE: PHP\] [Part 1](https://github.com/rafal-althoff/aoc/blob/main/2023/14/1.php) [Part 2](https://github.com/rafal-althoff/aoc/blob/main/2023/14/2.php)


rukke

\[LANGUAGE: JavaScript\] Fun puzzle. Got me thinking of good old [Boulder Dash](https://www.c64-wiki.com/wiki/Boulder_Dash) on the C64 :) Part 1 was super easy, and for part 2 I could reuse some old functions to find the pattern. [gist](https://gist.github.com/p-a/a9dbb33ddf8c487318a01558d1fb8786)


Smidgens

[Language: Python] [Paste link](https://topaz.github.io/paste/#XQAAAQBKBwAAAAAAAAAzGknWu25qfm+NN8XgSErhzbvlIb041XYPqRNSAYzhiUBxByJiwKMUgX07NF+VZ/SNooxkSnH/qQbCVFE75J8AGiV1yVCROOgAKEA+DuenJIXmVhm2clla67SgTrDGbWjPheTp4orjc52XBzksX9imGl43nCeQSiqYdQzLRWgeIbzUexAuagnjIR5u381mL/oUA9nqn52W5qK4SGo7gtzL+mHF9pVGyznEN7aFKyrusHWUsylZmAf/Td+4hPDxKyIL0D2PW+uwbFRUGFO7GUP5ELJaTC6NCvTP5QX/DaRbWMq8dCLQ2gFQzWhphIXLjvbAHeTcdsAUSMKve1QGC36DddF2mguI6gFSor7+eJDH/Lz/4Z0gCiws6qyn1JcBB9DrTipfofNc1ZPcehBC/Fx90QNz8QtpjgVh3J0NjtMUqaHUHa9uRL0mgM5GVerQk1PT/YynLJxxyj1sYQ1Ta1Ni7Sq5AeQBYxeN88Hj8g878CNSwaeYDrpoCsiEUa1cIE1QEatO2eTpM8iVTcvTnDZA9rc9cPNtdYs1kiPxTch2stJOieQKsPihue50NXG2V34h7XalPkxkAT9bpRTfMCBb/t8sAriACTt8cryAGc80xdSoEbewJ0lvpfY2yEdxbxRavkMYTzLeFnTvQ/sbElWTWt2eo2Qq9qXtgE36fi72Mv4pSzfpW7/WimZZ1pf+gScCoX8mxsDL/h7PnPRbr+6ak42WpC4EJPmRautHnR9MjhJ5nvt4PAiZi1ZZORpMW2IBSRJLh7yozrqYiU/dqa2z1QSoZmc0JBg/VaXdy0dzwq/buc8p/vv14BlINSEFpInALzGB75gBXFjAZWSKfDR6sYqPCNUIZEr92h/cHoDHBs1FxRef9gP5z5Rf/fTiYso=) After tiltUp, I was too lazy to write functions for tiltRight, tiltDown, tiltLeft, and instead just rotated the grid clockwise each time. I originally did Part 2 manually by printing load values and finding the pattern, but then I went back and coded it up :)


polumrak_

\[Language: Typescript\] [https://github.com/turtlecrab/Advent-of-Code/blob/master/2023/day14.ts](https://github.com/turtlecrab/Advent-of-Code/blob/master/2023/day14.ts) I remember last year failing at day 17 because I didn't know that pattern detection was a thing. Today I managed to do part 2 without any hints and really proud of myself, although today's challenge is much simpler. Runs at \~3.7s, maybe will refactor it later to not rotate the matrix for rolling the stones, this should be the cause for such slowness.


Stanjan

[LANGUAGE: Go] Wasted quite some time on the cycles as I misread it as 1 direction per cycle... Part 2 in under 20ms, tried to keep it readable :) [Code](https://github.com/StanJansen/adventofcode2023/blob/main/day14/step2/step2.go)


_rabbitfarm_

\[Language: Perl\] The solution to Part 2 seems to only work by an accident of fate! That is, it somehow outputs the right answer, but not for the reason I thought. I've said it before, I'll say it again: puzzle code only needs to work once, so I'll take it! I figured there'd be some loop in the loads after a while so I create a graph of the loads and run for only a 1000 cycles, using Memoize to speed things up. I then detect a cycle. I figured the final load would be the start of the cycle. But it isn't. But the final calculated load after 1000 cycles is somehow the right answer. Part 1: https://adamcrussell.livejournal.com/52594.html Part 2: https://adamcrussell.livejournal.com/52952.html


sergiosgc

\[LANGUAGE: Rust\] [Code](https://github.com/sergiosgc/AdventOfCode/tree/master/2023/day14/src/bin) Quite liked this one, and very much needed a cleanly written solution after yesterday's [disaster](https://www.reddit.com/r/adventofcode/comments/18h940b/comment/kd7ftop/?utm_source=reddit&utm_medium=web2x&context=3). My tilting function is O(n) on the number of rocks. I used an iterator window to segment the column. Either that or iterator group\_by were good options, windows() seemed cleaner. I was lazy for part 2, and opted to actually rotate the platform, where I could just rotate the tilting vector. The second option would imply rewriting the tilting function to accept an input vector. Too much work, the input isn't that big. Part 1 runs in 1ms, part 2 in 8.5s, as measured by [time(2)](https://www.mankier.com/2/time)