Daniel-Nikpayuk_SICP-Solutions/Chapter 3/3.5/exercise-3.58 (fraction expansion)/exercise.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Copyright 2015 Daniel Nikpayuk
;;
;; This file is part of SICP Solutions.
;;
;; SICP Solutions is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
;;
;; SICP Solutions is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
;; of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License along with SICP Solutions. If not, see
;; <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (expand num den radix)
  (cons-stream
   (quotient (* num radix) den)
   (expand (remainder (* num radix) den) den radix)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Okay, so num*radix is broken into its quotient and its remainder given den. Its quotient is the first
;; element and its remainder is used to recurse the procedure. As best I can tell, it expands fractions,
;; for example 1/4=0.25 (base 10).

;; What are the successive elements produced by (expand 1 7 10) ? What is produced by (expand 3 8 10) ?

(expand 1 7 10)
; (1 (expand 3 7 10))
; (1 4 (expand 2 7 10))
; (1 4 2 (expand 6 7 10))
; (1 4 2 8 (expand 4 7 10))
; (1 4 2 8 5 (expand 5 7 10))
; (1 4 2 8 5 7 (expand 1 7 10))
; repeat!

