Hi from /sci/... There was just a short thread about the digits of pi. I personally think that phi (golden ratio) is far more interesting and was hoping one of you gentlemen might have some code to compute arbitrary digits of phi in any base chosen by the user. Hopefully it isn't offensive to ask that it be in C.
Since it's purely random, there's going to be some sort of image in there, eventually. Just curious to see what the first "significant" finding is.
You will have to modify it yourself for it to work in positive integer bases greater than 10, but as long as you're willing to write the lookup, it's no problem.
#lang racket
(define stream-car car)
(define (stream-cdr str) (force (cdr str)))
(define-syntax stream-cons
(syntax-rules ()
((_ a b) (cons a (delay b)))))
(define (make-consumer-emitter-base base a b c d cf)
(define (consume)
(let ((t (stream-car cf)))
(let ((a (+ b (* a t)))
(b a)
(c (+ d (* c t)))
(d c))
(make-consumer-emitter-base base a b c d (stream-cdr cf)))))
(define (emit?)
(cond ((or (zero? c) (zero? d)) #f)
((= (quotient a c) (quotient b d)) #t)
(else #f)))
(define (emit-base)
(if (not (emit?))
(consume)
(let ((t (quotient a c)))
(let ((a (* base (- a (* t c))))
(b (* base (- b (* t d)))))
(stream-cons t (make-consumer-emitter-base base a b c d cf))))))
(emit-base))