Solve a Numbrix puzzle: Difference between revisions

→‎{{header|zkl}}: marked maybe incorrect...
m (→‎{{header|Julia}}: Fix broken markup)
(→‎{{header|zkl}}: marked maybe incorrect...)
 
(7 intermediate revisions by 4 users not shown)
Line 73:
 
=={{header|11l}}==
{{incorrect|11l|3rd solution has "00 00" in it where "02 01" shd be (as Python)}}
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V neighbours = [[-1, 0], [0, -1], [1, 0], [0, 1]]
[Int] exists
V lastNumber = 0
Line 161 ⟶ 162:
r = solve(‘17 . . . 11 . . . 59 . 15 . . 6 . . 61 . . . 3 . . . 63 . . . . . . 66 . . . . 23 24 . 68 67 78 . 54 55’""
‘ . . . . 72 . . . . . . 35 . . . 49 . . . 29 . . 40 . . 47 . 31 . . . 39 . . . 45’, 9, 9)
show_result(r)</langsyntaxhighlight>
 
{{out}}
Line 197 ⟶ 198:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">SolveNumbrix(Grid, Locked, Max, row, col, num:=1, R:="", C:=""){
if (R&&C) ; if neighbors (not first iteration)
{
Line 259 ⟶ 260:
}
return StrReplace(map, ">")
}</langsyntaxhighlight>
Examples:<langsyntaxhighlight AutoHotkeylang="autohotkey">;--------------------------------
Grid := [[0, 0, 0, 0, 0, 0, 0, 0, 0]
,[0, 0, 46, 45, 0, 55, 74, 0, 0]
Line 288 ⟶ 289:
return
 
</syntaxhighlight>
</lang>
Outputs:<pre>49 50 51 52 53 54 75 76 81
48 47 46 45 44 55 74 77 80
Line 304 ⟶ 305:
Any non-numeric value indicates a no-go.<br/>
If there are cells that require more characters, then a 2-dimensional array of ints must be used. Any number < 0 indicates a no-go.
<langsyntaxhighlight lang="csharp">using System.Collections;
using System.Collections.Generic;
using static System.Console;
Line 445 ⟶ 446:
}
 
}</langsyntaxhighlight>
{{out}}
<pre>
Line 470 ⟶ 471:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">
#include <vector>
#include <sstream>
Line 626 ⟶ 627:
return system("pause");
}
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 663 ⟶ 664:
From the refactored C++ version with more precise typing. The NumbrixPuzzle struct is created at compile-time, so its asserts and exceptions can catch most malformed puzzles at compile-time.
{{trans|C++}}
<langsyntaxhighlight lang="d">import std.stdio, std.conv, std.string, std.range, std.array, std.typecons, std.algorithm;
 
struct {
Line 871 ⟶ 872:
writefln("One solution:\n%(%-(%2s %)\n%)\n", solution);
}
}</langsyntaxhighlight>
{{out}}
<pre>One solution:
Line 909 ⟶ 910:
{{trans|Ruby}}
This solution uses HLPsolver from [[Solve_a_Hidato_puzzle#Elixir | here]]
<langsyntaxhighlight lang="elixir"># require HLPsolver
adjacent = [{-1, 0}, {0, -1}, {0, 1}, {1, 0}]
Line 937 ⟶ 938:
0 0 0 0 0 0 0 0 0
"""
HLPsolver.solve(board2, adjacent)</langsyntaxhighlight>
 
{{out}}
Line 988 ⟶ 989:
=={{header|Go}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,106 ⟶ 1,107:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,138 ⟶ 1,139:
 
This is a Unicon-specific solution, based on the Unicon Hidato problem solver:
<langsyntaxhighlight lang="unicon">global nCells, cMap, best
record Pos(r,c)
 
Line 1,227 ⟶ 1,228:
QMouse(puzzle, visit(loc.r+1,loc.c), self, val) # South
QMouse(puzzle, visit(loc.r, loc.c-1), self, val) # West
end</langsyntaxhighlight>
 
{{Out}}Sample runs:
Line 1,286 ⟶ 1,287:
=={{header|Java}}==
{{works with|Java|8}}
<langsyntaxhighlight lang="java">import java.util.*;
 
public class Numbrix {
Line 1,376 ⟶ 1,377:
}
}
}</langsyntaxhighlight>
 
<pre>49 50 51 52 53 54 75 76 81
Line 1,390 ⟶ 1,391:
=={{header|Julia}}==
See the Hidato module [[Solve_a_Hidato_puzzle#Julia | here]].
<langsyntaxhighlight lang="julia">using .Hidato
 
const numbrixmoves = [[-1, 0], [0, -1], [0, 1], [1, 0]]
Line 1,403 ⟶ 1,404:
hidatosolve(board, maxmoves, numbrixmoves, fixed, starts[1][1], starts[1][2], 1)
printboard(board)
</langsyntaxhighlight>{{output}}<pre>
0 0 0 0 0 0 0 0 0
0 0 46 45 0 55 74 0 0
Line 1,447 ⟶ 1,448:
 
Uses the Hidato puzzle solver module, which has its source code listed [[Solve_a_Hidato_puzzle#Julia | here]] in the Hadato task.
<langsyntaxhighlight lang="julia">using .Hidato # Note that the . here means to look locally for the module rather than in the libraries
 
const numbrix1 = """
Line 1,482 ⟶ 1,483:
hidatosolve(board, maxmoves, numbrixmoves, fixed, starts[1][1], starts[1][2], 1)
printboard(board)
</syntaxhighlight>
</lang>
{{output}}
<pre>
Line 1,528 ⟶ 1,529:
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.2.0
 
val example1 = listOf(
Line 1,617 ⟶ 1,618:
if (solve(startRow, startCol, 1, 0)) printResult(n + 1)
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,647 ⟶ 1,648:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[NeighbourQ, CellDistance, VisualizeHidato, HiddenSingle, \
NakedN, HiddenN, ChainSearch, HidatoSolve, Cornering, ValidPuzzle, \
GapSearch, ReachDelete, GrowNeighbours]
Line 2,012 ⟶ 2,013:
indices = Flatten[Position[cells, #] & /@ clues[[All, 1]]];
candidates[[indices]] = clues[[All, 2]];
out = HidatoSolve[cells, candidates];</langsyntaxhighlight>
{{out}}
Outputs a graphical representation of the two numbrix puzzles and their solutions.
Line 2,019 ⟶ 2,020:
{{trans|Go}}
With many changes, for instance using a “Numbrix” object as context, adding a procedure to create this object, etc.
<langsyntaxhighlight Nimlang="nim">import algorithm, sequtils, strformat, strutils
 
const Moves = [(1, 0), (0, 1), (-1, 0), (0, -1)]
Line 2,112 ⟶ 2,113:
numbrix.print()
else:
echo "No solution."</langsyntaxhighlight>
 
{{out}}
Line 2,141 ⟶ 2,142:
=={{header|Perl}}==
Tested on perl v5.26.1
<langsyntaxhighlight Perllang="perl">#!/usr/bin/perl
 
use strict;
Line 2,180 ⟶ 2,181:
($_ = $in) =~ s/00(?=.{$gap}$have)/$want/s and solve( $want, $_ ); # U
}
}</langsyntaxhighlight>
 
{{out|case=Example 1}}
Line 2,207 ⟶ 2,208:
 
=={{header|Phix}}==
<!--(phixonline)-->
<lang Phix>sequence board, knownx, knowny
<syntaxhighlight lang="phix">
with javascript_semantics
include sets.e
sequence board, placed, px, py
integer w, h, limit, missing
bool solved
 
function get_moves(integer n)
integer size, limit, nchars, tries
sequence res = {}
string fmt, blank
integer x = px[n], y = py[n]
 
if x>1 and board[y,x-1]=0 then res &= {{x-1,y}} end if
constant ROW = 1, COL = 2
if x<w and board[y,x+1]=0 then res &= {{x+1,y}} end if
constant moves = {{-1,0},{0,-1},{0,1},{1,0}}
if y>1 and board[y-1,x]=0 then res &= {{x,y-1}} end if
 
if y<h and board[y+1,x]=0 then res &= {{x,y+1}} end if
function onboard(integer row, integer col)
return res
return row>=1 and row<=size and col>=nchars and col<=nchars*size
end function
 
procedure solve()
function solve(integer row, integer col, integer n)
if missing=0 then
integer nrow, ncol
tries+ solved = 1true
else
if n>limit then return 1 end if
-- scan for next to place, which will be the lowest
if knownx[n] then
-- of those with either n+1 or n-1 already placed,
for move=1 to length(moves) do
-- checking that all nrowneeded =can row+moves[move][ROW]still be placed.
integer place
ncol = col+moves[move][COL]*nchars
sequence if nrow = knownx[n]moves
for n=limit to 1 andby ncol = knowny[n]-1 thendo
if not if solve(nrow,ncol,placed[n+1)] then return 1 end if
exitbool plus1 = false
if n<limit and placed[n+1] then
place = n
plus1 = true
moves = get_moves(n+1)
if length(moves)=0 then
return -- fail/backtrack
end if
end if
if n>1 and placed[n-1] then
place = n
if plus1 then
moves = intersection(moves,get_moves(n-1))
else
moves = get_moves(n-1)
end if
if length(moves)=0 then
return -- fail/backtrack
end if
end if
end if
end for
returnmissing 0-= 1
for m in moves do
integer {x,y} = m
px[place] = x
py[place] = y
board[y,x] = place
placed[place] = true
solve()
if solved then return end if
placed[place] = false
board[y,x] = 0
end for
missing += 1
end if
end procedure
sequence wmoves = {}
 
for move=1 to length(moves) do
procedure Numbrix(string s)
nrow = row+moves[move][ROW]
atom t0 = time()
ncol = col+moves[move][COL]*nchars
board = if onboardsplit(nrows,ncol'\n')
for i,line andin board[nrow][ncol]='.' thendo
board[nrow][ncol-nchars+1..ncoli] = sprintfapply(fmtsplit(substitute(line,'.','0')),nto_number)
if solve(nrow,ncol,n+1) then return 1 end if
board[nrow][ncol-nchars+1..ncol] = blank
end if
end for
w = length(board[1])
return 0
h = length(board)
end function
limit = w*h
 
placed = repeat(false,limit)
procedure Numbrix(sequence s)
px = repeat(0,limit)
integer y, ch, ch2, k
atom t0 py = timerepeat(0,limit)
smissing = split(s,'\n')0
sizefor x=1 length(s)to w do
for y=1 to h do
limit = size*size
integer byx = board[y][x]
nchars = length(sprintf(" %d",limit))
if byx then
fmt = sprintf(" %%%dd",nchars-1)
placed[byx] = true
blank = repeat('.',nchars)
px[byx] = x
board = repeat(repeat(' ',size*nchars),size)
py[byx] = y
knownx = repeat(0,limit)
knowny = repeat(0,limit) else
missing += 1
for x=1 to size do
for y=nchars to size*nchars by nchars do
ch = s[x][y]
if ch!='.' then
k = ch-'0'
ch2 = s[x][y-1]
if ch2!=' ' then
k += (ch2-'0')*10
board[x][y-1] = ch2
end if
knownx[k] = x
knowny[k] = y
end if
board[x][y] = ch
end for
end for
triessolved = 0false
if solve(knownx[1],knowny[1],2) then
putsprintf(1,join(board,"%s\n\n"),s)
if not solved then
printf(1,"\nsolution found in %d tries (%3.2fs)\n",{tries,time()-t0})
puts(1,"No solutions\n\n")
else
puts(1,"nointeger solutionsnchars found\n= length(sprintf("%d",limit))
string fmt = sprintf(" %%%dd",nchars)
printf(1,"solution found in %s:\n\n",elapsed(time()-t0))
board = apply(true,join_by,{board,1,w,{""},{""},{fmt}})
printf(1,"%s\n\n",{join(board,"\n")})
end if
end procedure
 
constant board1boards = {"""
. . . . . . . . .
. . 46 45 . 55 74 . .
Line 2,295 ⟶ 2,323:
. 18 . . 11 . . 64 .
. . 24 21 . 1 2 . .
. . . . . . . . .""","""
Numbrix(board1)
 
constant board2 = """
. . . . . . . . .
. 11 12 15 18 21 62 61 .
Line 2,307 ⟶ 2,332:
. 38 . . . . . 72 .
. 43 44 47 48 51 76 77 .
. . . . . . . . .""","""
17 . . . 11 . . . 59
Numbrix(board2)</lang>
. 15 . . 6 . . 61 .
. . 3 . . . 63 . .
. . . . 66 . . . .
23 24 . 68 67 78 . 54 55
. . . . 72 . . . .
. . 35 . . . 49 . .
. 29 . . 40 . . 47 .
31 . . . 39 . . . 45""","""
109 0 0 0 0 0 0 0 0 0 0 0 0 0 43
0 0 0 0 0 0 0 65 0 0 0 0 0 0 0
0 0 101 100 0 92 0 76 0 68 0 48 3 0 0
0 0 102 97 0 0 80 0 74 0 0 49 6 0 0
0 0 0 0 0 0 79 0 73 0 0 0 0 0 0
0 0 116 0 0 0 0 0 0 0 0 0 10 0 0
0 0 0 118 217 0 0 0 0 0 55 52 0 0 0
0 121 120 0 0 0 0 213 0 0 0 0 12 35 0
0 0 0 166 167 0 0 0 0 0 205 204 0 0 0
0 0 162 0 0 0 0 0 0 0 0 0 14 0 0
0 0 0 0 0 0 173 0 177 0 0 0 0 0 0
0 0 156 153 0 0 150 0 178 0 0 201 16 0 0
0 0 155 154 0 144 0 180 0 188 0 200 17 0 0
0 0 0 0 0 0 0 183 0 0 0 0 0 0 0
135 0 0 0 0 0 0 0 0 0 0 0 0 0 21"""}
papply(boards,Numbrix)
</syntaxhighlight>
{{out}}
<pre>
. . . . . . . . .
. . 46 45 . 55 74 . .
. 38 . . 43 . . 78 .
. 35 . . . . . 71 .
. . 33 . . . 59 . .
. 17 . . . . . 67 .
. 18 . . 11 . . 64 .
. . 24 21 . 1 2 . .
. . . . . . . . .
 
solution found in 0.1s:
 
49 50 51 52 53 54 75 76 81
48 47 46 45 44 55 74 77 80
Line 2,320 ⟶ 2,382:
28 25 24 21 10 1 2 3 4
27 26 23 22 9 8 7 6 5
 
solution found in 580 tries (0.00s)
. . . . . . . . .
. 11 12 15 18 21 62 61 .
. 6 . . . . . 60 .
. 33 . . . . . 57 .
. 32 . . . . . 56 .
. 37 . 1 . . . 73 .
. 38 . . . . . 72 .
. 43 44 47 48 51 76 77 .
. . . . . . . . .
 
solution found in 0.0s:
 
9 10 13 14 19 20 63 64 65
8 11 12 15 18 21 62 61 66
Line 2,330 ⟶ 2,404:
40 43 44 47 48 51 76 77 78
41 42 45 46 49 50 81 80 79
 
solution found in 334 tries (0.00s)
17 . . . 11 . . . 59
. 15 . . 6 . . 61 .
. . 3 . . . 63 . .
. . . . 66 . . . .
23 24 . 68 67 78 . 54 55
. . . . 72 . . . .
. . 35 . . . 49 . .
. 29 . . 40 . . 47 .
31 . . . 39 . . . 45
 
solution found in 0.0s:
 
17 16 13 12 11 10 9 60 59
18 15 14 5 6 7 8 61 58
19 20 3 4 65 64 63 62 57
22 21 2 1 66 79 80 81 56
23 24 69 68 67 78 77 54 55
26 25 70 71 72 75 76 53 52
27 28 35 36 73 74 49 50 51
30 29 34 37 40 41 48 47 46
31 32 33 38 39 42 43 44 45
 
109 0 0 0 0 0 0 0 0 0 0 0 0 0 43
0 0 0 0 0 0 0 65 0 0 0 0 0 0 0
0 0 101 100 0 92 0 76 0 68 0 48 3 0 0
0 0 102 97 0 0 80 0 74 0 0 49 6 0 0
0 0 0 0 0 0 79 0 73 0 0 0 0 0 0
0 0 116 0 0 0 0 0 0 0 0 0 10 0 0
0 0 0 118 217 0 0 0 0 0 55 52 0 0 0
0 121 120 0 0 0 0 213 0 0 0 0 12 35 0
0 0 0 166 167 0 0 0 0 0 205 204 0 0 0
0 0 162 0 0 0 0 0 0 0 0 0 14 0 0
0 0 0 0 0 0 173 0 177 0 0 0 0 0 0
0 0 156 153 0 0 150 0 178 0 0 201 16 0 0
0 0 155 154 0 144 0 180 0 188 0 200 17 0 0
0 0 0 0 0 0 0 183 0 0 0 0 0 0 0
135 0 0 0 0 0 0 0 0 0 0 0 0 0 21
 
solution found in 0.5s:
 
109 108 87 86 85 84 83 64 63 62 61 46 45 44 43
110 107 88 89 90 91 82 65 66 67 60 47 2 1 42
111 106 101 100 99 92 81 76 75 68 59 48 3 4 41
112 105 102 97 98 93 80 77 74 69 58 49 6 5 40
113 104 103 96 95 94 79 78 73 70 57 50 7 8 39
114 115 116 225 224 223 222 221 72 71 56 51 10 9 38
123 122 117 118 217 218 219 220 209 208 55 52 11 36 37
124 121 120 119 216 215 214 213 210 207 54 53 12 35 34
125 164 165 166 167 168 169 212 211 206 205 204 13 32 33
126 163 162 161 160 171 170 175 176 191 192 203 14 31 30
127 128 157 158 159 172 173 174 177 190 193 202 15 28 29
130 129 156 153 152 151 150 179 178 189 194 201 16 27 26
131 132 155 154 143 144 149 180 181 188 195 200 17 24 25
134 133 138 139 142 145 148 183 182 187 196 199 18 23 22
135 136 137 140 141 146 147 184 185 186 197 198 19 20 21
</pre>
 
=={{header|Picat}}==
<syntaxhighlight lang="picat">
import sat, util.
 
main([File]) =>
Lines = read_file_lines(File),
Dim = Lines.len(),
Board = new_array(Dim, Dim),
Max = Dim*Dim,
Board :: 1..Max,
Bvars = Board.vars(),
all_different(Bvars),
 
foreach ( R in 1..Dim )
Line = Lines[R].split(),
if( Line.len() != Dim ) then
printf("Line %d too short or too long, failing\n", R),
abort
end,
foreach ( C in 1..Dim ) % empty cell: _ or 0
if ( Line[C] != ['_'] ) then % data as 49 _ _ 32 _ _...
Num = Line[C].to_int(),
if ( Num != 0 ) then % data as 0 11 12 15 18...
Board[R,C] #= Num
end
end
end
end,
 
% each cell but that with value 1 must be +1 larger then one of its neighbours
% some numbrix puzzles do not have min and/or max values,
% but this method works for all cases
foreach ( R in 1..Dim, C in 1..Dim )
Nei = [(R1,C1) : (R1, C1) in [(R-1,C), (R,C+1), (R+1,C), (R,C-1)],
between(1, Dim, R1), between(1, Dim, C1)],
Consnei = [ Board[R,C] #= Board[R1,C1] + 1 : (R1,C1) in Nei ],
Board[R,C] #!= 1 #=> sum(Consnei) #= 1
end,
 
time2(solve(Bvars)),
printboard(Board).
 
printboard(A) =>
N = A.len,
nl,
foreach ( I in 1..N )
foreach ( J in 1..A[I].len )
if ( A[I,J] == 0 ) then
printf(" ")
else
printf("%4w", A[I,J])
end
end,
nl
end.
 
</syntaxhighlight>
{{out}}
<pre>
Solution 1:
49 50 51 52 53 54 75 76 81
48 47 46 45 44 55 74 77 80
37 38 39 40 43 56 73 78 79
36 35 34 41 42 57 72 71 70
31 32 33 14 13 58 59 68 69
30 17 16 15 12 61 60 67 66
29 18 19 20 11 62 63 64 65
28 25 24 21 10 1 2 3 4
27 26 23 22 9 8 7 6 5
 
Solution 2:
9 10 13 14 19 20 63 64 65
8 11 12 15 18 21 62 61 66
7 6 5 16 17 22 59 60 67
34 33 4 3 24 23 58 57 68
35 32 31 2 25 54 55 56 69
36 37 30 1 26 53 74 73 70
39 38 29 28 27 52 75 72 71
40 43 44 47 48 51 76 77 78
41 42 45 46 49 50 81 80 79
 
Problem, no starting (1) nor end (225) points (2.344 seconds):
109 0 0 0 0 0 0 0 0 0 0 0 0 0 43
0 0 0 0 0 0 0 65 0 0 0 0 0 0 0
0 0 101 100 0 92 0 76 0 68 0 48 3 0 0
0 0 102 97 0 0 80 0 74 0 0 49 6 0 0
0 0 0 0 0 0 79 0 73 0 0 0 0 0 0
0 0 116 0 0 0 0 0 0 0 0 0 10 0 0
0 0 0 118 217 0 0 0 0 0 55 52 0 0 0
0 121 120 0 0 0 0 213 0 0 0 0 12 35 0
0 0 0 166 167 0 0 0 0 0 205 204 0 0 0
0 0 162 0 0 0 0 0 0 0 0 0 14 0 0
0 0 0 0 0 0 173 0 177 0 0 0 0 0 0
0 0 156 153 0 0 150 0 178 0 0 201 16 0 0
0 0 155 154 0 144 0 180 0 188 0 200 17 0 0
0 0 0 0 0 0 0 183 0 0 0 0 0 0 0
135 0 0 0 0 0 0 0 0 0 0 0 0 0 21
 
Solution:
109 108 87 86 85 84 83 64 63 62 61 46 45 44 43
110 107 88 89 90 91 82 65 66 67 60 47 2 1 42
111 106 101 100 99 92 81 76 75 68 59 48 3 4 41
112 105 102 97 98 93 80 77 74 69 58 49 6 5 40
113 104 103 96 95 94 79 78 73 70 57 50 7 8 39
114 115 116 225 224 223 222 221 72 71 56 51 10 9 38
123 122 117 118 217 218 219 220 209 208 55 52 11 36 37
124 121 120 119 216 215 214 213 210 207 54 53 12 35 34
125 164 165 166 167 168 169 212 211 206 205 204 13 32 33
126 163 162 161 160 171 170 175 176 191 192 203 14 31 30
127 128 157 158 159 172 173 174 177 190 193 202 15 28 29
130 129 156 153 152 151 150 179 178 189 194 201 16 27 26
131 132 155 154 143 144 149 180 181 188 195 200 17 24 25
134 133 138 139 142 145 148 183 182 187 196 199 18 23 22
135 136 137 140 141 146 147 184 185 186 197 198 19 20 21
</pre>
 
=={{header|Prolog}}==
<langsyntaxhighlight lang="prolog">/*
* Solver
*/
Line 2,440 ⟶ 2,685:
_, 29, _, _, 40, _, _, 47, _,
31, _, _, _, 39, _, _, _, 45
]).</langsyntaxhighlight>
{{out}}
<pre>
Line 2,483 ⟶ 2,728:
 
=={{header|Python}}==
{{incorrect|Python|3rd solution has "00 00" in it where "02 01" shd be}}
<lang python>
<syntaxhighlight lang="python">
from sys import stdout
neighbours = [[-1, 0], [0, -1], [1, 0], [0, 1]]
Line 2,582 ⟶ 2,828:
" . . . . 72 . . . . . . 35 . . . 49 . . . 29 . . 40 . . 47 . 31 . . . 39 . . . 45", 9, 9)
show_result(r)
</langsyntaxhighlight>{{out}}<pre>
49 50 51 52 53 54 75 76 81
48 47 46 45 44 55 74 77 80
Line 2,623 ⟶ 2,869:
 
<code>hidato-family-solver.rkt</code>
<langsyntaxhighlight lang="racket">#lang racket
;;; Used in my solutions of:
;;; "Solve a Hidato Puzzle"
Line 2,717 ⟶ 2,963:
[(solution-starting-at 0) => values]))
(and sltn (hash->puzzle sltn)))</langsyntaxhighlight>
 
<langsyntaxhighlight lang="racket">#lang racket
(require "hidato-family-solver.rkt")
 
Line 2,753 ⟶ 2,999:
#(0 38 0 0 0 0 0 72 0)
#(0 43 44 47 48 51 76 77 0)
#(0 0 0 0 0 0 0 0 0)))))</langsyntaxhighlight>
 
{{out}}
Line 2,787 ⟶ 3,033:
* [[Solve the no connection puzzle#Raku|Solve the no connection puzzle]]
 
<syntaxhighlight lang="raku" perl6line>my @adjacent = [-1, 0],
[ 0, -1], [ 0, 1],
[ 1, 0];
Line 2,903 ⟶ 3,149:
say "$tries tries";
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,937 ⟶ 3,183:
 
''Hidato'' &nbsp; and &nbsp; ''Numbrix'' &nbsp; are registered trademarks.
<langsyntaxhighlight lang="rexx">/*REXX program solves a Numbrix (R) puzzle, it also displays the puzzle and solution. */
maxR= 0; maxC= 0; maxX= 0; /*define maxR, maxC, and maxX. */
minR= 9e9; minC= 9e9; minX= 9e9; /* " minR, minC, " minX. */
Line 2,996 ⟶ 3,242:
say _
end /*r*/
say; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the input of:}} <br>
<tt> 1 1 . . . . . . . . ./2 1 . . 24 21 . 1 2 . ./3 1 . 18 . . 11 . . 64 ./4 1 . 17 . . . . . 67 ./5 1 . . 33 . . . 59 . ./6 1 . 35 . . . . . 71 ./7 1 . 38 . . 43 . . 78 ./8 1 . . 46 45 . 55 74 . ./9 1 . . . . . . . . . </tt>
Line 3,051 ⟶ 3,297:
=={{header|Ruby}}==
This solution uses HLPsolver from [[Solve_a_Hidato_puzzle#With_Warnsdorff | here]]
<langsyntaxhighlight lang="ruby">require 'HLPsolver'
 
ADJACENT = [[-1, 0], [0, -1], [0, 1], [1, 0]]
Line 3,079 ⟶ 3,325:
0 0 0 0 0 0 0 0 0
EOS
HLPsolver.new(board2).solve</langsyntaxhighlight>
Which produces:
<pre>
Line 3,129 ⟶ 3,375:
=={{header|SystemVerilog}}==
 
<langsyntaxhighlight lang="systemverilog">
 
//////////////////////////////////////////////////////////////////////////////
Line 3,255 ⟶ 3,501:
end
endprogram
</syntaxhighlight>
</lang>
 
Running the above program in ncverilog
Line 3,285 ⟶ 3,531:
Following loosely the structure of [[Solve_a_Hidato_puzzle#Tcl]].
 
<langsyntaxhighlight Tcllang="tcl"># Loop over adjacent pairs in a list.
# Example:
# % eachpair {a b} {1 2 3} {puts $a $b}
Line 3,481 ⟶ 3,727:
puts "\n== No Solution for Puzzle $i =="
}
}</langsyntaxhighlight>
 
{{Out}}
Line 3,533 ⟶ 3,779:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./sort" for Sort
import "./fmt" for Fmt
 
var example1 = [
Line 3,621 ⟶ 3,867:
if (solve.call(startRow, startCol, 1, 0)) printResult.call(n + 1)
n = n + 1
}</langsyntaxhighlight>
 
{{out}}
Line 3,651 ⟶ 3,897:
 
=={{header|zkl}}==
{{incorrect|zkl|[Maybe], see python issue, which is not evident in the output here...}}
{{trans|Python}}
This code solves Hidato, Hopido and Numbrix puzzles.
<langsyntaxhighlight lang="zkl"> // Solve Hidato/Hopido/Numbrix puzzles
class Puzzle{ // hold info concerning this puzzle
var board, nrows,ncols, cells,
Line 3,710 ⟶ 3,957:
False
}
} // Puzzle</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">hi1:= // 0==empty cell, X==not a cell
#<<<
"0 0 0 0 0 0 0 0 0
Line 3,747 ⟶ 3,994:
puzzle.print_board();
println();
}</langsyntaxhighlight>
{{out}}
<pre>
7,795

edits