Welcome to Dream.In.Code
Become an Expert!

Join 137,392 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,119 people online right now. Registration is fast and FREE... Join Now!




new ruby question : deck of cards

 
Reply to this topicStart new topic

new ruby question : deck of cards

capty99
6 Sep, 2006 - 10:07 PM
Post #1

the real kya
Group Icon

Joined: 26 Apr, 2001
Posts: 9,178



Thanked: 16 times
Dream Kudos: 550
My Contributions
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

CODE

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: 7 Sep, 2006 - 07:24 AM
User is offlineProfile CardPM
+Quote Post

Seth
RE: New Ruby Question : Deck Of Cards
1 Dec, 2006 - 08:53 AM
Post #2

New D.I.C Head
*

Joined: 1 Dec, 2006
Posts: 12


My Contributions
I think you want something like this:
CODE
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:
CODE

[2, heart]
[3, heart]
...

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 02:36AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month