Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,27 @@
;; code adapted from Racket and Common Lisp
;; Illustrates matching on structures
(require 'match)
(require 'struct)
(define (N-tostring n) (format "%s %d" (N-color n) (N-value n)))
(struct N (color left value right) #:tostring N-tostring)
(define (balance t)
(match t
[(N '⚫️ (N '🔴 (N '🔴 a x b) y c) z d) (N '🔴 (N '⚫️ a x b) y (N '⚫️ c z d))]
[(N '⚫️ (N '🔴 a x (N '🔴 b y c)) z d) (N '🔴 (N '⚫️ a x b) y (N '⚫️ c z d))]
[(N '⚫️ a x (N '🔴 (N '🔴 b y c) z d)) (N '🔴 (N '⚫️ a x b) y (N '⚫️ c z d))]
[(N '⚫️ a x (N '🔴 b y (N '🔴 c z d))) (N '🔴 (N '⚫️ a x b) y (N '⚫️ c z d))]
[else t]))
(define (ins value: x tree: t)
(match t
['empty (N '🔴 'empty x 'empty)]
[(N c l v r) (cond [(< x v) (balance (N c (ins x l) v r))]
[(> x v) (balance (N c l v (ins x r)))]
[else t])]))
(define (insert value: x tree: s)
(match (ins x s) [(N _ l v r) (N '⚫️ l v r)]))

View file

@ -0,0 +1,8 @@
(define (t-show n (depth 0))
(when (!eq? 'empty n)
(t-show (N-left n) (+ 12 depth))
(writeln (string-pad-left (format "%s" n ) depth))
(t-show (N-right n) (+ 12 depth))))
(define T (for/fold [t 'empty] ([i 32]) (insert (random 100) t)))
(t-show T)