Problem 3 in Project Euler
What is the largest prime factor in 600851475143
Super simple. The library numbers have a function primeFactors(). It simply returns all prime factors.
Put that inside a max(), and you have the result.
library(numbers)
max(primeFactors(600851475143))
## [1] Censored
Using the library purrr, it can be written like this, and this is a way of coding that I need a bit more practice in, so lets do it that way as well.
library(purrr)
600851475143 %>%
primeFactors() %>%
max()
## [1] Censored
The %>% are a pipe function. It takes whats on the left, and passes it to whats on the right. In this case the number is piped to the function primeFactors(), and the result of that function is piped to the max() function. And you get the result.
Lesson learned – nope. I already knew that numbers is a pretty useful library.