Solve triangle solitaire puzzle: Difference between revisions

EasyLang
(EasyLang)
Line 363:
0 0 1 0 0
Solved</pre>
 
=={{header|EasyLang}}==
<lang>global nc brd$[] .
#
func init . .
repeat
s$ = input
until s$ = ""
nc = len s$ + 1
for c$ in str_chars s$
brd$[] &= c$
.
brd$[] &= "\n"
.
.
call init
#
func try_move pos dir . res .
res = 0
if brd$[pos] = "●" and brd$[pos + dir] = "●" and brd$[pos + 2 * dir] = "·"
brd$[pos] = "·"
brd$[pos + dir] = "·"
brd$[pos + 2 * dir] = "●"
res = 1
.
.
func undo_move pos dir . .
brd$[pos] = "●"
brd$[pos + dir] = "●"
brd$[pos + 2 * dir] = "·"
.
func solve . res .
for pos range len brd$[]
if brd$[pos] = "●"
for dir in [ -nc - 1 (-nc + 1) 2 nc + 1 nc - 1 (-2) ]
call try_move pos dir moved
if moved = 1
call solve solved
call undo_move pos dir
if solved = 1
break 2
.
.
.
n_tees += 1
.
.
res = 0
if solved = 1 or n_tees = 1
print str_join brd$[]
res = 1
.
.
call solve res
#
input_data
┏━━━━━━━━━┓
┃ · ┃
┃ ● ● ┃
┃ ● ● ● ┃
┃ ● ● ● ● ┃
┃● ● ● ● ●┃
┗━━━━━━━━━┛
<lang>
 
=={{header|Elixir}}==
1,995

edits