<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>All About Interop : Sudoku</title><link>http://blogs.msdn.com/dotnetinterop/archive/tags/Sudoku/default.aspx</link><description>Tags: Sudoku</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Sudoku Generator and Solver in C#</title><link>http://blogs.msdn.com/dotnetinterop/archive/2008/03/14/sudoku-generator-and-solver-in-c.aspx</link><pubDate>Sat, 15 Mar 2008 01:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8212295</guid><dc:creator>DotNetInterop</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/dotnetinterop/comments/8212295.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dotnetinterop/commentrss.aspx?PostID=8212295</wfw:commentRss><description>&lt;P&gt;Seems like building a Sudoku application is almost a&amp;nbsp;compulsory thing for&amp;nbsp;programmers these days.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I've &lt;A class="" href="http://blogs.msdn.com/dotnetinterop/archive/tags/Sudoku/default.aspx" mce_href="http://blogs.msdn.com/dotnetinterop/archive/tags/Sudoku/default.aspx"&gt;written about my prior efforts&lt;/A&gt;. Here's an update.&amp;nbsp; Rather than force you all to use the XBAP I published last year, here's a standalone WPF app.&amp;nbsp; C# Source and EXE include. &lt;/P&gt;
&lt;P&gt;It uses the DLX (Dancing Links) algorithm from Donald Knuth.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Pretty speedy. It is a WPF app, but there are no fancy WPF graphics.&amp;nbsp; It just generates a table, and that's about it.&amp;nbsp; This one is handy if you like to do Sudoku on paper.&amp;nbsp; I've uses this app to generate and print out puzzles that I can do with my kids.&lt;/P&gt;
&lt;P&gt;Source: &lt;A href="http://cid-842434ebe9688900.skydrive.live.com/self.aspx/Games/Sudoku-1.0-source.zip"&gt;http://cid-842434ebe9688900.skydrive.live.com/self.aspx/Games/Sudoku-1.0-source.zip&lt;/A&gt;&lt;BR&gt;EXE:&amp;nbsp; &lt;A href="http://cid-842434ebe9688900.skydrive.live.com/self.aspx/Games/Sudoku.exe"&gt;http://cid-842434ebe9688900.skydrive.live.com/self.aspx/Games/Sudoku.exe&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Cheers!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8212295" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dotnetinterop/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.msdn.com/dotnetinterop/archive/tags/Sudoku/default.aspx">Sudoku</category></item><item><title>Sudoku Toy redux - using C# DancingLinks Engine</title><link>http://blogs.msdn.com/dotnetinterop/archive/2007/06/07/sudoku-toy-redux-using-c-dancinglinks-engine.aspx</link><pubDate>Thu, 07 Jun 2007 21:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3146521</guid><dc:creator>DotNetInterop</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/dotnetinterop/comments/3146521.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dotnetinterop/commentrss.aspx?PostID=3146521</wfw:commentRss><description>&lt;P&gt;&lt;A class="" href="http://blogs.msdn.com/dotnetinterop/archive/2006/02/15/532103.aspx" mce_href="http://blogs.msdn.com/dotnetinterop/archive/2006/02/15/532103.aspx"&gt;A while back I posted a toy app&lt;/A&gt; that generates (and optionally solves) a Sudoku puzzle.&amp;nbsp; It was under the rubric of Interop because the inner engine of this toy used an implementation of the &lt;A class="" href="http://en.wikipedia.org/wiki/Dancing_Links" mce_href="http://en.wikipedia.org/wiki/Dancing_Links"&gt;Dancing Links&lt;/A&gt; engine for Sudoku, built in Java.&amp;nbsp; The original Dancing Links algorithm was proposed by &lt;A class="" href="http://en.wikipedia.org/wiki/Donald_Knuth" mce_href="http://en.wikipedia.org/wiki/Donald_Knuth"&gt;Donald Knuth&lt;/A&gt;;&amp;nbsp; I found a Java engine that produced a string representation of a valid puzzle.&amp;nbsp; I hooked that engine up to an Acrobat-generation library, the Acrobat ActiveX control from &lt;A class="" href="http://www.oldversion.com/program.php?n=acrobat" mce_href="http://www.oldversion.com/program.php?n=acrobat"&gt;Adobe Acrobat v5&lt;/A&gt;, all stitched together into a Winforms app built in C#. That's a lot of interop.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The toy worked, but it had some challenges.&amp;nbsp; First, Adobe was apparently discouraging use of the Acrobat ActiveX control.&amp;nbsp; It was available in Acrobat v5 but them removed from subsequent releases of Acrobat reader.&amp;nbsp; So in order to install and use this toy, you had to go get an old code base, one which had several known security problems. That was one problem.&amp;nbsp; Also Acrobat v5 did not install alongside Acrobat v6, 7, or now, 8.&amp;nbsp; So anyone that already had a current or recent Acrobat&amp;nbsp; Reader, couldn't use this toy.&amp;nbsp; Also, the hassle of installation was a problem in general.&lt;/P&gt;
&lt;P&gt;XBAP to the rescue!&amp;nbsp; I revisited the Sudoku puzzle generator, and now I have &lt;A class="" title="Sudoku Puzzle Generator" href="http://dinoch.dyndns.org:8080/sudoku/" mce_href="http://dinoch.dyndns.org:8080/sudoku/"&gt;a new version&lt;/A&gt;.&amp;nbsp; It is &lt;A class="" href="http://channel9.msdn.com/Showpost.aspx?postid=216764" mce_href="http://channel9.msdn.com/Showpost.aspx?postid=216764"&gt;an XBAP, based on WPF&lt;/A&gt;, and runs in the IE browser.&amp;nbsp; No more Acrobat requirement.&amp;nbsp; No more unsupported ActiveX controls.&amp;nbsp; The use of WPF within this app is pretty mundane - I just create a table with WPF.&amp;nbsp; It uses the same Dancing Links engine code, but I ported it from Java to C#, in order to avoid the use of the discontinued J# compiler.&amp;nbsp; It was a very straightforward port, and there were no problems whatever.&amp;nbsp; I didn't even use the JLCA, I just hand-ported it with judicious use of search-and-replace.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;This is an interop blog, right?&amp;nbsp; So where is the interop now?&amp;nbsp; This is a C# app, using WPF, and it runs in IE.&amp;nbsp;&amp;nbsp; With all that, it's hard for me to call this interop. At best it is re-use of an existing Java-based asset, but I did have to &lt;EM&gt;convert&lt;/EM&gt; the Java logic to C# .&amp;nbsp; But it's an update to an older post, so I thought y'all wouldn't mind if I put it here. &lt;/P&gt;
&lt;P&gt;Anyway, &lt;A class="" href="http://dinoch.dyndns.org:8080/sudoku" mce_href="http://dinoch.dyndns.org:8080/sudoku"&gt;try it out&lt;/A&gt;.&amp;nbsp;&amp;nbsp; In order to run this, you need IE7.&amp;nbsp; Also, if you don't have the .NET Framework v3.0 installed on your machine, you will get it if you run this app.&amp;nbsp; That download can be a drag!!&amp;nbsp; You have been warned.&lt;/P&gt;
&lt;H3&gt;Some notes&lt;/H3&gt;
&lt;P&gt;How did I build the WPF part?&amp;nbsp; Well the WPF itself, as I said, is nothing to write home about.&amp;nbsp; WPF can do some amazing things with dynamnic graphics and animation, but this app doesn't do those fancy things. Basically this is WPF generating a table at runtime. &amp;nbsp;I built all the XAML code by hand using a text editor.&amp;nbsp; I've included the code here as an attachment for those who want to check it out. &lt;/P&gt;
&lt;P&gt;Also - just to be clear - this is a puzzle generator, not a puzzle app.&amp;nbsp; I use it to generate puzzles, which I then print out, and solve.&amp;nbsp; I don't like to solve Sudoku on the computer, I prefer to do it on paper (tree hater).&amp;nbsp; So the app here just creates a new puzzle.&amp;nbsp; If you want to click on a puzzle and try to enter numbers to solve the puzzle yourself, this app will not help you.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Also, the app only solves Sudoku puzzles that it generates. you cannot insert arbitrary sudoku puzzles in and ask for a solution.&amp;nbsp; maybe that is for another day. &lt;/P&gt;
&lt;P&gt;Given that Silverlight is out, and we have&amp;nbsp;Expression Blend and so on, it seems like I ought to produce a Silverlight version of this thing.&amp;nbsp; That is on my list for later!&amp;nbsp; By the way, if anyone else wants to build a Sudoku App, the C# DancingLinks engine contained in this project is a good piece of re-usable infrastructure.&amp;nbsp; If you do grab that part of the project, let me know, I'm interested in hearing how you are using it. &lt;/P&gt;
&lt;P&gt;Cheers!&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3146521" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/dotnetinterop/attachment/3146521.ashx" length="451270" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/dotnetinterop/archive/tags/Not+Really+Interop/default.aspx">Not Really Interop</category><category domain="http://blogs.msdn.com/dotnetinterop/archive/tags/Sudoku/default.aspx">Sudoku</category></item><item><title>Re-use of existing Java code (Sudoku engine)</title><link>http://blogs.msdn.com/dotnetinterop/archive/2006/02/15/re-use-of-existing-java-code-sudoku-engine.aspx</link><pubDate>Wed, 15 Feb 2006 16:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:532103</guid><dc:creator>DotNetInterop</dc:creator><slash:comments>15</slash:comments><comments>http://blogs.msdn.com/dotnetinterop/comments/532103.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dotnetinterop/commentrss.aspx?PostID=532103</wfw:commentRss><description>&lt;FONT face=Tahoma size=2&gt;
&lt;H3&gt;Re-use of existing Java code (Sudoku engine) &lt;/H3&gt;&lt;!-- ------------------------------------------------------- --&gt;
&lt;P&gt;This isn't so much about systems interop, as it is about code re-use and language interop.&lt;/P&gt;
&lt;P&gt;You've seen Sudoku, the "number place" puzzle. &lt;A href="http://en.wikipedia.org/wiki/Sudoku"&gt;Wikipedia says&lt;/A&gt; that it was created by a US puzzle magazine, but popularized (and given its recognized name) by the Japanese. &lt;/P&gt;
&lt;CENTER&gt;&lt;IMG src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/13/Sudoku-by-L2G-20050714.gif/250px-Sudoku-by-L2G-20050714.gif"&gt; &lt;/CENTER&gt;
&lt;P&gt;Last year during the summer holiday my wife gave me a book of Sudoku puzzles to do on the beach with my kids. The first one we tried was a real challenge, but gradually we caught on to the technique. Now we do the puzzles that come in the daily paper, regularly. They started to get a little too easy for us, so our thought was, maybe we could generate puzzles ourselves? &lt;/P&gt;
&lt;P&gt;I thought - this is a nice little programming project. The next thought was: to generate a valid Sudoku, you have to solve it, to verify there is only one solution. The simple brute force solver method I imagined would be easy to code, but wouldn't be very fast. And I hadn't thought about sudoku generation algorithms. This was getting messy. Maybe somebody has already done this for me? &lt;/P&gt;
&lt;P&gt;In short order I found lots of Sudoku sites and an abundance of algorithms and code implementations for generators and solvers. I tried a couple and found &lt;A href="http://www.klepphelmer.com/Sudoku/DLXEngine.java"&gt;one that looked good and fast&lt;/A&gt; - implemented in Java by Rolf Sandberg, based on a C implementation by Günter Stertenbrink, which was based on the Dancing Links algorithm described by &lt;A href="http://en.wikipedia.org/wiki/Knuth"&gt;Donald Knuth&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;As a port from C, the Java code is not the most object-oriented or elegant, but I didn't care about that. I wanted a toy to generate Sudoku puzzles. It worked great, but there was one big drawback. The generated puzzles looked like this: &lt;/P&gt;&lt;PRE&gt; . . 8 1 . . . . .
 . 9 1 . . . . . 7
 . . . . 5 . 3 . 2
 6 . . 3 . 2 8 . 4
 3 . 9 . . . 5 . .
 . . . . . 6 . . .
 . 1 . . . . . 2 8
 . . 6 . . . . . .
 . 5 . . 7 . . . .
&lt;/PRE&gt;
&lt;P&gt;It was a command line tool, and it generated string output. What I really wanted was a puzzle I could print out, easily, and hand to my sons and say "have at it!" &lt;/P&gt;
&lt;P&gt;I had previously fiddled with &lt;A href="http://itextsharp.sourceforge.net"&gt;itextsharp&lt;/A&gt;, a library for creating PDFs from within .NET. (This is a port of &lt;A href="http://www.lowagie.com/iText"&gt;iText&lt;/A&gt;, which is a Java library with the same purpose). PDF generation would seem to be a good fit. &lt;/P&gt;
&lt;H3&gt;Here Comes the Part About Interop &lt;/H3&gt;
&lt;P&gt;The cool thing was, I didn't have to do anything to the Java code to get it to work with my C# WinForms code. I just compiled it with VJ#, and BAM! it's ready to go. So no changes were required, but I did actually make a few changes in Sandberg's Java code. I added a DTO class for the puzzle. I added a few helper methods like solve() and generate() and rate(). But I left most everything intact. (re-factoring was tempting but I didn't want to spend the time understanding the code) &lt;/P&gt;
&lt;P&gt;So.... I built a Winform app in C#, to wrap around that generator engine. I added in the PDF generation, and added a print button. Boom, a Sudoku generation toy. Its pedigree includes Java source code, C# code, and an activeX control from 2000. All seamlessly connected. &lt;/P&gt;
&lt;CENTER&gt;&lt;IMG src="http://cheeso.members.winisp.net/dl/SudokuToy-1.jpg"&gt; &lt;/CENTER&gt;
&lt;P&gt;&lt;A href="http://cheeso.members.winisp.net/dl/SudokuToy-1.1-Setup.zip"&gt;Grab the finished binary&lt;/A&gt; (with a Windows Installer) if you want to use the toy. It will run on Windows XP, requires .NET 1.1 and Adobe Acrobat Reader. &lt;A href="http://cheeso.members.winisp.net/dl/SudokuToy-1.1a-sln.zip"&gt;Grab the VS 2003 Solution&lt;/A&gt; if you want to examine or tweak the code. &lt;/P&gt;
&lt;P&gt;This is just one small illustration, but it shows: if you have source code repositories in your shop, or even if you have existing Java apps, and you want to update or extend them, you may be able to re-use that code very simply in .NET. &lt;/P&gt;
&lt;P&gt;-Dino &lt;/P&gt;&lt;/FONT&gt;&lt;!-- ------------------------------------------------------- --&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=532103" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dotnetinterop/archive/tags/Interop/default.aspx">Interop</category><category domain="http://blogs.msdn.com/dotnetinterop/archive/tags/Sudoku/default.aspx">Sudoku</category><category domain="http://blogs.msdn.com/dotnetinterop/archive/tags/Java/default.aspx">Java</category></item></channel></rss>