朝日新聞2004年11月20日パズルパーク解答

プログラムの出力結果は以下の通り。

Find A:10, B: 4, C: 8, D: 0, E: 2, F: 6, G: 4
Find A:10, B: 4, C: 8, D: 0, E: 2, F: 6, G: 4
Find A: 8, B: 4, C:10, D: 2, E: 0, F: 4, G: 6
Find A: 8, B: 4, C:10, D: 2, E: 0, F: 4, G: 6
cnt:5040

4件出力されているが上2件,下2件は同じ。

これはネズミが2匹いたため。上2件と下2件は左右が対称の結果なので,実質1件。

図示すると以下の通り。

プログラムは以下の通り。

#include "puzutl.h"

YesNo used[7];
int   nleg[7] = { 10, 8, 6, 2, 0, 4, 4 }; // イカ,蛸(タコ),甲虫(カブトムシ),雀(スズメ),蛇(ヘビ),鼠(ネズミ),鼠(ネズミ)の足の数

int main( int argc, cstring argv[])
{
  int           cnt = 0;
  for( int a=0; a< 7; a++) {
    used[a] = YES;
    for( int b=0; b< 7; b++) {
      if( used[b]) continue;
      used[b] = YES;
      for( int c=0; c< 7; c++) {
        if( used[c]) continue;
        used[c] = YES;
        for( int d=0; d< 7; d++) {
          if( used[d]) continue;
          used[d] = YES;
          for( int e=0; e< 7; e++) {
            if( used[e]) continue;
            used[e] = YES;
            for( int f=0; f< 7; f++) {
              if( used[f]) continue;
              used[f] = YES;
              for( int g=0; g< 7; g++) {
                if( used[g]) continue;
                int n1 = nleg[a] + nleg[d];
                int n2 = nleg[b] + nleg[d] + nleg[f] ;
                int n3 = nleg[f] + nleg[g] ;
                int n4 = nleg[b] + nleg[e] + nleg[g] ;
                int n5 = nleg[c] + nleg[e] ;
                if( n1 == n2 && n2 == n3 && n3 == n4 && n4 == n5) {
                  ps( "Find A:%2d, B:%2d, C:%2d, D:%2d, E:%2d, F:%2d, G:%2d\n", nleg[a], nleg[b], nleg[c], nleg[d], nleg[e], nleg[f], nleg[g]);
                }
                cnt++;
              }
              used[f] = NO;
            }
            used[e] = NO;
          }
          used[d] = NO;
        }
        used[c] = NO;
      }
      used[b] = NO;
    }
    used[a] = NO;
  }
  ps( "cnt:%d\n", cnt);
  return    0;
}