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 Feb 2, 2022
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 Jan 18, 2022
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 Dec 2, 2021
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 Nov 25, 2021
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 Oct 29, 2021
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 Oct 15, 2021
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):