2008-10-25から1日間の記事一覧

Problem 3

The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ? 素因数分解した。 p003 = last.pfac$600851475143 pfac 1 = [] pfac m = q:(pfac m') where (q,m') = head [(n,div m n)|n<-[2..(floor.sqr…

Problem 2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...Find the sum of all the even-valued terms in the sequence whi…

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. 始めの問題だけあって簡単。手計算でできる。 p001 = sum …

無限リストを含むリストの型?

Haskellではリストは以下の3つに分けられる有限リスト [1,2,3,4] , [1,20,30] 無限リスト [1..] そして最後が擬リスト 例えば _|_,1:2:_|_, 10:20:30:40:50:_|_ 要するに、末尾がbotになっている。 上の二つのリストとの関係は擬リストの極限が無限リストと…

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. 速く動かすのに、意外と手こずった。…