TIMTOWTDI - or perhaps I misunderstand the problem...

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11162510 use warnings; use Time::HiRes qw( time ); use List::AllUtils qw( shuffle ); my @stock = shuffle split //, 'A23456789TJQK' x 4; my $ninecardlist = join '', splice @stock, 0, 9; my $start = time; while( @stock > 1 ) { print "$ninecardlist\n"; my ($left, $right) = splice @stock, 0, 2; $ninecardlist =~ s/(.)(.*?)\1/ print "play $left & $right over $1's\n"; "$left$2$right"/e or last; } @stock > 1 or print "$ninecardlist\n"; print @stock < 2 ? "Succeeded in consuming the entire deck.\n" : "Failed to consume the entire deck.\n"; printf "%d passes in %d microseconds\n", 52 - @stock, (time - $start) +* 1e6;

Outputs:

T7AJJQ342 play A & 9 over J's T7AA9Q342 play 8 & T over A's T78T9Q342 play T & 3 over T's T7839Q342 play 8 & 5 over 3's T7889Q542 play 5 & 6 over 8's T7569Q542 play 6 & 7 over 5's T7669Q742 play 9 & 8 over 7's T9669Q842 play A & 6 over 9's TA666Q842 play 4 & K over 6's TA4K6Q842 play 3 & A over 4's TA3K6Q8A2 play Q & J over A's TQ3K6Q8J2 play 7 & 6 over Q's T73K668J2 play T & 4 over 6's T73KT48J2 play K & Q over T's K73KQ48J2 play 7 & 3 over K's 7733Q48J2 play 2 & 4 over 7's 2433Q48J2 play 8 & 9 over 2's 8433Q48J9 play J & 2 over 8's J433Q42J9 play 9 & K over J's 9433Q42K9 play 2 & K over 9's 2433Q42KK play Q & 5 over 2's Q433Q45KK Succeeded in consuming the entire deck. 51 passes in 125 microseconds

In reply to Re^2: pop() on a fast multi-core cpu by tybalt89
in thread pop() on a fast multi-core cpu by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.