The constraint module presented in PyCon Brasil and later on EuroPython 2005 is now available. Here is a trivial example, solving the classical rooks problem:
problem = Problem()
numpieces = 8
cols = range(numpieces)
rows = range(numpieces)
problem.addVariables(cols, rows)
for col1 in cols:
for col2 in cols:
if col1 < col2:
problem.addConstraint(lambda row1, row2: row1 != row2,
(col1, col2))
solutions = problem.getSolutions()
Have fun!
Update: It was also presented in FISL 2006.
University of Massachusetts has a very nice Problem of the Week service where they post a new math related problem every monday. At that time they report the percentage of people that correctly answered the question as well. To submit an answer, check the rules page. They’re usually very quick at answering if a given solution is correct or not.
This week’s problem is not specially challenging though. The problem name is Turn the page, and consists of the following question:
A novel has 527 pages (pages 1 – 527). How many digits will it take to number all 527 pages from 1 to 527?
How many people wouldn’t know how to solve that? Solving with eyes closed is kind of fun, but with help from a calculator or from any programming language it’s trivial. In python, that single line does the job:
sum([len(str(i)) for i in range(1,527+1)])
Let’s hope for a more interesting problem next week. There are some good problems from previous weeks available as well.
Petals Around the Rose is an interesting brain teaser. Here is a copy of the game description:
The name of the game is Petals Around the Rose. The name of the game is important. The computer will roll five dice and ask you to guess the score for the roll. The score will always be zero or an even number. Your mission is to work out how the computer calculates the score and become a Potentate of the Rose.
Simple and challenging.