Ludic numbers: Difference between revisions

→‎{{header|Clojure}}: Add implementation.
(Initial implementation in PL/I)
(→‎{{header|Clojure}}: Add implementation.)
Line 109:
Triples below 250: (1 3 7) (5 7 11) (11 13 17) (23 25 29) (41 43 47) (173 175 179) (221 223 227) (233 235 239)
</pre>
 
=={{header|Clojure}}==
<lang clojure>(defn ints-from [n]
(cons n (lazy-seq (ints-from (inc n)))))
 
(defn drop-nth [n seq]
(cond
(zero? n) seq
(empty? seq) []
:else (concat (take (dec n) seq) (lazy-seq (drop-nth n (drop n seq))))))
 
(def ludic ((fn ludic
([] (ludic 1))
([n] (ludic n (ints-from (inc n))))
([n [f & r]] (cons n (lazy-seq (ludic f (drop-nth f r))))))))
 
(defn ludic? [n] (= (first (filter (partial <= n) ludic)) n))
(print "First 25: ")
(println (take 25 ludic))
(print "Count below 1000: ")
(println (count (take-while (partial > 1000) ludic)))
(print "2000th through 2005th: ")
(println (map #(nth ludic %) (range 1999 2006)))
(print "Triplets < 250: ")
(println (filter (partial every? ludic?)
(for [i (range 250)] (list i (+ i 2) (+ i 6)))))</lang>
{{output}}
<pre>First 25: (1 2 3 5 7 11 13 17 23 25 29 37 41 43 47 53 61 67 71 77 83 89 91 97 107)
Count below 1000: 142
2000th through 2005th: (21475 21481 21487 21493 21503 21511 21523)
Triplets < 250: ((1 3 7) (5 7 11) (11 13 17) (23 25 29) (41 43 47) (173 175 179) (221 223 227) (233 235 239))</pre>
 
=={{header|D}}==
1,481

edits