Advice - Printing All Options

W

Wood Yee

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!
 
P

Paul Smith

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!


a = [1,2,3]
b = ["a","b","c"]
c = [7,8,9]

a.each {|x| b.each {|y| c.each {|z| puts "#{x}/#{y}/#{z}"}}}

There's probably a better way.
 
W

Wood Yee

a = [1,2,3]
b = ["a","b","c"]
c = [7,8,9]

a.each {|x| b.each {|y| c.each {|z| puts "#{x}/#{y}/#{z}"}}}

There's probably a better way.
--
Paul Smith
http://www.nomadicfun.co.uk

(e-mail address removed)

PERFECT!! You totally nailed it! That's exactly what I wanted. Woo hoo!
I'll study the code and learn from this. Thanks SO much!

Here's what I did:

Positions = ['Rear', 'Mount', 'Knee', 'Side', 'Turtle', 'Guard']
Direction = ['Top', 'Bottom']
Side = ['Left', 'Right']

Positions.each {|x| Direction.each {|y| Side.each {|z| puts
"#{x}/#{y}/#{z}"}}}
 
W

Wood Yee

Hey - one more thing. How can I go further and make this more random. I
ran the program and got this:

Rear/Top/Left
Rear/Top/Right
Rear/Bottom/Left
Rear/Bottom/Right
Mount/Top/Left
Mount/Top/Right
Mount/Bottom/Left
Mount/Bottom/Right
Knee/Top/Left
Knee/Top/Right
Knee/Bottom/Left
Knee/Bottom/Right
Side/Top/Left
Side/Top/Right
Side/Bottom/Left
Side/Bottom/Right
Turtle/Top/Left
Turtle/Top/Right
Turtle/Bottom/Left
Turtle/Bottom/Right
Guard/Top/Left
Guard/Top/Right
Guard/Bottom/Left
Guard/Bottom/Right


Can I drill down even further? Example - Guard/Bottom/Right, then
Turtle/Top/Right, etc? Thanks!
 
M

Marnen Laibow-Koser

Wood said:
Hey - one more thing. How can I go further and make this more random. I
ran the program and got this:

Rear/Top/Left
Rear/Top/Right
Rear/Bottom/Left
Rear/Bottom/Right
Mount/Top/Left
Mount/Top/Right
Mount/Bottom/Left
Mount/Bottom/Right
Knee/Top/Left
Knee/Top/Right
Knee/Bottom/Left
Knee/Bottom/Right
Side/Top/Left
Side/Top/Right
Side/Bottom/Left
Side/Bottom/Right
Turtle/Top/Left
Turtle/Top/Right
Turtle/Bottom/Left
Turtle/Bottom/Right
Guard/Top/Left
Guard/Top/Right
Guard/Bottom/Left
Guard/Bottom/Right


Can I drill down even further?

What do you mean?
Example - Guard/Bottom/Right, then
Turtle/Top/Right, etc? Thanks!

If you just want random order, that's easy. Check out sort_by and rand.
Best,
-- 
Marnen Laibow-Koser
http://www.marnen.org
(e-mail address removed)
 
W

Wood Yee

What do you mean?

When I ran my program, it printed out all options for each Position.
Now, I'd like to print them out in random order. For example:

Mount/Top/Left
Knee/Top/Right
Side/Bottom/Left
etc,

instead of

Mount/Top/Left
Mount/Top/Right
Mount/Bottom/Left
Mount/Bottom/Right
Knee/Top/Left
Knee/Top/Right
Knee/Bottom/Left
Knee/Bottom/Right
etc,

Thanks!
 
A

Aldric Giacomoni

Wood said:
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.
 
P

Paul Smith

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

:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top