Skip to content

Instantly share code, notes, and snippets.

@Wilfred
Created September 12, 2009 09:23
Show Gist options
  • Select an option

  • Save Wilfred/185773 to your computer and use it in GitHub Desktop.

Select an option

Save Wilfred/185773 to your computer and use it in GitHub Desktop.
; code for project euler problem 1
(defn returnIfFactor
[x]
(if (or (= (mod x 5) 0) (= (mod x 3) 0))
x
0))
(defn problem1
[x]
(if (= x 0)
0
(+ (returnIfFactor x) (problem1 (- x 1)))))
(println (problem1 999))
; euler problem 2
(defn fibs [x y]
(lazy-seq
(cons x (fibs y (+ x y)))))
(defn problem2 [l]
(if (>= (first l) 4000000)
0
(if (even? (first l))
(+ (first l) (problem2 (rest l)))
(problem2 (rest l)))))
(println (problem2 (fibs 1 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment