diff --git a/1/RobFreiburger.rb b/1/RobFreiburger.rb new file mode 100644 index 0000000..830195d --- /dev/null +++ b/1/RobFreiburger.rb @@ -0,0 +1,9 @@ +sum = 0 + +1.upto(999).each do |i| + if (i % 3 == 0) || (i % 5 == 0) + sum += i + end +end + +puts sum \ No newline at end of file diff --git a/2/RobFreiburger.rb b/2/RobFreiburger.rb new file mode 100644 index 0000000..74015a1 --- /dev/null +++ b/2/RobFreiburger.rb @@ -0,0 +1,18 @@ +sum = 0 + +def fib(n) + return n if n < 2 + vals = [0, 1] + (n-1).times do + vals.push(vals[-1] + vals[-2]) + end + return vals +end + +fib(34).each do |value| + if value <= 4000000 + sum += value if value.even? + end +end + +puts sum \ No newline at end of file diff --git a/3/RobFreiburger.rb b/3/RobFreiburger.rb new file mode 100644 index 0000000..a7be145 --- /dev/null +++ b/3/RobFreiburger.rb @@ -0,0 +1,2 @@ +require 'prime' +puts Prime.prime_division(600851475143).last[0] \ No newline at end of file diff --git a/4/RobFreiburger.rb b/4/RobFreiburger.rb new file mode 100644 index 0000000..50a1498 --- /dev/null +++ b/4/RobFreiburger.rb @@ -0,0 +1,13 @@ +largest_palindrome = 0 + +(100..999).each do |x_value| + (100..999).each do |y_value| + test_value = x_value * y_value + + if (test_value.to_s == test_value.to_s.reverse) && (test_value > largest_palindrome) + largest_palindrome = test_value + end + end +end + +puts largest_palindrome \ No newline at end of file diff --git a/5/RobFreiburger.rb b/5/RobFreiburger.rb new file mode 100644 index 0000000..2d2a5b4 --- /dev/null +++ b/5/RobFreiburger.rb @@ -0,0 +1,16 @@ +# Is computationally-inefficient + +smallest_num = 1 + +while true do + results = Array.new(20) + (1..20).each do |i| + results.push((smallest_num % i) == 0) + end + + break unless results.include?(false) + + smallest_num += 1 +end + +puts smallest_num \ No newline at end of file