This file contains hidden or 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
upto = 20 | |
def prime? x | |
(2..x-1).each { |y| return false if x % y == 0 } | |
true | |
end | |
# For speed reasons we want to find max possible increment | |
def increment upto | |
a = 1 |
This file contains hidden or 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
def palindrome? x | |
y = x.to_s | |
checks = y.length / 2 | |
y[0..(checks-1)] == y[-checks..-1].reverse | |
end | |
def divideable? x | |
999.downto(100).each { |y| return true if x % y == 0 && (x / y).to_s.length == 3 } | |
false | |
end |
This file contains hidden or 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
# We make array of prime numbers with modulus 0 as long as product_sum < n | |
def prime? n | |
(2..(n-1)).each { |x| return false if n % x == 0 } | |
true | |
end | |
n = 600_851_475_143 | |
a = [] | |
product_sum = 1 |
This file contains hidden or 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
# Create Fibonnaci Array | |
a = [1,2] | |
upto = 4_000_000 | |
while a[-2] + a[-1] < upto | |
a << a[-2] + a[-1] | |
end | |
# Create sum of even Fibonnaci numbers | |
sum = 0 | |
a.each { |x| sum+= x if x.even? } |
This file contains hidden or 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
y = 0 | |
(1..999).each { |x| y = y + x if (x % 3 == 0) || (x % 5 == 0) } | |
puts y |
NewerOlder