Solve triangle solitaire puzzle: Difference between revisions
Content added Content deleted
m (→{{header|Julia}}: add starting position display) |
|||
Line 683: | Line 683: | ||
v[div(i*i-i+2,2):div(i*(i+1),2)]), ""), 1:5), "\n") |
v[div(i*i-i+2,2):div(i*(i+1),2)]), ""), 1:5), "\n") |
||
const solutiontext = |
const solutiontext = ["Starting board:\n" * triangletext([0; ones(Int, 14)]) * "\n"] |
||
function solve(mv, turns=1, bd=[0; ones(Int, 14)]) |
function solve(mv, turns=1, bd=[0; ones(Int, 14)]) |
||
Line 706: | Line 706: | ||
for (i, move) in enumerate(moves) |
for (i, move) in enumerate(moves) |
||
if solve(move) |
if solve(move) |
||
println(join(reverse(solutiontext), "")) |
println(join([solutiontext[1]; reverse(solutiontext[2:end])], "")) |
||
break |
break |
||
elseif i == length(moves) |
elseif i == length(moves) |
||
Line 714: | Line 714: | ||
</lang>{{out}} |
</lang>{{out}} |
||
<pre> |
<pre> |
||
Starting board: |
|||
0 |
|||
1 1 |
|||
1 1 1 |
|||
1 1 1 1 |
|||
1 1 1 1 1 |
|||
move 4 to 1 |
move 4 to 1 |
||
1 |
1 |