This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;;; Project Euler Problem 16 solution | |
| ;;;; http://projecteuler.net/problem=16 | |
| (use 'clojure.test) | |
| (import 'java.math.BigInteger) | |
| ;; Character/digit usage from: https://gist.github.com/4276901 | |
| (def solve | |
| (comp (partial apply +) | |
| (partial map #(Character/digit ^char % 10)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (use 'clojure.test) | |
| ;; ピタゴラス数チェック | |
| (defn pythagorean? | |
| [a b c] | |
| (= (* c c) (+ (* a a) (* b b)))) | |
| (is (pythagorean? 3 4 5)) | |
| ;; 合計が a+b+c かつ 0 < a < b < c になるような組の列挙 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; seq-end-inclusive を割れそうな数の候補 | |
| (defn denominators [seq-end-inclusive] | |
| (for [d (range 2 (+ seq-end-inclusive 1)) | |
| :while (<= (* d d) seq-end-inclusive) | |
| ] | |
| d)) | |
| ;; end-inclusive 以下の素数列をエラトステネスの篩で | |
| (defn gen-primes [end-inclusive] | |
| (reduce (fn [primes d] (filter #(or (= %1 d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (use 'clojure.set) | |
| (defn n-multiples [n end] (set (range 0 end n))) | |
| (defn solve [] | |
| (apply + (union (n-multiples 3 1000) | |
| (n-multiples 5 1000)))) |
NewerOlder