If anyone doesn't know what the Moore neighbourhood is: it's the eight squares surrounding any square of a square grid.
I admit it, I'm feeling lazy. I could do it myself, with a bit of head-scratching, no doubt. But it's a nice little problem, particularly if you're au fait with a programming language that supports automatic backtracking, such as
(
Read more... )
Comments 15
But I totally don't.
Reply
Imagine you have a chess board, a white queen, eight white pawns and eight black pawns.
Put the white queen on one of the squares in the middle of the chessboard (we don't actually need the queen as such, but she makes a convenient marker for the square that we've chosen).
There are eight squares that are adjacent to the queen, right? one at the top, one at the bottom, one on the left, one on the right, and the four corner squares. Those eight squares are called the Moore neighbourhood of the square with the queen on ( ... )
Reply
Guess what I'm doing tomorrow with my Gifted & Talented year 5 maths group! I was bored of practicing calculator skills anyway.
(only need to work out for 3 & 4 and double it, right?)
Reply
Yes, the solutions for the cases w = n and w = 8-n, where w is the number of white pawns in an arrangement, are identical under interchange of white and black pawns, so you only really need to work out w = 0 through w = 4.
The thing that makes this problem worthwhile as a programming puzzle is that although it's perfectly possible to find all the solutions by trial and error, it's much nicer if you can discover a neat way of finding them.
If it turns out that your group likes this puzzle, you might like to try out the eight queens puzzle - I had a lot of fun with that, and variants of it, when I was about your maths group's age.
Reply
(Sorry, terrible not-a-reference.)
Reply
I may get it out of the library again and try one more time :)
Reply
Reply
As to your question:
Vs lbh'ir sbhaq svsglbar, V'z zvffvat n srj, naq rvgure lbhe ernfbavat be zvar vf fperjl: fvapr rirel fgngr unf n qhny fgngr ol rkpunatvat juvgr cvrprf sbe oynpx naq ivpr irefn, V ernfba gung gurer zhfg or na rira ahzore bs qvfgvapg fgngrf :)
V'ir bayl hfrq crapvy-naq-cncre ybtvp sbe zl pnyphyngvbaf fb sne, ohg V'ir sbhaq bar qvfgvapg fgngr jvgu ab juvgr cvrprf (gevivny); gjb jvgu bar juvgr; fvk jvgu gjb juvgr; rvtug jvgu guerr juvgr; naq gjryir jvgu sbhe juvgr. Ol gur vagrepunatr vqrn tvira nobir, gurer zhfg nyfb or rvtug jvgu svir juvgr; fvk jvgu fvk juvgr; gjb jvgu frira juvgr; naq bar jvgu rvtug juvgr. Vs gur Fcvevg bs Nevguzrgvp unfa'g qrfregrq zr ragveryl, gung tvirf n gbgny bs sbheglfvk fgngrf.
V jbaqre sebz jurer lbhe rkgen svir unir zngrevnyvfrq?
Reply
Reply
www
bQw
bbb
and
wwb
bQb
bww
I've accounted for those in the numbers that I gave you.
Reply
I'll have a stab at it this weekend. Do you know the answer?
Reply
Unfortunately, our answers are currently not in agreement, so it'll be fun to see what you come up with :)
Reply
Reply
I once wrote a PostScript program that calculated the Ackermann function; unfortunately at that time the only PostScript interpreter that I had access to was the one built into the departmental laser printer. Tying up the printer like that wasn't much appreciated when someone had a pressing need to print their thesis :)
Yes, I suppose it could be done in PostScript, but it's much easier to implement a backtracking solver in Icon or Prolog (Icon would be my language of choice). Of course, if it's possible to find a nice representation of the problem, there may be no need for that kind of brute-force approach. Whether such a nice representation actually exists is another problem...
Reply
Leave a comment