Skip to content

Instantly share code, notes, and snippets.

View evanthebouncy's full-sized avatar
💯
每人都发小红花

evanthebouncy

💯
每人都发小红花
View GitHub Profile
@evanthebouncy
evanthebouncy / q14.py
Created September 13, 2025 16:57
q14
E = {
"A": [],
"B": ["A", "E"],
"C": ["D", "H"],
"D": ["B"],
"E": ["F"],
"F": [],
"G": ["A"],
"H": ["B", "G"],
}
@evanthebouncy
evanthebouncy / q13.py
Created September 13, 2025 14:32
q13
E = {
"A": [],
"B": ["A", "E"],
"C": ["D", "H"],
"D": ["B"],
"E": ["F"],
"F": [],
"G": ["A"],
"H": ["B", "G"],
}
@evanthebouncy
evanthebouncy / toposort.py
Created September 7, 2025 16:30
topological sort
E = { "A": ["E"],
"B": ["A", "C", "G"],
"C": ["A"],
"D": ["B", "G"],
"E": ["F"],
"F": [],
"G": ["A", "F"],
}
N = 8
def neighbors(board):
occupied = set(board)
for r in range(N):
for c in range(N):
if (r, c) not in occupied:
yield board + ((r, c),)
def solve_8q_one():
@evanthebouncy
evanthebouncy / quick_sort_time.py
Created August 17, 2025 12:30
quick_sort_time_simulation
import random
import numpy as np
def simulate_T(n):
if n <= 1:
return 0
# the pivot may end up randomly anywhere from 0 to n-1
pivot_index = random.randint(0, n - 1)
first_half = simulate_T(pivot_index)
@evanthebouncy
evanthebouncy / path_to_ruin.py
Created December 1, 2024 18:18
path to ruin, of Nassim Nicholas Taleb's school of thought. martingale and non-ergodic thing
import numpy as np
import matplotlib.pyplot as plt
# roll out of a particular game, start at position n, and roll a coin of some prob to move up or down.
# if it reaches 0, you lose
def simulate_game_log_space(start_n, coin_prob):
trajectory = []
n = start_n
for i in range(1000):
trajectory.append(n)
@evanthebouncy
evanthebouncy / 3pt_arc.py
Created May 5, 2024 22:01
rendering a 3 point arc in openCV2 . . . I do not wish what I did upon anyone
import numpy as np
import matplotlib.pyplot as plt
import json
import cv2
import math
# open the ./data_train.json
GRID = 64
IMG_W = GRID * 20
@evanthebouncy
evanthebouncy / 20Q_LLM.py
Created March 26, 2023 21:35
a simple set up to play 20 questions with LLM
# a self play version of 20 quetsions with gpt playing against itself
from langchain.llms import OpenAI
# from langchain.chat_models import ChatOpenAI
llm = OpenAI(model_name="gpt-3.5-turbo-0301")
# an oracle
def get_oracle(concept):
def give_answer(question):
prompt = f"For a {concept}, \
{question}. Answer with a single word [YES, NO]"
@evanthebouncy
evanthebouncy / nim.py
Last active March 1, 2023 20:28
stone game from 名侦探学院 2023-03-01 (aka nim)
# get all possible next states
def get_next_state(tuple_state):
ret = []
# for all index of tuple_state, subtract any number of stones 1 through maximum possible
for i in range(len(tuple_state)):
for j in range(1, tuple_state[i]+1):
# create new state
new_state = list(tuple_state)
new_state[i] -= j
@evanthebouncy
evanthebouncy / rectangle_lm.py
Last active September 1, 2025 20:25
language modeling for rectangles
from rectangle import is_inside, is_correct, inside, outside, W
import random
import string
# for the purpose of showing this is a "language model", all programs here are
# written as STRINGS, you need to call eval(prog) on them to get the actual program
def writer1():
return ''.join(random.choice(string.printable) for i in range(9))