24 game/Solve: Difference between revisions

Content added Content deleted
Line 4,611: Line 4,611:
set patterns {
set patterns {
{((A x B) y C) z D}
{((A x B) y C) z D}
{(A x (B y C)) z D}
{(A x (B y C)) z D}
{(A x B) y (C z D)}
{(A x B) y (C z D)}
{A x ((B y C) z D)}
{A x ((B y C) z D)}
{A x (B y (C z D))}
{A x (B y (C z D))}
}
}
# Encoding the various permutations of digits
# Encoding the various permutations of digits
Line 4,622: Line 4,622:
set operations {+ - * /}
set operations {+ - * /}


# Given a list of four integers (precondition not checked!) return a list of
# Given a list of four integers (precondition not checked!)
# solutions to the 24 game using those four integers.
# return a list of solutions to the 24 game using those four integers.
proc find24GameSolutions {values} {
proc find24GameSolutions {values} {
global operations patterns permutations
global operations patterns permutations
Line 4,669: Line 4,669:
}
}
print24GameSolutionFor $argv</lang>
print24GameSolutionFor $argv</lang>
{{out}}
Demonstrating it in use:
Demonstrating it in use:
<span style="color:silver">''bash$''</span> <span style="color:brown">tclsh8.4 24player.tcl 3 2 8 9</span>
<span style="color:silver">''bash$''</span> <span style="color:brown">tclsh8.4 24player.tcl 3 2 8 9</span>