Solving KenKen – ASP.NET hobby project

Were you bad at math in school? Did your childhood nightmares involve floating ÷ ? If so, your math teacher was unfortunately not Tetsuya Miyamoto.

Tetsuya Miyamoto, a very intelligent math teacher from Japan is the inventor of the logic puzzle KenKen1. Tetsuya believed in the art of teaching without teaching and learnt how not to scare his pupils away! KenKen which loosely means cleverness squared (ken X ken) is very much like Sudoku with the addition of simple mathematical rules.

I love KenKen and have been addicted to it for some time now. So early one morning I decided I’d write a computer program to solve it. At first I thought it was going to be a piece of cake. One day is all it would take. After all, how hard was it to find the list of numbers that multiply to twenty four? Turns out, it was; not hard but definitely tricky. Then again, which software project ever completed within estimates ;-)

I wrote the project in C# (ASP.NET) but I wonder if F# would have been a better choice given the mathematical nature of the problem. The lazy me, who didn’t want to learn another syntax sadly skipped this. Maybe I can write an F# program to solve Sudoku ?

My program is not exactly a computerized solution to KenKen. It moves one step at a time and mimics the way a human being (mostly me) would typically solve this puzzle. This also means that the success of this approach is limited by my ability to solve it. I personally have not been able to solve a 7 x 7 hard puzzle and hence, my program can’t solve it either (any help appreciated !). The solution also doesn’t use backtracking2 because although it is very easy for a computer, it is very hard for a human being after a certain level.

So, this is how the application looks. It has been deployed using AppHarbor3 and you can check it out over here (kenken.apphb.com).

This is what those numbers mean !

So check it out, have some fun and keep that brain running ;-)

  1. KenKen® is a registered trademark of Nextoy, LLC. Puzzle content ©2011 KenKen Puzzle LLC. (www.kenken.com)
  2. Backtracking is a common technique in computer science used for finding solutions to certain problems. In simple words, you guess a solution and then move forward. If your guess was invalid you wont be able to solve the problem correctly and you will discard this solution. You then backtrack, and guess again, till finally your guess is accurate!
  3. AppHarbor allows you to deploy your application on the web and was such a joy to use (appharbor.com)
Advertisements

13 thoughts on “Solving KenKen – ASP.NET hobby project

  1. Hi Preeti,

    I have a human solution to your 7 x 7 “unsolved” puzzle. If you’d like to see it, reply to me personally. My email address is Langfelder@aol.com

    I tried reaching you via Spoke but was unwilling to join. I don’t link up with social networks. Hope to hear from you.

    Regards,

    Steve

    Stephen B. Langfelder
    31 Mulford Drive
    Wayne, NJ 07470
    973-633-1802
    email: Langfelder@aol.com

  2. Pingback: Big Bad Sudoku

  3. Pretti,

    Great program. I know how you can fix it to solve the 7×7 and most other kenkens. Everything you have done is fine but you need to add another function that checks for consistency within a cage. My following comments relate to your 7×7 unsolved kenken.

    For example, take the possible solution of (2, 3, 3) in cage 13. Cells 13b and 13c cannot be 2 because otherwise there would be two 3’s in the same row or column in the cage. Therefore, in this possible solution to the cell, the 2 in cells 13b and 13c would be eliminated, and 3’s in cell 13a would be eliminated.

    Simpler is to check for consistency in cage 22 enabling you to solve cage 6 and fully solve the 7×7 kenken. In cage 22, take the (1,3,6,7) possible solution. In cell 22b, 1 is the only choice in this possible solution. Therefore, 1 is not a possible solution in cell 22a (or 22d). This leads to a value of 1 being forced into cell 6b (the only possible 1 in the column) and the kenken can be solved.

    • Hi Harvey, Thank you for your comment and for the tip on solving the 7×7. I will try implementing it and will post an update if I do – with credit to you of course! Sorry for taking forever to respond to this message. I’m finally getting back to some fun programming :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s