Skip to content

Instantly share code, notes, and snippets.

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

evanthebouncy

💯
每人都发小红花
View GitHub Profile
@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 November 15, 2022 13:48
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))
@evanthebouncy
evanthebouncy / rectangle_synth.py
Created August 15, 2022 02:10
rectangle synthesis
from rectangle import is_inside, is_correct, inside, outside, W
import random
def random_writer(spec):
# ignores the spec
T, D, L, R = random.randint(0,W), random.randint(0,W), random.randint(0,W), random.randint(0,W)
return [T, D, L, R]
def better_writer(spec):
# get the coordinates of spec that are inside
@evanthebouncy
evanthebouncy / rectangle.py
Last active September 1, 2022 11:24
rectangle programming task
import random
# some globals
W = 6
inside = True
outside = False
def interpret(program, inputt):
T, D, L, R = program
i, j = inputt
@evanthebouncy
evanthebouncy / rectangle.py
Last active August 13, 2022 07:41
rectangle
import random
# some globals
W = 6
def exe(prog, x):
T, D, L, R = prog
i, j = x
return i >= L and i <= R and j >= T and j <= D
# check if a spec is satisfied
# the tiling environment, a grid world where you place tetris pieces
import random
# the dimension of the grid
L = 6
# hardcoding a few pieces, it's fine
PIECES = [
[[1,1,1,1]], # horizontal line
@evanthebouncy
evanthebouncy / hugging_face_alchemy_world_model.ipynb
Last active July 28, 2022 01:27
hugging_face_alchemy_world_model.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
np.random.seed(0)
def generate_pair():
# make two random numbers x and y
# make x first randomly from 1 to 10
x = np.random.randint(1, 11)
y = np.random.randint(1, 11)
x_y = x + y