このディレクトリの索引
http://hibari.2ch.net/test/read.cgi/tech/1305867431/859
#  [1] 授業単元:C言語課題 
#  [2] 問題文 
#  下記の虫食い算をfor文を使い、計算によって、 
#  求めるプログラムを作成しなさい。 
#  ただし、void ○○という文、puzzle文を使用してはならない。 
#    、■ 
#    ×□□
#   −−−− 
#    □□□ 
#   □□□  
#   −−−− 
#   9□□□ 
#   
#  ◆ 、□ 
#    ×□□ 
#   −−−− 
#    □□□ 
#   □4□  
#   −−−− 
#   □3□□ 
#  

虫食い算(A,1,*,C,D,=,E,F,G,+,H,I,J,=,9,L,M,N) :-
        member(A,[0,1,2,3,4,5,6,7,8,9]),
        member(C,[0,1,2,3,4,5,6,7,8,9]),
        member(D,[0,1,2,3,4,5,6,7,8,9]),
        _第一段 is (A * 10 + 1) * D,
        _第ニ段 is (A * 10 + 1) * C,
        _答え is _第一段 + _第ニ段 * 10,
        9 is _答え // 1000,
        E is _第一段 // 100,
        Em is _第一段 mod 100,
        F is Em // 10,
        G is F mod 10,
        H is _第ニ段 // 100,
        Hm is _第ニ段 mod 100,
        I is Hm // 10,
        J is I mod 10,
        Km is _答え mod 1000, 
        L is Km // 100,
        Lm is Km  mod 100,
        M is Lm // 10,
        N is Lm mod 10.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

虫食い算(A,1,*,C,D,=,E,F,G,+,H,I,J,=,9,L,M,N) :-
        member(A,[0,1,2,3,4,5,6,7,8,9]),
        member(D,[0,1,2,3,4,5,6,7,8,9]),
        member(E,[0,1,2,3,4,5,6,7,8,9]),
        member(F,[0,1,2,3,4,5,6,7,8,9]),
        member(G,[0,1,2,3,4,5,6,7,8,9]),
        _第一段 is (A * 10 + 1) * D,
        _第一段 is E * 100 + F * 10 + G,
        member(C,[0,1,2,3,4,5,6,7,8,9]),
        member(H,[0,1,2,3,4,5,6,7,8,9]),
        member(I,[0,1,2,3,4,5,6,7,8,9]),
        member(J,[0,1,2,3,4,5,6,7,8,9]),
        _第ニ段 is (A * 10 + 1) * C,
        _第ニ段 is H * 100 + I * 10 + J,
        member(L,[0,1,2,3,4,5,6,7,8,9]),
        member(M,[0,1,2,3,4,5,6,7,8,9]),
        member(N,[0,1,2,3,4,5,6,7,8,9]),
        _答え is _第一段 + _第ニ段 * 10,
        _答え is 9 * 1000 + L * 100 + M * 10 + N.