# Advice - Printing All Options

**URL:** <https://www.ruby-forum.com/t/advice-printing-all-options/179714>\
**Category:** Ruby\
**Created:** [December 2, 2009, 2:52pm UTC](https://www.ruby-forum.com/t/advice-printing-all-options/179714 "2009-12-02T14:52:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 2, 2009, 2:52pm UTC](https://www.ruby-forum.com/t/advice-printing-all-options/179714/1 "2009-12-02T14:52:10Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 2, 2009, 3:17pm UTC](https://www.ruby-forum.com/t/advice-printing-all-options/179714/2 "2009-12-02T15:17:30Z")

</div>

On Wed, Dec 2, 2009 at 1:52 PM, Wood Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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.

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
Paul S.  
[http://www.nomadicfun.co.uk](http://www.nomadicfun.co.uk)

removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 2, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/advice-printing-all-options/179714/3 "2009-12-02T15:25:54Z")

</div>

> 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 S.  
> [http://www.nomadicfun.co.uk](http://www.nomadicfun.co.uk)
> 
> removed\_email\_address@domain.invalid

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}”}}}

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 2, 2009, 3:30pm UTC](https://www.ruby-forum.com/t/advice-printing-all-options/179714/4 "2009-12-02T15:30:42Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 2, 2009, 3:35pm UTC](https://www.ruby-forum.com/t/advice-printing-all-options/179714/5 "2009-12-02T15:35:30Z")

</div>

Wood Y. wrote:

> 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](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 2, 2009, 3:47pm UTC](https://www.ruby-forum.com/t/advice-printing-all-options/179714/6 "2009-12-02T15:47:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 2, 2009, 3:46pm UTC](https://www.ruby-forum.com/t/advice-printing-all-options/179714/7 "2009-12-02T15:46:11Z")

</div>

2009/12/2 Marnen Laibow-Koser [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > Mount/Bottom/Left  
> > Turtle/Top/Right  
> > 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.

1.9 also has #shuffle.

Cheers

robert

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 2, 2009, 4:18pm UTC](https://www.ruby-forum.com/t/advice-printing-all-options/179714/8 "2009-12-02T16:18:23Z")

</div>

On Wed, Dec 2, 2009 at 3:13 PM, Aldric G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > 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/](http://www.ruby-forum.com/).

–  
Paul S.  
[http://www.nomadicfun.co.uk](http://www.nomadicfun.co.uk)

removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 2, 2009, 4:13pm UTC](https://www.ruby-forum.com/t/advice-printing-all-options/179714/9 "2009-12-02T16:13:31Z")

</div>

Wood Y. 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.
