File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 2525 习题完成情况:
2626 - 章节一: 43/46
2727 - 章节二: 88/97
28- - 章节三: 57 /82
28+ - 章节三: 58 /82
2929 - 章节四: TODO
3030 - 章节五: TODO
3131* 运行
Original file line number Diff line number Diff line change 1+ #lang racket
2+ (require "stream.rkt " )
3+
4+ ;;; 实际上实现了一个流式长除法算法, 用于将分数num/den转换为以radix为基数的无限小数表示
5+ (define (expand num den radix)
6+ (cons-stream
7+ (quotient (* num radix) den)
8+ (expand (remainder (* num radix) den) den radix)))
9+
10+ (module+ test
11+ (require rackunit)
12+
13+ (test-case "Test for expand "
14+ (define x (expand 3 8 10 ))
15+ ;; 3/8 = 0.375 (有限小数)
16+ (check-equal? (stream-to-list x 10 ) '(3 7 5 0 0 0 0 0 0 0 ))
17+
18+ (define s (expand 1 7 10 ))
19+ ;; (expand 1 7 10) 对应 1/7 = 0.142857142857... (循环小数)
20+ (check-equal? (stream-to-list s 10 ) '(1 4 2 8 5 7 1 4 2 8 ))))
You can’t perform that action at this time.
0 commit comments