735c2b5c9430

Problem 47
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 27 Feb 2017 00:47:17 +0000
parents 6124d264353e
children 45b4d825074f
branches/tags (none)
files src/euler.lisp

Changes

--- a/src/euler.lisp	Mon Feb 27 00:38:16 2017 +0000
+++ b/src/euler.lisp	Mon Feb 27 00:47:17 2017 +0000
@@ -1393,6 +1393,30 @@
       (finding i :such-that (and (compositep i)
                                  (counterexamplep i))))))
 
+(defun problem-47 ()
+  ;; The first two consecutive numbers to have two distinct prime factors are:
+  ;;
+  ;; 14 = 2 × 7
+  ;; 15 = 3 × 5
+  ;;
+  ;; The first three consecutive numbers to have three distinct prime factors are:
+  ;;
+  ;; 644 = 2² × 7 × 23
+  ;; 645 = 3 × 5 × 43
+  ;; 646 = 2 × 17 × 19
+  ;;
+  ;; Find the first four consecutive integers to have four distinct prime
+  ;; factors each. What is the first of these numbers?
+  (flet ((factor-count (n)
+           (length (remove-duplicates (prime-factorization n)))))
+    (iterate
+      (with run = 0)
+      (for i :from 1)
+      (if (= 4 (factor-count i))
+        (incf run)
+        (setf run 0))
+      (finding (- i 3) :such-that (= run 4)))))
+
 
 ;;;; Tests --------------------------------------------------------------------
 (def-suite :euler)
@@ -1444,6 +1468,7 @@
 (test p44 (is (= 5482660 (problem-44))))
 (test p45 (is (= 1533776805 (problem-45))))
 (test p46 (is (= 5777 (problem-46))))
+(test p47 (is (= 134043 (problem-47))))
 
 
 ;; (run! :euler)