Project Euler Problem 3
The factors function will return a list of all the factors of a number in descending order. The function problem3 creates a list of all the factors of 600851475143 using the factor function. With this list, the factor function is applied again to each element. The first element found, where the factor function returns a single element list with that element having the value of 1, is returned because it's prime.
(defun factors (num)
(loop for i from (isqrt num) downto 1
if (zerop (mod num i))
collect i))
(defun problem3 ()
(find '(1) (factors 600851475143) :test #'equal :key #'factors))
No comments:
Post a Comment