2008-10-01から1ヶ月間の記事一覧

ワイン

今日はワインを飲んだ。この前家で飲んだのとは大違い。おいしかった。

Problem 34

145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.Find the sum of all numbers which are equal to the sum of the factorial of their digits.Note: as 1! = 1 and 2! = 2 are not sums they are not included. import Data.Char p034 m= […

Problem 32

The product 7254 is unusual, as the identity, 39 x 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 thr…

Problem 31

In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation: 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).It is possible to make £2 in the following way: 1£1 + 150p + 220p + 15p + 12…

Problem 30

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: 1634 = 14 + 64 + 34 + 44 8208 = 84 + 24 + 04 + 84 9474 = 94 + 44 + 74 + 44As 1 = 14 is not a sum it is not included.The sum of these…

Problem 33

The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.We shall consider fractions like, 30/50 =…

Problem 27

Euler published the remarkable quadratic formula:n² + n + 41It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and certainl…

Problem 26

unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given: 1/2 = 0.5 1/3 = 0.(3) 1/4 = 0.25 1/5 = 0.2 1/6 = 0.1(6) 1/7 = 0.(142857) 1/8 = 0.125 1/9 = 0.(1) 1/10 = 0.1 Wh…

Problem 25

The Fibonacci sequence is defined by the recurrence relation: Fn = Fn1 + Fn2, where F1 = 1 and F2 = 1.Hence the first 12 terms will be: F1 = 1 F2 = 1 F3 = 2 F4 = 3 F5 = 5 F6 = 8 F7 = 13 F8 = 21 F9 = 34 F10 = 55 F11 = 89 F12 = 144The 12th t…

3人寄れば

3人寄れば文殊の知恵 とはいいますが、所詮、たいした専門知識も持っていない人が集まってもねぇというわけで今日は 3人寄れば大混乱 でした。よく分からないこと P=NP、P≠NP? P=NPは決定不能? 決定不能とはどういうことか? 証明可能とは証明木が構成でき…

Problem 29

Consider all integer combinations of ab for 2 a 5 and 2 b 5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, 35=243 42=16, 43=64, 44=256, 45=1024 52=25, 53=125, 54=625, 55=3125If they are then placed in numerical order, with any repeats remov…

Problem 28

Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13It can be verified that the sum of both diagonals is 101.What…

Problem 23

A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.A number whos…

Problem 22

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 each name, multiply this value …

Problem 21

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 called amicable numbers.For example, th…

Problem 17

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 written out in words, how many letters…

Problem 20

Find the sum of the digits in the number 100! *Main Data.Char> sum.map digitToInt.show$foldl (*) 1 [1..100] 648

Problem 19

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 February alone, Which has twen…

Problem 18

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 from top to bottom of the triang…

Problem 24

A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicog…

Problem 16

2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.What is the sum of the digits of the number 2^1000? *Main> sum.map digitToInt.show$2^1000 1366

Problem 15

Starting in the top left corner of a 2x2 grid, there are 6 routes (without backtracking) to the bottom right corner. How many routes are there through a 20x20 grid? Integerを使えば簡単。 p015 n = product[n+1..2*n]`div`product[1..n]

Problem 14

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 4 2 1 It can be seen that t…

Problem 13

Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. そのまま。 main =replicateM 100 (liftM read getLine)>>=putStrLn.(take 10).show.sum {-- $ time ./p010.exe < p013.txt 5537376230 ./p010.exe < p013.txt 0.…

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 o…

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 …

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. 自分が実装したエラトステネスのふるいは遅かった。単純な素数生成。 p010 = sum$takeWhile(<2000000)$primes primes = 2:filter isPrime [3,5..]…

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, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. とりあえず…

Problem 8

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

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 10001st prime number? エラトステネスのふるいを普通に実装したら遅かった。高速化に手間取った。 sieve ms ns= ms++(sieve ps rs) whe…