2009-01-01から1年間の記事一覧
引き続き「計算機プログラムの構造と解釈」を使って 今度はSchemeとRubyでの 記号データの扱い方を見ていこうと思います なおSchemeのコードは本書からの抜粋で 説明は自分の要約です Schemeではクオート(`)を使って データオブジェクトを記号として表現で…
リチャード M ストールマン フリーソフトウェアと 自由な社会を 描く人 Richard M. Stallman 時代を代表する プログラマ 哲学者 ソフトウェアは 料理のレシピと 同じよう それを手にした 何人も 原材料を入手して 自由に手を入れ 作れます 受け取るあなたが …
全文翻訳は適法か - 理系兼業主婦日記より したがって、ブログにおける翻訳の公開についても、特に著作権者(この場合は村上春樹氏)からの許諾を得ていない限りは、全文の翻訳は違法であると判断するのが妥当でしょう。 世の中は危険がいっぱいである 通り…
「計算機プログラムの構造と解釈」の 図形言語のところでつまずいているので もう一度高階関数に対する自分の理解を Rubyを使って整理してみる 「高階関数」とはその引数として関数を取ったり その戻り値として関数を返したりする関数のことである 今3つの数…
「計算機プログラムの構造と解釈」を読んでいる 2.2.4章に高階手続きを使った図形言語のサンプルが出てくる 何度か読み返しコードを実行しRuby版も一応できたけど 高階手続きの使い方に自分の思考がついていけない とりあえずRuby版をShoesで描画できるよう…
引き続き「計算機プログラムの構造と解釈」を使って SchemeとRubyで写像の入れ子を見ていきます なおSchemeのコードは本書からの抜粋で 説明は自分の要約です 整数の和の素数列 1からnの範囲において j 素数になるものを見つける例を通して写像の入れ子を学…
引き続き「計算機プログラムの構造と解釈」を使って SchemeとRubyでリストの接続インタフェース*1 としての使用について見ていこうと思います なおSchemeのコードは本書からの抜粋で 説明は自分の要約です リストの接続インタフェースとしての使用 いま構造…
引き続き「計算機プログラムの構造と解釈」を使って 今度はSchemeとRubyでのリストの操作を見ていこうと思います なおSchemeのコードは本書からの抜粋で 説明は自分の要約です リスト要素の参照 Schemeにはデータオブジェクトの並びを表現する リストという…
前回に引き続き「[rakuten:book:10825992:title]」を使って 今度はSchemeとRubyにおける データ抽象の違いを見ていこうと思います なおSchemeのコードは本書からの抜粋で 説明は自分の要約です 有理数演算手続き 有理数に対する演算(例えばadd_rat)を考える…
前回に引き続き「[rakuten:book:10825992:title]」を使って SchemeとRubyで平方根の求め方と 手続きを出力とする高階手続きをまとめてみました なおSchemeのコードは本書からの抜粋で 説明は自分の要約です Newton法を使って平方根を求める 平方根を求めると…
「計算機プログラムの構造と解釈」という本を図書館で借りた プログラマー必読の名著で Amazonによればこれ1冊でコンピュータのすべてがわかるらしい 主著者はLISPの一方言であるSchemeという言語を作った人で 本書もSchemeで書かれている Ruby以外知らない…
Problem 22 - Project Eulerより Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for …
Problem 21 - Project Eulerより Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a != b, then a and b are an amicable pair and each of a and b are calle…
Problem 19 - Project Eulerより You are given the following information, but you may prefer to do some research for yourself.1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest have thirty-one, Saving …
Problem 20 - Project Eulerより n! means n × (n - 1)× ... × 3 × 2 × 1 Find the sum of the digits in the number 100! n!は n × (n - 1)× ... × 3 × 2 × 1を意味する。 100!における桁の合計を求めよ。 Integerクラスのインスタンスメソッドとして !とsu…
Problem 18 - Project Eulerより 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 5 2 4 6 8 5 9 3That is, 3 + 7 + 4 + 9 = 23. Find the maximum total…
Problem 17 - Project Eulerより If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the numbers from 1 to 1000 (one thousand) inclusive were writte…
Problem 15 - Project Eulerより Starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner. How many routes are there through a 20×20 grid? 2×2グリッドの左上の角からスタートした場合、…
Problem 16 - Project Eulerより and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number ? の各桁の合計は 3 + 2 + 7 + 6 + 8 = 26である。 の各桁の合計はいくつか。 算数的でないけど def sum_of_digits(n) …
Problem 14 - Project Eulerより 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 …
Problem 12 - Project Eulerより 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, …
Problem 13 - Project Eulerより Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 以下の50桁数字100個の合計における最初の10桁を算出せよ。 配列に入れてinject(:+)します number = <
Problem 10 - Project Eulerより 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万未満の素数すべての和を求めよ。 Problem3で既に素数を…
Problem 11 - Project Eulerより 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 4…
Problem 8 - Project Eulerより Find the greatest product of five consecutive digits in the 1000-digit number. 以下の1000桁の数字における連続した5つの数の積の最大値を求めよ。7316717653133062491922511967442657474235534919493496983520312774506…
Problem 9 - Project Eulerより A Pythagorean triplet is a set of three natural numbers, a For example, . There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. ピタゴラス数とは、次の関係にある3つの自…
Problem 6 - Project Eulerより The sum of the squares of the first ten natural numbers is, The square of the sum of the first ten natural numbers is, Hence the difference between the sum of the squares of the first ten natural numbers and t…
Problem 7 - Project Eulerより 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 10001st prime number? 最初の6つの素数2、3、5、7、11、および13を並べれば、6番目が13であることがわ…
Problem 5 - Project Eulerより 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 number that is evenly divisible by all of the numbers from 1 to 20? 2520は1から10…
Problem 4 - Project Eulerより 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. 回…