Created
November 14, 2013 13:16
-
-
Save kashi/7466601 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
http://nabetani.sakura.ne.jp/hena/ord12rotdice/ | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
void roll(char *s, char *got) | |
{ | |
int t, n, w, t2; | |
t = t2 = 1; n = 2; w = 3; | |
while (t2 > 0) { | |
*got++ = '0' + t; | |
t2 = t; | |
switch (*s++) { | |
case 'N': | |
t = 7 - n; | |
n = t2; | |
break; | |
case 'E': | |
t = w; | |
w = 7 - t2; | |
break; | |
case 'W': | |
t = 7 - w; | |
w = t2; | |
break; | |
case 'S': | |
t = n; | |
n = 7 - t2; | |
break; | |
case '\0': | |
t2 = 0; | |
break; | |
} | |
} | |
*got = '\0'; | |
} | |
void test(char *s, char *expected) | |
{ | |
char got[100]; | |
roll(s, got); | |
if (strcmp(got, expected) == 0) { | |
printf("%s : OK\n", s); | |
} else { | |
printf("%s : NG : got=%s, expected=%s\n", s, got, expected); | |
} | |
} | |
int main() | |
{ | |
/*0*/ test( "NNESWWS", "15635624" ); | |
/*1*/ test( "EEEE", "13641" ); | |
/*2*/ test( "WWWW", "14631" ); | |
/*3*/ test( "SSSS", "12651" ); | |
/*4*/ test( "NNNN", "15621" ); | |
/*5*/ test( "EENN", "13651" ); | |
/*6*/ test( "WWNN", "14651" ); | |
/*7*/ test( "SSNN", "12621" ); | |
/*8*/ test( "NENNN", "153641" ); | |
/*9*/ test( "NWNNN", "154631" ); | |
/*10*/ test( "SWWWSNEEEN", "12453635421" ); | |
/*11*/ test( "SENWSWSNSWE", "123123656545" ); | |
/*12*/ test( "SSSWNNNE", "126546315" ); | |
/*13*/ test( "SWNWSSSWWE", "12415423646" ); | |
/*14*/ test( "ENNWWS", "1354135" ); | |
/*15*/ test( "ESWNNW", "1321365" ); | |
/*16*/ test( "NWSSE", "154135" ); | |
/*17*/ test( "SWNWEWSEEN", "12415154135" ); | |
/*18*/ test( "EWNWEEEEWN", "13154532426" ); | |
/*19*/ test( "WNEWEWWWSNW", "145151562421" ); | |
/*20*/ test( "NNEE", "15631" ); | |
/*21*/ test( "EEEEWNWSW", "1364145642" ); | |
/*22*/ test( "SENNWWES", "123142321" ); | |
/*23*/ test( "SWWWSNSNESWW", "1245363635631" ); | |
/*24*/ test( "WESSENSE", "141263231" ); | |
/*25*/ test( "SWNSSESESSS", "124146231562" ); | |
/*26*/ test( "ENS", "1353" ); | |
/*27*/ test( "WNN", "1453" ); | |
/*28*/ test( "SSEENEEEN", "1263124536" ); | |
/*29*/ test( "NWSNNNW", "15414632" ); | |
/*30*/ test( "ESSSSSWW", "132453215" ); | |
/*31*/ test( "ESE", "1326" ); | |
/*32*/ test( "SNWNWWNSSSS", "121456232453" ); | |
/*33*/ test( "SWEESEN", "12423653" ); | |
/*34*/ test( "NEEWNSSWWW", "15323631562" ); | |
/*35*/ test( "WSEW", "14212" ); | |
/*36*/ test( "SWSNNNSNWE", "12464131353" ); | |
/*37*/ test( "ENWEWSEEW", "1351513545" ); | |
/*38*/ test( "WSEWN", "142124" ); | |
/*39*/ test( "EWNEESEWE", "1315321414" ); | |
/*40*/ test( "NESEEN", "1531263" ); | |
/*41*/ test( "WSW", "1426" ); | |
/*42*/ test( "ENEWE", "135656" ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment