4-rings or 4-squares puzzle: Difference between revisions
Content added Content deleted
(Added OCaml solution) |
|||
Line 1,770: | Line 1,770: | ||
Number of solutions :2860 |
Number of solutions :2860 |
||
</pre> |
|||
=={{header|AutoHotkey}}== |
|||
<syntaxhighlight lang="autohotkey"> |
|||
rotina(min,max,unique) |
|||
{ |
|||
global totalcount := 0 |
|||
global totalunique := 0 |
|||
global result := "min=" min " max=" max " unique=" unique "`n`n" |
|||
max := max - min + 1 |
|||
loop %max% |
|||
{ |
|||
a := min + A_Index - 1 |
|||
loop %max% |
|||
{ |
|||
b := min + A_Index - 1 |
|||
loop %max% |
|||
{ |
|||
c := min + A_Index - 1 |
|||
loop %max% |
|||
{ |
|||
d := min + A_Index - 1 |
|||
loop %max% |
|||
{ |
|||
e := min + A_Index - 1 |
|||
loop %max% |
|||
{ |
|||
f := min + A_Index - 1 |
|||
loop %max% |
|||
{ |
|||
g := min + A_Index - 1 |
|||
sum := a+b |
|||
if (b+c+d = sum and d+e+f = sum and f+g = sum) |
|||
{ |
|||
totalcount += 1 |
|||
if (unique=0) |
|||
continue |
|||
if not (a=b or a=c or a=d or a=e or a=f or a=g or b=c or b=d or b=e or b=f or b=g or c=d or c=e or c=f or c=g or d=e or d=f or d=g or e=f or e=g or f=g) |
|||
{ |
|||
result .= a " " b " " c " " d " " e " " f " " g "`n" |
|||
totalunique += 1 |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
rotina(1,7,1) |
|||
MsgBox %result% `ntotal unique = %totalunique% `ntotalcount = %totalcount% |
|||
rotina(3,9,1) |
|||
MsgBox %result% `ntotal unique = %totalunique% `ntotalcount = %totalcount% |
|||
rotina(0,9,0) |
|||
MsgBox %result% `ntotalcount = %totalcount% |
|||
ExitApp |
|||
return |
|||
</syntaxhighlight> |
|||
{{Output}} |
|||
<pre> |
|||
min=1 max=7 unique=1 |
|||
3 7 2 1 5 4 6 |
|||
4 5 3 1 6 2 7 |
|||
4 7 1 3 2 6 5 |
|||
5 6 2 3 1 7 4 |
|||
6 4 1 5 2 3 7 |
|||
6 4 5 1 2 7 3 |
|||
7 2 6 1 3 5 4 |
|||
7 3 2 5 1 4 6 |
|||
total unique = 8 |
|||
totalcount = 497 |
|||
--------------------------- |
|||
OK |
|||
--------------------------- |
|||
min=3 max=9 unique=1 |
|||
7 8 3 4 5 6 9 |
|||
8 7 3 5 4 6 9 |
|||
9 6 4 5 3 7 8 |
|||
9 6 5 4 3 8 7 |
|||
total unique = 4 |
|||
totalcount = 180 |
|||
--------------------------- |
|||
OK |
|||
--------------------------- |
|||
min=0 max=9 unique=0 |
|||
totalcount = 2860 |
|||
--------------------------- |
|||
OK |
|||
--------------------------- |
|||
</pre> |
</pre> |
||