From: Paul Smith Date: 2009-12-03T00:17:16+09:00 Subject: Re: Advice - Printing All Options On Wed, Dec 2, 2009 at 3:13 PM, Aldric Giacomoni wrote: > Wood Yee wrote: >> Hi! I've set a project for myself but I don't know where to begin >> (newbie). Here's what I'm trying to do: >> >> I'm trying to come up with a drill for my martial arts class where I can >> flow from position to position, from top to bottom, and to left and >> right. Here's an example: Position 1/being on Top of opponent/Focus on >> Left Side. Then go to, say, Position 2/being on Bottom of Opponent/Focus >> on Right Side. In other words, I'd like a list of all different >> combinations for these 3 areas (Position/Top-Bottom/Left-Right). I've >> played around with rand with arrays but can't get what I'm looking for. >> Thanks so much! > > This is, as others have shown, rather trivial code. While I applaud your > intent, which I presume is to not leave out any positions, your training > will benefit from you doing this work in your head and with your body > from the start. But, still, to achieve it, change the "puts" line, which prints to screen, to instead put the result in an array. cobinations = [] Positions = ['Rear', 'Mount', 'Knee', 'Side', 'Turtle', 'Guard'] Direction = ['Top', 'Bottom'] Side = ['Left', 'Right'] Positions.each {|x| Direction.each {|y| Side.each {|z| combinations << [#{x}/#{y}/#{z}]}}} puts combinations.shuffle puts combinations.shuffle puts combinations.shuffle :) > -- > Posted via http://www.ruby-forum.com/. > > -- Paul Smith http://www.nomadicfun.co.uk paul@pollyandpaul.co.uk