This file contains 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
import sys | |
import getch | |
from collections import defaultdict | |
class Oracle: | |
def __init__(self, window_size: int): | |
self.window_size = window_size | |
self.window: str = '' | |
self.patterns: defaultdict[str, dict[str, int]] = defaultdict(lambda: defaultdict(int)) |
This file contains 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
<canvas id="canvas"></canvas> | |
<script> | |
const WIDTH = 1500 | |
const HEIGHT = 800 | |
const canvas = document.getElementById("canvas") | |
const ctx = canvas.getContext("2d") | |
canvas.width = WIDTH | |
canvas.height = HEIGHT |
This file contains 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 print_cells(cells: list[int]): | |
print(''.join('■' if i == 1 else ' ' for i in cells)) | |
def next_step(cells: list[int], rules: list[int]) -> list[int]: | |
new_cells: list[int] = [False] * len(cells) | |
for i in range(len(cells)): | |
left = cells[(i - 1) % len(cells)] | |
right = cells[(i + 1) % len(cells)] | |
idx = int(''.join([str(left), str(cells[i]), str(right)]), 2) |
This file contains 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
import cv2 | |
import numpy as np | |
size = 28 | |
drawing = False | |
win_name = "Draw digit" | |
def draw(event, x, y, flags, *param): | |
global drawing | |
if event == cv2.EVENT_LBUTTONDOWN: |
This file contains 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
<canvas id="canvas"></canvas> | |
<script> | |
const WIDTH = 500 | |
const HEIGHT = 500 | |
const canvas = document.getElementById("canvas") | |
const ctx = canvas.getContext("2d") | |
canvas.width = WIDTH | |
canvas.height = HEIGHT |
This file contains 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 dataclasses import dataclass | |
from datetime import datetime, timezone, timedelta | |
from pylunar import MoonInfo | |
def datetime_to_tuple(date: datetime) -> tuple[int, int, int, int, int, int]: | |
return (date.year, date.month, date.day, date.hour, date.minute, date.second) | |
def min_points(x: list[int], y: list[float]) -> tuple[list[int], list[float]]: |
This file contains 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
import cv2 | |
import numpy as np | |
import plotly.graph_objects as go | |
image = cv2.imread("earth.jpeg", cv2.IMREAD_COLOR) | |
height, width, _ = image.shape | |
image = cv2.resize(image, (300, int(height * 300 / width))) | |
height, width, _ = image.shape |
This file contains 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
import numpy as np | |
from matplotlib import collections as mc, pyplot as plt | |
Point = tuple[float, float] | |
Line = tuple[Point, Point] | |
def get_lines(multiplier: int, modulus: int) -> list[Line]: | |
start = np.arange(1, modulus) | |
end = start * multiplier % modulus | |
angle = 2 * np.pi / modulus |
This file contains 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
# geometry/point.py | |
import math | |
from dataclasses import dataclass | |
from typing import Optional | |
@dataclass | |
class Point: | |
x: float = 0 |
This file contains 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 math import gcd | |
from functools import reduce | |
from typing import Iterator | |
def lcm(nums: list[int]) -> int: | |
_lcm = lambda a, b: (a * b) // gcd(a, b) | |
return reduce(_lcm, nums) | |
def partitions(n: int, s: int = 1) -> Iterator[int]: | |
yield (n,) |
NewerOlder