Solve triangle solitaire puzzle: Difference between revisions
Content added Content deleted
m (→{{header|Picat}}: Added {{out}}) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 34: | Line 34: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">F DrawBoard(board) |
||
V peg = [‘’] * 16 |
V peg = [‘’] * 16 |
||
L(n) 1.<16 |
L(n) 1.<16 |
||
Line 112: | Line 112: | ||
AddPeg(&board, land) |
AddPeg(&board, land) |
||
DrawBoard(board) |
DrawBoard(board) |
||
print("Peg #. jumped over #. to land on #.\n".format(hex(peg), hex(over), hex(land)))</ |
print("Peg #. jumped over #. to land on #.\n".format(hex(peg), hex(over), hex(land)))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 211: | Line 211: | ||
=={{header|D}}== |
=={{header|D}}== |
||
{{trans|Ruby}} |
{{trans|Ruby}} |
||
< |
<syntaxhighlight lang="d">import std.stdio, std.array, std.string, std.range, std.algorithm; |
||
immutable N = [0,1,1,1,1,1,1,1,1,1,1,1,1,1,1]; |
immutable N = [0,1,1,1,1,1,1,1,1,1,1,1,1,1,1]; |
||
Line 263: | Line 263: | ||
} |
} |
||
writeln(l.empty ? "No solution found." : l); |
writeln(l.empty ? "No solution found." : l); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 365: | Line 365: | ||
=={{header|EasyLang}}== |
=={{header|EasyLang}}== |
||
<lang>brd$[] = strchars " |
<syntaxhighlight lang="text">brd$[] = strchars " |
||
┏━━━━━━━━━┓ |
┏━━━━━━━━━┓ |
||
┃ · ┃ |
┃ · ┃ |
||
Line 401: | Line 401: | ||
call solve solution$ |
call solve solution$ |
||
print solution$ |
print solution$ |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Elixir}}== |
=={{header|Elixir}}== |
||
Inspired by Ruby |
Inspired by Ruby |
||
< |
<syntaxhighlight lang="elixir">defmodule IQ_Puzzle do |
||
def task(i \\ 0, n \\ 5) do |
def task(i \\ 0, n \\ 5) do |
||
fmt = Enum.map_join(1..n, fn i -> |
fmt = Enum.map_join(1..n, fn i -> |
||
Line 447: | Line 447: | ||
end |
end |
||
IQ_Puzzle.task</ |
IQ_Puzzle.task</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 552: | Line 552: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import "fmt" |
import "fmt" |
||
Line 666: | Line 666: | ||
fmt.Printf("Peg %X jumped over %X to land on %X\n\n", peg, over, land) |
fmt.Printf("Peg %X jumped over %X to land on %X\n\n", peg, over, land) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 674: | Line 674: | ||
=={{header|J}}== |
=={{header|J}}== |
||
<syntaxhighlight lang="j"> |
|||
<lang J> |
|||
NB. This is a direct translation of the python program, |
NB. This is a direct translation of the python program, |
||
NB. except for the display which by move is horizontal. |
NB. except for the display which by move is horizontal. |
||
Line 856: | Line 856: | ||
NB. Solution NB. return Solution however Solution is global. |
NB. Solution NB. return Solution however Solution is global. |
||
) |
) |
||
</syntaxhighlight> |
|||
</lang> |
|||
Example linux session with program in file CrackerBarrel.ijs |
Example linux session with program in file CrackerBarrel.ijs |
||
<pre> |
<pre> |
||
Line 895: | Line 895: | ||
Print one possible solution. |
Print one possible solution. |
||
<syntaxhighlight lang="java"> |
|||
<lang Java> |
|||
import java.util.ArrayList; |
import java.util.ArrayList; |
||
import java.util.Arrays; |
import java.util.Arrays; |
||
Line 1,083: | Line 1,083: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,121: | Line 1,121: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="julia">moves = [[1, 2, 4], [1, 3, 6], [2, 4, 7], [2, 5, 9], [3, 5, 8], [3, 6, 10], [4, 5, 6], |
||
[4, 7, 11], [4, 8, 13], [5, 8, 12], [5, 9, 14], [6, 9, 13], [6, 10, 15], |
[4, 7, 11], [4, 8, 13], [5, 8, 12], [5, 9, 14], [6, 9, 13], [6, 10, 15], |
||
[7, 8, 9], [8, 9, 10], [11, 12, 13], [12, 13, 14], [13, 14, 15]] |
[7, 8, 9], [8, 9, 10], [11, 12, 13], [12, 13, 14], [13, 14, 15]] |
||
Line 1,157: | Line 1,157: | ||
end |
end |
||
end |
end |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
Starting board: |
Starting board: |
||
Line 1,260: | Line 1,260: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="scala">// version 1.1.3 |
||
data class Solution(val peg: Int, val over: Int, val land: Int) |
data class Solution(val peg: Int, val over: Int, val land: Int) |
||
Line 1,335: | Line 1,335: | ||
println("Peg %X jumped over %X to land on %X\n".format(peg, over, land)) |
println("Peg %X jumped over %X to land on %X\n".format(peg, over, land)) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,439: | Line 1,439: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">ClearAll[Showstate] |
||
Showstate[state_List, pos_] := Module[{p, e}, |
Showstate[state_List, pos_] := Module[{p, e}, |
||
p = {#, FirstPosition[pos, #, Missing[], {2}]} & /@ state; |
p = {#, FirstPosition[pos, #, Missing[], {2}]} & /@ state; |
||
Line 1,484: | Line 1,484: | ||
state = DeleteCases[Range[15], x]; |
state = DeleteCases[Range[15], x]; |
||
continue = True; |
continue = True; |
||
SolvePuzzle[{state, {}}, {y}]</ |
SolvePuzzle[{state, {}}, {y}]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Outputs a graphical overview, by clicking one can go through the different states. |
Outputs a graphical overview, by clicking one can go through the different states. |
||
Line 1,490: | Line 1,490: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="nim">import sequtils, strutils |
||
type |
type |
||
Line 1,565: | Line 1,565: | ||
board[land] = true |
board[land] = true |
||
board.draw() |
board.draw() |
||
echo "Peg $1 jumped over $2 to land on $3\n".format(peg.toHex(1), over.toHex(1), land.toHex(1))</ |
echo "Peg $1 jumped over $2 to land on $3\n".format(peg.toHex(1), over.toHex(1), land.toHex(1))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,668: | Line 1,668: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="perl">@start = qw< |
||
0 |
0 |
||
1 1 |
1 1 |
||
Line 1,719: | Line 1,719: | ||
print $result ? $result : "No solution found"; |
print $result ? $result : "No solution found"; |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre style="height:60ex;overflow:scroll;">Starting with |
<pre style="height:60ex;overflow:scroll;">Starting with |
||
Line 1,839: | Line 1,839: | ||
Twee brute-force string-based solution. Backtracks a mere 366 times, whereas starting with the 5th peg missing backtracks 19388 times (all in 0s, obvs). |
Twee brute-force string-based solution. Backtracks a mere 366 times, whereas starting with the 5th peg missing backtracks 19388 times (all in 0s, obvs). |
||
<!--< |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #000080;font-style:italic;">-- demo\rosetta\IQpuzzle.exw</span> |
<span style="color: #000080;font-style:italic;">-- demo\rosetta\IQpuzzle.exw</span> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">moves</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{-</span><span style="color: #000000;">11</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">11</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">}</span> |
<span style="color: #008080;">constant</span> <span style="color: #000000;">moves</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{-</span><span style="color: #000000;">11</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">11</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">}</span> |
||
Line 1,869: | Line 1,869: | ||
"""</span> |
"""</span> |
||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">start</span><span style="color: #0000FF;">&</span><span style="color: #000000;">solve</span><span style="color: #0000FF;">(</span><span style="color: #000000;">start</span><span style="color: #0000FF;">,</span><span style="color: #000000;">14</span><span style="color: #0000FF;">),</span><span style="color: #008000;">'\n'</span><span style="color: #0000FF;">),</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"-"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">))</span> |
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">start</span><span style="color: #0000FF;">&</span><span style="color: #000000;">solve</span><span style="color: #0000FF;">(</span><span style="color: #000000;">start</span><span style="color: #0000FF;">,</span><span style="color: #000000;">14</span><span style="color: #0000FF;">),</span><span style="color: #008000;">'\n'</span><span style="color: #0000FF;">),</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"-"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">))</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
Line 1,887: | Line 1,887: | ||
Adapted to the English game (also in demo\rosetta\IQpuzzle.exw): |
Adapted to the English game (also in demo\rosetta\IQpuzzle.exw): |
||
<!--< |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">moves</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">15</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">15</span><span style="color: #0000FF;">}</span> |
<span style="color: #008080;">constant</span> <span style="color: #000000;">moves</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">15</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">15</span><span style="color: #0000FF;">}</span> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">solve</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">board</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">left</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">solve</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">board</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">left</span><span style="color: #0000FF;">)</span> |
||
Line 1,922: | Line 1,922: | ||
"""</span> |
"""</span> |
||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">start</span><span style="color: #0000FF;">&</span><span style="color: #000000;">solve</span><span style="color: #0000FF;">(</span><span style="color: #000000;">start</span><span style="color: #0000FF;">,</span><span style="color: #000000;">32</span><span style="color: #0000FF;">),</span><span style="color: #008000;">'\n'</span><span style="color: #0000FF;">),</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">8</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"-"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">))</span> |
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">start</span><span style="color: #0000FF;">&</span><span style="color: #000000;">solve</span><span style="color: #0000FF;">(</span><span style="color: #000000;">start</span><span style="color: #0000FF;">,</span><span style="color: #000000;">32</span><span style="color: #0000FF;">),</span><span style="color: #008000;">'\n'</span><span style="color: #0000FF;">),</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">8</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"-"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">))</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
Line 1,961: | Line 1,961: | ||
=={{header|Picat}}== |
=={{header|Picat}}== |
||
This version use the constraint solver (cp). |
This version use the constraint solver (cp). |
||
< |
<syntaxhighlight lang="picat">import cp. |
||
go => |
go => |
||
Line 2,089: | Line 2,089: | ||
printf(" %2d %2d %2d %2d\n",B[7],B[8],B[9],B[10]), |
printf(" %2d %2d %2d %2d\n",B[7],B[8],B[9],B[10]), |
||
printf(" %2d %2d %2d %2d %2d\n",B[11],B[12],B[13],B[14],B[15]), |
printf(" %2d %2d %2d %2d %2d\n",B[11],B[12],B[13],B[14],B[15]), |
||
nl.</ |
nl.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,251: | Line 2,251: | ||
Works with SWI-Prolog and module(lambda). |
Works with SWI-Prolog and module(lambda). |
||
< |
<syntaxhighlight lang="prolog">:- use_module(library(lambda)). |
||
iq_puzzle :- |
iq_puzzle :- |
||
Line 2,347: | Line 2,347: | ||
select(End, Free, F1), |
select(End, Free, F1), |
||
display(Tail, [Start, Middle | F1]). |
display(Tail, [Start, Middle | F1]). |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output : |
Output : |
||
<pre> ?- iq_puzzle. |
<pre> ?- iq_puzzle. |
||
Line 2,469: | Line 2,469: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
<syntaxhighlight lang="python"># |
|||
<lang Python># |
|||
# Draw board triangle in ascii |
# Draw board triangle in ascii |
||
# |
# |
||
Line 2,564: | Line 2,564: | ||
AddPeg(board,land) # board order changes! |
AddPeg(board,land) # board order changes! |
||
DrawBoard(board) |
DrawBoard(board) |
||
print "Peg %X jumped over %X to land on %X\n" % (peg,over,land)</ |
print "Peg %X jumped over %X to land on %X\n" % (peg,over,land)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,669: | Line 2,669: | ||
Oh and there are some useful triangle numbers functions thrown in for free! |
Oh and there are some useful triangle numbers functions thrown in for free! |
||
< |
<syntaxhighlight lang="racket">#lang racket |
||
(define << arithmetic-shift) |
(define << arithmetic-shift) |
||
(define bwbs? bitwise-bit-set?) |
(define bwbs? bitwise-bit-set?) |
||
Line 2,747: | Line 2,747: | ||
;; Solve #1 missing -> #13 left alone |
;; Solve #1 missing -> #13 left alone |
||
(for-each display-board (find-path (flip-peg 1 full-board) (flip-peg 13 empty-board)))</ |
(for-each display-board (find-path (flip-peg 1 full-board) (flip-peg 13 empty-board)))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,834: | Line 2,834: | ||
{{trans|Sidef}} |
{{trans|Sidef}} |
||
<syntaxhighlight lang="raku" line> |
|||
<lang perl6> |
|||
constant @start = < |
constant @start = < |
||
0 |
0 |
||
Line 2,884: | Line 2,884: | ||
last if $result |
last if $result |
||
}; |
}; |
||
say $result ?? $result !! "No solution found";</ |
say $result ?? $result !! "No solution found";</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style="height:60ex;overflow:scroll;">Starting with |
<pre style="height:60ex;overflow:scroll;">Starting with |
||
Line 2,988: | Line 2,988: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby"># Solitaire Like Puzzle Solver - Nigel Galloway: October 18th., 2014 |
||
G = [[0,1,3],[0,2,5],[1,3,6],[1,4,8],[2,4,7],[2,5,9],[3,4,5],[3,6,10],[3,7,12],[4,7,11],[4,8,13],[5,8,12],[5,9,14],[6,7,8],[7,8,9],[10,11,12],[11,12,13],[12,13,14], |
G = [[0,1,3],[0,2,5],[1,3,6],[1,4,8],[2,4,7],[2,5,9],[3,4,5],[3,6,10],[3,7,12],[4,7,11],[4,8,13],[5,8,12],[5,9,14],[6,7,8],[7,8,9],[10,11,12],[11,12,13],[12,13,14], |
||
[3,1,0],[5,2,0],[6,3,1],[8,4,1],[7,4,2],[9,5,2],[5,4,3],[10,6,3],[12,7,3],[11,7,4],[13,8,4],[12,8,5],[14,9,5],[8,7,6],[9,8,7],[12,11,10],[13,12,11],[14,13,12]] |
[3,1,0],[5,2,0],[6,3,1],[8,4,1],[7,4,2],[9,5,2],[5,4,3],[10,6,3],[12,7,3],[11,7,4],[13,8,4],[12,8,5],[14,9,5],[8,7,6],[9,8,7],[12,11,10],[13,12,11],[14,13,12]] |
||
Line 3,002: | Line 3,002: | ||
l=false; G.each{|g| l=solve(N,N.inject(:+),g); break if l} |
l=false; G.each{|g| l=solve(N,N.inject(:+),g); break if l} |
||
puts l ? l : "No solution found" |
puts l ? l : "No solution found" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre style="height:64ex;overflow:scroll"> |
<pre style="height:64ex;overflow:scroll"> |
||
Line 3,107: | Line 3,107: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Ruby}} |
{{trans|Ruby}} |
||
< |
<syntaxhighlight lang="ruby">const N = [0,1,1,1,1,1,1,1,1,1,1,1,1,1,1] |
||
const G = [ |
const G = [ |
||
Line 3,146: | Line 3,146: | ||
var r = '' |
var r = '' |
||
G.each {|g| (r = solve(N, 1, g)) && break } |
G.each {|g| (r = solve(N, 1, g)) && break } |
||
say (r ? r : "No solution found")</ |
say (r ? r : "No solution found")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,253: | Line 3,253: | ||
'''Notes:''' |
'''Notes:''' |
||
This program uses a brute-force method with a string of 25 characters to internally represent the 15 spots on the peg board. One can set the starting removed peg and intended last remaining peg by editing the header variable declarations named '''''Starting''''' and '''''Target'''''. If one doesn't care which spot the last peg lands on, the '''''Target''''' variable can be set to 0. The constant '''''n''''' can be changed for different sized peg boards, for example with '''''n = 6''''' the peg board would have 21 positions. |
This program uses a brute-force method with a string of 25 characters to internally represent the 15 spots on the peg board. One can set the starting removed peg and intended last remaining peg by editing the header variable declarations named '''''Starting''''' and '''''Target'''''. If one doesn't care which spot the last peg lands on, the '''''Target''''' variable can be set to 0. The constant '''''n''''' can be changed for different sized peg boards, for example with '''''n = 6''''' the peg board would have 21 positions. |
||
< |
<syntaxhighlight lang="vbnet"> |
||
Imports System, Microsoft.VisualBasic.DateAndTime |
Imports System, Microsoft.VisualBasic.DateAndTime |
||
Line 3,379: | Line 3,379: | ||
If Diagnostics.Debugger.IsAttached Then Console.ReadLine() |
If Diagnostics.Debugger.IsAttached Then Console.ReadLine() |
||
End Sub |
End Sub |
||
End Module</ |
End Module</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
'''A full solution:''' |
'''A full solution:''' |
||
Line 3,485: | Line 3,485: | ||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/fmt" for Conv, Fmt |
||
var board = List.filled(16, true) |
var board = List.filled(16, true) |
||
Line 3,564: | Line 3,564: | ||
drawBoard.call() |
drawBoard.call() |
||
Fmt.print("Peg $X jumped over $X to land on $X\n", peg, over, land) |
Fmt.print("Peg $X jumped over $X to land on $X\n", peg, over, land) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,573: | Line 3,573: | ||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |
||
{{trans|Phix}} |
{{trans|Phix}} |
||
< |
<syntaxhighlight lang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Solve_triangle_solitare_puzzle |
||
// by Galileo, 04/2022 |
// by Galileo, 04/2022 |
||
Line 3,601: | Line 3,601: | ||
start$ = "\n\n 0 \n 1 1 \n 1 1 1 \n 1 1 1 1 \n1 1 1 1 1" |
start$ = "\n\n 0 \n 1 1 \n 1 1 1 \n 1 1 1 1 \n1 1 1 1 1" |
||
print start$, solve$(start$, 14)</ |
print start$, solve$(start$, 14)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,693: | Line 3,693: | ||
{{trans|D}} |
{{trans|D}} |
||
{{Trans|Ruby}} |
{{Trans|Ruby}} |
||
< |
<syntaxhighlight lang="zkl">var N=T(0,1,1,1,1,1,1,1,1,1,1,1,1,1,1); |
||
var G=T( T(0,1, 3), T(0,2, 5), T(1,3, 6), T( 1, 4, 8), T( 2, 4, 7), T( 2, 5, 9), |
var G=T( T(0,1, 3), T(0,2, 5), T(1,3, 6), T( 1, 4, 8), T( 2, 4, 7), T( 2, 5, 9), |
||
T(3,4, 5), T(3,6,10), T(3,7,12), T( 4, 7,11), T( 4, 8,13), T( 5, 8,12), |
T(3,4, 5), T(3,6,10), T(3,7,12), T( 4, 7,11), T( 4, 8,13), T( 5, 8,12), |
||
Line 3,727: | Line 3,727: | ||
reg l; |
reg l; |
||
foreach g in (G){ if(l=solve(N,1,g)) break; } |
foreach g in (G){ if(l=solve(N,1,g)) break; } |
||
println(l and l or "No solution found.");</ |
println(l and l or "No solution found.");</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style="height:32ex;overflow:scroll"> |
<pre style="height:32ex;overflow:scroll"> |