Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rebcabin committed Dec 15, 2023
1 parent 21dcfc4 commit c5c9830
Show file tree
Hide file tree
Showing 6 changed files with 14,715 additions and 8 deletions.
97 changes: 97 additions & 0 deletions AlgImperSem008.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@; scheme-r5rs

;; runs only in gambit (gsi AlgImperSem008.smc)

;; (define-syntax bugger-or
;; (syntax-rules ()
;; [(_) #f]
Expand Down Expand Up @@ -337,3 +339,98 @@ parameter f of d, a free variable in the body of b."
(pp (itak 1 12 8 4)) ; (1733 5)
(pp (itak 1 18 12 6)) ; (63609 7)
;; (pp (itak 1 28 20 12)) ; (2493349 13)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ____ ___ ____ ____
;; / ___|_ _/ ___| _ \
;; \___ \| | | | |_) |
;; ___) | | |___| __/
;; |____/___\____|_|

;; ___ _ ___
;; / __| |_ | __|
;; | (__| ' \ |__ \
;; \___|_||_| |___/

;; (define (gcd a b)
;; (if (= b 0)
;; a
;; (gcd b (remainder a b))))

(define (factorial n)
(define (iter product counter)
(if (> counter n)
product
(iter (* counter product)
(+ counter 1))))
(iter 1 1))

;;; Exercise 5.1:

;; +-----+ +--------+ +-----+
;; \ 1 / | | \ 1 /
;; \ / | V \ /
;; | | .--------. |
;; | | \ +1 / |
;; (X) p<-1 | \_____/ (X) c<-1
;; | | | |
;; | | (X) c<-c++ |
;; | | | |
;; v | V |
;; +-----+ | +-----+ | +-----+
;; +->| p | +-----| c |<------+ | n |
;; | +-----+ +-----+ +-----+
;; | | | |
;; | +------+ +------+------+ +------+
;; | | | | |
;; | .--+---+--. .--+---+--.
;; | \ * / \ < /
;; | \_____/ \_____/
;; | | |
;; (X) p<-t (X) t<-pc (X) t<-lt
;; | | |
;; | | V
;; | | +-----+
;; | +------------->| |
;; +-----------------------------| t |
;; | |
;; +-----+
;; |
;; |
;; V
;; ---
;; / \
;; | #t |
;; \___/

;; start
;; |
;; V
;; +-------+
;; | c<-1 |
;; +-------+
;; |
;; V
;; +-------+
;; | p<-1 |
;; +-------+
;; |
;; V
;; +-------+
;; | t<-lt |
;; +-------+
;; |
;; V
;; / \ yes
;; +-------->< < >-----> done (answer in reg. p)
;; | \ /
;; | | no
;; | V
;; | +-------+
;; | | t<-pc |
;; | +-------+
;; | |
;; | V
;; +-------+ +-------+
;; | c<-c++|<--| p<-t |
;; +-------+ +-------+
Loading

0 comments on commit c5c9830

Please sign in to comment.