For those a fan of Guile:
(use-modules (srfi srfi-1)) (let find-kaprekars ([kaprekars '()] [currNum 1]) (if (= (length kaprekars) 8) (reverse kaprekars) (if (let ([cnStr (string-append "0" (number->string (expt currNum 2)))]) (any (lambda (index) (let ([scndPart (string->number (substring cnStr index))]) (if (zero? scndPart) #f (= (+ (string->number (substring cnStr 0 index)) scndPart) currNum)))) (iota (1- (string-length cnStr)) 1))) (find-kaprekars (cons currNum kaprekars) (1+ currNum)) (find-kaprekars kaprekars (1+ currNum)))))
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
For those a fan of Guile: