On Sun, Sep 4, 2011 at 5:10 PM, Kane Williams <theburrick / hotmail.com> wrote:
> Thanks guys! You've both been helpful! Now how would I make it so that
> it would return a float? Perhaps up to two decimal places? Here's my
> code so far : http://pastie.org/2479748
>
> I tried making the range into a float, but then I'm not sure how that
> would work, at what decimal point range it would end up at, it gave me
> an error anyways.
>


Sorry for the repost.
Slight modifications.


# integers
per =  24 # 2_400_000
(1..per).each do |a|
  c = (a.to_f**2+(per-a)**2)/(2*(per-a))
  b = per-a-c
  p [a,b.to_i,c.to_i] if a>=1 && b>=1 && c>=1 && b==b.to_i && c==c.to_i
end

puts

# some floats
per =  24.3
(0..per).each do |a|
  c = (a.to_f**2+(per-a)**2)/(2*(per-a))
  b = per-a-c
  p [a,b,c] if a>0 && b>0 && c>0
end




Harry