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 (

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. (
  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 (

.NET Vs Java – The F5 puppets

This is more of a rant than a useful discussion, so if you’re expecting the later go write yourself a Hello World ;-)

In 2002, for a class project I had the option of working with either Microsoft Foundation Classes (MFC) or Java. After having worked with Windows SDK in the last semester, the decision was clear. Anything that didn’t come from Microsoft was going to be OK. So I started reading this book – The Java Programming Language and that is when it happened. I fell in love with James. James Gosling that is. How funny, how intelligent, how brilliant this man might be I thought. If it wasn’t for my employer who made me write Java Server Pages (JSP), I might still have been in love. I’m not quite sure, but I guess it had something to do with the fact that my job involved staring at the “Null Pointer Exception” in the Apache command window for four hours a day, that brought my love story to an end.

In 2003, I was forced to move from Java to .NET. I wasn’t ready for the separation, but the HR lady would hear nothing of it. What did I expect? Human Resources and Programmers are a match made in hell. So there I was, staring reluctantly at my first .NET program. I pressed F5. Everything worked, I didn’t see a “Null Pointer Exception”. Wait a minute I thought, what about the web server? I don’t remember starting it, or installing it, or reading the ten page documentation on how to configure it. I cried. My life as a programmer was over. I was reduced to a Visual Studio puppet – my only task henceforth would be to click F5. I starred enviously at my friends who after two days of debugging had discovered that their program was crashing because they were using JDK 1.3.2 instead of JDK 1.3.1. Oh how I missed being a programmer.

I’ve missed being a programmer for the last seven years now, but I seemed to have survived the million F5s and the zillion “Microsoft Programmer” jokes ;-) Last weekend I started a little hobby project with my husband and a friend – both loyal to the sun, who of course sold their souls to the oracle. The project was to be in Java, no discussion needed there.

So I installed Eclipse. A Java editor that looked professional and was free. Was I falling in love again? Maybe. I then needed to install some Google plugins for our project – what hobby project is complete without involving Google? Ok, it didn’t work, it couldn’t find java. Ummm… why? Well turns out because Eclipse uses its own java compiler or something (don’t ask me!), as javac clearly didn’t exist on my machine. Interesting. So after installing Eclipse I install the JDK! Fine. Subversion crashes. Ummm… Why? Don’t know again – some clash apparently with the java version and the class paths. I found myself digging through the Environment Variables and looking for issues with the “path”. I’d forgotten all about “Environment Variables” in windows, I was hoping they were dead by now. Yikes. Anyway, after it was all sorted out I created some beautiful java classes only to eventually discover that I had the wrong version of Eclipse to write JSP files!

As you can tell, I am not a good java developer. I couldn’t even install the right version of Eclipse. I gave up, someone would have to write the JSP for me. Neither my husband nor my friend seemed too keen on writing that JSP – not sure why. My husband got stuck with it as my friend had a genuine reason, he was a “server side programmer” so he couldn’t be expected to write front end stuff. As a Microsoft developer, you do not have the liberty of making such statements. If you did, it wouldn’t be long before you heard – “Geez man, my 5 year old son can create an ASP.NET website – all you have to do is click F5 !”

Microsoft WebMatrix – a tool for the lazy?

Microsoft realized it was unfair that children and wives were unable to experience the joy of creating web applications. So last week they introduced a brand new shinny toy in the market – WebMatrix. Sadly, they forgot about toy-safety which any toy manufacturer will tell you is a cardinal sin.

If you want to know what WebMatrix is, you can check Scott Guthrie’s blog post here that explains it in detail. To sum it up, in Scott Gu’s very own words…

WebMatrix is a task-focused tool that is designed to make it really easy to get started with web development. It minimizes the number of concepts someone needs to learn in order to get simple things done, and includes and integrates all of the pieces necessary to quickly build Web sites.

In 2003 when ASP.NET joined web development, it was great. There was nothing like it in the market that let you create web applications so easily. You didn’t exactly have to understand how the internet worked, you didn’t have to worry about POST or GET verbs, because when ViewState, Event Handlers and Page_Load got together all you had to do was party! Unfortunately, because the entry constraints were so low, some not-so-good developers joined the scene creating some not-so-good applications that resulted in not-so-good user experiences. But the party still went on, as there was a community of very good ASP.NET developers always ready to help. Not only did they provide answers to problems, but they also developed long term solutions and methodologies like TDD, SoC that would help you create beautiful and maintainable applications.

In Scott Gu’s post on WebMatrix, he lists an example where database, business logic and user interface code all sit hand in hand on the same page. Click here for a snapshot. A decade of web development has taught us one thing – not to write such code. Numerous tools and technologies, Microsoft’s very own ASP.NET MVC prevent us from doing so. Why then would we want to teach a failing technique to a bunch of fresh minds?

Just because a child cannot fully grasp the idea behind gravity does not mean we teach children the earth is flat.

I like the idea, to be able to create web applications without knowing everything there is to know. Visual Studio can be daunting and overwhelming and a simpler tool for the beginner is a great idea. However, since the users is naive, the onus lies on the product manufacturer (in this case Microsoft) to help you create a good product.

There should be no way to write the example code shown. A tool like WebMatrix should force constraints and restrict users from creating such a mess. Maybe a user might not understand why he is forced to write database code in one file and user interface code in another. He might even find it an inconvenience. But you the manufacturer know what is good for this child-developer. It is for the developers of WebMatrix and not its users to identify pitfalls and force constrains around them. This might reduce flexibility, but wan’t this tool meant for simple applications in the first place?

I’m still not sure who WebMatrix is for. Microsoft says it is not for professional web developers. So is it then for people who can write SQL queries, learn Razor (MS’s new MVC view engine), understand open source projects like BlogEngine.Net, purchase web domains and hosting, but simply cannot take the effort to create good applications, even if it was for their own good? The word that comes to mind is Lazy.

ASP.NET MVC – The ‘Hello, World!’ Mind Map

Update [19th July 2010]: I’ve uploaded the mind map on MindMeister here. This should allow you to download and view the mind map in any format you wish.

Mind Map 2: A mind map to understand your first ASP.NET MVC Application

For an introduction to ASP.NET MVC you can find my first Mind Map here.

Summarized View- Quick glance
Mind Map: Understanding your first ASP.NET MVC application (summarized view)

Mind Map: Hello World in ASP.NET MVC (summarized view)

Detailed Mind Map – Click image to load full size readable Mind Map
Mind Map: Hello World in ASP.NET MVC (detailed view)

Mind Map: Hello World in ASP.NET MVC (detailed view)

ASP.NET MVC – Mind Map to the rescue!

Update [16th July 2010]: I’ve uploaded the mind map on MindMeister here. This should allow you to download and view the mind map in any format you wish.

Skip to part 2 : ASP.NET MVC – The ‘Hello, World!’ Mind Map

Any man who reads too much and uses his own brain too little falls into lazy habits of thinking
– Albert Einstein

Lucky for him, Einstein wasn’t a programmer! I love reading stuff, but mostly just ‘once’. Sadly with technology, I seem to follow the ‘Out of sight is Out of mind’ philosophy, forcing me to re-read a lot of topics I’ve covered before. Trust me; nothing is worse than having to wade through ninety percent of the known to find that ten percent you are looking for – nothing.

Recently, Praful introduced me to the concept of Mind Maps and I liked it. I’ve been studying ASP.NET MVC and thought it would be refreshing to take notes using a Mind Map. I struggled with the first one, but I’m really beginning to like them. I created my first Mind Map yesterday in FreeMind, a free Mind Mapping software. It is a really easy to use once you get the hang of it.

My first Mind Map – An introduction to ASP.NET MVC.

Summarized View- Quick glance
Mind Map for an introduction to ASP.NET MVC (Summary View)

Mind Map: ASP.NET MVC - Introduction (summarized view)

Detailed Mind Map – Click image to load full size readable Mind Map
Mind Map: ASP.NET MVC - Introduction

Mind Map: ASP.NET MVC - Introduction (detailed view)

And what is a Mind Map? Well a Mind Map is simply a graphical way to take notes. Tony Buzan is one of the prominent promoters of the Mind Mapping technique and claims it can be used as a mnemonic device to remember stuff! I sure hope hes telling the truth!

My next ASP.NET MVC Mind Map is going to be – Understanding your first ASP.NET MVC application. Stay tuned :)

Part 2 : ASP.NET MVC – The ‘Hello, World!’ Mind Map