\ Problem: \ The 5-digit number, 16807=75, is also a fifth power. Similarly, the \ 9-digit number, 134217728=89, is a ninth power. \ How many n-digit positive integers exist which are also an nth power? \ They don't count 0^1 (0 is not deemed to be positive) \ Solution: \ 10^n produces a n+1-digit integer, so we need only look at bases 0-9. : n-digits { n -- n2 } \ number of n-th powers with n digits \ for n=1, it does not count 0 and 1 (I correct for the 1 below) \ this works by just seeing what the lowest x is that fits in \ 10^(n-1), and then rounding x up to an integer n 1- 0 d>f n 0 d>f f/ falog f>d drop 9 swap - ; : solve ( -- ) 1 1 begin ( n sum ) over n-digits dup 0> while + swap 1+ swap repeat drop nip ; solve . cr