diff --git a/python/dudeney.py b/python/dudeney.py new file mode 100644 index 0000000000..4986868e41 --- /dev/null +++ b/python/dudeney.py @@ -0,0 +1,44 @@ +# Copyright 2010 Pierre Schaus (pschaus@gmail.com) +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from constraint_solver import pywrapcp + +def dudeney(n): + solver = pywrapcp.Solver('Dudeney') + x = [solver.IntVar(range(10), 'x' + str(i)) for i in range(n)] + nb = solver.IntVar(range(3, 10 ** n), 'nb') + s = solver.IntVar(range(1, 9 * n + 1), 's') + + solver.Add(nb == s * s * s) + solver.Add(sum([10 ** (n - i - 1) * x[i] for i in range(n)]) == nb) + solver.Add(sum([x[i] for i in range(n)]) == s) + + solution = solver.Assignment() + solution.Add(nb) + collector = solver.AllSolutionCollector(solution) + + solver.Solve(solver.Phase(x, + solver.INT_VAR_DEFAULT, + solver.INT_VALUE_DEFAULT), + [collector]) + + for i in range(collector.solution_count()): + current = collector.solution(i) + nbsol = current.Value(nb) + print nbsol + + print "#fails:",solver.failures() + print "time:",solver.wall_time() + +if __name__ == '__main__': + dudeney(6) diff --git a/python/golomb8.py b/python/golomb8.py index 7ed0aa8f1e..806f3ee5e7 100644 --- a/python/golomb8.py +++ b/python/golomb8.py @@ -3,7 +3,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/python/jobshop_ft06.py b/python/jobshop_ft06.py index fd0da7d0d2..1fe7b97260 100644 --- a/python/jobshop_ft06.py +++ b/python/jobshop_ft06.py @@ -3,7 +3,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/python/magic_sequence_distribute.py b/python/magic_sequence_distribute.py index 7ea3755e58..349113cfc6 100644 --- a/python/magic_sequence_distribute.py +++ b/python/magic_sequence_distribute.py @@ -3,7 +3,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/python/rabbit_pheasant.py b/python/rabbit_pheasant.py index b594dff949..88310eb4ed 100644 --- a/python/rabbit_pheasant.py +++ b/python/rabbit_pheasant.py @@ -3,7 +3,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/python/sendmore.py b/python/sendmore.py index 0bde745557..02c7e0f7b6 100644 --- a/python/sendmore.py +++ b/python/sendmore.py @@ -3,7 +3,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/python/simple_meeting.py b/python/simple_meeting.py index 2fc8683a0a..2fa1a36da6 100644 --- a/python/simple_meeting.py +++ b/python/simple_meeting.py @@ -3,7 +3,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/python/sudoku.py b/python/sudoku.py index 759a2c3cd2..2d254edc66 100644 --- a/python/sudoku.py +++ b/python/sudoku.py @@ -3,7 +3,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/python/zebra.py b/python/zebra.py index bb9384b488..a1a7a25d8b 100644 --- a/python/zebra.py +++ b/python/zebra.py @@ -3,7 +3,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS,