Skip to content

Commit

Permalink
2023/14
Browse files Browse the repository at this point in the history
sooo many off by ones again

      --------Part 1--------   --------Part 2--------
Day       Time   Rank  Score       Time   Rank  Score
 14   10:47:42  22765      0   12:53:42  17267      0

Adjusted: 8:45, 2:14:45
  • Loading branch information
sportshead committed Dec 14, 2023
1 parent d49995a commit b2d8082
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 0 deletions.
10 changes: 10 additions & 0 deletions years/2023/14/_input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
O....#....
O.OO#....#
.....##...
OO.#O....O
.O.....O#.
O.#..O.#.#
..O..#O..O
.......O..
#....###..
#OO..#....
100 changes: 100 additions & 0 deletions years/2023/14/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
...O..O.O.O.#.OO....#..O.O#.#O...#.OO.##.#...O#...#.##........##.#O#..#......#.OO......#.....O.#..O.
..OO...O.##.#...O.....OO#.O..O......O#...........#.O.#..#.###O....O..........#...O..#..#....O..#OO.O
.#OO.......#.#....O..O.#......#...#O......#...O.OO..........O..O.#.O.OO.O#OO.O....#..O#..O..O.....#.
OO..O#..OO.....#..OO..#..OOO#..O......O.##..O#....OOO.##........O.#.O....#..O.O...#....#..O#..#.O.##
#O.O.....O.#.#.#.#.#......O#..O..O.#...O..O.O.O...O.O.O.OOO.....O...O..O...###O.OOO...#..OO..O#O#...
.......O...OO.O.O.OO.OO..O....#O...O.#O........##.O...#....#O...#.....O..OO.O.##...O#####.OO.O....#.
##.....O#...O..O....OO....OO#.O....O.#..O.#.O.....OO......OO...OO#....#.........#.....#..O.O....O...
O#.#.OO........O....#.O...O.##..###.#.O.#......#.....O.....O#...#.#O..O....O##O#..O..O#.#..#.....O..
O..O#....#...O#......OO.#...#OOOO...O..O...O###O.O###.....#....#O#O#OOO....O.#....OO..O....O...##.O.
.......O#O..........#...OOO..OO##..O...O#...#O.O..O..O...#O.....O#O.#........OO.#OO....#O.O.#.O...O#
.#.#.....O.#.O.#.##..#O.....#O.##O....O#O.O#.....#...O..##O............O.O#.#....O....O.O.........O.
....O#..O#.#.O.........OO..O#O..#.....#.#..O..O....#.#...OO......#...#..#..O##O..O.#...........O#..#
...O..........O..#O#..OO#.#...OO.O.O#.O.OO..#........#..OO..O.OO.....#.#O....O.O#O.OO.#...O.#O...O..
..O..OO..#O..O#..O..O#.#..OO...O.O...#.O..O.......O...OOO.........OO..O......#..#..O...O..O##.#OO...
........OO.O.O...O..##...O##...O..O..O.OO..O.#.#.....#.O.O.O.....O.##...O#O..#......##.#...O.O...O..
OO#..............#...O.......#.O.....O..##.......O.O##....#O..#.O...#O#.O.##.O#....#...O..O..#....O.
..#.O...#.....O...O..#.##O..O....O.O.....O..O........O...#O...#..O...O....O..O....#.O..O.O......#...
...OO.O...#..#...O.OO#......O..O.O.#..#..........###..#.#.......#.O..#.O......OO.#.O#..O..O.O..#..O.
...#.......O##O..#O...#.#.#..#..#...#.....OOO#.O#O#.....O......OO....#.#.OO....O.O.##O..O....O#O.#.O
##O#.OO.O#....O.#..O..O..##...O..#O.O...........#O.##....#...O....#OO.OO....O....#OO#O.......O......
#O..#.....O....O.O#O..O.O.O....O.O#.OOO...#.#.O.OOO#.O#....#.OO#.###.....#...O#O.#.....OO..O.....O.O
##..#....#.O.#.#...OO.O.....#.#.#.###......##.....O....#...O##OO.O.OO.OO##.O.......#..O##.....OOO.#O
......O.#..OO..O......#OO....O..O...O....O.....OO......##.#.OO....O.....O..O..O.#.#..#..OO#.O..OO...
....##...O.O.O.O.O..O..#O..#........#.O..O...#.O.....###.O..O.#..O......O##....O.....O.#.....#....OO
#....#..........#.......O.O#.........#.#..O......O..O#.O..O.##.##..O..#OO.O#...............O#.#O....
..##..O#O.#......O#..#....#.O...O...O.O.O#....##.#...O..O#......#.O#.#.......O#O...#.##..#..OO..O...
...O.#..O.....OO##.....OO.#......O.OO..#.O##.#....O#.O.#....#..O#.O.#...#........#.#.#O..O...#O..#..
...##..........O#.#......O.......OOO...O..............O.O##........#........O.....O....#O#.#.....#O.
.#......O...O..#...#..#.O#.....O..OO#O...O.....##.#.#......OO..O##......#...O.O....O..##...O....#O..
..#O.O...#..O..OO.#..OO...##...#..O#O....O...O.....#O#..#.O.......O........#OO..O....#.#O.........#O
.#.....O.##...#....O..O..#.O.#.#OO...#........#..O.#.#....#.O..O.#O.#..#.......#..............##.O.#
...O..#...#.O....O.O#.#...#.#...........O.O..#.#..O.......#O.OOO.#.....#.O.#...#O....#O.O.......##..
.#....OOOO..O.....O.OO#O..#...#.....O....O...#..##.O..O.#..O..#.O#..O.O...O#.....OO........O..OO#..O
O.#.O.#...#O...#O.#......#O...O.#.O.O#O#..#.........##.O.OO..#....OOO##...O##.##.#.O...#.O.#O#......
O..##..O...O#OO#O..O..O...###..OOO...#O#......##..O.........O#.....O..#...#O......#.#..O....O......O
........#O#..##O....OO..#..#.#...#.#.#...OO...O###.#O.#OO.#..#.O.......O..O..O..OO...O....O..#...#..
.....O...O....#.#.O#...O..O.#.#O.OO#OO.O.#.....#.#..#..O.#O....##......O##O##.O#..O.###....O#O.O.#..
..##....#.O.#.#O#.O..O....OO#O..O....#....#.O.O.#...#OO....#O.#..#O.......O.O.O.#.....#O..O.O......#
.O..#..........#..O.#..#.#..O..O.O#..#..O..#.....O#..#..#OO...O#.O..OOO.....O..O..OOO..#..O..#....O.
.....O..#.#..#......OO...#..O.#..##....#O..O.O.O..O.#..OOO..O.OO......###..#..O#.OO####..#..OO.#....
#.#...O.....O....#O..#..##.O.#...O.#.##.OO...#..#O.O...#.....#...O.O.O...O.#.#..#..O.....O..OO.O..OO
..#O..O.O...O##O.O..#..O.##O##..O.OOO#O...O....#.O#............OO.#.O..#...........O......O.#..##...
.....O.O...#O.O...O#....#..#...O.#..OOO.O.OO.O##..#...#..O#O#..O..##...#....OO........#..O.O.#...#O#
O#..O....O.#...#...#...O#.#..OO#.#..O...O.OO....O...#.#O.###.#...##..OO..##....O.OO...OOO.O.#.......
O.O.#.........#####..O..#.OO..O.OOO...#O#..O.............OOO...O.....#..OO...O......#O....OO...OO.O.
#.O#...O##.O.#.........#.#.#..O......#.#....O...OOO.O...#....#.O#....O.....O.....#.O..#..#.#O.......
#..O......#.......O#O.OO#......#...#.....O#..O.O.#.....O..#.#.....##...#...O...#.#.O..O.O.....O...#.
.OOO.O...#O.#..O#O...#..#O#..#.......###...#.#......#O###.....#...#....###O#.O....##O...#.#...O..#..
.O...OO.......O.O#O#.O.#O.O...O....OO#.....#..#.....O....OO.#......O#OO...O##.#..#.#..O..O...#...#..
...O....O..O#O....#.........###..O.....O...O#....O#.....#.#.....#.O.#.OO..#.O###.....#O#...#.OO#....
#.#.....O#O....O......O#..##OO......O#..#O.O#..#...O.O##OO#.......O...#...OO.....#.O.....O#O#.....#.
..OO##.#..OO#O.......O.O..OO#..O....O#.O.O.#.#..#........O.....#...........#O.......O.#.#.......#.O.
.##O.....O....#...O..O.OOO.O.OO..#.#..O.........#...##..#..O#....#..O..#O....O......#O..O#..#O..#O..
#O.......O#......O.......O.O.#.......OO....#.....#O.#......O#OO...O.....O......O...#..O........#.OO.
O....#...OO.O..O......#O.O...#.OOO.OO....#....O.O#..O#..#...O.O...O..#O....#O...O..OO........#O.O.#O
#O#..O.........#......#OO..O#.OO#O##..#.O...O#.....#..#O#..OO.#.O#....O.O..##O#O..#O......#.O.OO.O.O
...##.....#..........#..O.O#....#..O...O......##.O.....#.OO#..OO...O..#..#O#..#.O.#..O#O..#......#..
#OO.O##..##O...#..O.O#OO#OO....##.#...O.#.#.#.#O#....O.......O.....#..#.O.#.#...........#........O..
#....O..#O#O............O#O..O.......O#.O.O##..###.#.O#O.#O....O............O..O....#.....O.OOOO....
.OO.OO..#O....#O....O.O..OOO..#..O..OO.....O...#.O.#.O.O.............O..#.O....O##..OO#.O.O.#O..O.#O
.....O......O...#.#....#.....OO...O....#O...#.#.O..##......O...O#.....O.O...#.......................
O..........#O...O#.OO..O.O.#.......#...............#....O...#.O.O..#..O....O....#...#O#.O....O.#....
#..O....O...O#..#OO.O....OO.#..O.O.O.O......O.O.....O....#..O#..O.OO....#..#.#...#......#...O#..O.OO
.......#..O....O.O........#O#OO.#O.O.OO....#..O.....O.#....O...#O.#.O.O.O....##..OO.#O..O#.......#.O
....O....O.O.##O..O..OO####O....O..O.........O.#...OO...#..#..#...#......#......O..#...O.....##...O.
.#OO#..O..O...O.OO....O.O....OO#..#O.O....O..OOO..##..................O....#....O..O...O......#.OO.O
.#.........O#.O#...#...O##.....O.OO.O.##O...O.#.##...OO.....##....#..O.OO#..O....#.#...O...O..OO....
.#.O...OO.OO.O.O#...#.#O.........#O..OO#O#.#.......#..O##....O#..#...#O......O.......O.....#..O..#..
.##..OO....O.....#O.....O..#..#O#..#......#..O.........O.........O#O..........#OOOO.......#.###.#.#O
.O..O..O...OO...OO......O.O..O.#O...#O#.O#..O#......#.O#O.......#..O##.O.O....OO#.O......##OO#.#...O
..#.O..#......#..#O.OO..O...#....O.##......#....O.O.O.....O.#...##....##....OO.O#.....O....O..#....#
O..#.OOO......O.O.OO...O......O.#.#OO.#.....##....#.##..O.....#.....O....#...OO....O#.#.#.........#.
.O......#O.......O..#.##...#.#.O....O.##..O#.OO.O.O#.#O#..##..O..##.O#O.O...#.OO.#.O..#.O.#.O.#.#O.O
.O..O.O..O.O...............OO...O.O.#..#...#.....#..O#.O.OO#.O......##O...O.....O.O.#.#..O..O.O.O.#.
O.........#...O#.O....O...O......#O..##..#O.O.#O..O..OO...#..#.#.#O.........O..OO..O.O.O#.O......#..
OO...........#.....O.O.#.#...O..#.#.#O.#.O#...#O.....O.OO.O..##.....##OO.........O...#OO#O...O....O.
.#.......O.#OO.#OO.O#.OOO...#..##.OO..O...OO.......O.#..OO.O.O..#...O...O.....O.##OOO#..O.....O.O.#O
O#.O.O.OO...#..O.....O#......#..O#OOO.OO#..O...O...O.#..O..#.O..#O.OO##...##.#.#O.#O.O.....##O..O#.#
O.#.#........#...O...#...O.O.O.#.O.....O.......#....#O..OO.#.......#.O...#.O.#..#...#O.###...#.....O
........OOO...O.OO.##O.O..#.O...O..#.......#OO#OO..O##O.......##.........O...OO.......#...#..O#O.#O#
..O#OOO.O#..##........O.......O.....#.O....OOO..O......#.......OO.......#..#.#.#.#....O#...#.O.....#
....O....#..#..O.O.O.O..O........O#....#..#.O..#OO.....OOOO....O#.O......#O..OOO#.O..#....#...O...OO
O#...O#......O...#..#......#.........O.#........#.O#.#...###.#O.O....#O.....#...#.##....O..##...OO..
....O....O........##.O.....#....O.....#..#........#OO.O.#OOO....#..#.#...###......O.O..#....OO......
.O#O....#OO#OOO.#.....O.O......##....#..OO.OOO.O##..#O.#.#...#.#....O..O#...O..OO.#.O...O..##...#...
.O#OO#..O.#OO.......##O#O.#.O..#.O#OO.OO.O.#.O#........#...O.#.O.O##O.........OO..O...O.O.O.....O#..
..##....###.O#.....O....OOO.O.....OO...O....OOOO.#........#.....#.#..O.#.....#...OOO.....OOO..#.O..#
.OO##.#.#....O..#..#.#..O.#..O.OO....O.O..O.OO.O.O.....#..#.............OOOO.O....O.O.O.#..#.......O
#.O.#.O#O.O.O.O.#.#......O#O..OO..O.....#....O..#..#O.............#....#OO....O##...#..O....O...#..O
....#...##...#...#....#.O.O#....#O.O.##.#.O...O#...O#....#.......O.#.#.....O....#.#O.O..O...O..O..#.
.O.##.#...O#OO.....O.........#O.O.O#..........OO.O...#..#.OO....O..#..#...O...OO......O##O.....O#O..
O#...........O....#O...O...O#..#.....#OO...OO..OO#OO..O.#.O#.OOO...O.....O..O...O...O.#O#.#O.....O..
O.OO.O.OOO.O##.#..OO....#....#O.#...O...OO..OO..O#O.....#...O...O...........O....#.O....O.O..#O#..##
#..#......O..OO#.......O..#......#O##....O...O.#.O#.#.O..#.#O..O..O#..O.O.#.OOO...OOO.#.#O.#....#.#.
O##..O......#OOO.#..O.O#.#...O...#...O...#O..OO..#.##O.......#O.#..#...#.O.....#.O.O.#..#.O.O..O...#
.#OOO.....O...#.......OOO.O.#.O.O#.#..#O.#....#O.#....#......#.O...OO..O..O..#O.##.OOO........O.O#..
...O.OO.O....#O...#...#OOO..O...#....OO....O...#..#O...#.#OO......O......O#.O#....#..#OOO.#....O.#..
..#.OOO....#.O..#.O#.#O...O.O.......#..OO.##.#.#..O..O....O#.#.....#..##.#O.......O#O##OO.O......OOO
..O.#...##O##O.O#...O.O#.#O.#...O........#.OO.O...##...O..O..##..O...O.#.....O...#O.#O#O.O......O.#O
..O.#..O.#.....O...#OO##..O.OOO...O.##O..O.O.......#.....O..O.##......O.....O#.........#.........O.#
40 changes: 40 additions & 0 deletions years/2023/14/part1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import input from "./input.txt";
import { transpose } from "@utils";

const lines = input.trim().split("\n");
const grid = lines.map((l) => [...l]);
const transp = transpose(grid);

let r = 0;
for (let i = 1; i < grid.length; i++) {
for (let j = 0; j < grid[0].length; j++) {
if (grid[i][j] === "O") {
for (let k = 0; k < i; k++) {
if (grid[k][j] === ".") {
const t = transp[j].slice(k, i);
if (!t.includes("#")) {
grid[i][j] = ".";
grid[k][j] = "O";

transp[j][i] = ".";
transp[j][k] = "O";

break;
}
}
}
}
}
}

for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid[0].length; j++) {
if (grid[i][j] === "O") {
r += grid.length - i;
console.log(r);
}
}
}
console.log(grid.map((l) => l.join("")).join("\n"));
console.log(r);
console.log("------");
87 changes: 87 additions & 0 deletions years/2023/14/part2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import input from "./input.txt";
import { transpose } from "@utils";

const lines = input.trim().split("\n");
let grid = lines.map((l) => [...l]);

const getRocks = (part: string): string => {
const amt = [...part].filter((n) => n === "O").length;
const newStr = "O".repeat(amt);

return newStr + ".".repeat(part.length - newStr.length);
};

const roll = (arr: string[]): string[] => {
const parts = arr.join("").split("#");

const newParts = [];
for (const part of parts) {
const newStr = getRocks(part);
newParts.push(newStr);
}

return [...newParts.join("#")];
};

const revRoll = (arr: string[]): string[] => roll(arr.reverse()).reverse();

const cycle = (grid: string[][]): string[][] => {
let transp = transpose(grid);
for (let i = 0; i < transp.length; i++) {
transp[i] = roll(transp[i]);
grid = transpose(transp);
}

for (let i = 0; i < grid.length; i++) {
grid[i] = roll(grid[i]);
transp = transpose(grid);
}

for (let i = 0; i < transp.length; i++) {
transp[i] = revRoll(transp[i]);
grid = transpose(transp);
}

for (let i = 0; i < grid.length; i++) {
grid[i] = revRoll(grid[i]);
}
return grid;
};

const getSum = (grid: string[][]): number => {
let r = 0;
for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid[0].length; j++) {
if (grid[i][j] === "O") {
r += grid.length - i;
}
}
}
return r;
};

const prettyHash = (grid: string[][]): string =>
grid.map((l) => l.join("")).join("\n");

let n = 0;
const MAX = 1e9;
const hashes: string[] = [];
let idx = -1;
while (idx === -1 && n < MAX) {
hashes.push(prettyHash(grid));
n++;

grid = cycle(grid);
idx = hashes.indexOf(prettyHash(grid));
}

const jmp = n - idx;

let rem = (MAX - idx) % jmp;
console.log(`got cycle from ${idx} to ${n}, ${rem} remaining`);
for (let i = 0; i < rem; i++) {
grid = cycle(grid);
}
//console.log(prettyHash(grid));
console.log(getSum(grid));
console.log("------");
1 change: 1 addition & 0 deletions years/2023/14/timestarted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-12-14T23:38:57+08:00

0 comments on commit b2d8082

Please sign in to comment.