Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Euler problem 30 is another number crunching problem that deals with numbers to the power of five. Two other Euler problems dealt with raising numbers to a power. The previous problem looked at permutations of powers and problem 16 asks for the sum of the digits of
Numberphile has a nice video about a trick to quickly calculate the fifth root of a number that makes you look like a mathematical wizard.
Euler Problem 30 Definition
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
As
The sum of these numbers is
Proposed Solution
The problem asks for a brute-force solution but we have a halting problem. How far do we need to go before we can be certain there are no sums of fifth power digits? The highest digit is
largest <- 6 * 9^5 answer <- 0 for (n in 2:largest) { power.sum <-0 i <- n while (i > 0) { d <- i %% 10 i <- floor(i / 10) power.sum <- power.sum + d^5 } if (power.sum == n) { print(n) answer <- answer + n } } print(answer)
View the most recent version of this code on GitHub.
The post Digit fifth powers: Euler Problem 30 appeared first on The Devil is in the Data.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.