![]() ![]() I decided to borrow from Ruby to create an extension method that iterates on an integer with an optional starting offset: The algorithm only needs to determine which of these "hops" is legal for the current board configuration. The Libs folder contains all the dependencies that FlowSharp uses, so you do not have to download and build that project.Ī lot of the work is done up front by setting up collections that have pre-determined all the possible "hops" from one "cell" to another.If you want to play around with recursive yields, there's a YieldTest folder with a simple demo (shown later in the article.).The actual demo app is found in the Demo folder.The SLN file is found in the BrainTeaser folder.Recursive with callback - again the search stack is an artifact of recursion.Recursive using yield - the search stack is an artifact of recursion.Iterative - the search stack is handled as handled as an actual Stack object.Implements three different algorithms so you can peruse the pros and cons of each:.As with the actual cheap game, there are 3 different colored pegs - yellow, blue, and red - which the UI implements, randomly assigned when you start the demo.Let's you single step through the solution and watch each step so you can memorize the solution and impress your friends!.Embeds FlowSharp so you can watch the algorithm go through the process of finding a solution (why re-invent the wheel?).Has a funky extension method which may or may not make the code more readable. ![]() implemented iteration and recursion alternatives.Īnd as is apt to occur, I went way overboard.had a snazzy UI so you could watch the algorithm processing.And more to the point, none of the algorithms presented: And of course, one can challenge oneself to write the code as elegantly and efficiently as possible, etc. OK, so while there are several solutions, I actually didn't find one in C#, and even if I had, there is a certain pleasure in writing something like this oneself, even if it's been done before. There's a C program here that solves the puzzle.There is a Java article here on CodeProject.Watching one of my coworkers futility go through various failed iterations, I had the obvious thought - write a program to find solutions to the puzzle! The second obvious thought was, someone must have done this! Well, turns out, not really. The goal is to remain with just one peg left.įor a roomful of programmers, no one (including me!) so far has been able to solve the puzzle. We've probably all played them - the idea being you start with one empty hole, the rest are filled with pegs, and each move consists of hopping a peg to an empty location, thus removing the peg you just hopped. We have these brain teaser puzzles at work: Step 1: Initializing the FlowSharp modules with the bootstrap loader.Why No Marshalling Onto The Main Thread?.The Recursive Step and Continue Algorithm.What about a Step-And-Continue callback?. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |