Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Card shuffle

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
my final assessment in my java class for this year is to design and implement a Java programme which takes as input the number of desired swaps, outputs an ordered Set of cards which are then "shuffled" and output again. The number of swaps must be at least 1 and not more than 1000.
im not asking for the code to be written for me, but i really dont have any idea of this one. can sumone possibly give me a detailed guideline as to how i shud do it.
p.s. u know, if any1 wants 2 write the whole thing id b happy to let them
thanx in advance
chris
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
What is your instructor's definition of "shuffle"? It's kind of an interesting problem to cut the deck perfectly and interleave the cards perfectly. Cards 1..52 wind up 1,26,2,27,3,28 etc. If you repeat this just the right number of times you get the original order back. I think.

Another way to shuffle is to lay all 52 cards out in a row. Point to the first one, swap it with some random card. Point to the second one, swap it with some random card. Every card wll be moved at least once, some more.

Either of those sound like a good shuffle routine?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Chris, please don't start more than one thread on the same topic. As I'm having an ongoing dialog with you here, I'm going to close this thread and leave that other one open.
    Bookmark Topic Watch Topic
  • New Topic