exercise-1.12-yang-hui-triangle.rkt 682 B

1234567891011121314151617181920212223242526272829
  1. #lang racket
  2. (define (calculate-cell row col)
  3. (cond
  4. ((< row 0) 0)
  5. ((and (= row 0) (= col 0)) 1)
  6. ((and (= row 0) (not (= col 0))) 0)
  7. ((> row 0) (+
  8. (calculate-cell (- row 1) (- col 1))
  9. (calculate-cell (- row 1) col)))))
  10. (define (calculate-row row col)
  11. (cond
  12. ((= col row) (list (calculate-cell row col)))
  13. (else (cons (calculate-cell row col) (calculate-row row (+ col 1))))))
  14. (define (yht row-count counter)
  15. (if
  16. (= counter row-count)
  17. (print (calculate-row (- row-count counter) 0))
  18. (begin
  19. (yht row-count (+ counter 1))
  20. (print (calculate-row (- row-count counter) 0)))))
  21. (define (yang-hui-triangle row-num)
  22. (yht row-num 0))
  23. (yang-hui-triangle 7)