Skip to content

Instantly share code, notes, and snippets.

@theblacksquid
theblacksquid / lambda.txt
Created July 3, 2016 03:53
Experiments into the lambda calculus
NULL := lam(x) => x
; Numbers and Arithmetic are natives ;
TRUE / CAR := lam(x,y) => x
FALSE / CDR := lam(x,y) => y
CONS := lam(x,y,z) => z (x y) ; create a pair
(define (add-set set1 set2)
(let main ((ls1 set1)
(ls2 set2))
(cond ((or (null? ls1)
(null? ls2)) ls2)
(else
(let ((curr (car ls1)))
(main (cdr ls1)
(map (lambda (i) (+ i curr)) ls2)))))))
(load "https://gist.githubusercontent.com/theblacksquid/204b43051078a548b7c5e8589f4f6fe8/raw/ed6aeb3be5218c6278acd0a593b287db3108e31c/grid-functions.scm")
(define (player-win? player game-state)
(let ((horiz (line-from-grid game-state 'horizontal 0))
(vert (line-from-grid game-state 'vertical 0))
(diag (line-from-grid game-state 'diagonal 0))
(anti-diag (line-from-grid game-state 'anti-diagonal 0)))
(or (and (points-eq? horiz)
(eqv? (car horiz) player))
(and (points-eq? vert)
(define (line . points)
points)
(define (get-x point)
(car point))
(define (get-y point)
(cdr point))
(define (slope point1 point2)
37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676
89261670696623633820136378418383684178734361726757
28112879812849979408065481931592621691275889832738
44274228917432520321923589422876796487670272189318
47451445736001306439091167216856844588711603153276
70386486105843025439939619828917593665686757934951
(define (collatz n)
(if (even? n)
(/ n 2)
(+ (* 3 n) 1)))
(define (power-of-2? n)
(cond ((< n 1) #f)
((= n 1) #t)
((> (mod n 2) 0) #t)
(else (power-of-2? (/ n 2)))))
(define (var? x) (symbol? x))
(define (same-var? x1 x2)
(and (var? x1)
(var? x2)
(eq? x1 x2)))
(define (sum? expr)
(and (pair? expr)
(eq? (car expr) '+)))
(define (unit? item)
(if (and (not (null? item))
(not (pair? item))
(not (eqv? item #\space)))
#t
#f))
(define (in-list? ls item)
(if (null? (cdr ls))
@theblacksquid
theblacksquid / core.rkt
Last active June 14, 2016 23:44
Beginnings of a toy Tick-Tack-Toe implementation in Racket
;#lang racket
;(require racket/gui)
(define grid
'((0 0 0)
(0 0 0)
(0 0 0)))
(define win-conds
'(((#t #t #t)
@theblacksquid
theblacksquid / lambdadice.rkt
Created April 2, 2016 03:49
rough version of lambdadice dice roller program
#lang racket/base
(require racket/gui)
(define roll-dice
(lambda (num-dice sides)
(if (= num-dice 1)
(+ 1 (random sides))
(+ (random sides)