Solve triangle solitaire puzzle: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added syntax colouring the hard way, phix/basics) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 30: | Line 30: | ||
Start with empty peg in '''X''' and solve with one peg in position '''Y'''. |
Start with empty peg in '''X''' and solve with one peg in position '''Y'''. |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>F DrawBoard(board) |
|||
V peg = [‘’] * 16 |
|||
L(n) 1.<16 |
|||
peg[n] = ‘.’ |
|||
I n C board |
|||
peg[n] = hex(n) |
|||
print(‘ #.’.format(peg[1])) |
|||
print(‘ #. #.’.format(peg[2], peg[3])) |
|||
print(‘ #. #. #.’.format(peg[4], peg[5], peg[6])) |
|||
print(‘ #. #. #. #.’.format(peg[7], peg[8], peg[9], peg[10])) |
|||
print(‘ #. #. #. #. #.’.format(peg[11], peg[12], peg[13], peg[14], peg[15])) |
|||
F RemovePeg(&board, n) |
|||
board.remove(n) |
|||
F AddPeg(&board, n) |
|||
board.append(n) |
|||
F IsPeg(board, n) |
|||
R n C board |
|||
V JumpMoves = [1 = [(2, 4), (3, 6)], |
|||
2 = [(4, 7), (5, 9)], |
|||
3 = [(5, 8), (6, 10)], |
|||
4 = [(2, 1), (5, 6), (7, 11), (8, 13)], |
|||
5 = [(8, 12), (9, 14)], |
|||
6 = [(3, 1), (5, 4), (9, 13), (10, 15)], |
|||
7 = [(4, 2), (8, 9)], |
|||
8 = [(5, 3), (9, 10)], |
|||
9 = [(5, 2), (8, 7)], |
|||
10 = [(9, 8)], |
|||
11 = [(12, 13)], |
|||
12 = [(8, 5), (13, 14)], |
|||
13 = [(8, 4), (9, 6), (12, 11), (14, 15)], |
|||
14 = [(9, 5), (13, 12)], |
|||
15 = [(10, 6), (14, 13)]] |
|||
[(Int, Int, Int)] Solution |
|||
F Solve(=board) |
|||
I board.len == 1 |
|||
R board |
|||
L(peg) 1.<16 |
|||
I IsPeg(board, peg) |
|||
V movelist = JumpMoves[peg] |
|||
L(over, land) movelist |
|||
I IsPeg(board, over) & !IsPeg(board, land) |
|||
V saveboard = copy(board) |
|||
RemovePeg(&board, peg) |
|||
RemovePeg(&board, over) |
|||
AddPeg(&board, land) |
|||
Solution.append((peg, over, land)) |
|||
board = Solve(board) |
|||
I board.len == 1 |
|||
R board |
|||
board = copy(saveboard) |
|||
Solution.pop() |
|||
R board |
|||
F InitSolve(empty) |
|||
V board = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] |
|||
RemovePeg(&board, empty) |
|||
Solve(board) |
|||
V empty_start = 1 |
|||
InitSolve(empty_start) |
|||
V board = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] |
|||
RemovePeg(&board, empty_start) |
|||
L(peg, over, land) Solution |
|||
RemovePeg(&board, peg) |
|||
RemovePeg(&board, over) |
|||
AddPeg(&board, land) |
|||
DrawBoard(board) |
|||
print("Peg #. jumped over #. to land on #.\n".format(hex(peg), hex(over), hex(land)))</lang> |
|||
{{out}} |
|||
<pre> |
|||
1 |
|||
. 3 |
|||
. 5 6 |
|||
7 8 9 A |
|||
B C D E F |
|||
Peg 4 jumped over 2 to land on 1 |
|||
1 |
|||
. 3 |
|||
4 . . |
|||
7 8 9 A |
|||
B C D E F |
|||
Peg 6 jumped over 5 to land on 4 |
|||
. |
|||
. . |
|||
4 . 6 |
|||
7 8 9 A |
|||
B C D E F |
|||
Peg 1 jumped over 3 to land on 6 |
|||
. |
|||
2 . |
|||
. . 6 |
|||
. 8 9 A |
|||
B C D E F |
|||
Peg 7 jumped over 4 to land on 2 |
|||
. |
|||
2 . |
|||
. 5 6 |
|||
. . 9 A |
|||
B . D E F |
|||
Peg C jumped over 8 to land on 5 |
|||
. |
|||
2 . |
|||
. 5 6 |
|||
. . 9 A |
|||
B C . . F |
|||
Peg E jumped over D to land on C |
|||
. |
|||
2 . |
|||
. 5 . |
|||
. . . A |
|||
B C D . F |
|||
Peg 6 jumped over 9 to land on D |
|||
. |
|||
. . |
|||
. . . |
|||
. . 9 A |
|||
B C D . F |
|||
Peg 2 jumped over 5 to land on 9 |
|||
. |
|||
. . |
|||
. . . |
|||
. . 9 A |
|||
B . . E F |
|||
Peg C jumped over D to land on E |
|||
. |
|||
. . |
|||
. . 6 |
|||
. . 9 . |
|||
B . . E . |
|||
Peg F jumped over A to land on 6 |
|||
. |
|||
. . |
|||
. . . |
|||
. . . . |
|||
B . D E . |
|||
Peg 6 jumped over 9 to land on D |
|||
. |
|||
. . |
|||
. . . |
|||
. . . . |
|||
B C . . . |
|||
Peg E jumped over D to land on C |
|||
. |
|||
. . |
|||
. . . |
|||
. . . . |
|||
. . D . . |
|||
Peg B jumped over C to land on D |
|||
</pre> |
|||
=={{header|D}}== |
=={{header|D}}== |