#!/usr/bin/perlusewarnings;usestrict;sub faro_shuffle{my($deck)=@_;die"Odd number of cards.\n"if@$deck%2;my$mid=@$deck/2;return[map@$deck[$_,$mid+$_],0..$mid-1]}useTest::Moretests=>5;useTest::Exception;is_deeplyfaro_shuffle([]),[],'empty';is_deeplyfaro_shuffle(['ace','two']),['ace','two'],'two cards';is_deeplyfaro_shuffle(['ace','two','three','four']),['ace','three','two','four'],'small deck';is_deeplyfaro_shuffle(['ace','two','three','four','five','six']),['ace','four','two','five','three','six'],'original example';throws_ok{faro_shuffle(['ace','two','three'])}qr/^Odd number of cards\.$/,"odd number exception";
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Perl solution. Tests stolen from Donald Feury.