2009-03-14 - 結城浩のはてな日記
答えは287桁目になるはずで、その値は0726024914。テキストの円周率表とrubyで簡単なスクリプトを作って力技で解いてみました (^^ゞ 以下はコード
def is_date(str)
days = [31,29,31,30,31,30,31,31,30,31,30,31]
return false if (str.length != 10)
month = str[0,2].to_i
day = str[2,2].to_i
hour = str[4,2].to_i
minute = str[6,2].to_i
second = str[8,2].to_i
return false if (month < 1 || month > 12)
return false if (day < 1 || day > days[month-1])
return false if (hour < 0 || hour > 23)
return false if (minute < 0 || minute > 59)
return false if (second < 0 || second > 59)
true
end
begin
if ARGV.length != 0
max = ARGV[0].to_i
end
rescue
max = 1000
end
fp = open("pi104.txt", "r")
pi=''
n=0
fp.each_byte { |c|
break if n > max
next if (c.chr < '0' || c.chr > '9')
pi += c.chr if n > 0
n += 1
}
pos = 0
while (current = (/[01]/ =~ pi)) do
pos += current+1
str = pi[current,10]
pi = pi[current+1 .. -1]
puts "match:#pos #{current} #{str}"
break if (is_date(str))
end
if (current)
puts "#{pos} #{str}"
else
puts "no date value"
end
2 years ago