-
Notifications
You must be signed in to change notification settings - Fork 0
/
104.clj
32 lines (23 loc) · 866 Bytes
/
104.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(ns e104
(:require [clojure.contrib.math :as math
clojure.contrib.string :as string
]))
(defn next-fib [[pos last value]]
[(inc pos) value (+ last value)])
(def fibs (iterate next-fib [2 1 1]))
(defn pandigital?
[numstring]
(and (= 9 (count numstring))
(= 9 (count (distinct (remove #(= \0 %) numstring))))))
(defn first-nine [somenum]
(take 9 (str somenum)))
(defn last-nine [somenum]
(take 9 (reverse (str somenum))))
(defn test-last [[pos last value]]
(pandigital? (last-nine value)))
(defn test-first [[pos last value]]
(pandigital? (first-nine value)))
(time (println (ffirst (take 1 (filter test-first fibs)))))
(time (println (ffirst (take 1 (filter test-last fibs)))))
(time (println (ffirst (take 1 (filter #(and (test-first %)
(test-last %)) fibs)))))