[ 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.

197 2023-10-18 07:05 *

>>195
I was thinking it might be possible to consider only the "exponential tower", since that can be "normalized" and that should get rid of most of the redundancies. But then it is possible that sqrt(2^6^8) is a "special" number and I would need to calculate at least some of its most significant digits, to see if it starts with 2681 or 268 followed by some digit and then an odd(?) amount of zeros.

199


VIP:

do not edit these