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 -S uv run --script | |
| # /// script | |
| # dependencies = ["Pillow>=11.3", "numpy"] | |
| # /// | |
| """ | |
| Generate the Cayley graph of the free group F2. | |
| """ | |
| from __future__ import annotations |
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 sys | |
| from math import gcd | |
| def mininum_number_of_item_needed_to_reach_gcd(xs: list[int]) -> int: | |
| g = gcd(*xs) | |
| cache: dict[tuple[int, int], int] = {} | |
| def rec(i: int, x: int) -> int: | |
| if x == g: |
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 faster implementation of `BigUint::to_string` ported from `_pylong.py` | |
| // See: https://github.com/python/cpython/blob/main/Lib/_pylong.py | |
| use num_bigint::BigUint; | |
| use num_integer::Integer; | |
| use std::collections::HashMap; | |
| fn div2n1n(a: &BigUint, b: &BigUint, n: usize) -> (BigUint, BigUint) { | |
| if a.bits() as usize <= 4000 + n { | |
| return a.div_rem(b); |
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 random | |
| import asyncio | |
| from contextlib import asynccontextmanager | |
| from typing import AsyncIterable, AsyncIterator, TypeVar | |
| from anyio import create_memory_object_stream, create_task_group | |
| from anyio.abc import ObjectReceiveStream, TaskStatus | |
| from anyio.streams.memory import MemoryObjectSendStream | |
| T = TypeVar("T") |
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 math | |
| import asyncio | |
| from contextlib import asynccontextmanager | |
| from typing import AsyncIterable, AsyncIterator, Awaitable, Callable | |
| from anyio import create_memory_object_stream, create_task_group, abc | |
| from anyio.streams.memory import MemoryObjectReceiveStream | |
| @asynccontextmanager | |
| async def amap[ |
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
| [package] | |
| name = "intersection" | |
| version = "0.1.0" | |
| edition = "2021" | |
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
| [features] | |
| ahash = ["dep:ahash"] |
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 python | |
| """ | |
| Convert an mp4 video file to uncompressed 80x48 video frames. | |
| The output data is meant to be used as direct memory for the 80x24 Turing complete | |
| console. In particular, pixels are grouped vertically so 2 pixels can fit into a | |
| single `▀` (`\xdf`) character. | |
| For instance, the following frame: |
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
| """ | |
| Write recursive functions as coroutines to make them stackless. | |
| Example: | |
| >>> @runable # Allow the function to run with a simple sync call | |
| ... @functools.cache # Cache the results | |
| ... @stackless # Make the coroutine stackless | |
| ... async def fib(n, m=10**9): | |
| ... if n <= 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
| #!/usr/bin/env python3 | |
| import json | |
| import time | |
| import random | |
| import shutil | |
| import argparse | |
| from urllib.request import Request, urlopen | |
| from imageio import imread |
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 python | |
| """ | |
| Serve a ptpython console using both telnet and ssh | |
| """ | |
| import pathlib | |
| import asyncio | |
| import asyncssh |
NewerOlder