Welcome to the CHICKEN Scheme pasting service

CHICKEN 5 fixnum version added by sytse on Mon Dec 7 18:55:48 2020

(import (only (chicken fixnum) fx= fx< fx> fx<= fx+))
 
(define factors-count
  (lambda (number)
    (let ((sqrt-temp (inexact->exact (ceiling (sqrt number)))))
      (define (loop current factors)
        (if (fx<= current sqrt-temp)
            (if (fx= 0 (remainder number current))
                   (loop (fx+ current 1) (fx+ factors 2))
                   (loop (fx+ current 1) factors))
            (fx+ 1 factors)))
      (loop 2 1))))
 
(define find-500
  (lambda ()
    (define (rec-find number triangle record factors)
      (if (fx< factors 500)
          (let* ((new-triangle (fx+ triangle number))
                 (new-factors (factors-count new-triangle)))
            (if (fx> new-factors record)
                (begin
                  (print new-factors "-" number)
                  (rec-find (fx+ number 1) new-triangle new-factors new-factors))
                (rec-find (fx+ number 1) new-triangle record new-factors)))
          triangle))
    (rec-find 7 21 0 (factors-count 21))))
 
(print (find-500))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Name of the egg which implements this service:
Visually impaired? Let me spell it for you (wav file) download WAV