--90e6ba53b0d465cafa04ac163bb7 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Sep 3, 2011 at 11:23 PM, Kane Williams <theburrick / hotmail.com>wrote: > Thanks for the reply! > > I wanted to get something out of the way first, some other guy made a > thread exactly the same as my one and it has generated 6 replys somehow. > It is located here http://www.ruby-forum.com/topic/2497160#new although > you can probably just see it for yourself on the frontpage. > > We are in no way connected, in fact I don't really know any other > programmers :O. So I would assume this is a glitch in the system. I hope > there is some way to merge these two threads together. > > Now to reply to the questions: > > > Is this no good? > > [7, 7.058823529, 9.941176471] > > > > or this? > > [6.5, 7.542857143, 9.957142857] > > > > > > Are you requiring only integers? > > Can you show some code? > > Yea for simplicity's sake I just want full integers, although I don't > really mind either way. > > Here is the Haskell code: > ghci> let rightTriangles' (a,b,c) | c <- [1..10], b <- [1..c], a <- > [1..b], a^2 + b^2 c^2, a+b+c 24] > ghci> rightTriangles' > [(6,8,10)] > > Which was found at the bottom of this tutorial: > http://learnyouahaskell.com/starting-out#tuples > > And I don't have any ruby code, that's why I'm posting here! :3 Just > wondering how I would start about to make a program which uses > Pythagoras Theorem. > > -- > Posted via http://www.ruby-forum.com/. > > A direct translation of that would look like this: def right_triangles results ] (1..10).each do |c| (1..c).each do |b| (1..b).each do |a| results << [a, b, c] if a+b+c 24 && a**2 + b**2 c**2 end end end results end right_triangles # [[6, 8, 10]] Ruby doesn't have list comprehensions like the Haskell example uses (Python might, not sure). If math functions and algorithms are your primary domain, then Haskell is a better choice than Ruby (Python is, too, for this domain), because it has libs and a community built around this use case. --90e6ba53b0d465cafa04ac163bb7--