横丁の名探偵

トップ > Cマガ電脳クラブ挑戦記録の部屋(過去) > Cマガ電脳クラブソースリスト(1998年分)



第93回(12月)端数よりダンゴ

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    int x;         /* X (1-9) /*
    int y;         /* Y (1-9) /*
    int z;         /* 左辺の0の個数 /*
    int maxx[81];  /* maxzに対応するX /*
    int maxy[81];  /* maxzに対応するY /*
    int maxz = -1; /* 左辺の0の個数の最大値。初期値 = -1 /*
    int maxn;      /* maxzに対応する(X,Y)の組の数 /*
    int yx;        /* YX = Y * 10 + X /*
    int a;         /* 左辺初期値 /*
    int s;         /* 左辺割り算時の余り /*
    int i;         /* 左辺割り算時のインデックス、答表示時のインデックス /*
    int n;         /* 左辺を分割した個数 /*
    for(x = 1 ; x < 10 ; x++) {
        for(y = 1 ; y < 10 ; y++) {
/* 左辺が奇数なら、右辺も奇数 /*
            if((y % 2) == 1 && (x % 2) == 0) continue;
/* 右辺が5の倍数なら、左辺も5の倍数 /*
            if(x == 5 && y != 5) continue;
            yx = y * 10 + x;
/* 右辺が4の倍数なら、左辺も4の倍数 /*
            if((yx % 4) == 0 && (y % 4) != 0) continue;
            z = 1;
            a = x * 10;
            while(1) {
/* 右辺が8の倍数なら、左辺も8の倍数 /*
                if((yx % 8) == 0 && (y % 8) != 0 && z > 1) break;
                n = (z + 1) / 7 + 1;
                if((z % 6) == 0) a = x;
                else             a *= 10;
                s = a % yx;
                for(i = n - 2 ; i > 0 ; i--) {
                    s = (s * 1000000) % yx;
                }
                s = (s + y) % yx;
                if(s == 0) {
                    if(z > maxz) {
                        maxx[0] = x;
                        maxy[0] = y;
                        maxn = 1;
                        maxz = z;
                    }
                    else if(z == maxz) {
                        maxx[maxn] = x;
                        maxy[maxn++] = y;
                    }
                    break;
                }
                z++;
            }
        }
    }
    printf("0の個数 = %d\n" , maxz);
    for(i = 0 ; i < maxn ; i++) {
        printf("X = %d , Y = %d\n" , maxx[i] , maxy[i]);
    }
    return(0);
}


第92回(11月)変形魔方陣

#include <stdio.h>
#define ON 1
#define OFF 0
int main(void)
{
    int p00 , p01 , p02 , p10 , p12 , p20 , p21 , p22;
    int i;
    int a[10];
    int count = 0;
    for(i = 1 ; i < 10 ; i++) a[i] = OFF;
    for(p00 = 1 ; p00 < 7 ; p00++) {
        a[p00] = ON;
        for(p02 = p00 + 1 ; p02 < 9 ; p02++) {
            a[p02] = ON;
            for(p20 = p02 + 1 ; p20 < 10 ; p20++) {
                a[p20] = ON;
                for(p22 = p00 + 1 ; p22 < 10 ; p22++) {
                    if(a[p22] == ON) continue;
                    a[p22] = ON;
                    for(p01 = 1 ; p01 < 10 ; p01++) {
                        if(a[p01] == ON) continue;
                        a[p01] = ON;
                        for(p10 = 1 ; p10 < 10 ; p10++) {
                            if(a[p10] == ON) continue;
                            a[p10] = ON;
                            p12 = p00 + p10 - p02;
                            if(p12 < 1 || a[p12] == ON) {
                                a[p10] = OFF;
                                continue;
                            }
                            a[p12] = ON;
                            p21 = p00 + p01 - p20;
                            if(p21 < 1 || p10 + p20 != p12 + p22 ||
                                a[p21] == ON) {
                                a[p10] = a[p12] = OFF;
                                continue;
                            }
                            count++;
                            a[p10] = a[p12] = OFF;
                        }
                        a[p01] = OFF;
                    }
                    a[p22] = OFF;
                }
                a[p20] = OFF;
            }
            a[p02] = OFF;
        }
        a[p00] = OFF;
    }
    printf("%d\n" , count);
    return(0);
}


第89回(8月)四を聞いて二十五を知る

#include <stdio.h>
#define ON 1
#define OFF 0
#define NN 5
#define U -1
#define SET 1
#define UNSET -1
typedef struct {
    int x0;
    int y0;
    int x1;
    int y1;
    int x2;
    int y2;
    int x3;
    int y3;
} XY;
void set(int a2[NN][NN][NN] , int x , int y , int n , int val)
{
    int i;
    for(i = 0 ; i < NN ; i++) a2[y][i][n] += val;
    for(i = 0 ; i < NN ; i++) a2[i][x][n] += val;
    if(x == y) {
        for(i = 0 ; i < NN ; i++) a2[i][i][n] += val;
    }
    if(x + y == 4) {
        for(i = 0 ; i < NN ; i++) a2[i][4 - i][n] += val;
    }
}
int status;
void check(int a1[NN][NN] , int a2[NN][NN][NN] , int x , int y)
{
    int i;
    if(x == NN) {
        x = 0;
        y++;
        if(y == NN) {
            status++;
            return;
        }
    }
    if(a1[y][x] == U) {
        for(i = 0 ; i < NN ; i++) {
            if(a2[y][x][i] > 0) continue;
            a1[y][x] = i;
            set(a2 , x , y , i , SET);
            check(a1 , a2 , x + 1 , y);
            set(a2 , x , y , i , UNSET);
            a1[y][x] = U;
            if(status == 2) return;
        }
    }
    else {
        check(a1 , a2 , x + 1 , y);
    }
}
int sub(int a4[NN][NN] , XY p ,
    int x0 , int y0 , int x1 , int y1 , int x2 , int y2 , int x3 , int y3)
{
    int x , y;
    int a5[NN][NN];
    for(y = 0 ; y < NN ; y++) {
        for(x = 0 ; x < NN ; x++) a5[y][x] = OFF;
    }
    a5[y0][x0] = ON;
    a5[y1][x1] = ON;
    a5[y2][x2] = ON;
    a5[y3][x3] = ON;
    if(a4[p.y0][p.x0] == a5[p.y0][p.x0] && a4[p.y1][p.x1] == a5[p.y1][p.x1] &&
       a4[p.y2][p.x2] == a5[p.y2][p.x2] && a4[p.y3][p.x3] == a5[p.y3][p.x3])
        return(ON);
    return(OFF);
}
int n = 0;
XY *a3;
void count(XY a)
{
    int x , y;
    int i;
    XY p;
    int a4[NN][NN];
    for(y = 0 ; y < NN ; y++) {
        for(x = 0 ; x < NN ; x++) {
            a4[y][x] = OFF;
        }
    }
    for(i = 0 ; i < n ; i++) {
        p.x0 = a3[i].x0;
        p.y0 = a3[i].y0;
        p.x1 = a3[i].x1;
        p.y1 = a3[i].y1;
        p.x2 = a3[i].x2;
        p.y2 = a3[i].y2;
        p.x3 = a3[i].x3;
        p.y3 = a3[i].y3;
        a4[p.y0][p.x0] = ON;
        a4[p.y1][p.x1] = ON;
        a4[p.y2][p.x2] = ON;
        a4[p.y3][p.x3] = ON;
        if(sub(a4 , p , 4 - a.x0 , a.y0 , 4 - a.x1 , a.y1 ,
            4 - a.x2 , a.y2 , 4 - a.x3 , a.y3) == ON) return;
        if(sub(a4 , p , a.x0 , 4 - a.y0 , a.x1 , 4 - a.y1 ,
            a.x2 , 4 - a.y2 , a.x3 , 4 - a.y3) == ON) return;
        if(sub(a4 , p , 4 - a.x0 , 4 - a.y0 , 4 - a.x1 , 4 - a.y1 ,
            4 - a.x2 , 4 - a.y2 , 4 - a.x3 , 4 - a.y3) == ON) return;
        if(sub(a4 , p , a.y0 , a.x0 , a.y1 , a.x1 ,
            a.y2 , a.x2 , a.y3 , a.x3) == ON) return;
        if(sub(a4 , p , 4 - a.y0 , a.x0 , 4 - a.y1 , a.x1 ,
            4 - a.y2 , a.x2 , 4 - a.y3 , a.x3) == ON) return;
        if(sub(a4 , p , a.y0 , 4 - a.x0 , a.y1 , 4 - a.x1 ,
            a.y2 , 4 - a.x2 , a.y3 , 4 - a.x3) == ON) return;
        if(sub(a4 , p , 4 - a.y0 , 4 - a.x0 , 4 - a.y1 , 4 - a.x1 ,
            4 - a.y2 , 4 - a.x2 , 4 - a.y3 , 4 - a.x3) == ON) return;
        a4[p.y0][p.x0] = ON;
        a4[p.y1][p.x1] = ON;
        a4[p.y2][p.x2] = ON;
        a4[p.y3][p.x3] = ON;
    }
    if(n == 0) a3 = (XY *)malloc(sizeof(XY));
    else       a3 = (XY *)realloc(a3 , sizeof(XY) * (n + 1));
    a3[n].x0 = a.x0;
    a3[n].y0 = a.y0;
    a3[n].x1 = a.x1;
    a3[n].y1 = a.y1;
    a3[n].x2 = a.x2;
    a3[n].y2 = a.y2;
    a3[n].x3 = a.x3;
    a3[n].y3 = a.y3;
    n++;
}
int main(void)
{
    static int t[] = {0 , 1 , 2 , 6 , 7};
    static int t2[] =
        {0,1,2,1,0 , 1,6,7,6,1 , 2,7,12,7,2 , 1,6,7,6,1 , 0,1,2,1,0};
    int i0 , i1 , i2 , i3;
    int a1[NN][NN];
    int a2[NN][NN][NN];
    XY a;
    int x , y;
    int i;
    for(y = 0 ; y < NN ; y++) {
        for(x = 0 ; x < NN ; x++) {
            a1[y][x] = U;
            for(i = 0 ; i < NN ; i++) a2[y][x][i] = 0;
        }
    }
    for(i = 0 ; i < 5 ; i++) {
        i0 = t[i];
        a.x0 = i0 % NN;
        a.y0 = i0 / NN;
        a1[a.y0][a.x0] = 0;
        set(a2 , a.x0 , a.y0 , 0 , SET);
        for(i1 = i0 + 1 ; i1 < 23 ; i1++) {
            if(t2[i1] < i0) continue;
            a.x1 = i1 % NN;
            a.y1 = i1 / NN;
            a1[a.y1][a.x1] = 1;
            set(a2 , a.x1 , a.y1 , 1 , SET);
            for(i2 = i1 + 1 ; i2 < 24 ; i2++) {
                if(t2[i2] < i0) continue;
                a.x2 = i2 % NN;
                a.y2 = i2 / NN;
                a1[a.y2][a.x2] = 2;
                set(a2 , a.x2 , a.y2 , 2 , SET);
                for(i3 = i2 + 1 ; i3 < 25 ; i3++) {
                    if(t2[i3] < i0) continue;
                    a.x3 = i3 % NN;
                    a.y3 = i3 / NN;
                    a1[a.y3][a.x3] = 3;
                    set(a2 , a.x3 , a.y3 , 3 , SET);
                    status = 0;
                    check(a1 , a2 , 0 , 0);
                    if(status == 1) count(a);
                    set(a2 , a.x3 , a.y3 , 3 , UNSET);
                    a1[a.y3][a.x3] = U;
                }
                set(a2 , a.x2 , a.y2 , 2 , UNSET);
                a1[a.y2][a.x2] = U;
            }
            set(a2 , a.x1 , a.y1 , 1 , UNSET);
            a1[a.y1][a.x1] = U;
        }
        set(a2 , a.x0 , a.y0 , 0 , UNSET);
        a1[a.y0][a.x0] = U;
    }
    printf("%d\n" , n);
    if(a3 != NULL) free(a3);
    return(1);
}


第88回(7月)Wペンタキューブ

#include <stdio.h>
#include <stdlib.h>
#define NW1 12
#define NW2 4
#define NX 6
#define NY 6
#define NZ 5
#define ON 1
#define OFF 0
#define U -1
typedef struct {
    int x;
    int y;
    int z;
} XYZ;
typedef struct {
    int bb[NZ][NY][NX];
} BBB;
XYZ xyz[NW1][NW2] = {
    1,0,0 ,  1, 1,0 ,  2, 1,0 ,  2, 2,0 ,
    0,1,0 ,  1, 1,0 ,  1, 2,0 ,  2, 2,0 ,
    0,1,0 , -1, 1,0 , -1, 2,0 , -2, 2,0 ,
    1,0,0 ,  0, 1,0 , -1, 1,0 , -1, 2,0 ,
    1,0,0 ,  1, 0,1 ,  2, 0,1 ,  2, 0,2 ,
    0,0,1 ,  1, 0,1 ,  1, 0,2 ,  2, 0,2 ,
    0,0,1 , -1, 0,1 , -1, 0,2 , -2, 0,2 ,
    1,0,0 ,  0, 0,1 , -1, 0,1 , -1, 0,2 ,
    0,1,0 ,  0, 1,1 ,  0, 2,1 ,  0, 2,2 ,
    0,0,1 ,  0, 1,1 ,  0, 1,2 ,  0, 2,2 ,
    0,0,1 ,  0,-1,1 ,  0,-1,2 ,  0,-2,2 ,
    0,1,0 ,  0, 0,1 ,  0,-1,1 ,  0,-1,2 };
int count = 0;
void toru(int bb[NZ][NY][NX] , int x , int y , int z , int m)
{
    int i;
    bb[z][y][x] = U;
    for(i = 0 ; i < NW2 ; i++) {
        bb[z + xyz[m][i].z][y + xyz[m][i].y][x + xyz[m][i].x] = U;
    }
}
int oku(int bb[NZ][NY][NX] , int x , int y , int z , int m)
{
    int i;
    if(x + xyz[m][0].x >= NX) return(OFF);
    if(y + xyz[m][0].y >= NY) return(OFF);
    if(x + xyz[m][3].x >= NX || x + xyz[m][3].x < 0) return(OFF);
    if(y + xyz[m][3].y >= NY || y + xyz[m][3].y < 0) return(OFF);
    if(z + xyz[m][3].z >= NZ) return(OFF);
    for(i = 0 ; i < NW2 ; i++) {
        if(bb[z + xyz[m][i].z][y + xyz[m][i].y][x + xyz[m][i].x] != U) {
            return(OFF);
        }
    }
    bb[z][y][x] = m;
    for(i = 0 ; i < NW2 ; i++) {
        bb[z + xyz[m][i].z][y + xyz[m][i].y][x + xyz[m][i].x] = m;
    }
    return(ON);
}
BBB *bbb = NULL;
void check(int bb[NZ][NY][NX])
{
    int i , k;
    int x , y , z;
    int p , q;
    int ss[12][12];
    int aa[NZ][NY][NX];
    int m;
    for(i = 0 ; i < count ; i++) {
        for(k = 0 ; k < 15 ; k++) {
            for(z = 0 ; z < NZ ; z++) {
                for(y = 0 ; y < NY ; y++) {
                    for(x = 0 ; x < NX ; x++) {
                        if     (k ==  0) aa[z][y][x] = bb[z][y][5 - x];
                        else if(k ==  1) aa[z][y][x] = bb[z][5 - y][x];
                        else if(k ==  2) aa[z][y][x] = bb[z][5 - y][5 - x];
                        else if(k ==  3) aa[z][y][x] = bb[z][x][y];
                        else if(k ==  4) aa[z][y][x] = bb[z][x][5 - y];
                        else if(k ==  5) aa[z][y][x] = bb[z][5 - x][y];
                        else if(k ==  6) aa[z][y][x] = bb[z][5 - x][5 - y];
                        else if(k ==  7) aa[z][y][x] = bb[4 - z][y][x];
                        else if(k ==  8) aa[z][y][x] = bb[4 - z][y][5 - x];
                        else if(k ==  9) aa[z][y][x] = bb[4 - z][5 - y][x];
                        else if(k == 10) aa[z][y][x] = bb[4 - z][5 - y][5 - x];
                        else if(k == 11) aa[z][y][x] = bb[4 - z][x][y];
                        else if(k == 12) aa[z][y][x] = bb[4 - z][x][5 - y];
                        else if(k == 13) aa[z][y][x] = bb[4 - z][5 - x][y];
                        else if(k == 14) aa[z][y][x] = bb[4 - z][5 - x][5 - y];
                    }
                }
            }
            for(p = 0 ; p < 12 ; p++) {
                for(q = 0 ; q < 12 ; q++) {
                    ss[p][q] = 0;
                }
            }
            for(z = 0 ; z < NZ ; z++) {
                for(y = 0 ; y < NY ; y++) {
                    for(x = 0 ; x < NX ; x++) {
                        ss[aa[z][y][x]][(bbb + i)->bb[z][y][x]]++;
                    }
                }
            }
            m = 0;
            for(p = 0 ; p < 12 ; p++) {
                for(q = 0 ; q < 12 ; q++) {
                    if(ss[p][q] != 0) m++;
                }
            }
            if(m == 12) return;
        }
    }
    if(count == 0) bbb = (BBB *)malloc(sizeof(BBB));
    else           bbb = (BBB *)realloc(bbb , sizeof(BBB) * (count + 1));
    for(z = 0 ; z < NZ ; z++) {
        for(y = 0 ; y < NY ; y++) {
            for(x = 0 ; x < NX ; x++) {
                (bbb + count)->bb[z][y][x] = bb[z][y][x];
            }
        }
    }
    count++;
}
void sub(int bb[NZ][NY][NX] , int x , int y , int z)
{
    int i;
    if(x == NX) {
        x = 0;
        y++;
        if(y == NY) {
            y = 0;
            z++;
            if(z == NZ) {
                check(bb);
                return;
            }
        }
    }
    while(bb[z][y][x] != U) {
        x++;
        if(x == NX) {
            x = 0;
            y++;
            if(y == NY) {
                y = 0;
                z++;
                if(z == NZ) {
                    check(bb);
                    return;
                }
            }
        }
    }
    for(i = 0 ; i < NW1 ; i++) {
        if(oku(bb , x , y , z , i) == ON) {
            sub(bb , x + 1 , y , z);
            toru(bb , x , y , z , i);
        }
    }
}
int main(void)
{
    int bb[NZ][NY][NX];
    int x , y , z;
    for(z = 0 ; z < NZ ; z++) {
        for(y = 0 ; y < NY ; y++) {
            for(x = 0 ; x < NX ; x++) bb[z][y][x] = U;
        }
    }
    oku(bb , 0 , 0 , 0 , 0);
    sub(bb , 0 , 0 , 0);
    toru(bb , 0 , 0 , 0 , 0);
    oku(bb , 0 , 0 , 0 , 4);
    sub(bb , 0 , 0 , 0);
    toru(bb , 0 , 0 , 0 , 4);
    oku(bb , 0 , 0 , 0 , 5);
    sub(bb , 0 , 0 , 0);
    toru(bb , 0 , 0 , 0 , 5);
    printf("%d\n" , count);
    if(bbb != NULL) free(bbb);
    return(0);
}


第87回(6月)正十二面体魔方陣

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    int i00 , i01 , i02 , i03 , i04 , i05 , i06 , i07 , i08 , i09 ,
        i10 , i11 , i12 , i13 , i14 , i15 , i16 , i17 , i18 , i19;
    int s01 , s02 , s03 , s05 , s06 , s08 , s10 , s12 , s15;
    int r[100];
    int j;
    int t = 52;
    while(1) {
     t++;
     for(j = 1 ; j < t ; j++) r[j] = 0;
     i00 = 1;
     r[i00] = 1;
     s01 = t - i00 - 9;
     for(i01 = 2 ; i01 <= s01 ; i01++) {
      r[i01] = 1;
      s02 = t - i00 - i01 - 5;
      for(i02 = 2 ; i02 <= s02 ; i02++) {
       if(r[i02] == 1) continue;
       r[i02] = 1;
       s03 = t - i00 - i01 - i02 - 2;
       for(i03 = 2 ; i03 <= s03 ; i03++) {
        if(r[i03] == 1) continue;
        r[i03] = 1;
        i04 = t - i00 - i01 - i02 - i03;
        if(r[i04] == 1) {
         r[i03] = 0;
         continue;
        }
        r[i04] = 1;
        s05 = t - i00 - i01 - 5;
        for(i05 = i04 + 1 ; i05 <= s05 ; i05++) {
         if(r[i05] == 1) continue;
         r[i05] = 1;
         s06 = t - i00 - i01 - i05 - 2;
         for(i06 = 2 ; i06 <= s06 ; i06++) {
          if(r[i06] == 1) continue;
          r[i06] = 1;
          i07 = t - i00 - i01 - i05 - i06;
          if(i07 < 2) {
           r[i06] = 0;
           break;
          }
          if(r[i07] == 1) {
           r[i06] = 0;
           continue;
          }
          r[i07] = 1;
          s08 = t - i01 - i02 - i07 - 2;
          for(i08 = 2 ; i08 <= s08 ; i08++) {
           if(r[i08] == 1) continue;
           r[i08] = 1;
           i09 = t - i01 - i02 - i07 - i08;
           if(i09 < 2) {
            r[i08] = 0;
            break;
           }
           if(r[i09] == 1) {
            r[i08] = 0;
            continue;
           }
           r[i09] = 1;
           s10 = t - i02 - i03 - i09 - 2;
           for(i10 = 2 ; i10 <= s10 ; i10++) {
            if(r[i10] == 1) continue;
            r[i10] = 1;
            i11 = t - i02 - i03 - i09 - i10;
            if(i11 < 2) {
             r[i10] = 0;
             break;
            }
            if(r[i11] == 1) {
             r[i10] = 0;
             continue;
            }
            r[i11] = 1;
            s12 = t - i03 - i04 - i11 - 2;
            for(i12 = 2 ; i12 < t ; i12++) {
             if(r[i12] == 1) continue;
             r[i12] = 1;
             i13 = t - i03 - i04 - i11 - i12;
             if(i13 < 2) {
              r[i12] = 0;
              break;
             }
             if(r[i13] == 1) {
              r[i12] = 0;
              continue;
             }
             r[i13] = 1;
             i14 = t - i00 - i04 - i05 - i13;
             if(i14 < 2) {
              r[i12] = 0;
              r[i13] = 0;
              continue;
             }
             if(r[i14] == 1) {
              r[i12] = 0;
              r[i13] = 0;
              continue;
             }
             r[i14] = 1;
             s15 = t - i06 - i07 - i08 - 2;
             for(i15 = 2 ; i15 <= s15 ; i15++) {
              if(r[i15] == 1) continue;
              r[i15] = 1;
              i16 = t - i06 - i07 - i08 - i15;
              if(i16 < 2) {
               r[i15] = 0;
               break;
              }
              if(r[i16] == 1) {
               r[i15] = 0;
               continue;
              }
              r[i16] = 1;
              i17 = t - i08 - i09 - i10 - i16;
              if(i17 < 2) {
               r[i15] = r[i16] = 0;
               break;
              }
              if(r[i17] == 1) {
               r[i15] = r[i16] = 0;
               continue;
              }
              r[i17] = 1;
              i18 = t - i10 - i11 - i12 - i17;
              if(i18 < 2) {
               r[i15] = r[i16] = r[i17] = 0;
               break;
              }
              if(r[i18] == 1) {
               r[i15] = r[i16] = r[i17] = 0;
               continue;
              }
              r[i18] = 1;
              i19 = t - i15 - i16 - i17 - i18;
              if(i19 < 2 || i12 + i13 + i14 + i18 + i19 != t ||
               i05 + i06 + i14 + i15 + i19 != t) {
               r[i15] = r[i16] = r[i17] = r[i18] = 0;
               continue;
              }
              if(r[i19] == 1) {
               r[i15] = r[i16] = r[i17] = r[i18] = 0;
               continue;
              }
              printf("最小定和 = %d\n" , t);
              printf("(%2d %2d %2d %2d %2d)\n" , i00 , i01 , i02 , i03 , i04);
              printf("(%2d %2d %2d %2d %2d)\n" , i00 , i01 , i05 , i06 , i07);
              printf("(%2d %2d %2d %2d %2d)\n" , i01 , i02 , i07 , i08 , i09);
              printf("(%2d %2d %2d %2d %2d)\n" , i02 , i03 , i09 , i10 , i11);
              printf("(%2d %2d %2d %2d %2d)\n" , i03 , i04 , i11 , i12 , i13);
              printf("(%2d %2d %2d %2d %2d)\n" , i00 , i04 , i05 , i13 , i14);
              printf("(%2d %2d %2d %2d %2d)\n" , i06 , i07 , i08 , i15 , i16);
              printf("(%2d %2d %2d %2d %2d)\n" , i08 , i09 , i10 , i16 , i17);
              printf("(%2d %2d %2d %2d %2d)\n" , i10 , i11 , i12 , i17 , i18);
              printf("(%2d %2d %2d %2d %2d)\n" , i12 , i13 , i14 , i18 , i19);
              printf("(%2d %2d %2d %2d %2d)\n" , i05 , i06 , i14 , i15 , i19);
              printf("(%2d %2d %2d %2d %2d)\n" , i15 , i16 , i17 , i18 , i19);
              return(1);
             }
             r[i14] = 0;
             r[i13] = 0;
             r[i12] = 0;
            }
            r[i11] = 0;
            r[i10] = 0;
           }
           r[i09] = 0;
           r[i08] = 0;
          }
          r[i07] = 0;
          r[i06] = 0;
         }
         r[i05] = 0;
        }
        r[i04] = 0;
        r[i03] = 0;
       }
       r[i02] = 0;
      }
      r[i01] = 0;
     }
     r[i00] = 0;
    }
}


第86回(5月)掛けても足しても

#include <stdio.h>
int main(void)
{
    int a[20];
    int j;
    int il0 , il1 , ir;
    int n = 4 , n1 , n2;
    int ml1 , ml2 , ml3 , mr1 , mr2;
    int madd , mmul;
    int cnt = 0;
    while(cnt == 0) {
        n++;
        n2 = n - 2;
        n1 = n - 1;
        for(j = 0 ; j < 10 ; j++) a[j] = 0;
        a[n1] = 1;
        while(a[n1] < 10) {
            for(ir = n2 ; ir > 0 ; ir--) {
                if(a[ir] == 0) continue;
                mr1 = mr2 = 0;
                for(j = n1 ; j >= ir + 1 ; j--) mr1 = mr1 * 10 + a[j];
                for(j = ir ; j >= 0 ; j--) mr2 = mr2 * 10 + a[j];
                madd = mr1 + mr2;
                mmul = mr1 * mr2;
                for(il0 = n2 ; il0 > 1 ; il0--) {
                    if(il0 == ir) continue;
                    if(a[il0] == 0) continue;
                    ml1 = 0;
                    for(j = n1 ; j >= il0 + 1 ; j--) ml1 = ml1 * 10 + a[j];
                    for(il1 = il0 - 1 ; il1 >= 0 ; il1--) {
                        if(il1 == ir) continue;
                        if(a[il1] == 0) continue;
                        ml2 = ml3 = 0;
                        for(j = il0 ; j >= il1 + 1 ; j--) ml2 = ml2 * 10 + a[j];
                        for(j = il1 ; j >= 0 ; j--) ml3 = ml3 * 10 + a[j];
                        if(ml1 + ml2 + ml3 != madd) continue;
                        if(ml1 * ml2 * ml3 != mmul) continue;
                        printf("%d +(*) %d +(*) %d = %d +(*) %d\n" ,
                            ml1 , ml2 , ml3 , mr1 , mr2);
                        cnt++;
                    }
                }
            }
            a[0]++;
            for(j = 0 ; j < n1 ; j++) {
                if(a[j] < 10) break;
                a[j] = 0;
                a[j + 1]++;
            }
        }
    }
    printf("%d\n" , n);
    return(0);
}


第85回(4月)省メモリものさし

#include <stdio.h>
int main(void)
{
    int  n , n7;
    int i0 , i1 , i2 , i3 , i4 , i5 , i6 , i7;
    int j;
    int r[37];
    for(n = 36 ; n >= 8 ; n--) {
      n7 = n - 7;
      for(j = 1 ; j <= 36 ; j++) r[j] = 0;
      i0 = 1;
      r[i0]++;
      for(i1 = 1 ; i1 < n7 ; i1++) {
        if(n - i0 - i1 < 6) break;
        r[i1]++;
        r[i0 + i1]++;
        for(i2 = 1 ; i2 < n7 ; i2++) {
          if(n - i0 - i1 - i2 < 5) break;
          r[i2]++;
          r[i1 + i2]++;
          r[i0 + i1 + i2]++;
          for(i3 = 1 ; i3 < n7 ; i3++) {
            if(n - i0 - i1 - i2 - i3 < 4) break;
            r[i3]++;
            r[i2 + i3]++;
            r[i1 + i2 + i3]++;
            r[i0 + i1 + i2 + i3]++;
            for(i4 = 1 ; i4 < n7 ; i4++) {
              if(n - i0 - i1 - i2 - i3 - i4 < 3) break;
              r[i4]++;
              r[i3 + i4]++;
              r[i2 + i3 + i4]++;
              r[i1 + i2 + i3 + i4]++;
              r[i0 + i1 + i2 + i3 + i4]++;
              for(i5 = 1 ; i5 < n7 ; i5++) {
                if(n - i0 - i1 - i2 - i3 - i4 - i5 < 2) break;
                r[i5]++;
                r[i4 + i5]++;
                r[i3 + i4 + i5]++;
                r[i2 + i3 + i4 + i5]++;
                r[i1 + i2 + i3 + i4 + i5]++;
                r[i0 + i1 + i2 + i3 + i4 + i5]++;
                for(i6 = 1 ; i6 < n7 ; i6++) {
                  i7 = n - i0 - i1 - i2 - i3 - i4 - i5 - i6;
                  if(i7 < 1) break;
                  r[i6]++;
                  r[i5 + i6]++;
                  r[i4 + i5 + i6]++;
                  r[i3 + i4 + i5 + i6]++;
                  r[i2 + i3 + i4 + i5 + i6]++;
                  r[i1 + i2 + i3 + i4 + i5 + i6]++;
                  r[i0 + i1 + i2 + i3 + i4 + i5 + i6]++;
                  r[i7]++;
                  r[i6 + i7]++;
                  r[i5 + i6 + i7]++;
                  r[i4 + i5 + i6 + i7]++;
                  r[i3 + i4 + i5 + i6 + i7]++;
                  r[i2 + i3 + i4 + i5 + i6 + i7]++;
                  r[i1 + i2 + i3 + i4 + i5 + i6 + i7]++;
                  r[n]++;
                  for(j = 1 ; j <= n ; j++) {
                    if(r[j] == 0) break;
                  }
                  if(j == n + 1) {
                      printf("%d + %d + %d + %d + %d + %d + %d + %d = %d\n" ,
                        i0 , i1 , i2 , i3 , i4 , i5 , i6 , i7 , n);
                      exit(0);
                  }
                  r[i7]--;
                  r[i6 + i7]--;
                  r[i5 + i6 + i7]--;
                  r[i4 + i5 + i6 + i7]--;
                  r[i3 + i4 + i5 + i6 + i7]--;
                  r[i2 + i3 + i4 + i5 + i6 + i7]--;
                  r[i1 + i2 + i3 + i4 + i5 + i6 + i7]--;
                  r[n]--;
                  r[i6]--;
                  r[i5 + i6]--;
                  r[i4 + i5 + i6]--;
                  r[i3 + i4 + i5 + i6]--;
                  r[i2 + i3 + i4 + i5 + i6]--;
                  r[i1 + i2 + i3 + i4 + i5 + i6]--;
                  r[i0 + i1 + i2 + i3 + i4 + i5 + i6]--;
                }
                r[i5]--;
                r[i4 + i5]--;
                r[i3 + i4 + i5]--;
                r[i2 + i3 + i4 + i5]--;
                r[i1 + i2 + i3 + i4 + i5]--;
                r[i0 + i1 + i2 + i3 + i4 + i5]--;
              }
              r[i4]--;
              r[i3 + i4]--;
              r[i2 + i3 + i4]--;
              r[i1 + i2 + i3 + i4]--;
              r[i0 + i1 + i2 + i3 + i4]--;
            }
            r[i3]--;
            r[i2 + i3]--;
            r[i1 + i2 + i3]--;
            r[i0 + i1 + i2 + i3]--;
          }
          r[i2]--;
          r[i1 + i2]--;
          r[i0 + i1 + i2]--;
        }
        r[i1]--;
        r[i0 + i1]--;
      }
      r[i0]--;
    }
    return(0);
}


第83回(2月)3数で大町どうさま

#include <stdio.h>
int main(void)
{
    int rn0 , rn1;
    int i , j , n , s;
    int cc[10];
    for(i = 1007 ; i < 2145 ; i++) {
        rn0 = ((i * (i + 1)) % 100000) * (i + 2);
        rn1 = (i * (i + 1) / 100000) * (i + 2) + rn0 / 100000;
        rn0 %= 100000;
        for(j = 0 ; j < 10 ; j++) cc[j] = 0;
        s = 10000;
        for(j = 0 ; j < 5 ; j++) {
            n = (rn1 / s) % 10;
            if(cc[n] == 0) cc[n] = 1;
            else break;
            n = (rn0 / s) % 10;
            if(cc[n] == 0) cc[n] = 1;
            else break;
            s /= 10;
        }
        if(s != 0) continue;
        printf("%d * %d * %d = %5d%5d\n" , i , i + 1 , i + 2 , rn1 , rn0);
    }
    return(0);
}


第82回(1月)ひとふで数環

#include <stdio.h>
int max = -1;
void sub(int r[] , int n , int p)
{
    int pp;
    if(r[p] == 1) {
        if(n > max) max = n;
        return;
    }
    else if(r[p] != 0) return;
    r[p] = n;
    pp = p + n;
    if(pp >= 100) pp -= 100;
    sub(r , n + 1 , pp);
    pp = p - n;
    if(pp < 0) pp += 100;
    sub(r , n + 1 , pp);
    r[p] = 0;
}
int main(void)
{
    int r[100];
    int i;
    for(i = 0 ; i < 100; i++) r[i] = 0;
    sub(r , 1 , 0);
    printf("%d\n" , max - 1);
    return(0);
}