1 Replies - 9437 Views - Last Post: 01 December 2006 - 09:53 AM Rate Topic: -----

#1 capty99  Icon User is offline

  • i am colt mccoy
  • member icon

Reputation: 98
  • View blog
  • Posts: 10,081
  • Joined: 26-April 01

new ruby question : deck of cards

Posted 06 September 2006 - 11:07 PM

okay,
im getting ruby down and i like it so far,
but i need a lil helping out...

i got to make a deck of cards for hw ( so dont spoil the fun and figure it out for me, just push me in the right direction )

i have set up two arrays to combine on top of eachother to create each individual card.... as seen below

SUIT = %w[ heart, diamond, club, spade ]
VALUE = %w[ 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A ]
SUIT.each do |suit| VALUE.each do |value|
puts value +  suit
end
end



now, when this outputs does it make a new array that i can access or is there a way i can convert that into an array,
because somehow i need to get at these cards and then be able to shuffle the deck and draw random ones off the top.

thanks in advance.


oh yeah,
here is the output from the part i have done :

2,heart,
3,heart,
4,heart,
5,heart,
6,heart,
7,heart,
8,heart,
9,heart,
10,heart,
J,heart,
Q,heart,
K,heart,
Aheart,
2,diamond,
3,diamond,
4,diamond,
5,diamond,
6,diamond,
7,diamond,
8,diamond,
9,diamond,
10,diamond,
J,diamond,
Q,diamond,
K,diamond,
Adiamond,
2,club,
3,club,
4,club,
5,club,
6,club,
7,club,
8,club,
9,club,
10,club,
J,club,
Q,club,
K,club,
Aclub,
2,spade
3,spade
4,spade
5,spade
6,spade
7,spade
8,spade
9,spade
10,spade
J,spade
Q,spade
K,spade
Aspade

This post has been edited by capty99: 07 September 2006 - 08:24 AM


Is This A Good Question/Topic? 0
  • +

Replies To: new ruby question : deck of cards

#2 Seth  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 01-December 06

Re: new ruby question : deck of cards

Posted 01 December 2006 - 09:53 AM

I think you want something like this:
SUIT = %w[ heart, diamond, club, spade ]
VALUE = %w[ 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A ]
new_array = []
SUIT.each do |suit|
  VALUE.each do |value|
	 new_array << [value,  suit]
  end
end


It'll create a new array with many subarrays:
[2, heart]
[3, heart]
...


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1