Perfect shuffling Algorithm

Source: Internet
Author: User
The perfect shuffling is to evenly divide a deck into two (26) parts, so that the loop repeats for a certain number of times and then changes back to the pre-shuffling order. That is, a_1, a_2 ........ a_n, B _1, B _2 ......... the B _n sequence is changed to B _1, a_1, B _2, a_2 ....... B _n, a_n I know this code is very SHI, just throwing bricks and asking you for better algorithms. Thank you.

The perfect shuffling is to evenly divide a deck into two (26) parts, so that the loop repeats for a certain number of times and then changes back to the pre-shuffling order. That is, a_1, a_2 ........ a_n, B _1, B _2 ......... the B _n sequence is changed to B _1, a_1, B _2, a_2 ....... B _n, a_n I know this code is very SHI, just throwing bricks and asking you for better algorithms. Thank you.

The perfect shuffling is to evenly divide a deck into two (26) parts, so that the loop repeats for a certain number of times and then changes back to the pre-shuffling order.
That is, a_1, a_2 ........ a_n, B _1, B _2 ......... the B _n sequence is changed to B _1, a_1, B _2, a_2 ....... B _n, a_n

I know this code is very SHI. I just threw bricks and asked everyone about better algorithms. Thank you!
<无>
// Perfect shuffling // $ time is the shuffling count function pshuffle ($ time = 8) {$ num = 52; $ res = $ data = range (1, $ num ); for ($ j = 0; $ j <$ time; $ j ++) {if ($ newdata) $ data = $ newdata; for ($ I = 0; $ I
  <$num 2){$newdata[$i*2]="$data[$i];}else{$key" = $i * 2 - $num + 1;$newdata[$key]="$data[$i];}}//返回次数//" if($newdata="=" $res){ return $j+1; break; }}ksort($newdata);return $newdata;}< pre><$num>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.