2009-03-03から1日間の記事一覧
問題 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 v…
問題 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 exa…
問題 n! means n × (n − 1) × ... × 3 × 2 × 1 Find the sum of the digits in the number 100! ソース class Integer def fact return 1 if self.zero? self * (self - 1).fact end end puts 100.fact.to_s.scan(/./).map{|x| x.to_i}.inject(:+) 解答 648 …
問題 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…
問題 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]3 That is, 3 + 7 + 4 + 9 = 23. Find the maximum total from top to bottom in…
問題 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]3 That is, 3 + 7 + 4 + 9 = 23. Find the maximum total from top to bottom of…
問題 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 l…
問題 The Fibonacci sequence is defined by the recurrence relation: F_(n) = F_(n−1) + F_(n−2), where F_(1) = 1 and F_(2) = 1. Hence the first 12 terms will be: F_(1) = 1 F_(2) = 1 F_(3) = 2 F_(4) = 3 F_(5) = 5 F_(6) = 8 F_(7) = 13 F_(8) = 2…
問題 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 le…
Project Eulerで使ったメソッドをまとめてみました 特にProject Eulerやっている人には便利だと思うのでぜひ使ってみてください。 (コレを使ったらほとんど答えになるので、自分で正解出した後でこんなやり方もあるんだ程度で。。←ツッコミどころ満載です)…
問題 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 numbe…