CoolShell 解谜游戏 Write Up

Posted on Aug 12, 2014
#include <stdio.h>
int  p, r, q;
char a[5000], f[5000], b, o, *s=f;
void interpret(char *c)
{
    char *d;
    r++;
    while( *c ) {
        switch(o=1,*c++) {
            case '<': p--;        break;             case '>': p++;        break;
            case '+': a[p]++;     break;
            case '-': a[p]--;     break;
            case '.': putchar(a[p]); fflush(stdout); break;
            case ',': a[p]=getchar();fflush(stdout); break;
            case '[':
                for( b=1,d=c; b && *c; c++ )
                b+=*c=='[', b-=*c==']';
                if(!b) {
                    c[-1]=0;
                    while( a[p] )
                    interpret(d);
                    c[-1]=']';
                    break;
                }
            case ']':
                puts("UNBALANCED BRACKETS"), exit(0);
            case '#':
  if(q>2)
                printf("- - - - - - - - - -/n%*s/n",*a,a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],3*p+2,"^");
                break;
            default: o=0;
        }
 if( p100)
            puts("RANGE ERROR"), exit(0);
    }
    r--;
}
main(int argc,char *argv[])
{
    FILE *z;
    q=argc;
    if(z=fopen(argv[1],"r")) {
 while( (b=getc(z)) > 0 )
            *s++=b;
        *s=0;
        interpret(f);
    }
}
#Thanks For Code by Mutalisk
content_de = '''Wxgcg txgcg ui p ixgff, txgcg ui p epm. I gyhgwt mrl lig txg ixgff wrsspnd tr irfkg txui \
hcrvfgs, nre, hfgpig tcm liunz txg crt13 ra "ixgff" tr gntgc ngyt fgkgf.'''.lower()
content = ''
keychr_de = 'pvwdgazxubqfsnrhocitlkeymj'

keychr = 'abcdefghijklmnopqrstuvwxyz'
for s_chr in content_de:

    if s_chr in keychr_de:

        content = content + keychr[keychr_de.index(s_chr)]

    else:

        content = content + s_chr
print content
* n皇后问题
* date       : 2010-3-12
* author     : lee
* change     :LinE
* change date:2014-8-4
*/

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;math.h&gt;

#define QUEEN 9    // the number of the queen
#define INITIAL -10000  //defines the initial value of  the board 

//container
int a[QUEEN];

//check if the queen can be placed on the position
int valid(int row, int col);
//initialize the board
void clear();
//print the result
void print();
//run the n-queen program 
void queen();

int main(void)
{
    clear();
    queen();
    return 0;
}

void clear()
{
    int *p;
    for (p = a; p &lt; a + QUEEN; ++p) {
        *p = INITIAL;
    }
}

void print()
{
    int i, j,l;
    for (i = 0; i &lt; QUEEN; ++i) {
        for (j = 0; j &lt; QUEEN; ++j) {
            if (a[i] != j) {
               //printf("%c ", '.');
             }
            else
            {
                 l=j+1;
                printf("%d",l);
                //printf("%c ", '#');
            }
        }
    }
    printf("\n");
    //printf("--------------------------------------------\n");
}


int valid(int row, int col)
{
    int i;
    for (i = 0; i &lt; QUEEN; ++i) {
        if (a[i] == col || abs(i - row) == abs(a[i] - col)) 
            return 0;
    }

    return 1;
}

void queen()
{
    int n = 0;
    int i = 0, j = 0;
    while (i &lt; QUEEN) {

        while (j &lt; QUEEN) {
            if (valid(i, j)) { //test if the queen can be placed on the position
                a[i] = j;     //place the queen on the next line
                j = 0;
                break;
            } else {         // if not, check the next position
                ++j;
            }
        }

        if (a[i] == INITIAL) {   //if the current queen can't find its place
            if (i == 0)        // and this is the first line ,then program end
                break;
            else  {           //else   backtrack
                --i;
                j = a[i] + 1;
                a[i] = INITIAL;
                continue;
            }
        }

        if (i == QUEEN - 1) {  //already got a solution, print the result
            //printf("answer %d : \n", ++n);
            print();
        //  _sleep(600);
            j = a[i] + 1;
            a[i] = INITIAL;
            continue;

        } 

        ++i;      // go on to place the queen on the next line if has any more 
    }
}
import math

COOLSHELL = 3*26**8+15*26**7+15*26**6+12*26**5+19*26**4+8*26**3+5*26**2+12*26**1+12*26**0
SHELL = 19*26**4+8*26**3+5*26**2+15*26**1+15*26**0
print 'COOLSHELL=',COOLSHELL
print 'SHELL=',SHELL
NUM = int(COOLSHELL / SHELL) + 1
print 'COOLSHELL / SHELL=',NUM
temp = NUM
a = temp / 26
b = temp % 26
c4 = chr( b + 64)
print 'a=',a
print 'b=',b
print c4
temp = a
a = temp / 26
b = temp % 26
c3 = chr( b + 64)
print 'a=',a
print 'b=',b
print c3
temp = a
a = temp / 26
b = temp % 26
c2 = chr( b + 64)
print 'a=',a
print 'b=',b
print c2
temp = a
a = temp / 26
b = temp % 26
c1 = chr( b + 64)
print 'a=',a
print 'b=',b
print c1
print 'Pass is :',c1+c2+c3+c4