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
| # === Parsing === | |
| obstacles = set() # (x, y) positions of the obstacles. | |
| initial_position = None | |
| with open("input.txt", "r") as f: | |
| for y, line in enumerate(f): | |
| for x, char in enumerate(line): | |
| if char == "#": | |
| obstacles.add((x, y)) | |
| elif char == "^": |
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
| # === Parsing === | |
| from collections import defaultdict | |
| illegal_before = defaultdict(set) | |
| print_orders = [] | |
| with open("input.txt", "r") as f: | |
| for line in iter(f.readline, "\n"): | |
| key, value = line.split("|") | |
| illegal_before[int(key)].add(int(value)) |
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
| # === Parsing === | |
| with open("input.txt", "r") as f: | |
| grid = [line.strip() for line in f] | |
| print(grid[0]) | |
| # === Part 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
| # === Parsing === | |
| import pathlib | |
| contents = pathlib.Path("input.txt").read_text() | |
| """ | |
| with open("input.txt", "r") as f: | |
| contents = f.read() | |
| """ |
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
| # === Parsing === | |
| reports = [] | |
| with open("input.txt", "r") as f: | |
| reports = [ | |
| [int(num) for num in line.split()] | |
| for line in f | |
| ] | |
| print(reports) |
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
| # === Parsing === | |
| left = [] | |
| right = [] | |
| with open("input.txt") as f: | |
| for line in f: | |
| l, r = map(int, line.split()) | |
| left.append(l) | |
| right.append(r) | |
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
| # https://mathspp.com/blog | |
| from dataclasses import dataclass | |
| @dataclass | |
| class Cell: | |
| """Class that represents a Sudoku board cell.""" | |
| row: int |
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
| class LogDict(dict): | |
| def __setitem__(self, key, value): | |
| print(f"Setting {key = } with {value = }") | |
| return super().__setitem__(key, value) | |
| def __getitem__(self, key): | |
| print(f"Getting {key = }") | |
| return super().__getitem__(key) |
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
| # A Tkinter calculator in a single Python *expression* | |
| # See https://www.reddit.com/r/Python/comments/ojab0n/i_see_your_17_loc_calculator_and_i_raise_you_a/ | |
| (tk := __import__("tkinter")) and (bt_draw := lambda k, c, l: (bt := tk.Button(w, text=k, command=lambda: bt_press(k), width=6)) and bt.grid(column=c, row=l)) and (update := lambda t: d.config(text=t)) and (bt_press := lambda k: update("") if k == "C" else update(d["text"][:-1]) if k == "<" else update(str(round(eval(d["text"]), 6))) if k == "=" else update(d["text"] + k)) and (w := tk.Tk()) and w.title("TKalc") or (d := tk.Label(w, text="")) and d.grid(column=0, row=0, columnspan=5) or [bt_draw(k, n%4 + 1, n//4 + 1) for n, k in enumerate("()C<789/456*123-.0=+")] and w.mainloop() |
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
| \documentclass[11pt]{article} | |
| \usepackage{fontspec} | |
| \setmainfont{APL385 Unicode} | |
| \setmonofont{APL385 Unicode}[Scale=MatchLowercase] | |
| \begin{document} | |
| I just want some ← +-×÷*⍟⌹○!? |⌈⌊⊥⊤⊣⊢ =≠≤<>≥≡≢ ∨∧⍲⍱ ↑↓⊂⊃⊆⌷⍋⍒ ⍳⍸∊⍷∪∩~ /\textbackslash⌿⍀ ,⍪⍴⌽⊖⍉ ¨⍨⍣.∘⍤⍥@ ⍞⎕⍠⌸⌺⌶⍎⍕ ⋄⍝→⍵⍺∇\& ¯⍬ |