perl script card shuffle

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions perl script card shuffle
# 1  
Old 09-11-2011
perl script card shuffle

Hi,
I have a problem that pertains to using perl script pop,shift,push only to shuffle a card and print out 5 top listed numbers.

HW problem from oreilly school of technology linux/unix course instructor name kelly hoover

#!/usr/bin/perl



@startingdeck = ("A H","2 H","3 H","4 H","5 H","6 H","7 H","8 H",

"9 H","10 H","J H","Q H","K H",

"A D","2 D","3 D","4 D","5 D","6 D","7 D","8 D",

"9 D","10 D","J D","Q D","K D",

"A C","2 C","3 C","4 C","5 C","6 C","7 C","8 C",

"9 C","10 C","J C","Q C","K C",

"A S","2 S","3 S","4 S","5 S","6 S","7 S","8 S",

"9 S","10 S","J S","Q S","K S");

My attempt is:
shift(@i),pop(@i),shift(@i),pop(@i),push(@i),pop(@i),shift(@i),push(@i),pop(@i);

print "@i[0..4]\n";

but this only shows that the numbers are shifted not shuffled, so second attempt is:
for $x (0 .. 99){
@shuffle = shift(@i), shift(@i), pop(@i), pop(@i);
push @i, @shuffle;
}
print "@i[0 .. 4]\n";

and this somehow only listed 1 number. Thank you all for help.
# 2  
Old 09-11-2011
You might want to try again using the mandatory template mentioned in the special rules
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Logic shuffle

Hi, Is there any way I can shuffle the numbers randomly. I have been trying to google and I found lots of 'generator' but is it possible to find the background logic to create randomness? Thanks, (3 Replies)
Discussion started by: Indra2011
3 Replies

2. Shell Programming and Scripting

Randomized shuffle words on each line

Hi Folks, I have a text file with a thousand lines consisting of words or a group of words separated by commas. I would like to randomize / shuffle the words on each line. Eg; file.txt Linux,Open,Free,Awesome,Best Things in Life,The Greatest Laptop,PC,Tablet,Home Computers,Digital... (2 Replies)
Discussion started by: martinsmith
2 Replies

3. Shell Programming and Scripting

How to shuffle odd and even columns?

Is there any way to place each even column name infront of its odd column using awk or others? input Ab name MGH26 B04 MGH26 B05 output name_Ab B04_MGH26 B05_MGH26 (4 Replies)
Discussion started by: quincyjones
4 Replies

4. Shell Programming and Scripting

Random shuffle of lines of a TXT file

Hello friends, I have a TXT file with 300 lines in it. I need to shuffle all the lines (randomly) so that they get into different order. Can anyone pls provide easy way, if any? I got it done by doing this below but I see it very lengthy/inefficient way. call random function to generate... (2 Replies)
Discussion started by: prvnrk
2 Replies

5. Shell Programming and Scripting

randomly shuffle two text files the same way

What I have are two text files that I need to shuffle randomly, but I need the two files to be randomly shuffled the same way. I have heard of shuf but I do not know how to use it for two files. Maybe there is also an easy/simple awk command I do not know about that could handle this problem. ... (3 Replies)
Discussion started by: adrunknarwhal
3 Replies

6. Shell Programming and Scripting

Passing variable and wild card character to grep in Perl

HI All, I have a script that needs to find out a list of files in a directory, i pass the search parameter as an argument. opendir ( DIR, $dir ) || die "Error in opening dir $dirname\n"; @filename1 = (grep {/$File_pattern/ } readdir(DIR)); The problem is my file patterns are like... (1 Reply)
Discussion started by: amit1_x
1 Replies

7. Shell Programming and Scripting

shuffle pack of words in line

hello i just seeking for a simple way to make a shuffle by block of words in a line. no matter shell (sh/bash) or perl should be like this: the message (which is line of some file) splits to packs (packs are random 5-10 words in each) then making a new line inserting those packs in a random... (9 Replies)
Discussion started by: tip78
9 Replies

8. UNIX Desktop Questions & Answers

Does Red Hat Fedora support Nvidia card 8800GTX and 260 card?

Does Red Hat Fedora support Nvidia card 8800GTX and 260 card? Does any Linux OS support Nvidia card? (1 Reply)
Discussion started by: sito
1 Replies
Login or Register to Ask a Question