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
require "prime" | |
count = 501 | |
tri_num = 0 | |
div = Array.new | |
num = 0 | |
loop do | |
num += 1 | |
tri_num += num |
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_split = Array.new | |
number_ary = Array.new | |
number_list = open("./problem11_num") | |
max = 0 | |
ans = 0 | |
while number_data = number_list.gets | |
number_split << number_data.chomp | |
end |
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_list = open("./problem13_num") | |
ans = 0 | |
while number_data = number_list.gets | |
number_ary << number_data.chomp | |
end | |
(0..99).each do |num| | |
ans += number_ary[num].to_i |
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
sum = 1000 | |
catch (:done) do | |
(1..(sum / 3 - 1)).each do |a| | |
((a+1)..(sum - a) / 2 - 1).each do |b| | |
c = sum - a - b | |
if (a**2 + b**2 == c**2) && (a + b + c == sum) | |
p a, b, c | |
p ans = a * b * c | |
throw :done |
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 |
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
require "mathn" | |
num = 2000000 | |
num_list = (2..num).to_a | |
pri_list = Array.new | |
sum_list = Array.new | |
tmp = 2 | |
sum = 0 | |
while tmp <= Math.sqrt(num) |
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
require "prime" | |
num = 3 | |
sum = 2 | |
while num <= 2000000 | |
sum += num if num.prime? | |
num += 2 | |
end | |
p sum |
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
require "prime" | |
pri = [] | |
num = 2 | |
while pri.size < 10001 | |
if Prime.instance.prime?(num) == true | |
pri << num | |
end | |
num += 1 | |
end |
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
sum = 0 | |
prod1 = 0 | |
prod2 = 0 | |
(1..100).each do |num| | |
prod1 += num ** 2 | |
sum += num | |
end | |
prod2 = sum ** 2 |
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
lcmnum = 11 | |
(12..20).each do |num| | |
lcmnum = lcmnum.lcm(num) | |
end | |
p lcmnum |