This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_data(fn): | |
data: list = [] | |
with open(fn) as f: | |
for line in f: | |
direction, distance = line.rstrip().split() | |
data.append((direction, int(distance))) | |
return data | |
class Submarine: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain | |
from more_itertools import chunked | |
def transpose_rows_to_columns(rows) -> list: | |
return [list(i) for i in zip(*rows)] | |
def get_data(fn): | |
numbers, *boards = open(fn).read().split('\n\n') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import lru_cache | |
from math import floor, ceil | |
from statistics import mean, median | |
def sum_c(pop: list[int], centroid: int) -> int: | |
@lru_cache | |
def gauss_sum(n: int) -> int: | |
return (n * (n + 1)) // 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enum import Enum | |
from typing import NamedTuple | |
from more_itertools import chunked | |
class Result(Enum): | |
NOTPRESENT = 1 | |
INCORRECT_LOCATION = 2 | |
CORRECT_LOCATION = 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frequencies:dict = { | |
"E": "12.02", | |
"T": "9.1", | |
"A": "8.12", | |
"O": "7.68", | |
"I": "7.31", | |
"N": "6.95", | |
"S": "6.28", | |
"R": "6.02", | |
"H": "5.92", |
OlderNewer