Skip to content

Instantly share code, notes, and snippets.

View letter_frequency.py
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",
@raeq
raeq / wordle.py
Created February 2, 2022 09:31
Wordle solver in python
View wordle.py
from enum import Enum
from typing import NamedTuple
from more_itertools import chunked
class Result(Enum):
NOTPRESENT = 1
INCORRECT_LOCATION = 2
CORRECT_LOCATION = 3
@raeq
raeq / day07.py
Created January 18, 2022 08:13
What is median...
View day07.py
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
View day04_part1.py
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')
@raeq
raeq / day02.py
Created December 2, 2021 09:52
AOC 2021 Day2 Part2
View day02.py
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:
View day01.py
import more_itertools
def get_data(filename: str) -> list:
with open(filename, 'r') as f:
return [int(line.rstrip('\n')) for line in f]
def make_couples(singles: list) -> list:
return zip(singles, singles[1:])
View rock_paper_scissors.py
import random
from collections import Counter
from enum import Enum, IntEnum, unique
@unique
class Outcome(Enum):
COMPUTER = 2
TIED = 0
PLAYER = 1
@raeq
raeq / cards.py
Created November 25, 2021 17:56
Simulate playing cards
View cards.py
import random
from typing import NamedTuple
class Card(NamedTuple):
suit: str
face: str
face_value: int
@property
def description(self):
@raeq
raeq / scratch_32.py
Created October 29, 2021 15:40
Chemical Structure
View scratch_32.py
from typing import NamedTuple, List
class Chemical_Structure(NamedTuple):
name: str
synonyms: List[str]
iupac_name: str
pubchem_cid: str
inchi: str
inchi_key: str
@raeq
raeq / morse.py
Created October 15, 2021 20:14
A package for working with Morse
View morse.py
"""A package for Morse encoding and decoding."""
from collections import UserDict
from time import sleep
from typing import NamedTuple
from pysinewave import SineWave
class MorseDict(UserDict):
def __init__(self, dictionary=None):