Hey, here is Problem 3. Not the most complicated problem. However, this version requires you to enter an argument in the command line.
#Project Euler
#Problem 3
require 'mathn'
usr_num = ARGV[0].to_i
puts usr_num.prime_division.last[0]
limitsthesky
Saturday, September 25, 2010
Monday, September 20, 2010
Project Euler 002
Hey, glad I got some followers. This is my response to the second one (check the link in the title of the post for the prompt). I recommend Project Euler as a way of jumping into Ruby, especially if you love Math.
#Project Euler
#Problem 2
a, b, sum = 1,2,0
while b < 4000000
sum += b if b.even?
a,b = b,a+b
end
puts sum
#Project Euler
#Problem 2
a, b, sum = 1,2,0
while b < 4000000
sum += b if b.even?
a,b = b,a+b
end
puts sum
Sunday, September 19, 2010
Project Euler 001
I have decided to use this blog to display the source code for Project Euler answers (and eventually other programming challenges as well). Enjoy!
#Project Euler
#Problem 1
x , total = 0,0
while x < 1000
total += x if x % 3 == 0 || x % 5 == 0
x+=1
end
range = 0..999
a = range.inject(0) do |sum,element|
element%3==0 || element%5==0 ? sum+element : sum
end
puts total
puts a
Monday, September 6, 2010
Post #2!!!
Today I mailed some textbooks I sold on eBay. It was so nice to make back a little money considering how much they cost new. Have any stories about your eBay experiences? Post them as comments!
Subscribe to:
Posts (Atom)