Skip to content

Instantly share code, notes, and snippets.

@tnoda
tnoda / problem_5.clj
Created December 11, 2012 14:50
Project Euler Problem 5 #mitori_clj
(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))
@ypsilon-takai
ypsilon-takai / pe_14.clj
Created December 13, 2012 10:36
Project euler 14
;; 去年最初に解いたときのやつ。
;; 「hotpo」というのは half or tripple plus one のアクロニムで、昔読んでいた(日経)サイエンス誌の連載で
;; これが紹介されたときの名前で、英語版Wikipediaには載っていました。
;; 今動かしてみたら、なぜかスタックオーバーフローになってしまう。
;; 1.2だと動くのかなぁ。と思ってやってみたら動く!!
;; なんでだろう。 スタックの深さが1.2の方が大きいのかなぁ。
;; 実行すると、 50秒くらいかかります。
;; "Elapsed time: 48273.476472 msecs"
@ponkore
ponkore / compiler.clj
Created December 13, 2012 13:15
hiccup の魔改造。hiccup の jar には手を入れずに、hiccup 内プライベート関数を書き換えて、改行とインデントをサポート。 だいたいできたけど、a とか span とか h1〜h6 とかのように、改行をいちいち入れないほうが見栄えが良いタグをちゃんと サポートしたい。
(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* " ")
;;; 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"
@ypsilon-takai
ypsilon-takai / pe_21.clj
Last active October 14, 2015 01:17
Project euler 21
;; 初めて解いたときのものです。
;; 約数の和を求めるために、素因数分解してそれを利用してます。
;; 思いつきをそのまま実装しちゃってる感じです。
;; Problem 21 : 2011/5/5
;;"Elapsed time: 1260.253748 msecs"
;; prime list
;; まずは素数列を作ってしまいます。
@ponkore
ponkore / problem-4-1.clj
Created December 14, 2012 13:35
Project Euler Problem 4
;;;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])
@plaster
plaster / pe-9.clj
Created December 15, 2012 07:21
Project Euler Problem 9 solution in Clojure (#mitori_clj)
(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 になるような組の列挙
@emanon001
emanon001 / problem_6.clj
Created December 15, 2012 09:08
Project Euler Problem 6 #mitori_clj
;;; 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)))
@ypsilon-takai
ypsilon-takai / pe_4_other.clj
Created December 17, 2012 07:55
Project euler 4
;;ざっと思い付いたものを実装してみました。
;; 合っているかどうかも未検証 (12/17)
;;(12/17 21:00)
;; やっぱり考慮がまったく足りていなかったので、基本は変えずに全面みなおし。
(defn palindromic? [s]
(= (seq s) (reverse s)))
@kohyama
kohyama / pep017.clj
Created December 19, 2012 10:19
Project Euler Problem 17
(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"