## Eureka

### September 24, 2019

Somebody’s homework today:

A number is a eureka number if the sum of the powers of its digits, with powers increasing, is equal to the number. For instance, 89 is a eureka number because 8**1 + 9**2 = 89, and 1306 is a eureka number because 1**1 + 3**2 + 6**4 = 1306.

Your task is to write a program to identify eureka numbers, and determine how many eureka numbers exist that are less than a million. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

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.