Day 14 - Advent of Code 2023

Working solutions for the day 14 puzzles.

Part One

""" day_14_01.py """

# usage: python3 day_14_01.py < input

import sys

raw = sys.stdin.read()
width, height = raw.index('\n'), raw.count('\n')
platform = [i for i in raw if i != '\n']

rounded = [i for i, j in enumerate(platform) if j == 'O']


def tilt_north(x):
    """ move rock north if possible """
    y = x - width
    return y if y > 0 and platform[y] == '.' else x


for i, j in enumerate(rounded):
    platform[j] = '.'
    k = tilt_north(j)
    while j != k:
        j = k
        k = tilt_north(j)
    rounded[i] = j
    platform[j] = 'O'

print(sum(height - i // width for i in rounded))

Part Two