[Clojure] Project Euler Problem 5 solution


For par condicio I have to show you the same problem solution but in my favorite language, Clojure.
Once again, it seems to me the coolest-freaking-awesome functional language in the world:

(defn div-1-20? [x]
  (defn aux [x acc]
    (cond
     (= x 0) false
     (= 0 acc) true
     (= 0 (mod x acc)) (aux x (dec acc))
     :else false))
  (aux x 20))

(first (filter div-1-20? (range)))

Even this solution runs in constant space, due to the range that generates a lazy sequence.
I love Clojure ❤

Bye!
Alfredo

References:

Racket vs Clojure

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...