Skip to content

Instantly share code, notes, and snippets.

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

evanthebouncy

💯
每人都发小红花
View GitHub Profile
@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
@evanthebouncy
evanthebouncy / with_backoff.py
Last active June 27, 2022 22:21
armando car with backoff
track = track4()
car = newCar(track)
startDisplay(track, car)
def control(sd, pastsd):
# average these values to be more smooth
leftt = sd[0] + pastsd[0];
mid = sd[1] + pastsd[1];
# this bit of assymetry is actually very clever, because
# "intuitively" assymetrical things has more information on it
@evanthebouncy
evanthebouncy / best_first_stats.py
Created April 15, 2022 00:33
plotting queue size upon successful termination as a function of temperature
import numpy as np
import random
from queue import PriorityQueue
# here is the task
# we want to construct a goal number, starting from a template of expression
# i.e. (E * E) + E = 11
# we can expand the expression E node further following the grammar
# E -> E + E | E * E | -3 | -2 | -1 | 1 | 2 | 3
@evanthebouncy
evanthebouncy / best_first_search.py
Created March 31, 2022 01:49
best first search
import numpy as np
import random
from queue import PriorityQueue
# here is the task
# we want to construct a goal number, starting from a template of expression
# i.e. (E * E) + E = 11
# we can expand the expression E node further following the grammar
# E -> E + E | E * E | -3 | -2 | -1 | 1 | 2 | 3
@evanthebouncy
evanthebouncy / ancestor.smt
Created October 19, 2020 19:53
simple ancestor relation encoding in z3 smt solver
(declare-sort Person)
(declare-fun ancestor (Person Person) Bool)
;; anti symmetry
(assert (forall ((x Person) (y Person))
(=> (ancestor x y) (not (ancestor y x)))))
;; transitivity
(assert (forall ((x Person) (y Person) (z Person))
(=> (and (ancestor x y) (ancestor y z))