Created
October 30, 2012 22:16
-
-
Save masahixixi/3983460 to your computer and use it in GitHub Desktop.
ProjectEuler #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
number_ary = [] | |
number_string = [] | |
ans = [] | |
number = open("./problem8_number") | |
while number_data = number.gets | |
number_ary << number_data.chomp | |
end | |
number_string = number_ary.join | |
(0..995).each do |num| | |
number_temp = number_string[num..num+4] | |
# num を先頭に5個取り出すなら number_string[num, 5] の方が分かりやすい | |
number_temp = number_temp.split("").map{|e| e.to_i} | |
number_temp = number_temp.inject(1){|prd, e| prd *= e} | |
ans << number_temp | |
end | |
ans2 = [] | |
ary = number_string.split("").map{|i| i.to_i } | |
(0..995).each do |idx| | |
ans2 << ary[idx, 5].inject(1){|prd,e| prd *= e } | |
end | |
p ans.sort.last | |
p ans2.max |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment