Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn tri*
- "Generates lazy sequence of triangular number"
- ([] (tri* 0 1))
- ([sum n]
- (let [new-sum (+ sum n)]
- (cons new-sum (lazy-seq (tri* new-sum (inc n)))))))
- (def tri (tri*))
- (defn triangular?
- "Is the number traingular? e.g. 1, 3, 6"
- [n]
- (= n (last (take-while #(>= n %) tri))))
- (dotimes [n 1000]
- (println (triangular? (rand-int 500000000))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement