食材(M:肉,F:魚,V:野菜,B:豆)の組合せは以下の通り。

プログラムを作るとしたら以下のようになる。
#include "puzutl.h"
YesNo used[7];
int val[7] = {1,3,5,9,12,6,2};
cstring s[7] = { "(M,M)", "(M,F)", "(M,V)", "(M,B)", "(V,B)", "(F,V)", "(F,F)"};
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;
if( !((val[a] & val[b]) ||
(val[b] & val[c]) ||
(val[c] & val[d]) ||
(val[d] & val[e]) ||
(val[e] & val[f]) ||
(val[f] & val[g]))) {
ps( "%s, %s, %s, %s, %s, %s, %s\n", s[a], s[b], s[c], s[d], s[e], s[f], s[g]);
}
cnt++;
used[g] = NO;
}
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;
}
プログラムを実行すると以下の出力を得る。
(M,F), (V,B), (M,M), (F,V), (M,B), (F,F), (M,V) (M,V), (F,F), (M,B), (F,V), (M,M), (V,B), (M,F) cnt:5040