- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Of course, all it was was a script that printed out the first line, accepted and discarded any input from the user, waited fifteen seconds and then printed out "I resign".
There were a number of users who struggled with this concept, however, and tried to have a genuine game of chess with it before getting very angry :)
Admin
But if you stored it in a doubly-linked list, you could just traverse it backwards. You have provided an example of how to use such a data structure, as per the request of one of the other commenters.
Admin
@AlpineR
Skipping the trivial case (one piece, one color), the smallest, simplest mosaic is a 1x5 set with all different colors.
ABCDE | ECADB
For a square set, you can achieve it with a 3x3 square assuming "touching" does not include corners
ABC | BGF DEF | IEA GHI | DCH
Fewest colors? 4, as in this 1x5 case:
ABCDD | DBDAC
And I believe the above is the smallest pair using the fewest colors (again, skipping the trivial case).
Admin
Infinitely programmable, within reason...
Admin
Admin
Java. It took us about 4 hours to do this...
It's rather slow, unfortunately.
Admin
Python version, I'm only printing the board in its final state. Pretty fast too.
Admin
I believe you can do it in a 1x4 like so:
ABCD | BDAC
Admin
ABCD | CADB
But I agree with your other answers.
Admin
Another Java implementation of Warnsdorff's algorithm:
Admin
Alright, let's flood this bitch with Java implementations!!!
Here's mine with GUI goodness, Warnsdorff's algorithm:
Admin
The case where m=1000 and n=1000 is quite amusing.
The case where m=3 and n=2 is also quite amusing.
My favourite is m=1 and n=1, which just about gets it right...
Apart from ignoring the rubric.
Can't we just leave this sort of thing for lab classes in CS201, and get back to something inventive, like Mandatory Fun Day?
Admin
Why not just start with a full board and connect ALL the tiles together with knight's moves? Then recursively try removing connections until each tile only has two such connections coming out of it; just have an algorithm to detect if all 64 knights are still connected at each removal.
Admin
Where can we submit our own problems for possible inclusion in Programming Praxis?
Admin
Admin
Interesting, but wouldn't it would be too expensive to test for the connectedness?
Admin
Yet another java implementation of the Warnsdorff's algorithm:
Admin
I prefer The Monty Python Knight's Tour I fart in your general direction. Now go away or I shall taunt you another time!.
Admin
Probably a hundred people already posted this solution, but here it is in all of its glory!
Admin
If you want something that hasn't been beaten to exhaustion, feel free to pick any of those.
Admin
I feel pretty stupid.
Admin
Admin
In all fairness, that is exactly the solution propoted by Nvidia: Twinview up 2 of them, then xinerama up the twins w/ a third. Performs about as good as I'd imagine vista+areo would on a PII. I hear the problem is located in the driver's RandR functions.
xserver-xgl works flawlessly, it's just not available as a deb for ubuntu past hardy. I read it was deprecated because current version X is supposed to support this behavior natively, but in my experience the native X support for multiple monitors goes to crap once you involve more than 1 video card (I loose all hardware acceleration capacity). It may be a configuration issue, but the people on Compiz/beryl, X, and Ubuntu IRC channels have not been able to locate it.
Admin
No Haskell yet? Well, here goes, bugs and all:
module Main where
import Data.List (delete, intersect)
board w h = [(x, y) | x <- [1..w], y <- [1..h]] movesFrom = zipWith hop [(-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1)] . repeat where (a, b)
hop
(c, d) = (a+c, b+d) tours' us s = movesFrom sintersect
us >>= (\m -> map (m:) $ tours' (delete m us) m) tours w h s = filter ((==) s . last) (tours' (board w h) s) main = print $ head $ tours 6 6 (1, 1)It worked before I "optimized" it, really!
Admin
Q: How does a pirate pass parameters to a C program? A: With "arrrrgv" and "arrrrgc".
Admin
I'm doin' it the hard way :p
Admin
Brute force using (everyone's favorite...) Excel VBA!! :)
Just paste the following into a new Excel Module, then call the function from the immediate window (Ctrl-G to show the immediate window) like "KnightTour 6,1,1"
Not recommended for boards larger than 8 :)
Admin
fyi - VBA converts all Integers to Longs, might as well just declare them as type Long to save a few milliseconds.
Admin
mate, its a sandwich. Both are between the pieces of bread. If the 'jelly' is on top, you have it upside down.
Admin
Thanks for providing a more interesting praxis.
Here's a Python 3 solution. You can port it to Python 2 by replacing the word "as" with a comma. This handles a 1516 board in a few seconds:
Admin
Admin
For anyone bitching about this being an already solved problem, I'd hate to know how the hell you got through high school, where most classes involved solving already solved problems.
As for the "re-inventing the wheel" argument, that's bullshit. If it wasn't, we'd have stone wheels on our cars. And if that were the case, you'd be bitching about your fuel consumption.
And if there's any other whiny little bitch out there who wants Alex to come up with "something original", who is still reading this post and whom I haven't offended yet, then go and program something that does the Knight's Tour on a three-dimensional board. Or on a 3D chess set.
Admin
Admin
As soon as I saw this, I thought of:
Admin
All of those whiners have been rebuked and have left already. Maybe you should try not to whine so much yourself.
I had a go at the 3D tour and it seems about the same as the 2D one. I tried out 1x1x2 jumps at first but couldn't find any tours for any small boards. This code assumes 0x1x2 jumps:
Admin
This website is about WTF. Programming Praxis is supposed to be easy. The real challenge is coming up with a solution that makes everyone else either think:
a) WTF... b) How the hell did you do that?!
For "b" take a look at the Regex expression which solved one of the previous puzzles. A mathematically true solution using no numbers what so ever. Brilliant.
Admin
Which inevitably leads to:
Q: Why did the Fortran main routine and subroutine have so many arguments?
A: Because they had nothing in COMMON.
Admin
Reinventing the wheel is NOT a waste of time if you seek to improve it or understand it better. And isn't the point of these coding challenges to understand our craft better through experience?
Admin
Here is a Knights tour but it doesn't go to the original location.
/******************************************
import java.util.*;
public class KnightTour { private static int iLength = 0; private static int iWidth = 0; private static int iX = 0; private static int iY = 0; //Each knight only has 8 possible moves because of overlap. //Up two over 1 //Down two over 1 //Right two up/down 1 //Left two up/down 1 private static int moves[] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{-1,2},{1,-2},{-1,-2}};
}
Admin
I wrote this in college in Applesoft Basic. I doubt the disks are still readable, though.
Admin
Hey Alex, this here is spam in poorly written swedish. Granted, its not as bad as the engrish stuff that pops up here. >.<
Anyway, translated into english;
Show respect for your partner's children if she / he already has children. There is nothing more disgusting than a spouse who treats children bad.
Google Translates take: Show respect to your partner's child if she / he has children in the past. No foul a spouse dealing with child maltreatment.
I like the last bit there. :)
Admin
Ah, well, seeing as no one has done it yet I'll post a shameless copy and paste conversion from the Wikipedia article to C#.
Admin
Admin
public void KnightsTour (Piece knight) { InfiniteImprobilityDrive drive = new InfiniteImprobilityDrive ();
// attach the infinite improbabilty drive to the knight knight.AttachDrive (drive);
// As we know, the infinite improbabilty drive, when // activated, visits all points in the universe // simultaneously, thus completing the knights tour. // Additionally, as demonstrated by the semi-evolved // simian known as Dent Arthur Dent, activating the drive // without first programming a destination results in the // drive returning to its original location. drive.Activate (); // Not only does the knight visit all the locations of // the board it's on, it also visits all the locations // of all the boards in the known universe. }
Admin
This sounds very elegant indeed. How abount using a http://en.wikipedia.org/wiki/Disjoint-set_data_structure ? (it solves the opposite problem, I guess, but that is left as an exercise for the reader.
Admin
After all those long and neat solutions, here is a compact (and rather obfuscated) one in C++. Not honoring the last point though.
Admin
Hahahaha Last week everyone complains things are too easy.
Now everyone complains the puzzle is too common - but few bother to propose a solution?
As Alex said (on the first page of the comments): we could cheat and find the answer, or you could challenge yourself to do it without looking for the answer outright. OR (as I think he also suggested) good opportunity to familiarise yourself with another language...
Admin
Admin
php
Admin
Did anyone say brute force? Using Prolog! (gprolog Syntax)