2014-01-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…

Project Euler その12

Problem14 The following iterative sequence is defined for the set of positive integers: n → n/2 (n is even) n → 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 → 40 → 20 → 10 → 5 → 16 → 8…

Project Euler その11

Problem13 Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 743249861995247410594742333095130581237…

Project Euler その10

Problem 11 In the 20×20 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…

Project Euler その9

Problem11がどうにもうまくいかないので先に進む。 Problem12 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, …

Project Euler その8

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. 訳 10以下の素数の和は2+3+5+7=17である。200万以下の全ての素数の和を求めよ。 コード i = 3 prime = [2] flag = 0 while(1): for j…

Project Euler その7

Problem 9 A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^2 + b^2 = c^2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc…

Project Euler その6

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. 訳 「回文数はどちらか…

Project Euler その5

飛ばしてたProblem3を解いた。 Problem 3 The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? 訳 「13195の素因数は5と7,13と29である。600851475143の素因数の内最大の要素は何か? 」 コー…

Project Euler その4

Problem8 Find the greatest product of five consecutive digits in the 1000-digit number. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 8586156078911294949545950173795833195285320880551…

Project Euler その3

Problem 7 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? 訳 最初の6つの素数をリストアップすると、2,3,5,7,11と13がある。6番目の素数に13を見ることができ…

Project Euler その2

Problem3,4がなんかめんどくさそうだったので一旦飛ばす。 Problem 5 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is divisible by all of th…

Project Euler その1

Pythonで解いてみた。 Problem 1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. 訳 10以下のすべての自…

ハイレゾへの道 

以前PCM1798とPCM2706を使ったUSBDACを作ったことがあった。 PCM2706でPCからの信号をI2Sに変換、PCM1798でD-A変換して出力といった感じ。PCM2704で作ったDACよりは高音質な気がしたけれど、PCM2706が16bitのI2Sしか吐けない。 だもんでハイレゾ音源を試すこ…

USBアイソレータの効果

かねてから気になっていたUSBアイソレータADuM4160を試してみた。 マルツで注文したらケース(リール?)に入ってた。このチップ、例としてはDACに挟んで、PC由来のノイズをカットするなどがあるらしい。 電源も別系統で用意するので、少なくとも電源は綺麗…