From 8564d3de284df4f591e2be1113619e3501c97fb6 Mon Sep 17 00:00:00 2001 From: Lowl3v3l Date: Tue, 11 Jul 2017 16:56:15 +0200 Subject: [PATCH] solved 47 in racket, ugly code --- 47/euler47.rkt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 47/euler47.rkt diff --git a/47/euler47.rkt b/47/euler47.rkt new file mode 100644 index 0000000..0c27b85 --- /dev/null +++ b/47/euler47.rkt @@ -0,0 +1,22 @@ +#lang racket + +(require math/number-theory) + +(define (primefactors x) + (if (prime? x) + (list x) + (for/or ((i (cons 2 (range 3 (+ 1 (ceiling (sqrt x))) 2))) + #:when (prime? i) + #:when (zero? (remainder x i))) + (cons i (primefactors (quotient x i)))))) + +(define (recur x) + (if (and + (equal? (length (remove-duplicates (primefactors x))) 4) + (equal? (length (remove-duplicates (primefactors (+ x 1)))) 4) + (equal? (length (remove-duplicates (primefactors (+ x 2)))) 4) + (equal? (length (remove-duplicates (primefactors (+ x 3)))) 4)) + x + (recur (+ x 1)))) + +(recur 2) \ No newline at end of file