This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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))))))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (line . points) | |
| points) | |
| (define (get-x point) | |
| (car point)) | |
| (define (get-y point) | |
| (cdr point)) | |
| (define (slope point1 point2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 37107287533902102798797998220837590246510135740250 | |
| 46376937677490009712648124896970078050417018260538 | |
| 74324986199524741059474233309513058123726617309629 | |
| 91942213363574161572522430563301811072406154908250 | |
| 23067588207539346171171980310421047513778063246676 | |
| 89261670696623633820136378418383684178734361726757 | |
| 28112879812849979408065481931592621691275889832738 | |
| 44274228917432520321923589422876796487670272189318 | |
| 47451445736001306439091167216856844588711603153276 | |
| 70386486105843025439939619828917593665686757934951 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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) '+))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;#lang racket | |
| ;(require racket/gui) | |
| (define grid | |
| '((0 0 0) | |
| (0 0 0) | |
| (0 0 0))) | |
| (define win-conds | |
| '(((#t #t #t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #lang racket/base | |
| (require racket/gui) | |
| (define roll-dice | |
| (lambda (num-dice sides) | |
| (if (= num-dice 1) | |
| (+ 1 (random sides)) | |
| (+ (random sides) |