2011-07-18から1日間の記事一覧

Project Eueler: problem13

問題 Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 ..... 回答 ar = [] DATA.each do |line| ar << …

Project Eueler: 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, 6, 10, 15, 21, 28, 36, 45, 55, ...Let us list the fact…

Project Eueler: problem11

問題 In the 2020 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 4…

Project Eueler: problem10

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.Find the sum of all the primes below two million. prime = [2] sum = 2 limit = 2000000 (3..limit).each do |x| flg = true prime.each do |y| if x % y == 0 flg = false ;break end end if flg …

Project Eueler: problem9

A Pythagorean triplet is a set of three natural numbers, a b c, for which,a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52.There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. (1..333).each do …

Project Eueler: problem8

Find the greatest product of five consecutive digits in the 1000-digit number. #Ruby str = "" DATA.each do |x| x = x.chomp! str = str + x end res = 0 (0..995).each do |x| t = 1 (0..4).each do |y| t = t*str[x+y,1].to_i end if res < t res = …