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
| import ast | |
| import os | |
| import re | |
| from collections import defaultdict | |
| from typing import Any | |
| def get_project_files(root: str = ".") -> list[str]: | |
| files: list[str] = [] | |
| for dirpath, dirnames, filenames in os.walk(root): |
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
| #!/usr/bin/env python3 | |
| """ | |
| FreeCAD script to create a mirrored solid box with elliptical depth profile and curved protrusions: | |
| - Main box: 45mm x 13-14mm (elliptical) x 18.5mm (solid, created by mirroring 22.5mm half) | |
| - Elliptical depth profile: 13mm at edges → 14mm at center (smooth curve) | |
| - Protrusions: 40mm wide x 7mm tall on each side (125mm total width) | |
| - First 28mm: 13mm → 7mm deep (smooth curved transition from main box) | |
| - Last 12mm: 7mm → 5mm deep, wraps around tip cylinder (circular contour on right end) | |
| - Main cylinder holes: 8mm diameter holes through protrusions (for handle mechanism) | |
| - Tip cylinders: 5mm outer diameter, 3mm inner, 12mm tall (extends 5mm below), with holes through protrusion |
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
| import itertools as it | |
| import re | |
| cubes = sorted(([*map(int, re.findall(r'\d+', l))] for l in open(0)), | |
| key=lambda p: p[2]) | |
| def points(c, dz=0): | |
| x1, y1, z1, x2, y2, z2 = c | |
| return it.product(range(x1, x2+1), range(y1, y2+1), range(z1-dz, z2+1-dz)) |
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 collections import * | |
| from math import * | |
| O, I = defaultdict(list), defaultdict(list) | |
| FLIP, CONJ = set(), set() | |
| for l in open(0): | |
| a, bs = l.strip().split(' -> ') | |
| a = a.strip() | |
| if a[0]=='%': | |
| a = a[1:] |
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
| import re | |
| wf, pt = open(0).read().split('\n\n') | |
| wfd = {} | |
| for l in wf.split(): | |
| w, cs = l.split('{') | |
| cd = list() | |
| conds = cs[:-1].split(',') | |
| for i, c in enumerate(conds): |
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
| x, y, A, L, P2 = 0, 0, 0, 0, True | |
| for d, s, c in map(str.split, open(0)): | |
| s = int(c[2:-2], 16) if P2 else int(s) | |
| if P2: d = "RDLU"[int(c[-2])] | |
| nx, ny = x, y | |
| if d=='R': | |
| ny += s | |
| elif d=='L': | |
| ny -= s | |
| elif d=='U': |
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
| import itertools as it | |
| L = [l.strip() for l in open(0)] | |
| N, M = len(L), len(L[0]) | |
| starts: list[tuple[int, int]] = list( | |
| it.chain(*zip(*(((i, -1), (i, M)) for i in range(N))), | |
| *zip(*(((-1, j), (N, j)) for j in range(M))))) | |
| ms = [(1, 0), (0, 1), (-1, 0), (0, -1)] | |
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 heapq import * | |
| L = [[*map(int, l.strip())] for l in open(0)] | |
| N, M = len(L), len(L[0]) | |
| MS = [(1, 0), (-1, 0), (0, 1), (0, -1)] | |
| x, y = 0, 0 | |
| E = (N-1, M-1) | |
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 chsh(s): | |
| hsh = 0 | |
| for c in s: | |
| hsh += ord(c) | |
| hsh *= 17 | |
| hsh %= 256 | |
| return hsh | |
| hshsum = 0 |
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 tilt(ls): | |
| for i in range(len(ls)): | |
| for j in range(len(ls[0])): | |
| if ls[i][j]!='O': continue | |
| new_loc = 0 | |
| for k in range(i-1, -1, -1): | |
| if ls[k][j]=='.': continue | |
| new_loc = k+1 | |
| break | |
| ls[i][j] = '.' |
NewerOlder