オフラインリアルタイムどう書くF07の問題

問題はこちら->http://nabetani.sakura.ne.jp/hena/ordf07walk/
リストより配列のほうが簡単と思われますので、nimで解いてみました。

```nim
import os
import strutils

var field:array[7,array[7,int]]
for i in 0..6:
    field[i][0]= -1
    field[i][6]= -1
    field[0][i]= -1
    field[6][i]= -1

const str0 =["12345/29496/19485/09594/82457",
             "88011/79992/69992/69993/55443",
             "45020/46871/46971/36771/33222",
             "23373/18323/34943/20613/79772",
             "55761/98788/56838/92226/57838",
             "96778/95391/95497/11300/85047"]

proc check(x,y:int)

proc check1(x,y,n:int)=
  var m=field[x][y]
  if m>=0:
     if abs(m-n)<2:
        check(x,y)

proc check(x,y:int)=
  var n=field[x][y]
  field[x][y]=(-1)
  check1(x+1,y,n)
  check1(x-1,y,n)
  check1(x,y+1,n)
  check1(x,y-1,n)

proc solve()=
  for data in str0:
      var strseq = data.split("/")
      var str:string
      for i in 0..4:
          str = strseq[i]
          for j in 0..4:
              field[i+1][j+1]=int(str[j])-48
      var str1=""
      check(1,3)
      for i in 1..5:
          str1=str1 & "/"
          for j in 1..5:
              var tmp=field[i][j]
              if tmp<0:
                 str1=str1 & "*"
              else:
                 str1=str1 & tmp.intTostr
      delete(str1,0,0)
      echo(str1)

solve()
```
prologでも配列を定義して解いてみました。
だいぶ無駄がありそうですが、データが少ないので問題ありません。

```prolog
pre([]).
pre([_,A,B|T]):-
         split_string(A,"/","",L0),atomics_to_string(L0,L),
         atom_chars(L,L1),functor(Field1,array,25),functor(Field2,array,25),
         maked(Field1,1,L1),solve(Field1,Field2,[(1,3)],S),
         (S==B->Str=" yes ";Str=" no  "),write(Str),write(S),write("\n"),pre(T).

solve(F1,F2,[],S):-mkstr(F1,F2,"",1,S).
solve(F1,F2,[H|T],S):-solve1(F1,F2,H,L),append(T,L,T1),solve(F1,F2,T1,S).
solve1(F1,F2,(X,Y),L):-
         N is (X-1)*5+Y,arg(N,F1,V),arg(N,F2,-9),
         findall((X1,Y1),check0(F1,F2,V,X,Y,(X1,Y1)),L).

mkstr(_,_,S,26,S):-!.
mkstr(F1,F2,S,N,RS):-
         arg(N,F2,V2),(var(V2)->(arg(N,F1,V1),number_chars(V1,[C]));C="*"),
         string_concat(S,C,S1),((N mod 5 =:=0,N\=25)->string_concat(S1,"/",S2);S2=S1),
         N1 is N+1,mkstr(F1,F2,S2,N1,RS).

check0(F1,F2,V,X,Y,(X1,Y1)):-X1 is X+1,Y1=Y,check1(F1,F2,V,X1,Y1).
check0(F1,F2,V,X,Y,(X1,Y1)):-X1 is X-1,Y1=Y,check1(F1,F2,V,X1,Y1).
check0(F1,F2,V,X,Y,(X1,Y1)):-Y1 is Y+1,X1=X,check1(F1,F2,V,X1,Y1).
check0(F1,F2,V,X,Y,(X1,Y1)):-Y1 is Y-1,X1=X,check1(F1,F2,V,X1,Y1).
check1(_,_,_,X,Y):-(X<1;X>5;Y<1;Y>5),!,fail.
check1(F1,F2,V,X,Y):-N is (X-1)*5+Y,arg(N,F2,V2),var(V2),arg(N,F1,V1),abs(V-V1)<2.

maked(_,_,[]).
maked(Field,I,[H|T]):-atom_number(H,N),arg(I,Field,N),I1 is I+1,maked(Field,I1,T).

start:-str(S),split_string(S,"\s,\n","\s",L0),pre(L0),!.
%start.

str("0   12345/29496/19485/09594/82457   *****/*9*9*/*9*8*/*9*9*/82**7
1   12345/11011/65432/71999/65432   *****/*****/*****/*1999/*****
2   11111/11111/11111/11111/11111   *****/*****/*****/*****/*****
3   88011/79992/69992/69993/55443   *****/*****/*****/*****/*****
4   45000/46871/46971/36771/33222   *****/*****/*****/*****/*****
5   45020/46871/46971/36771/33222   45*20/46871/46971/36771/33222
6   21550/70587/91453/20343/96389   21**0/70*87/91***/20***/96*89
7   74438/33621/27261/91783/17242   7***8/**6**/*726*/91783/17242
8   33422/69349/24553/04129/52082   ***22/69**9/2***3/0*129/52082
9   24573/71679/48704/19786/91834   2***3/71**9/4**04/1***6/91*34
10  23373/18323/34943/20613/79772   ***7*/*8***/349**/2061*/7977*
11  78255/11128/48232/09427/78865   78*55/****8/48***/094*7/78865
12  82972/68827/34779/89986/45211   82*72/6**27/34**9/****6/45211
13  16702/45602/15203/44906/64628   1**02/***02/1*203/**906/6*628
14  52832/05787/66710/81714/75749   52*32/0****/***10/81*14/75*49
15  84555/63383/52164/43916/20026   8****/***83/***64/**916/20026
16  72261/21028/90154/71654/51861   7**61/***28/9**54/7*654/5*861
17  98787/56708/35188/42175/68339   *****/***0*/3*1**/421*5/68339
18  92767/16790/84897/69765/75734   92***/1***0/84**7/69***/75***
19  40454/92023/68721/31223/92629   40***/920**/687**/3****/9*6*9
20  55761/98788/56838/92226/57838   55**1/*****/56*3*/92226/57838
21  43367/35324/40338/35675/17028   ***67/*5**4/*0**8/*5675/17028
22  97490/41513/42468/23325/27098   97*90/4**13/4**68/****5/*7098
23  65658/53785/10987/14550/03167   ****8/*3**5/10***/14550/03167
24  96825/07774/18726/17112/37496   9**25/0***4/1**26/1*112/3*496
25  66674/65657/14666/32917/83223   ****4/*****/1****/3291*/83223
26  74344/97459/97302/14439/35689   7****/97**9/97*02/1***9/3**89
27  63956/98856/98586/88356/59386   63*56/***56/**586/**356/5*386
28  55204/29155/42023/28114/27173   55*04/29*55/42***/28***/27*7*
29  96259/76240/06333/98212/70575   96**9/76**0/06***/98***/70575
30  96778/95391/95497/11300/85047   9****/9**91/9**97/11*00/85047
31  12618/16611/96673/43535/82667   12*18/1**11/9***3/43*35/82***
32  84348/77650/49246/62965/07154   ****8/****0/492*6/62965/07154
33  21172/32169/46995/38254/43735   ***72/***69/*6995/*8254/**735
34  98528/96666/78713/82600/76116   98*28/9****/***13/*2*00/**116
35  56543/64480/21582/03631/46244   *****/***80/21*82/03*31/46244
36  42865/87706/56970/17609/39789   42*65/***06/**970/1**0*/39***
37  41774/61265/57974/29143/55908   41***/612**/579**/291**/55908
38  03797/09776/26074/20987/35589   03*9*/09***/260*4/20***/355**
39  72261/22155/23330/53106/43155   7**61/***55/****0/**106/**155
40  56420/39322/05102/76122/03879   56**0/39***/05***/76***/03879
41  77665/95657/13657/94094/13762   *****/9***7/13**7/94094/13762
42  66110/25706/49002/77901/36519   66***/257*6/49***/779**/365*9
43  21244/58340/37447/06079/25691   *****/58**0/37**7/06079/25691
44  10180/11677/22208/34867/28064   ***80/**677/***08/**867/*8064
45  34503/83687/42707/02558/12933   ***03/8**87/4**07/**558/**933").
```
2017.10.27追加
prologのほうcheck0が重複した感じでしたので少し改良しました。

```prolog
solve1(F1,F2,(X,Y),L):-
         N is (X-1)*5+Y,arg(N,F1,V),arg(N,F2,-9),
         X1 is X+1,X2 is X-1,Y1 is Y+1,Y2 is Y-1,L1= [(X1,Y),(X2,Y),(X,Y1),(X,Y2)],
         findall((X3,Y3),(member((X3,Y3),L1),check1(F1,F2,V,X3,Y3)),L).

mkstr(_,_,S,26,S):-!.
mkstr(F1,F2,S,N,RS):-
         arg(N,F2,V2),(var(V2)->(arg(N,F1,V1),number_chars(V1,[C]));C="*"),
         string_concat(S,C,S1),((N mod 5 =:=0,N\=25)->string_concat(S1,"/",S2);S2=S1),
         N1 is N+1,mkstr(F1,F2,S2,N1,RS).

check1(_,_,_,X,Y):-(X<1;X>5;Y<1;Y>5),!,fail.
check1(F1,F2,V,X,Y):-N is (X-1)*5+Y,arg(N,F2,V2),var(V2),arg(N,F1,V1),abs(V-V1)<2.

```