% File : sudoku378.pl % Author : N.-F. ZHOU and K. Akama % Date : 1996 % Purpose: solve a Japanese arithmetic puzzle with 378 variables. % problem produced by T. Unemi /********************************************************************* This puzzle, called SUDOKU, is popular in Japan. In this problem, one is required to place 25 hexadecimal digits from [0-9A-O] on a 25*25 board such that any row and any column of the board, and any one of the 25 subsquares has different digits placed. -----+-----+-----+-----+----- | | | | | | | |4KL35 | | |IG7O9|ND0CJ | |45LK3|HA261| |54K3L|2H6A1|8EFMB| -----+-----+-----+-----+----- C| | | | O 9| C| | |8F E B| 9| D|L45 K|H2 6 3| 1|8M F |O7I G| CD 1|M8FE |IO 7G|0NJCD| 3K -----+-----+-----+-----+----- BE| 7G| JN| 4| 21 1A| E| 7| N|L CD| K|6 |B8M | IG 9 9G| ND| 5 | H6 | FB 3K| 6H |MB |9IOG7| JD -----+-----+-----+-----+----- 8EF| OI | N0J| 3 | A IG7| 0J | L5| 2H| E JDN| 54| 6H| BF |9 7 G 5K4| 6H2|B M8|GO9 |C N HA2| B F|9G |D0C |3L4 -----+-----+-----+-----+----- A6 | BM | I9 | D 0| 4 KL | A16 | F B | | N D0 | 3L | H16|F 8 |G O7 GO | DC J|K4 |21 H |E 8M EM |7 9OI| NJC | 3K5 | 1 62 -----+-----+-----+-----+----- *********************************************************************/ go:- statistics(runtime,[S|_]), vars(Vars), gosub(Vars), statistics(runtime,[E|_]), T is E-S, write(T), write(' milliseconds'). gosub(Vars):- reverse(Vars,Vars1), labeling([ff],Vars1), display_board(Vars). gosub(Vars). vars(Vars):- Vars=[A11,A12,A13,A14,A15,B11,B12,B13,B14,B15,C11,C12,C13,C14,C15, D11,D12,D13,D14,D15,E11,E12,E13,E14,E15, A21,A22,A23,A24,A25,B21,B22,B23,B24,B25,C21,C22,C23,C24,C25, D21,D22,D23,D24,D25,E21,E22,E23,E24,E25, A31,A32,A33,A34,A35,B31,B32,B33,B34,B35,C31,C32,C33,C34,C35, D31,D32,D33,D34,D35,E31,E32,E33,E34,E35, A41,A42,A43,A44,A45,B41,B42,B43,B44,B45,C41,C42,C43,C44,C45, D41,D42,D43,D44,D45,E41,E42,E43,E44,E45, A51,A52,A53,A54,A55,B51,B52,B53,B54,B55,C51,C52,C53,C54,C55, D51,D52,D53,D54,D55,E51,E52,E53,E54,E55, F11,F12,F13,F14,F15,G11,G12,G13,G14,G15,H11,H12,H13,H14,H15, I11,I12,I13,I14,I15,J11,J12,J13,J14,J15, F21,F22,F23,F24,F25,G21,G22,G23,G24,G25,H21,H22,H23,H24,H25, I21,I22,I23,I24,I25,J21,J22,J23,J24,J25, F31,F32,F33,F34,F35,G31,G32,G33,G34,G35,H31,H32,H33,H34,H35, I31,I32,I33,I34,I35,J31,J32,J33,J34,J35, F41,F42,F43,F44,F45,G41,G42,G43,G44,G45,H41,H42,H43,H44,H45, I41,I42,I43,I44,I45,J41,J42,J43,J44,J45, F51,F52,F53,F54,F55,G51,G52,G53,G54,G55,H51,H52,H53,H54,H55, I51,I52,I53,I54,I55,J51,J52,J53,J54,J55, K11,K12,K13,K14,K15,L11,L12,L13,L14,L15,M11,M12,M13,M14,M15, N11,N12,N13,N14,N15,O11,O12,O13,O14,O15, K21,K22,K23,K24,K25,L21,L22,L23,L24,L25,M21,M22,M23,M24,M25, N21,N22,N23,N24,N25,O21,O22,O23,O24,O25, K31,K32,K33,K34,K35,L31,L32,L33,L34,L35,M31,M32,M33,M34,M35, N31,N32,N33,N34,N35,O31,O32,O33,O34,O35, K41,K42,K43,K44,K45,L41,L42,L43,L44,L45,M41,M42,M43,M44,M45, N41,N42,N43,N44,N45,O41,O42,O43,O44,O45, K51,K52,K53,K54,K55,L51,L52,L53,L54,L55,M51,M52,M53,M54,M55, N51,N52,N53,N54,N55,O51,O52,O53,O54,O55, P11,P12,P13,P14,P15,Q11,Q12,Q13,Q14,Q15,R11,R12,R13,R14,R15, S11,S12,S13,S14,S15,T11,T12,T13,T14,T15, P21,P22,P23,P24,P25,Q21,Q22,Q23,Q24,Q25,R21,R22,R23,R24,R25, S21,S22,S23,S24,S25,T21,T22,T23,T24,T25, P31,P32,P33,P34,P35,Q31,Q32,Q33,Q34,Q35,R31,R32,R33,R34,R35, S31,S32,S33,S34,S35,T31,T32,T33,T34,T35, P41,P42,P43,P44,P45,Q41,Q42,Q43,Q44,Q45,R41,R42,R43,R44,R45, S41,S42,S43,S44,S45,T41,T42,T43,T44,T45, P51,P52,P53,P54,P55,Q51,Q52,Q53,Q54,Q55,R51,R52,R53,R54,R55, S51,S52,S53,S54,S55,T51,T52,T53,T54,T55, U11,U12,U13,U14,U15,V11,V12,V13,V14,V15,W11,W12,W13,W14,W15, X11,X12,X13,X14,X15,Y11,Y12,Y13,Y14,Y15, U21,U22,U23,U24,U25,V21,V22,V23,V24,V25,W21,W22,W23,W24,W25, X21,X22,X23,X24,X25,Y21,Y22,Y23,Y24,Y25, U31,U32,U33,U34,U35,V31,V32,V33,V34,V35,W31,W32,W33,W34,W35, X31,X32,X33,X34,X35,Y31,Y32,Y33,Y34,Y35, U41,U42,U43,U44,U45,V41,V42,V43,V44,V45,W41,W42,W43,W44,W45, X41,X42,X43,X44,X45,Y41,Y42,Y43,Y44,Y45, U51,U52,U53,U54,U55,V51,V52,V53,V54,V55,W51,W52,W53,W54,W55, X51,X52,X53,X54,X55,Y51,Y52,Y53,Y54,Y55], domain(Vars,0,24), E21#=4,E22#=20,E23#=21,E24#=3,E25#=5,D31#=18,D32#=16,D33#=7,D34#=24,D35#=9,E31#=23,E32#=13,E33#=0,E34#=12,E35#=19,C41#=4,C42#=5,C43#=21,C44#=20,C45#=3,D41#=17,D42#=10,D43#=2,D44#=6,D45#=1,B51#=5,B52#=4,B53#=20,B54#=3,B55#=21,C51#=2,C52#=17,C53#=6,C54#=10,C55#=1,D51#=8,D52#=14,D53#=15,D54#=22,D55#=11,F15#=12,J15#=24,F25#=9,G25#=12,J21#=8,J22#=15,J24#=14,F35#=11,G35#=9,H35#=13,I31#=21,I32#=4,I33#=5,I35#=20,J31#=17,J32#=2,J35#=6,F45#=3,G45#=1,H41#=8,H42#=22,H44#=15,I41#=24,I42#=7,I43#=18,I45#=16,J43#=12,J44#=13,F55#=1,G51#=22,G52#=8,G53#=15,G54#=14,H51#=18,H52#=24,H54#=7,H55#=16,I51#=0,I52#=23,I53#=19,I54#=12,I55#=13,J53#=3,J54#=20,K14#=11,K15#=14,L14#=7,L15#=16,M14#=19,M15#=23,N15#=4,O14#=2,O15#=1,K24#=1,K25#=10,L25#=14,M25#=7,N25#=23,O21#=21,K34#=12,K35#=13,L35#=20,M31#=6,N31#=11,N32#=8,N33#=22,O32#=18,O33#=16,O35#=9,K44#=9,K45#=16,L44#=23,L45#=13,M44#=5,N42#=17,N43#=6,O44#=15,O45#=11,K54#=3,K55#=20,L52#=6,L53#=17,M51#=22,M52#=11,N51#=9,N52#=18,N53#=24,N54#=16,N55#=7,O52#=19,O53#=13,P13#=8,P14#=14,P15#=15,Q13#=24,Q14#=18,R13#=23,R14#=0,R15#=19,S13#=3,T15#=10,P23#=18,P24#=16,P25#=7,Q23#=0,Q24#=19,R24#=21,R25#=5,S24#=2,S25#=17,T25#=14,P33#=19,P34#=13,P35#=23,Q34#=5,Q35#=4,R34#=6,R35#=17,S33#=11,S34#=15,T31#=9,T33#=7,T35#=16,P43#=5,P44#=20,P45#=4,Q43#=6,Q44#=17,Q45#=2,R41#=11,R44#=22,R45#=8,S41#=16,S42#=24,S43#=9,T41#=12,T43#=23,P53#=17,P54#=10,P55#=2,Q52#=11,Q55#=15,R51#=9,R52#=16,S51#=13,S52#=0,S53#=12,T51#=3,T52#=21,T53#=4,U12#=10,U13#=6,V13#=11,V14#=22,W13#=18,W14#=9,X13#=13,X15#=0,Y15#=4,U22#=20,U23#=21,V22#=10,V23#=1,V24#=6,W22#=15,W24#=11,Y25#=23,U32#=13,U33#=0,V33#=3,V34#=21,W33#=17,W34#=1,W35#=6,X31#=15,X34#=8,Y31#=16,Y34#=24,Y35#=7,U42#=16,U43#=24,V42#=13,V43#=12,V45#=19,W41#=20,W42#=4,X41#=2,X42#=1,X44#=17,Y41#=14,Y43#=8,Y44#=22,U52#=14,U53#=22,V51#=7,V53#=9,V54#=24,V55#=18,W52#=23,W53#=19,W54#=12,X52#=3,X53#=20,X54#=5,Y52#=1,Y54#=6,Y55#=2, % block all_distinct([A11,A12,A13,A14,A15,A21,A22,A23,A24,A25,A31,A32,A33,A34,A35,A41,A42,A43,A44,A45,A51,A52,A53,A54,A55]), all_distinct([B11,B12,B13,B14,B15,B21,B22,B23,B24,B25,B31,B32,B33,B34,B35,B41,B42,B43,B44,B45,B51,B52,B53,B54,B55]), all_distinct([C11,C12,C13,C14,C15,C21,C22,C23,C24,C25,C31,C32,C33,C34,C35,C41,C42,C43,C44,C45,C51,C52,C53,C54,C55]), all_distinct([D11,D12,D13,D14,D15,D21,D22,D23,D24,D25,D31,D32,D33,D34,D35,D41,D42,D43,D44,D45,D51,D52,D53,D54,D55]), all_distinct([E11,E12,E13,E14,E15,E21,E22,E23,E24,E25,E31,E32,E33,E34,E35,E41,E42,E43,E44,E45,E51,E52,E53,E54,E55]), all_distinct([F11,F12,F13,F14,F15,F21,F22,F23,F24,F25,F31,F32,F33,F34,F35,F41,F42,F43,F44,F45,F51,F52,F53,F54,F55]), all_distinct([G11,G12,G13,G14,G15,G21,G22,G23,G24,G25,G31,G32,G33,G34,G35,G41,G42,G43,G44,G45,G51,G52,G53,G54,G55]), all_distinct([H11,H12,H13,H14,H15,H21,H22,H23,H24,H25,H31,H32,H33,H34,H35,H41,H42,H43,H44,H45,H51,H52,H53,H54,H55]), all_distinct([I11,I12,I13,I14,I15,I21,I22,I23,I24,I25,I31,I32,I33,I34,I35,I41,I42,I43,I44,I45,I51,I52,I53,I54,I55]), all_distinct([J11,J12,J13,J14,J15,J21,J22,J23,J24,J25,J31,J32,J33,J34,J35,J41,J42,J43,J44,J45,J51,J52,J53,J54,J55]), all_distinct([K11,K12,K13,K14,K15,K21,K22,K23,K24,K25,K31,K32,K33,K34,K35,K41,K42,K43,K44,K45,K51,K52,K53,K54,K55]), all_distinct([L11,L12,L13,L14,L15,L21,L22,L23,L24,L25,L31,L32,L33,L34,L35,L41,L42,L43,L44,L45,L51,L52,L53,L54,L55]), all_distinct([M11,M12,M13,M14,M15,M21,M22,M23,M24,M25,M31,M32,M33,M34,M35,M41,M42,M43,M44,M45,M51,M52,M53,M54,M55]), all_distinct([N11,N12,N13,N14,N15,N21,N22,N23,N24,N25,N31,N32,N33,N34,N35,N41,N42,N43,N44,N45,N51,N52,N53,N54,N55]), all_distinct([O11,O12,O13,O14,O15,O21,O22,O23,O24,O25,O31,O32,O33,O34,O35,O41,O42,O43,O44,O45,O51,O52,O53,O54,O55]), all_distinct([P11,P12,P13,P14,P15,P21,P22,P23,P24,P25,P31,P32,P33,P34,P35,P41,P42,P43,P44,P45,P51,P52,P53,P54,P55]), all_distinct([Q11,Q12,Q13,Q14,Q15,Q21,Q22,Q23,Q24,Q25,Q31,Q32,Q33,Q34,Q35,Q41,Q42,Q43,Q44,Q45,Q51,Q52,Q53,Q54,Q55]), all_distinct([R11,R12,R13,R14,R15,R21,R22,R23,R24,R25,R31,R32,R33,R34,R35,R41,R42,R43,R44,R45,R51,R52,R53,R54,R55]), all_distinct([S11,S12,S13,S14,S15,S21,S22,S23,S24,S25,S31,S32,S33,S34,S35,S41,S42,S43,S44,S45,S51,S52,S53,S54,S55]), all_distinct([T11,T12,T13,T14,T15,T21,T22,T23,T24,T25,T31,T32,T33,T34,T35,T41,T42,T43,T44,T45,T51,T52,T53,T54,T55]), all_distinct([U11,U12,U13,U14,U15,U21,U22,U23,U24,U25,U31,U32,U33,U34,U35,U41,U42,U43,U44,U45,U51,U52,U53,U54,U55]), all_distinct([V11,V12,V13,V14,V15,V21,V22,V23,V24,V25,V31,V32,V33,V34,V35,V41,V42,V43,V44,V45,V51,V52,V53,V54,V55]), all_distinct([W11,W12,W13,W14,W15,W21,W22,W23,W24,W25,W31,W32,W33,W34,W35,W41,W42,W43,W44,W45,W51,W52,W53,W54,W55]), all_distinct([X11,X12,X13,X14,X15,X21,X22,X23,X24,X25,X31,X32,X33,X34,X35,X41,X42,X43,X44,X45,X51,X52,X53,X54,X55]), all_distinct([Y11,Y12,Y13,Y14,Y15,Y21,Y22,Y23,Y24,Y25,Y31,Y32,Y33,Y34,Y35,Y41,Y42,Y43,Y44,Y45,Y51,Y52,Y53,Y54,Y55]), % horizontal all_distinct([A11,A12,A13,A14,A15,B11,B12,B13,B14,B15,C11,C12,C13,C14,C15,D11,D12,D13,D14,D15,E11,E12,E13,E14,E15]), all_distinct([A21,A22,A23,A24,A25,B21,B22,B23,B24,B25,C21,C22,C23,C24,C25,D21,D22,D23,D24,D25,E21,E22,E23,E24,E25]), all_distinct([A31,A32,A33,A34,A35,B31,B32,B33,B34,B35,C31,C32,C33,C34,C35,D31,D32,D33,D34,D35,E31,E32,E33,E34,E35]), all_distinct([A41,A42,A43,A44,A45,B41,B42,B43,B44,B45,C41,C42,C43,C44,C45,D41,D42,D43,D44,D45,E41,E42,E43,E44,E45]), all_distinct([A51,A52,A53,A54,A55,B51,B52,B53,B54,B55,C51,C52,C53,C54,C55,D51,D52,D53,D54,D55,E51,E52,E53,E54,E55]), all_distinct([F11,F12,F13,F14,F15,G11,G12,G13,G14,G15,H11,H12,H13,H14,H15,I11,I12,I13,I14,I15,J11,J12,J13,J14,J15]), all_distinct([F21,F22,F23,F24,F25,G21,G22,G23,G24,G25,H21,H22,H23,H24,H25,I21,I22,I23,I24,I25,J21,J22,J23,J24,J25]), all_distinct([F31,F32,F33,F34,F35,G31,G32,G33,G34,G35,H31,H32,H33,H34,H35,I31,I32,I33,I34,I35,J31,J32,J33,J34,J35]), all_distinct([F41,F42,F43,F44,F45,G41,G42,G43,G44,G45,H41,H42,H43,H44,H45,I41,I42,I43,I44,I45,J41,J42,J43,J44,J45]), all_distinct([F51,F52,F53,F54,F55,G51,G52,G53,G54,G55,H51,H52,H53,H54,H55,I51,I52,I53,I54,I55,J51,J52,J53,J54,J55]), all_distinct([K11,K12,K13,K14,K15,L11,L12,L13,L14,L15,M11,M12,M13,M14,M15,N11,N12,N13,N14,N15,O11,O12,O13,O14,O15]), all_distinct([K21,K22,K23,K24,K25,L21,L22,L23,L24,L25,M21,M22,M23,M24,M25,N21,N22,N23,N24,N25,O21,O22,O23,O24,O25]), all_distinct([K31,K32,K33,K34,K35,L31,L32,L33,L34,L35,M31,M32,M33,M34,M35,N31,N32,N33,N34,N35,O31,O32,O33,O34,O35]), all_distinct([K41,K42,K43,K44,K45,L41,L42,L43,L44,L45,M41,M42,M43,M44,M45,N41,N42,N43,N44,N45,O41,O42,O43,O44,O45]), all_distinct([K51,K52,K53,K54,K55,L51,L52,L53,L54,L55,M51,M52,M53,M54,M55,N51,N52,N53,N54,N55,O51,O52,O53,O54,O55]), all_distinct([P11,P12,P13,P14,P15,Q11,Q12,Q13,Q14,Q15,R11,R12,R13,R14,R15,S11,S12,S13,S14,S15,T11,T12,T13,T14,T15]), all_distinct([P21,P22,P23,P24,P25,Q21,Q22,Q23,Q24,Q25,R21,R22,R23,R24,R25,S21,S22,S23,S24,S25,T21,T22,T23,T24,T25]), all_distinct([P31,P32,P33,P34,P35,Q31,Q32,Q33,Q34,Q35,R31,R32,R33,R34,R35,S31,S32,S33,S34,S35,T31,T32,T33,T34,T35]), all_distinct([P41,P42,P43,P44,P45,Q41,Q42,Q43,Q44,Q45,R41,R42,R43,R44,R45,S41,S42,S43,S44,S45,T41,T42,T43,T44,T45]), all_distinct([P51,P52,P53,P54,P55,Q51,Q52,Q53,Q54,Q55,R51,R52,R53,R54,R55,S51,S52,S53,S54,S55,T51,T52,T53,T54,T55]), all_distinct([U11,U12,U13,U14,U15,V11,V12,V13,V14,V15,W11,W12,W13,W14,W15,X11,X12,X13,X14,X15,Y11,Y12,Y13,Y14,Y15]), all_distinct([U21,U22,U23,U24,U25,V21,V22,V23,V24,V25,W21,W22,W23,W24,W25,X21,X22,X23,X24,X25,Y21,Y22,Y23,Y24,Y25]), all_distinct([U31,U32,U33,U34,U35,V31,V32,V33,V34,V35,W31,W32,W33,W34,W35,X31,X32,X33,X34,X35,Y31,Y32,Y33,Y34,Y35]), all_distinct([U41,U42,U43,U44,U45,V41,V42,V43,V44,V45,W41,W42,W43,W44,W45,X41,X42,X43,X44,X45,Y41,Y42,Y43,Y44,Y45]), all_distinct([U51,U52,U53,U54,U55,V51,V52,V53,V54,V55,W51,W52,W53,W54,W55,X51,X52,X53,X54,X55,Y51,Y52,Y53,Y54,Y55]), % vertical all_distinct([A11,A21,A31,A41,A51,F11,F21,F31,F41,F51,K11,K21,K31,K41,K51,P11,P21,P31,P41,P51,U11,U21,U31,U41,U51]), all_distinct([A12,A22,A32,A42,A52,F12,F22,F32,F42,F52,K12,K22,K32,K42,K52,P12,P22,P32,P42,P52,U12,U22,U32,U42,U52]), all_distinct([A13,A23,A33,A43,A53,F13,F23,F33,F43,F53,K13,K23,K33,K43,K53,P13,P23,P33,P43,P53,U13,U23,U33,U43,U53]), all_distinct([A14,A24,A34,A44,A54,F14,F24,F34,F44,F54,K14,K24,K34,K44,K54,P14,P24,P34,P44,P54,U14,U24,U34,U44,U54]), all_distinct([A15,A25,A35,A45,A55,F15,F25,F35,F45,F55,K15,K25,K35,K45,K55,P15,P25,P35,P45,P55,U15,U25,U35,U45,U55]), all_distinct([B11,B21,B31,B41,B51,G11,G21,G31,G41,G51,L11,L21,L31,L41,L51,Q11,Q21,Q31,Q41,Q51,V11,V21,V31,V41,V51]), all_distinct([B12,B22,B32,B42,B52,G12,G22,G32,G42,G52,L12,L22,L32,L42,L52,Q12,Q22,Q32,Q42,Q52,V12,V22,V32,V42,V52]), all_distinct([B13,B23,B33,B43,B53,G13,G23,G33,G43,G53,L13,L23,L33,L43,L53,Q13,Q23,Q33,Q43,Q53,V13,V23,V33,V43,V53]), all_distinct([B14,B24,B34,B44,B54,G14,G24,G34,G44,G54,L14,L24,L34,L44,L54,Q14,Q24,Q34,Q44,Q54,V14,V24,V34,V44,V54]), all_distinct([B15,B25,B35,B45,B55,G15,G25,G35,G45,G55,L15,L25,L35,L45,L55,Q15,Q25,Q35,Q45,Q55,V15,V25,V35,V45,V55]), all_distinct([C11,C21,C31,C41,C51,H11,H21,H31,H41,H51,M11,M21,M31,M41,M51,R11,R21,R31,R41,R51,W11,W21,W31,W41,W51]), all_distinct([C12,C22,C32,C42,C52,H12,H22,H32,H42,H52,M12,M22,M32,M42,M52,R12,R22,R32,R42,R52,W12,W22,W32,W42,W52]), all_distinct([C13,C23,C33,C43,C53,H13,H23,H33,H43,H53,M13,M23,M33,M43,M53,R13,R23,R33,R43,R53,W13,W23,W33,W43,W53]), all_distinct([C14,C24,C34,C44,C54,H14,H24,H34,H44,H54,M14,M24,M34,M44,M54,R14,R24,R34,R44,R54,W14,W24,W34,W44,W54]), all_distinct([C15,C25,C35,C45,C55,H15,H25,H35,H45,H55,M15,M25,M35,M45,M55,R15,R25,R35,R45,R55,W15,W25,W35,W45,W55]), all_distinct([D11,D21,D31,D41,D51,I11,I21,I31,I41,I51,N11,N21,N31,N41,N51,S11,S21,S31,S41,S51,X11,X21,X31,X41,X51]), all_distinct([D12,D22,D32,D42,D52,I12,I22,I32,I42,I52,N12,N22,N32,N42,N52,S12,S22,S32,S42,S52,X12,X22,X32,X42,X52]), all_distinct([D13,D23,D33,D43,D53,I13,I23,I33,I43,I53,N13,N23,N33,N43,N53,S13,S23,S33,S43,S53,X13,X23,X33,X43,X53]), all_distinct([D14,D24,D34,D44,D54,I14,I24,I34,I44,I54,N14,N24,N34,N44,N54,S14,S24,S34,S44,S54,X14,X24,X34,X44,X54]), all_distinct([D15,D25,D35,D45,D55,I15,I25,I35,I45,I55,N15,N25,N35,N45,N55,S15,S25,S35,S45,S55,X15,X25,X35,X45,X55]), all_distinct([E11,E21,E31,E41,E51,J11,J21,J31,J41,J51,O11,O21,O31,O41,O51,T11,T21,T31,T41,T51,Y11,Y21,Y31,Y41,Y51]), all_distinct([E12,E22,E32,E42,E52,J12,J22,J32,J42,J52,O12,O22,O32,O42,O52,T12,T22,T32,T42,T52,Y12,Y22,Y32,Y42,Y52]), all_distinct([E13,E23,E33,E43,E53,J13,J23,J33,J43,J53,O13,O23,O33,O43,O53,T13,T23,T33,T43,T53,Y13,Y23,Y33,Y43,Y53]), all_distinct([E14,E24,E34,E44,E54,J14,J24,J34,J44,J54,O14,O24,O34,O44,O54,T14,T24,T34,T44,T54,Y14,Y24,Y34,Y44,Y54]), all_distinct([E15,E25,E35,E45,E55,J15,J25,J35,J45,J55,O15,O25,O35,O45,O55,T15,T25,T35,T45,T55,Y15,Y25,Y35,Y45,Y55]). display_board([A11,A12,A13,A14,A15,B11,B12,B13,B14,B15,C11,C12,C13,C14,C15, D11,D12,D13,D14,D15,E11,E12,E13,E14,E15, A21,A22,A23,A24,A25,B21,B22,B23,B24,B25,C21,C22,C23,C24,C25, D21,D22,D23,D24,D25,E21,E22,E23,E24,E25, A31,A32,A33,A34,A35,B31,B32,B33,B34,B35,C31,C32,C33,C34,C35, D31,D32,D33,D34,D35,E31,E32,E33,E34,E35, A41,A42,A43,A44,A45,B41,B42,B43,B44,B45,C41,C42,C43,C44,C45, D41,D42,D43,D44,D45,E41,E42,E43,E44,E45, A51,A52,A53,A54,A55,B51,B52,B53,B54,B55,C51,C52,C53,C54,C55, D51,D52,D53,D54,D55,E51,E52,E53,E54,E55, F11,F12,F13,F14,F15,G11,G12,G13,G14,G15,H11,H12,H13,H14,H15, I11,I12,I13,I14,I15,J11,J12,J13,J14,J15, F21,F22,F23,F24,F25,G21,G22,G23,G24,G25,H21,H22,H23,H24,H25, I21,I22,I23,I24,I25,J21,J22,J23,J24,J25, F31,F32,F33,F34,F35,G31,G32,G33,G34,G35,H31,H32,H33,H34,H35, I31,I32,I33,I34,I35,J31,J32,J33,J34,J35, F41,F42,F43,F44,F45,G41,G42,G43,G44,G45,H41,H42,H43,H44,H45, I41,I42,I43,I44,I45,J41,J42,J43,J44,J45, F51,F52,F53,F54,F55,G51,G52,G53,G54,G55,H51,H52,H53,H54,H55, I51,I52,I53,I54,I55,J51,J52,J53,J54,J55, K11,K12,K13,K14,K15,L11,L12,L13,L14,L15,M11,M12,M13,M14,M15, N11,N12,N13,N14,N15,O11,O12,O13,O14,O15, K21,K22,K23,K24,K25,L21,L22,L23,L24,L25,M21,M22,M23,M24,M25, N21,N22,N23,N24,N25,O21,O22,O23,O24,O25, K31,K32,K33,K34,K35,L31,L32,L33,L34,L35,M31,M32,M33,M34,M35, N31,N32,N33,N34,N35,O31,O32,O33,O34,O35, K41,K42,K43,K44,K45,L41,L42,L43,L44,L45,M41,M42,M43,M44,M45, N41,N42,N43,N44,N45,O41,O42,O43,O44,O45, K51,K52,K53,K54,K55,L51,L52,L53,L54,L55,M51,M52,M53,M54,M55, N51,N52,N53,N54,N55,O51,O52,O53,O54,O55, P11,P12,P13,P14,P15,Q11,Q12,Q13,Q14,Q15,R11,R12,R13,R14,R15, S11,S12,S13,S14,S15,T11,T12,T13,T14,T15, P21,P22,P23,P24,P25,Q21,Q22,Q23,Q24,Q25,R21,R22,R23,R24,R25, S21,S22,S23,S24,S25,T21,T22,T23,T24,T25, P31,P32,P33,P34,P35,Q31,Q32,Q33,Q34,Q35,R31,R32,R33,R34,R35, S31,S32,S33,S34,S35,T31,T32,T33,T34,T35, P41,P42,P43,P44,P45,Q41,Q42,Q43,Q44,Q45,R41,R42,R43,R44,R45, S41,S42,S43,S44,S45,T41,T42,T43,T44,T45, P51,P52,P53,P54,P55,Q51,Q52,Q53,Q54,Q55,R51,R52,R53,R54,R55, S51,S52,S53,S54,S55,T51,T52,T53,T54,T55, U11,U12,U13,U14,U15,V11,V12,V13,V14,V15,W11,W12,W13,W14,W15, X11,X12,X13,X14,X15,Y11,Y12,Y13,Y14,Y15, U21,U22,U23,U24,U25,V21,V22,V23,V24,V25,W21,W22,W23,W24,W25, X21,X22,X23,X24,X25,Y21,Y22,Y23,Y24,Y25, U31,U32,U33,U34,U35,V31,V32,V33,V34,V35,W31,W32,W33,W34,W35, X31,X32,X33,X34,X35,Y31,Y32,Y33,Y34,Y35, U41,U42,U43,U44,U45,V41,V42,V43,V44,V45,W41,W42,W43,W44,W45, X41,X42,X43,X44,X45,Y41,Y42,Y43,Y44,Y45, U51,U52,U53,U54,U55,V51,V52,V53,V54,V55,W51,W52,W53,W54,W55, X51,X52,X53,X54,X55,Y51,Y52,Y53,Y54,Y55]):- write_line([A11,A12,A13,A14,A15,B11,B12,B13,B14,B15,C11,C12,C13,C14,C15, D11,D12,D13,D14,D15,E11,E12,E13,E14,E15]),nl, write_line([A21,A22,A23,A24,A25,B21,B22,B23,B24,B25,C21,C22,C23,C24,C25, D21,D22,D23,D24,D25,E21,E22,E23,E24,E25]),nl, write_line([A31,A32,A33,A34,A35,B31,B32,B33,B34,B35,C31,C32,C33,C34,C35, D31,D32,D33,D34,D35,E31,E32,E33,E34,E35]),nl, write_line([A41,A42,A43,A44,A45,B41,B42,B43,B44,B45,C41,C42,C43,C44,C45, D41,D42,D43,D44,D45,E41,E42,E43,E44,E45]),nl, write_line([A51,A52,A53,A54,A55,B51,B52,B53,B54,B55,C51,C52,C53,C54,C55, D51,D52,D53,D54,D55,E51,E52,E53,E54,E55]),nl, write_line([F11,F12,F13,F14,F15,G11,G12,G13,G14,G15,H11,H12,H13,H14,H15, I11,I12,I13,I14,I15,J11,J12,J13,J14,J15]),nl, write_line([F21,F22,F23,F24,F25,G21,G22,G23,G24,G25,H21,H22,H23,H24,H25, I21,I22,I23,I24,I25,J21,J22,J23,J24,J25]),nl, write_line([F31,F32,F33,F34,F35,G31,G32,G33,G34,G35,H31,H32,H33,H34,H35, I31,I32,I33,I34,I35,J31,J32,J33,J34,J35]),nl, write_line([F41,F42,F43,F44,F45,G41,G42,G43,G44,G45,H41,H42,H43,H44,H45, I41,I42,I43,I44,I45,J41,J42,J43,J44,J45]),nl, write_line([F51,F52,F53,F54,F55,G51,G52,G53,G54,G55,H51,H52,H53,H54,H55, I51,I52,I53,I54,I55,J51,J52,J53,J54,J55]),nl, write_line([K11,K12,K13,K14,K15,L11,L12,L13,L14,L15,M11,M12,M13,M14,M15, N11,N12,N13,N14,N15,O11,O12,O13,O14,O15]),nl, write_line([K21,K22,K23,K24,K25,L21,L22,L23,L24,L25,M21,M22,M23,M24,M25, N21,N22,N23,N24,N25,O21,O22,O23,O24,O25]),nl, write_line([K31,K32,K33,K34,K35,L31,L32,L33,L34,L35,M31,M32,M33,M34,M35, N31,N32,N33,N34,N35,O31,O32,O33,O34,O35]),nl, write_line([K41,K42,K43,K44,K45,L41,L42,L43,L44,L45,M41,M42,M43,M44,M45, N41,N42,N43,N44,N45,O41,O42,O43,O44,O45]),nl, write_line([K51,K52,K53,K54,K55,L51,L52,L53,L54,L55,M51,M52,M53,M54,M55, N51,N52,N53,N54,N55,O51,O52,O53,O54,O55]),nl, write_line([P11,P12,P13,P14,P15,Q11,Q12,Q13,Q14,Q15,R11,R12,R13,R14,R15, S11,S12,S13,S14,S15,T11,T12,T13,T14,T15]),nl, write_line([P21,P22,P23,P24,P25,Q21,Q22,Q23,Q24,Q25,R21,R22,R23,R24,R25, S21,S22,S23,S24,S25,T21,T22,T23,T24,T25]),nl, write_line([P31,P32,P33,P34,P35,Q31,Q32,Q33,Q34,Q35,R31,R32,R33,R34,R35, S31,S32,S33,S34,S35,T31,T32,T33,T34,T35]),nl, write_line([P41,P42,P43,P44,P45,Q41,Q42,Q43,Q44,Q45,R41,R42,R43,R44,R45, S41,S42,S43,S44,S45,T41,T42,T43,T44,T45]),nl, write_line([P51,P52,P53,P54,P55,Q51,Q52,Q53,Q54,Q55,R51,R52,R53,R54,R55, S51,S52,S53,S54,S55,T51,T52,T53,T54,T55]),nl, write_line([U11,U12,U13,U14,U15,V11,V12,V13,V14,V15,W11,W12,W13,W14,W15, X11,X12,X13,X14,X15,Y11,Y12,Y13,Y14,Y15]),nl, write_line([U21,U22,U23,U24,U25,V21,V22,V23,V24,V25,W21,W22,W23,W24,W25, X21,X22,X23,X24,X25,Y21,Y22,Y23,Y24,Y25]),nl, write_line([U31,U32,U33,U34,U35,V31,V32,V33,V34,V35,W31,W32,W33,W34,W35, X31,X32,X33,X34,X35,Y31,Y32,Y33,Y34,Y35]),nl, write_line([U41,U42,U43,U44,U45,V41,V42,V43,V44,V45,W41,W42,W43,W44,W45, X41,X42,X43,X44,X45,Y41,Y42,Y43,Y44,Y45]),nl, write_line([U51,U52,U53,U54,U55,V51,V52,V53,V54,V55,W51,W52,W53,W54,W55, X51,X52,X53,X54,X55,Y51,Y52,Y53,Y54,Y55]),nl. write_line([]). write_line([X|Xs]):- int_to_letter(X,Y), write(Y), write_line(Xs). % read in the initial board and generate constraints read_board(F):- see(F), read_5_lines('A'), read_5_lines('F'), read_5_lines('K'), read_5_lines('P'), read_5_lines('U'), seen. read_5_lines(A):- read_line(A,1,1), read_line(A,2,1), read_line(A,3,1), read_line(A,4,1), read_line(A,5,1). read_line(A,I,J):- get0(X), read_line_rest(A,I,J,X). read_line_rest(A,I,J,X):- X=:=10,!. % newline read_line_rest(A,I,J,X):- J=:=6,!, next_letter(A,B), read_line_rest(B,I,1,X). read_line_rest(A,I,J,X):- X=:=32,!, J1 is J+1, get0(X1), read_line_rest(A,I,J1,X1). read_line_rest(A,I,J,X):- build_var_name(A,I,J,Var), letter_to_int(X,Int), write(Var#=Int),write(','), J1 is J+1, get0(X1), read_line_rest(A,I,J1,X1). build_var_name(A,I,J,Var):- name(A,[Ai]), name(I,[Ii]), name(J,[Ji]), name(Var,[Ai,Ii,Ji]). letter_to_int(X,Int):- X>=0'0,X=<0'9,!, Int is X-0'0. letter_to_int(X,Int):- X>=0'A,X=<0'Z,!, Int is X-0'A+10. letter_to_int(X,Int):- write('wrong letter'),nl. int_to_letter(X,L):- X>=0,X=<9,!, L = X. int_to_letter(X,L):- X>=10,X=<25,!, Li is X-10+0'A, name(L,[Li]). int_to_letter(X,L):- write('wrong int'),nl. next_letter(A,B):- name(A,[Ai]), Bi is Ai+1, name(B,[Bi]). reverse(X,Y):- reverse1(X,[],Y). reverse1([],L0,L):- L=L0. reverse1([X|Xs],L0,L):- reverse1(Xs,[X|L0],L).