Skip to content

Instantly share code, notes, and snippets.

@cielavenir
Created September 3, 2012 23:11
Show Gist options
  • Select an option

  • Save cielavenir/3614606 to your computer and use it in GitHub Desktop.

Select an option

Save cielavenir/3614606 to your computer and use it in GitHub Desktop.
Project Euler 44
#!/usr/bin/ruby
a=1.step(9999).map{|i|i*(3*i-1)/2}
h={}
a.each{|e|h[e]=1}
b=[]
a.length.times{|i|
(i+1).step(a.length-1){|j|
if h[a[j]+a[i]] && h[a[j]-a[i]] then b.push(a[j]-a[i]) end
}
}
p b.min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment