Skip to content

Instantly share code, notes, and snippets.

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

evanthebouncy

💯
每人都发小红花
View GitHub Profile
import random
from time import time
from sklearn.neighbors import KNeighborsClassifier
import numpy as np
from mlagents_envs.environment import UnityEnvironment
from mlagents_envs.envs.unity_gym_env import UnityToGymWrapper
unity_env = UnityEnvironment("gg_det")
env = UnityToGymWrapper(unity_env)
<!DOCTYPE html>
<html>
<body>
<div>
<span style="float: left">
<canvas id="myCanvas" width="800" height="800"
style="border:1px solid #d3d3d3;">
@evanthebouncy
evanthebouncy / grid_manual.py
Created January 23, 2026 15:09
manually play the grid game
# play_gridworld_terminal.py
# Terminal-playable GridWorld + trajectory tracking (only dependency: numpy)
from __future__ import annotations
from dataclasses import dataclass
from typing import Dict, List, Optional, Tuple
import numpy as np
@dataclass(frozen=True)
@evanthebouncy
evanthebouncy / resolution_lower.py
Created January 18, 2026 08:24
resolution lower bound
import numpy as np
# generate a random number between 0 and 1
# calculate its distance (min) to either 0 and 1 (absolute value of difference)
def do_once():
x = np.random.rand()
return min(abs(x - 0), abs(x - 1))
# do it many times and get the average value
def do_many_times(n):
@evanthebouncy
evanthebouncy / kruskal.py
Created September 21, 2025 15:27
kruskal
E = {
"A": [("B", 4), ("H", 8)],
"B": [("A", 4), ("C", 8), ("H", 11)],
"C": [("B", 8), ("D", 7), ("F", 4), ("I", 2)],
"D": [("C", 7), ("E", 9), ("F", 14)],
"E": [("D", 9), ("F", 10)],
"F": [("C", 4), ("D", 14), ("E", 10), ("G", 2)],
"G": [("F", 2), ("H", 1), ("I", 6)],
"H": [("A", 8), ("B", 11), ("G", 1), ("I", 7)],
"I": [("C", 2), ("G", 6), ("H", 7)],
@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)