{{ message }}

Instantly share code, notes, and snippets.

# Aaron Tinioaptinio

• Angeles City, Philippines
Created Nov 4, 2009
Project Euler Problem 1
View euler001.rb
 (1...1000).to_a.select {|n| n.remainder(3) == 0 || n.remainder(5) == 0}.reduce(:+)
Created Nov 4, 2009
Project Euler Problem 2
View euler002.rb
 fib = [1, 2] def fib.next self[-1] + self[-2] end fib << fib.next while fib.next < 4_000_000 fib.select {|f| f.remainder(2) == 0}.reduce(:+)
Created Nov 4, 2009
Project Euler Problem 3
View euler003.rb
 require 'mathn' 600851475143.prime_division.last.first
Created Nov 4, 2009
Project Euler Problem 4
View euler004.rb
 def palindrome?(integer) string = integer.to_s string == string.reverse end products = [] 999.step(100, -1).to_a.each do |a| 999.step(100, -1).to_a.each do |b| product = a*b
Created Nov 4, 2009
Project Euler Problem 7
View euler007.rb
 require 'mathn' prime = Prime.new 10_000.times {prime.succ} prime.succ
Created Nov 4, 2009
Project Euler Problem 9
View euler009.rb
 def pythagorean_triple(m, n) m, n = n, m if m > n [n**2 - m**2, 2*m*n, n**2 + m**2] end infinity = 1.0/0.0 catch :answer_found do (1..infinity).each do |m| (m+1..infinity).each do |n|
Created Nov 4, 2009
Project Euler Problem 5
View euler005.rb
 (1..20).to_a.reduce :lcm
Created Nov 4, 2009
Project Euler Problem 6
View euler006.rb
 (1..100).to_a.reduce(:+)**2 - (1..100).to_a.reduce {|sum_of_squares, n| sum_of_squares + n**2}
Created Nov 4, 2009
Project Euler Problem 8
View euler008.rb
 numbers = <
Created Nov 5, 2009
Project Euler Problem 10
View euler010.rb
 require 'mathn' Prime.new.inject(0) { |sum, n| break(sum) if n >= 2_000_000 sum + n }
You can’t perform that action at this time.