2014-05-01から1ヶ月間の記事一覧

Project Euler その14

Problem18 By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. 3 7 4 2 4 6 8 5 9 3 That is, 3 + 7 + 4 + 9 = 23. Find the maximum total from top to bottom …

Project Euler その13

Problem15 Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. How many such routes are there through a 20×20 grid? 訳 2x2の格子の左上の隅…

Clojure演習 ライブラリ書いてみた-2

memoize 前回こんなコードを書いていた。 (defn get-content [c sm] (let [rdr ((memoize get-data) sm)] (assoc {} c (first (:content (first (html/select (html/html-resource rdr) [c]))))) )) これでキャッシュされると思っていたらしい。アホか。 (de…

Clojure演習 ライブラリを書いてみた

ネタ ニコニコ動画のAPIを叩くだけのライブラリを書くことにした。 ニコニコ動画APIとは (ニコニコドウガエーピーアイとは) [単語記事] - ニコニコ大百科 けっこういろいろあるので、とりあえずgetthumbinfoだけでも書いてみよう。 パーサライブラリ jQuery…

4Clojure-Part2

Factorial Fun (fn [n] (loop [n n f 1] (if (zero? n) f (recur (dec n) (* f n))))) そのまんま。 Interpose a Sequence (fn [x coll] (loop [coll coll s ()] (if (empty? coll) (rest (reverse s)) (recur (rest coll) (cons (first coll) (cons x s)) )…

4Clojure-Part1

Find the odd numbers (fn [coll] (loop [coll coll odds ()] (if (empty? coll) (reverse odds) (recur (rest coll) (if (odd? (first coll)) (cons (first coll) odds) odds))))) もうちょっと短くしたいな・・・ Reverse a Sequence (fn my-reverse [coll…

Minecraftの栄養を考える

発端 「クラフターってずっと同じ物食ってて不健康にならないのか」などと誰かが言っていた。 たしかに同じものを大量に作ってはずっと食べ続けている事が多い。普通なら何かしら体調を崩しているはず。 だったらそういうMODを書けばよいのだ。ordros/MineHe…