solutions/Structure and Interpretatio.../sicp-ex-1.12.rkt

33 lines
809 B
Racket
Raw Permalink Normal View History

2024-04-16 19:13:00 -04:00
; 1
; 1 1
; 1 2 1
; 1 3 3 1
; 1 4 6 4 1
; . . . .
; I am sure that I have chosen the worst possible way
(define (pasc-step row col num curr-row curr-col)
(cond
((or (< col 0) (> col row)) 0)
((or (= col 1) (= col row)) 1)
((= curr-row row) num)
((or (= col 2) (= col (- row 1))) (- row 1))
((or (> col 2) (< col (- row 1))) (pasc-step
row
col
(+ num (if (< curr-col col)
(pasc-step curr-row (+ curr-col 1) 1 2 2)
(pasc-step curr-row (- curr-col 1) 1 2 2)))
(+ curr-row 1)
(if (< curr-col col) (+ curr-col 1) curr-col)))))
(define (locate-pasc row col)
(pasc-step row col 1 2 2))
(locate-pasc 2 1)
(locate-pasc 3 2)
(locate-pasc 4 3)
(locate-pasc 5 2)
(locate-pasc 5 4)
(locate-pasc 6 4)
(locate-pasc 7 3)