[ prog / sol / mona ]

prog


What are you working on?

195 2023-10-17 20:06

I saw a picture pointing out that sqrt(2^6^2^1^4^4) = 262144, so I wanted to write a Guile program to find other such numbers:

(use-modules ((rnrs) :version (6) :select (div-and-mod))
             (srfi srfi-11)
             (srfi srfi-41))

;; Go through the digits of a positive integer, right-to-left.
(define (fold-digits f n a)
  (cond
   ((> 10 n) (f a n))
   (else
    (let-values (((rest digit) (div-and-mod n 10)))
      (fold-digits f rest (f a digit))))))

(define (special? n)
  (= (sqrt (fold-digits (lambda (x y) (expt y x)) n 1)) n))

(display
  (stream->list 3 (stream-filter special? (stream-from 0))))
(newline)

But it quickly gets stuck at 268 as calculating 2^(6^8)=2^1679616 is taking a bit too long... Now I am thinking about how to avoid this and other impossible calculations.

199


VIP:

do not edit these