## Eureka

### September 24, 2019

This is simple:

(define (eureka? n) (do ((ds (digits n) (cdr ds)) (e 1 (+ e 1)) (x 0 (+ x (expt (car ds) e)))) ((null? ds) (= x n))))

There are 18 eureka numbers less than a million:

> (filter eureka? (range 1000000)) (0 1 2 3 4 5 6 7 8 9 89 135 175 518 598 1306 1676 2427)

OEIS A032799 tells us there are a finite number of eureka numbers, with all terms having at most 22 digits. You can run the program at https://ideone.com/GqNPTp.

Here is my take on it using Julia 1.1.1: https://pastebin.com/vw8CzNVC

To be honest, I was expecting a few more Eureka numbers in this range. Anyway, good drill to warm up for some more challenging coding. Cheers!

Here is my solution using Klong:

I really should have proofread before I changed my solution starting with 1, to a solution starting with 0:

Klong version

Here’s a solution in C.

Output:

Here’s a quick and dirty Haskell version.

On the OEIS page on this series MAPLE code was given to calculate all these numbers faster. I translated the code into Python. It finds all numbers within 10 minutes an takes about 45 minutes to try all the numbers up to 22 digits (the maximum possible). The code uses a branch and bound strategy. The commented code and the output is on Ideone.

@Paul – thanks for posting that, I’d looked at the OEIS Maple code but couldn’t make head or tail of it, though I suspected it was doing something clever as you have revealed.