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
(ns tnoda.projecteuler.problem-5 | |
(:import org.apache.commons.math.util.MathUtils) ; [org.apache.commons/commons-math "2.2"] | |
(:use clojure.test)) | |
(defn- solver* | |
[n] | |
(reduce (fn [^long x ^long y] (MathUtils/lcm x y)) (range 1 (inc n)))) | |
(def solver (partial solver* 20)) |
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
;; 去年最初に解いたときのやつ。 | |
;; 「hotpo」というのは half or tripple plus one のアクロニムで、昔読んでいた(日経)サイエンス誌の連載で | |
;; これが紹介されたときの名前で、英語版Wikipediaには載っていました。 | |
;; 今動かしてみたら、なぜかスタックオーバーフローになってしまう。 | |
;; 1.2だと動くのかなぁ。と思ってやってみたら動く!! | |
;; なんでだろう。 スタックの深さが1.2の方が大きいのかなぁ。 | |
;; 実行すると、 50秒くらいかかります。 | |
;; "Elapsed time: 48273.476472 msecs" |
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
(ns hiccup-mod.compiler | |
(:require [hiccup.compiler :as c])) | |
;;; | |
;;; CAUTION!!! hiccup.compiler の end-tag、render-element を書き換える。 | |
;;; | |
;;; public vars | |
(def ^{:dynamic true :doc " default is two white space."} | |
*html-indent-characters* " ") |
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 #8 | |
;;; http://projecteuler.net/problem=8 | |
;;; http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%208 | |
(use 'clojure.test) | |
(def input | |
(str | |
"73167176531330624919225119674426574742355349194934" | |
"96983520312774506326239578318016984801869478851843" |
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
;; 初めて解いたときのものです。 | |
;; 約数の和を求めるために、素因数分解してそれを利用してます。 | |
;; 思いつきをそのまま実装しちゃってる感じです。 | |
;; Problem 21 : 2011/5/5 | |
;;"Elapsed time: 1260.253748 msecs" | |
;; prime list | |
;; まずは素数列を作ってしまいます。 |
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
;;;A palindromic number reads the same both ways. | |
;;;The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99. | |
;;;Find the largest palindrome made from the product of two 3-digit numbers. | |
;;;左右どちらから読んでも同じ値になる数を回文数という。 2桁の数の積で表される回文数のうち、 | |
;;;最大のものは 9009 = 91 × 99 である。 | |
;;;では、3桁の数の積で表される回文数のうち最大のものはいくらになるか。 | |
(ns projecteuler.problem-4 | |
(:require [clojure.string :as str]) |
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
;;; Project Euler Problem 6 | |
;;; 「二乗の和と和の二乗の差はいくつか?」 | |
;;; http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%206 | |
(use 'clojure.test) | |
(defn sum-of-squares | |
"与えられた数列についてその二乗の和を返します" | |
[nums] | |
(apply + (map #(* % %) nums))) |
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
;;ざっと思い付いたものを実装してみました。 | |
;; 合っているかどうかも未検証 (12/17) | |
;;(12/17 21:00) | |
;; やっぱり考慮がまったく足りていなかったので、基本は変えずに全面みなおし。 | |
(defn palindromic? [s] | |
(= (seq s) (reverse s))) | |
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
(require '[clojure.test :refer (is)]) | |
(defn in-words | |
"Represents the given number in English words without spaces nor hyphens. | |
This works with a number in the range from 1 to 1000" | |
[n] | |
(cond | |
(< n 20) | |
(["" "one" "two" "three" "four" "five" "six" "seven" "eight" | |
"nine" "ten" "eleven" "twelve" "thirteen" "fourteen" |