1 ! Copyright (c) 2009 Aaron Schaefer.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.functions ranges project-euler.common
7 ! https://projecteuler.net/problem=63
12 ! The 5-digit number, 16807 = 7^5, is also a fifth power.
13 ! Similarly, the 9-digit number, 134217728 = 8^9, is a ninth
16 ! How many n-digit positive integers exist which are also an nth
23 ! Only have to check from 1 to 9 because 10^n already has too
24 ! many digits. In general, x^n has n digits when:
26 ! 10^(n-1) <= x^n < 10^n
28 ! ...take the left side of that equation, solve for n to see
31 ! n = log(10) / [ log(10) - log(x) ]
33 ! Round down since we already know that particular value of n is
36 : euler063 ( -- answer )
37 9 [1..b] [ log [ 10 log dup ] dip - /i ] map-sum ;
39 ! [ euler063 ] 100 ave-time
40 ! 0 ms ave run time - 0.0 SD (100 trials)