This file contains 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 (binarysearch lst n) | |
(let loop ((lst lst)) | |
(receive(left right) | |
(split-at lst (div (length lst) 2)) | |
(cond ((null? left)#f) | |
((null? right)#f) | |
((eq? (last left) n)#t) | |
((eq? (car right) n)#t) | |
((> (last left) n)(loop left)) | |
((< (car right) n)(loop right))))))) |
This file contains 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 (binarysearch lst n) | |
(let loop ((lst lst)) | |
(receive(left right) | |
(split-at lst (div (length lst) 2)) | |
(cond ((null? left)#f) | |
((null? right)#f) | |
((eq? (last left) n)#t) | |
((eq? (car right) n)#t) | |
((> (last left) n)(loop left)) | |
((< (car right) n)(loop right)))))) |
This file contains 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
#(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 0 | |
#(1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 0 | |
#(2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 0 | |
#(3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 0 | |
#(4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 0 | |
#(5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 0 | |
#(6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 0 | |
#(6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 0 | |
#(5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 0 | |
#(5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 1 |
This file contains 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
#!/usr/local/bin/gosh | |
(use srfi-1) | |
(use file.util) | |
(define (inter lst mem n) | |
(let loop ((lst lst)) | |
(if (null? lst) | |
(values n mem) | |
(begin | |
(if (list? (car lst)) | |
(until (zero? (vector-ref mem n)) |
This file contains 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 (reverse-string str) | |
(let1 lst (string->list str) | |
(list->string (reverse lst)))) |
This file contains 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
(use srfi-1) | |
(define (sort lst) | |
(let loop ((lst lst)(result '())(n (- (length lst) 1))) | |
(if (null? (cdr lst)) | |
(reverse (cons (car lst) result)) | |
(let1 min1 (apply min lst) | |
(loop (delete1 lst) (cons min1 result) (- n 1)))))) | |
(define (delete1 lst) | |
(let1 min1 (apply min lst) | |
(let loop ((lst lst)(result '())) |
This file contains 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 (sort lst) | |
(let loop ((lst lst) (result '()) (n (- (length lst) 1))) | |
(cond | |
((null? (cdr lst)) | |
(if (zero? n) | |
(reverse (cons (car lst) result)) | |
(loop (reverse(cons (car lst) result)) '() (- n 1)))) | |
((> (car lst) (cadr lst)) | |
(begin | |
(loop (cons (car lst) (cddr lst)) (cons (cadr lst) result) n))) |
This file contains 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 (bublesort lst) | |
(let loop ((lst lst) (result '())) | |
(print lst ":" result) ;デバッグ | |
(cond | |
((null? (cdr lst))(reverse (cons (car lst)result))) | |
((> (car lst) (cadr lst)) | |
(begin | |
(loop (delete (cadr lst) lst) (cons (cadr lst) result)))) | |
(else | |
(begin |
This file contains 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
`r`````````````.H.e.l.l.o.,. .w.o.r.l.d.!.a |
This file contains 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 (fact . ls) | |
(if (null? ls) 1 (* (car ls) (apply fact (cdr ls))))) | |
(define (fact/cps . ls) | |
(call/cc | |
(lambda(cont) | |
(cond | |
((null? ls) 1) | |
((eqv? (car ls) 0)(cont 0)) | |
(else (* (car ls) (apply fact/cps (cdr ls)))))))) |