Skip to content

Instantly share code, notes, and snippets.

@ponkore
ponkore / Problem010.clj
Created April 29, 2012 11:46
Project Euler Problem 10
;;; The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
;;; Find the sum of all the primes below two million.
(defn primes [n]
(loop [prime-list '(2) search-list (take-while #(< % n) (iterate inc 2))]
(let [prime-list-max (first prime-list)
search-list-next (filter #(not (zero? (mod % prime-list-max))) search-list)]
(if (< n (* prime-list-max prime-list-max))
(sort (concat prime-list search-list-next))
(recur (conj prime-list (first search-list-next)) search-list-next)))))
@ponkore
ponkore / Problem011.clj
Created April 30, 2012 01:42
Project Euler Problem 11
;;; In the 20x20 grid below, four numbers along a diagonal line have been marked in red.
;;;
;;; 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
;;; 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
;;; 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
;;; 52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
;;; 22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
;;; 24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
;;; 32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
;;; 67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
@ponkore
ponkore / Problem012.clj
Created May 5, 2012 09:03
Project Euler Problem 12
;;; The sequence of triangle numbers is generated by adding the natural numbers.
;;; So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
;;;
;;; 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
;;;
;;; Let us list the factors of the first seven triangle numbers:
;;;
;;; 1: 1
;;; 3: 1,3
;;; 6: 1,2,3,6
@ponkore
ponkore / hoge.clj
Created July 14, 2012 13:12
RubyにおけるシーケンスはObject#repeatに任せなさい!を Clojure でやってみた
;;; http://melborne.github.com/2012/07/12/object-repeat-take-care-of-sequence/
;;; を Clojure でやってみた。
;;; 9.、10. は挫折www
;;; 2012/07/16 11:02 追記:9.、10.についての解答をtnoda さんが作成されました。
;;; https://gist.github.com/3111930 の 9.、10. になります。
;;; 1. 初項1、公差2の等差数列の最初の20項を求めなさい。
(take 20 (iterate #(+ % 2) 1))
;;; => (1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39)
@ponkore
ponkore / StatefulIntegerExample.clj
Created July 23, 2012 07:36
Clojure Programming Example 2-1. Implementation of a mutable integer in "Clojure"
;;; Clojure Programming Chapter 2. Functional Programming
;;; Example 2-1. Implementation of a mutable integer in "Clojure"
(defprotocol IStatefulInteger
(setInt [this new-state])
(intValue [this]))
(deftype StatefulInteger [^{:volatile-mutable true} state]
IStatefulInteger
(setInt [this new-state] (set! state new-state))
(intValue [this] state)
@ponkore
ponkore / logger-01.clj
Created July 25, 2012 01:49
Clojure Programming Chapter2 P.73〜P.76 logger
(defn print-logger
[writer]
#(binding [*out* writer]
(println %)))
(def *out*-logger (print-logger *out*))
;= #'user/*out*-logger
(*out*-logger "hello")
; hello
;= nil
@ponkore
ponkore / hoge.clj
Created August 2, 2012 05:45
mapリテラルでは8対までは array-map、それより多い対は hash-map が生成される。
;; @___otabat___ さんのツイート https://twitter.com/___otabat___/status/230890089218195456
;; より引用
;; 「Clojureでmapリテラルを使うとき、8対目まではarray-map、9対目からhash-mapに変わるなどデータと内部実装が異なるのは注意。」
;; を試してみた。
user=> (class {:a 10 :b 20})
;= clojure.lang.PersistentArrayMap
user=> (class {:a 10 :b 20 :c 30 :d 40 :e 50 :f 60 :g 70 :h 80})
;= clojure.lang.PersistentArrayMap (:a〜:h 8対まで)
user=> (class {:a 10 :b 20 :c 30 :d 40 :e 50 :f 60 :g 70 :h 80 :i 90})
;= clojure.lang.PersistentHashMap (:a〜:i 9対、PersistentHashMap に変わった!!)
@ponkore
ponkore / memo.sh
Created August 3, 2012 05:19
github上でgithubにフォークしたリモートリポジトリを本家リモートリポジトリに追随する
# http://d.hatena.ne.jp/haru-s/20110405/1302006637 に答えがそのままあるが、一応メモ
# github fork 追従 で見つけた
$ git remote
origin
# 本家のリモートリポジトリの短縮名を登録する.
$ git remote add github git://github.com/liquidz/misaki.git
# 本家の更新をローカルで反映させる.
@ponkore
ponkore / notify-patch.diff
Created August 4, 2012 03:45
[misaki] テンプレート保存時にコンパイルエラーが発生した時に、Mac の Growl に通知を出してみる。
diff --git a/project.clj b/project.clj
index 99624f3..5b53fba 100644
--- a/project.clj
+++ b/project.clj
@@ -9,6 +9,7 @@
[clj-time "0.3.7"]
[clj-text-decoration "0.0.1"]
[clj-pretty-error "0.0.5"]
+ [clj-gntp "0.0.1"] ; https://github.com/mattn/clj-gntp
[uochan/watchtower "0.1.2"]
@ponkore
ponkore / remove-dup-declaration.diff
Created August 6, 2012 12:38
duplicated declaration in config.clj
diff --git a/src/misaki/config.clj b/src/misaki/config.clj
index ee06fbe..dfffb85 100644
--- a/src/misaki/config.clj
+++ b/src/misaki/config.clj
@@ -57,8 +57,6 @@
(declare ^:dynamic *post-sort-type*)
;; Compile options for ClojureScript
(declare ^:dynamic *cljs-compile-options*)
-;; Current site data
-(declare ^:dynamic *site*)