12
0
Shuffling a deck of cards is hard for kids, so they must figure out ways to get a reasonable well shuffled deck as simply as possible.
One way to do this that gives reasonably good results is:
- Take the top card out and insert it a random place in the deck
- Take the bottom card out and insert it in a random place in the deck
- Continue until you believe it's good enough.
Note that you shall never insert a card in the top or bottom spot, it should be placed somewhere in the deck.
Instead of shuffling cards, we'll shuffle alphanumerical characters: 0-9
, A-J
, a-j
, q-z
and Q-Z
.
Start with the string shown below and shuffle the characters the way it's described above. You can choose if you want to continue shuffling infinitely or shuffle the cards 100 rounds (100 cards from the top and 100 cards from the bottom).
0123456789abcdefghijqrstuvwxyzABCDEFGHIJQRSTUVWXYZ
The challenge is to display the characters being shuffled. Each "shuffle" (take out and insert card) shall take between 0.25 and 0.35 seconds.
The gif below shows an example output:
This is code-golf so the shortest code in bytes wins.
"Why don't you have a-t
instead of a-j
, q-z
?" Because this shall illustrate suits of cards, not just characters. And yes, there are 5 suits.
Note: I have decided to stop using the check mark on code-golf-challenges. Relevant meta posts here and here.
How are there 5 suits? – TrojanByAccident – 2017-01-09T08:29:13.723
1@TrojanByAccident The five sets are cards (ASCII characters) by suit are
0-9
,A-J
,a-j
,q-z
andQ-Z
, according to the question. – mbomb007 – 2017-01-09T22:14:35.377and there are 50 cards, not 52. perhaps the kids lost some. – Jasen – 2017-01-09T22:28:14.593
@mbomb007 I was asking how there were 5 suits of cards. Unless I'm missing something, there's only Spades, Clubs, Hearts, and Diamonds. That's 4. – TrojanByAccident – 2017-01-09T23:25:16.247
2@TrojanByAccident This doesn't use cards. It uses ASCII instead of cards. These are the five suits of ASCII. Instead of shuffling cards, we'll shuffle alphanumerical characters – mbomb007 – 2017-01-10T01:27:42.817
@mbomb007 I know it doesn't use actual cards, but ". . .Because this shall illustrate suits of cards. . ." – TrojanByAccident – 2017-01-10T01:28:37.393
@TrojanByAccident Because having more characters to shuffle makes it more interesting. – mbomb007 – 2017-01-10T01:29:03.007
@mbomb007 just wondering about the wording, was all :P – TrojanByAccident – 2017-01-10T01:30:50.967