Pretty-printing peg solitaire boards

Hi, I'm trying to pretty-print (with Text . PrettyPrint . HughesPJ) a set of peg solitaire boards. No matter what I try, I always get this: 00# 00# 0000#00 0000000 0000000 000 000 : 00# 00# 0000000 0000000 0000000 000 000 but what I really want is this: 00# 00# 00# 00# 0000#00 0000000 0000000 : 0000000 0000000 000 000 000 000 000 What I'm I doing wrong? When I have two boards a,b::Doc, I'm composing them with a <+> colon <+> b and rendering them with just 'render'. Should I try something else? Thanks, Maurício

On Sun, Nov 25, 2007 at 03:40:26AM -0200, Maurício wrote:
Hi,
I'm trying to pretty-print (with Text . PrettyPrint . HughesPJ) a set of peg solitaire boards. No matter what I try, I always get this:
00# 00# 0000#00 0000000 0000000 000 000 : 00# 00# 0000000 0000000 0000000 000 000
but what I really want is this:
00# 00# 00# 00# 0000#00 0000000 0000000 : 0000000 0000000 000 000 000 000 000
What I'm I doing wrong? When I have two boards a,b::Doc, I'm composing them with
a <+> colon <+> b
and rendering them with just 'render'. Should I try something else?
Right; Text.PrettyPrint is designed for rendering code, where there is a natural 1D structure. For instance, stmt <> semi does the right thing for code - sticking the semicolon at the very end. For text graphics you want to do something else... Stefan

On 25/11/2007, Maurício
Hi,
I'm trying to pretty-print (with Text . PrettyPrint . HughesPJ) a set of peg solitaire boards. No matter what I try, I always get this:
00# 00# 0000#00 0000000 0000000 000 000 : 00# 00# 0000000 0000000 0000000 000 000
Just curious. Are you working on the algorithm also? :)

Hi,
I'm trying to pretty-print (with Text . PrettyPrint . HughesPJ) a set of peg solitaire boards. No matter what I try, I always get this: (...)
Just curious. Are you working on the algorithm also? :)
Sure. It's done already. I did generate a file with all possible (i.e., solvable) positions, but I have to rebuild it due to a bug. However, I'm doing that because there's a single position which my brother could not solve, and he believes it to be impossible, so we want to check: #0# ###0### ####### ####### ### ### If you are not interested in that very particular situation, there are many solutions in the net, including references for a math analysis (textbook only, I could not find it on P2P). Just check for peg solitaire in wikipedia. If you ever prefer my messy, Portuguese documented code to that, just ask me and I'll send it with a few explanations :) Best, Maurício

Maur??cio wrote:
I have to rebuild it due to a bug. However, I'm doing that because there's a single position which my brother could not solve, and he believes it to be impossible, so we want to check:
#0# ###0### ####### ####### ### ###
I guess you meant
#0# #0# ###0### ####### ####### ### ###
This indeed can not be solved. Color the Solitaire board as follows, abc bca abcabca bcabcab bca cab Let A, B, and C be the number of pegs that have color a, b, and c, respectively. Every move replaces a peg of two of the colors by a peg of the third color. So no move changes the parities of A+B, B+C or C+A. Now for your example, A+B, B+C and C+A are initially even. It's easy to see that with a single peg left two of these numbers must be odd, and therefore there is no solution. (I think you can find this argument in "Winnning Ways for your mathematical plays" by Berlekamp, Conway and Guy somewhere.) HTH, Bertram

(...)However, I'm doing that because there's a single position which my brother could not solve, and he believes it to be impossible(...)
I guess you meant #0# #0# ###0### ####### ####### ### ###
This indeed can not be solved. (...)
Actually, I did mean to start with: ### ### ###0### ####### ####### ### ### and then go to: #0# #0# ####### ####### ####### ### ### My brother's idea is that he can solve any board after you choose the initial peg to be removed and the first move. He can do it for any combination, except for this one. But your argument is very interesting, indeed! I'll try to find that book, we'll like to read it. Best, Maurício

Maur??cio wrote:
Actually, I did mean to start with:
### ### ###0### ####### ####### ### ###
and then go to:
#0# #0# ####### ####### ####### ### ###
My brother's idea is that he can solve any board after you choose the initial peg to be removed and the first move. He can do it for any combination, except for this one.
Heh. He's in for a surprise, there are actually solutions for this. It was surprisingly hard to find one though. Thanks for the puzzle. (I won't spoil it here. Ask me off list if you're interested.)
But your argument is very interesting, indeed! I'll try to find that book, we'll like to read it.
It's a series of three books actually. Sadly it's been a long time since I've read them so I forgot which volume covers which topics. Bertram

Actually, I did mean to start with: (...)
#0# #0# ####### ####### ####### ### ###
(...)
Heh. He's in for a surprise, there are actually solutions for this. (...)
If you don't want to spoil it here, and it won't take too much of your time to write it down, you can send it to my e-mail: 'briqueabraque@yahoo.com'
(...) I'll try to find that book, we'll like to read it.
It's a series of three books actually. Sadly it's been a long time since I've read them so I forgot which volume covers which topics.
Actually, it seems there's an old edition in two volumes and a new one, in four volumes. I just read the first chapter of volume I in Amazon, and it's really a nice reading. Maurício

You could use Text.Pandoc.Blocks (http://pandoc.googlecode.com/svn/trunk/Text/Pandoc/Blocks.hs). Something like this should do the trick:
boards = map (docToBlock 7) [a, b] -- 7 is width of block colon = docToBlock 1 $ text "\n\n\n:" -- thin block for the colon boardSet = render $ blockToDoc $ hsepBlocks $ intersperse colon boards
John +++ Maurício [Nov 25 07 03:40 ]:
Hi,
I'm trying to pretty-print (with Text . PrettyPrint . HughesPJ) a set of peg solitaire boards. No matter what I try, I always get this:
00# 00# 0000#00 0000000 0000000 000 000 : 00# 00# 0000000 0000000 0000000 000 000
but what I really want is this:
00# 00# 00# 00# 0000#00 0000000 0000000 : 0000000 0000000 000 000 000 000 000
What I'm I doing wrong? When I have two boards a,b::Doc, I'm composing them with
a <+> colon <+> b
and rendering them with just 'render'. Should I try something else?
Thanks, Maurício
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Bertram Felgenhauer
-
John MacFarlane
-
Maurício
-
Stefan O'Rear
-
Vimal