Skip to content

Instantly share code, notes, and snippets.

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 /
Created February 2, 2022 09:31
Wordle solver in python
from enum import Enum
from typing import NamedTuple
from more_itertools import chunked
class Result(Enum):
raeq /
Created January 18, 2022 08:13
What is median...
from functools import lru_cache
from math import floor, ceil
from statistics import mean, median
def sum_c(pop: list[int], centroid: int) -> int:
def gauss_sum(n: int) -> int:
return (n * (n + 1)) // 2
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 /
Created December 2, 2021 09:52
AOC 2021 Day2 Part2
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:
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:])
import random
from collections import Counter
from enum import Enum, IntEnum, unique
class Outcome(Enum):
TIED = 0
raeq /
Created November 25, 2021 17:56
Simulate playing cards
import random
from typing import NamedTuple
class Card(NamedTuple):
suit: str
face: str
face_value: int
def description(self):
raeq /
Created October 29, 2021 15:40
Chemical Structure
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 /
Created October 15, 2021 20:14
A package for working with Morse
"""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):