Giter VIP home page Giter VIP logo

project-euler's Introduction

Project Euler with sprinkles of Clojure

Some random Project Euler solutions in Clojure, because, why not.

Multiples of 3 and 5
(defn sum-multiples-3-5
  [upper-bound]
  (reduce + (filter #(or
                      (= (mod % 5) 0)
                      (= (mod % 3) 0)) (range 1 upper-bound))))

Even Fibinocci Numbers
(defn fib [a b] (lazy-seq (cons a (fib b (+ b a)))))

(reduce + (filter #(= (mod % 2) 0)   (take-while #(< % 4000000) (fib 0 1) )))
Largest prime factor
(defn prime? [x] (not (some #(= (mod x %) 0) (range 2 (+ (Math/sqrt x) 1)))))

(defn prime-factors [x]
  (filter #(and (prime? %) (= (mod x %) 0))
          (range 2 (+ (Math/sqrt x) 1))))
Largest palindrome product
(defn tens
  ([n] (tens n 1))
  ([n x] (if (< n 10) x
                      (tens (quot n 10) (* x 10)))))

(defn reverse'
  [n mult]
  (if (= 0 n) 0
              (+ (* (mod n 10) mult) (reverse' (quot n 10) (quot mult 10)))))

(defn largest-palindrome-product [digits]
(let [max' (reduce * (for [x (range 0 digits)] 10))]
  (apply max (filter #(= (reverse' % (tens %)) %)
                     (for [x (range 1 max') y (range 1 max')] (* x y))))))
Smallest multiple
(defn divdes-all [num s]
  (if (empty? s) true
                 (and (= (mod num (first s)) 0)
                      (divides-all num (rest s)))))

(defn get-divisors
  ([n] (get-divisors (range n 1 -1) []))
  ([s accum]
   (if (empty? s)
     accum
     (let [x (first s)]
       (get-divisors (filter #(not= (mod x %) 0) (rest s)) (conj accum x))))))



(+ 1 (first (filter #(divides-all  (+ 1 %) (get-divisors 20))(range))))

project-euler's People

Contributors

warebot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.