Skip to content

Instantly share code, notes, and snippets.

@gb96
Created February 14, 2011 22:47
Show Gist options
  • Save gb96/826754 to your computer and use it in GitHub Desktop.
Save gb96/826754 to your computer and use it in GitHub Desktop.
/**
* For N=13 recursive swap() evaluates TOPSWOPS for 0-based deck passed as args.
*
* @param v00
* @param v01
* @param v02
* @param v03
* @param v04
* @param v05
* @param v06
* @param v07
* @param v08
* @param v09
* @param v10
* @param v11
* @param v12
* @return
*/
static int swap(final char v00, final char v01, final char v02,
final char v03, final char v04, final char v05, final char v06,
final char v07, final char v08, final char v09, final char v10,
final char v11, final char v12) {
switch (v00) {
case 0:
return 0;
case 1:
if (v01 == 0) return 1;
return 1 + swap(v01, v00, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12);
case 2:
if (v02 == 0) return 1;
return 1 + swap(v02, v01, v00, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12);
case 3:
if (v03 == 0) return 1;
return 1 + swap(v03, v02, v01, v00, v04, v05, v06, v07, v08, v09, v10, v11, v12);
case 4:
if (v04 == 0) return 1;
return 1 + swap(v04, v03, v02, v01, v00, v05, v06, v07, v08, v09, v10, v11, v12);
case 5:
if (v05 == 0) return 1;
return 1 + swap(v05, v04, v03, v02, v01, v00, v06, v07, v08, v09, v10, v11, v12);
case 6:
if (v06 == 0) return 1;
return 1 + swap(v06, v05, v04, v03, v02, v01, v00, v07, v08, v09, v10, v11, v12);
case 7:
if (v07 == 0) return 1;
return 1 + swap(v07, v06, v05, v04, v03, v02, v01, v00, v08, v09, v10, v11, v12);
case 8:
if (v08 == 0) return 1;
return 1 + swap(v08, v07, v06, v05, v04, v03, v02, v01, v00, v09, v10, v11, v12);
case 9:
if (v09 == 0) return 1;
return 1 + swap(v09, v08, v07, v06, v05, v04, v03, v02, v01, v00, v10, v11, v12);
case 10:
if (v10 == 0) return 1;
return 1 + swap(v10, v09, v08, v07, v06, v05, v04, v03, v02, v01, v00, v11, v12);
case 11:
if (v11 == 0) return 1;
return 1 + swap(v11, v10, v09, v08, v07, v06, v05, v04, v03, v02, v01, v00, v12);
case 12:
if (v12 == 0) return 1;
return 1 + swap(v12, v11, v10, v09, v08, v07, v06, v05, v04, v03, v02, v01, v00);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment