HomeAboutCodePastes
aboutsummaryrefslogtreecommitdiff
path: root/chicken/p69.scm
blob: 5c26ae83a34d88ab2c9d0f5a12c03538394bd169 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/chicken-scheme
;; AUTOCOMPILE: -O3

;; This is pretty slow...
(import (math number-theory)
        (chicken fixnum)
        (chicken flonum)
        (srfi 1))

(define (p69)
  (let ((vals (map (lambda (n)
                     (/ (exact->inexact n)
                        (totient n)))
                   (iota #e1e6 1))))
    (let loop ((vs vals)
               (m 0.0)
               (n 1)
               (i 1))
      (cond ((null? vs) n)
            ((fp> (car vs) m) (loop (cdr vs) (car vs) i (fx+ i 1)))
            (else (loop (cdr vs) m n (fx+ i 1)))))))

(time (print (p69)))