Jump to content

4-rings or 4-squares puzzle: Difference between revisions

→‎{{header|XPL0}}: Recursive solution.
m (→‎{{header|Phix}}: marked p2js compatible, now part of distro)
(→‎{{header|XPL0}}: Recursive solution.)
Line 6,162:
 
=={{header|XPL0}}==
<lang XPL0>procint FourSq(Lo Show, HiLow, UniqueHigh, Digit(7\a..g\), Count;
proc Rings(Level);
int Lo, Hi, Unique;
int Level; \of recursion
int A, B, C, D, E, F, G; \(must be in order)
int CntD, TTemp, I, Set;
[for AD:= LoLow to HiHigh do
[Cnt:= 0;
[Digit(Level):= D;
for A:= Lo to Hi do
if Level < 7-1 then Rings(Level+1)
[for B:= Lo to Hi do
else [for C Temp:= LoDigit(0) to+ HiDigit(1); do\solution?
if Temp = Digit(1) + Digit(2) + Digit(3) and
[D:= A-C;
Temp = Digit(3) + Digit(4) + Digit(5) and
if D >= Lo then
[for E: Temp = LoDigit(5) to+ HiDigit(6) dothen
[FCount:= BCount+C-E1;
G:= A+B-F; if Show then
if F>=Lo & F<=Hi & G>=Lo & G< [Set:=Hi then0; \digits must be unique
[T for I:= A+B;0 to 7-1 do
if T=B+C+D & T=D+E+F & T Set:=F+G thenSet ! 1<<Digit(I);
[Cnt: if Set = Cnt+1;%111_1111 << Low then
if Unique then [for I:= 0 to 7-1 do
[if 1<<A + 1<<B + 1<<C + 1<<D + 1<<E + 1<<F +[IntOut(0, Digit(I)); 1<<G =ChOut(0, $7F<<Lo^ then)];
[T:= @A; \show solutionCrLf(0);
for I:= 0 to 6 do ];
[IntOut(0, T(I)); ChOut(0, ^ )];
CrLf(0);
];
];
];
];
];
];
];
];
];
if not Unique then
[IntOut(0, Cnt); Text(0, " solutions")];
CrLf(0);
];
 
[FourSq(1, 7,Show:= true);
Low:= 1; High:= 7;
FourSq(3, 9, true);
Rings(0);
FourSq(0, 9, false);
CrLf(0);
Low:= 3; High:= 9;
Rings(0);
CrLf(0);
Show:= false;
Low:= 0; High:= 9; Count:= 0;
Rings(0);
IntOut(0, Count);
CrLf(0);
]</lang>
 
Line 6,220 ⟶ 6,219:
9 6 5 4 3 8 7
 
2860 solutions
</pre>
 
297

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.