Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds @RobFreiburger's solutions. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions 1/RobFreiburger.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions 2/RobFreiburger.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions 3/RobFreiburger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'prime'
puts Prime.prime_division(600851475143).last[0]
13 changes: 13 additions & 0 deletions 4/RobFreiburger.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions 5/RobFreiburger.rb
Original file line number Diff line number Diff line change
@@ -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