オフラインリアルタイムどう書く過去問（E09）

問題はこちら->http://nabetani.sakura.ne.jp/hena/orde09_penwa/
単純な図形でかつとっかかりがなさそうでしたので挑戦してみました。
元に戻ったかどうか確認するには座標を用いるしかなさそうだと思い、しばらくながめていましたら、
直交座標で五角形の各辺に対応する法線ベクトルを(±2,±1),(±1,±2),(0,±2),(2±,0)とし、
その値だけ移動するとすれば解けそうなので試してみました。
うまくいく理由は、四つの五角形が接する頂点の角度が90度（回転）で、
また左右、上下に対称な図形（反転）だからのようです。(つまり、(±1,±1),(0,±2)(±2,0)等も可)


```prolog
move(u,ru,r,rd).
move(u,lu,l,ld).
move(u,rd,l,ru).
move(u,ld,r,lu).
move(u,vd,d,vd).
move(d,ru,l,rd).
move(d,lu,r,ld).
move(d,rd,r,ru).
move(d,ld,l,lu).
move(r,vd,l,vd).
move(A,DA,B,DB):-move(B,DB,A,DA).

rot(lu,c,ru).
rot(ru,c,rd).
rot(rd,c,vd).
rot(vd,c,ld).
rot(ld,c,lu).
rot(A,a,B):-rot(B,c,A).

vec(u,ru,1,2).
vec(u,lu,-1,2).
vec(u,ld,-2,-1).
vec(u,vd,0,-2).
vec(u,rd,2,-1).
vec(d,D,X,Y):-vec(u,D,X1,Y1),X is -X1,Y is -Y1.
vec(r,D,X,Y):-vec(u,D,X1,Y1),X is Y1,Y is -X1.
vec(l,D,X,Y):-vec(r,D,X1,Y1),X is -X1,Y is -Y1.

solve(_,_,_,_,[],_,'-').
solve(X,Y,P,D,['F'|T],L,R):-!,
         vec(P,D,X1,Y1),plus(X,X1,X2),plus(Y,Y1,Y2),move(P,D,P1,D1),
         (nth0(N0,L,(X2,Y2))->(length(L,N1),N is N1-N0-1,concat_atom([N1,N],',',R))
         ;solve(X2,Y2,P1,D1,T,[(X2,Y2)|L],R)).
solve(X,Y,P,D,[H|T],L,R):-rot(D,H,D1),solve(X,Y,P,D1,T,L,R).

start:-str(S),split_string(S,"\s\n","\s",L),go(L),!.

go([]).
go([A,B,C|T]):-
       atom_chars(B,L),atom_chars(C1,C), solve(0,0,d,vd,L,[(0,0)],R),
       (R==C1->Str="good ";Str=" bad "),write(Str),writeln(R),go(T).

str("0       FcFcFaF         3,0
1       FccFaaFcFcF     -
2       ccFaF   -
3       cFcFaaF         -
4       aFccFcFcF       4,1
5       cFaFaFaFaaF     4,0
6       cFccFaFaaFaF    5,1
7       cFaaFaaFcFcFccF         5,2
8       aaFaFaaFaFccFaFccF      6,0
9       aaFaaFcFccFcFccFccFaF         6,1
10      aFccFccFaaFccFcFcFcFaF  7,4
11      ccFaaFaaFaFccFaaFaFcFccFaaF     -
12      aaFaFaFcFaFaaFaFaFaaFccFaaFaaF  8,3
13      aaFccFaFaFccFaaFaaFaaFccFccFcFaFaF      13,10
14      aFaFaaFaaFaaFccFaFccFaFaaFccFccFaaFccF  11,0
15      ccFccFcFaaFaaFaFccFaaFaFcFaaFaaFcFcFcF  10,2
16      aaFaaFaaFccFccFaFaaFaaFaFccFcFcFccFaaFaFccFccF  10,3
17      ccFaFccFaaFaaFcFccFaFcFccFccFaaFccFaFaaFaFaFccF         11,3
18      cFcFaFaaFaFccFaaFcFaFaaFccFaFaaFccFaFcFaaFccFcF         12,0
19      cFaFaaFcFaaFaaFaFccFaaFcFaaFccFaaFccFaFcFccFaFaFaFcFcF  19,16
20      aFaFccFaaFccFccFaFccFaFaaFccFaaFccFcFccFaFaFccFaaFccFcF         15,11
21      aFccFccFccFaaFaaFcFcFaaFccFaFcFccFaaFaFcFaaFcFaFccFccFaFaF      23,20
22      cFaFaaFcFaFaaFccFccFaaFaFccFccFccFaFaFccFccFccFaaFcFcFcFaF      22,18
23      aFcFaFccFccFaFccFaaFaFaaFaaFaFcFaFcFcFcFaFaFaaFaaFaFaaFcFccFaF  14,4
24      cFaFaaFcFaFccFcFccFaFaaFaaFaFcFccFccFaFcFaFaaFccFaFaFccFcFaFaFaaF       22,19
25      aaFaaFaFcFccFaaFcFaaFccFaFaFcFaFaaFaFaFaFcFccFaFaaFcFcFccFccFccFcF      16,11
26      cFaaFaFcFaFaaFccFaaFaFccFccFaaFccFcFaFaaFaaFaFccFcFccFccFaFaaFcFcFaF    26,23
27      cFaaFccFaFcFaFcFaaFccFaFccFaaFcFaFaaFccFaaFccFcFaFaaFaFcFccFccFaFcFaaFccFcF     -
28      ccFccFaaFaFccFaaFaaFcFccFaaFaFcFccFccFccFaFaaFcFaFccFaaFcFcFaFccFaFccFaaFaaFaF  -
29      aaFccFaFccFccFaaFccFaFcFccFaFccFcFcFaFcFcFaaFaaFcFccFccFcFaFaaFaFcFcFaaFaaFaaF  19,5
30      aFaaFccFaFaaFaaFccFccFaFcFaaFaaFaaFccFaFccFaaFaaFaFccFccFcFaaFaFccFccFaFcFaaFccF        -
31      aaFaFaaFcFccFccFaFcFaaFaaFaFccFccFccFaFaaFccFcFaaFccFaaFccFaaFccFccFccFcFaaFcFaaFccF    30,23
32      aaFccFaFaaFccFcFaFccFaFcFccFaaFccFaFcFaaFccFaaFaFccFccFccFcFccFaFccFcFaaFaFcFccFcFaFaaF         32,17
33      ccFcFcFaFaaFaFaaFccFcFccFaFcFaFccFaaFcFccFcFaaFcFaaFcFaaFaaFcFaaFaFaFaFaaFccFaaFcFcFaFaF        18,14
34      ccFaFaaFaaFcFaaFaaFaaFaaFaaFaFccFcFaaFaFcFccFaaFcFaFaaFccFccFaaFcFaaFaaFaaFccFaaFcFcFaFaFccFaFcFccF     17,0
35      aaFccFccFaFcFaFcFaFccFccFccFaFccFccFcFaFcFaaFccFcFccFccFaaFcFccFaaFccFccFaFccFcFcFaaFaFccFcFaaFaaFcF    24,11
36      aaFccFaFccFaaFaaFcFaFcFaFcFaaFaaFccFaFcFaFaaFcFaaFaFcFaaFccFcFaaFccFaaFccFaaFccFcFaFcFaFccFaaFaaFccFaaF         -
37      aFaaFaFaaFcFccFaaFccFaFcFaaFccFccFcFcFaFaFcFccFcFccFaaFcFaFcFaaFcFaFaaFccFaaFccFaFaaFaFcFaFccFaFaaFaFaaF        17,14
38      aaFcFaaFccFaaFaaFcFaaFccFccFaFcFaFcFccFcFaaFaaFaFcFaFcFaaFcFaFaaFaFccFccFccFcFaFaFcFcFaFcFaaFcFaaFcFcFaaF       27,23
39      ccFaFccFaFcFaFccFcFaaFccFccFcFaFccFccFaaFaaFaFaaFcFaaFccFcFaaFcFccFaaFcFaFccFccFaFccFaaFaaFcFcFccFaFccFcFcF     25,18
40      cFcFccFaFaaFaaFccFccFcFccFccFaFcFaaFcFccFccFcFccFaFaFaFaFaFaaFaFcFaFccFcFccFaaFccFaaFccFcFaFaaFccFaFccFcFaaF    16,4
41      aFcFcFaaFcFaaFcFaFaaFaaFaaFaFcFccFccFccFaFaaFaFaaFaaFcFcFccFaFaaFcFaFaaFccFaaFcFccFcFcFccFaaFcFaFccFaaFaaFccF   19,15
42      ccFaaFcFaFccFaFccFaFcFaaFaaFccFaaFccFcFaFaFccFaFaaFaFaaFaFaaFaaFccFaaFaFcFaaFaFaFcFaaFcFaFaaFaaFcFccFaaFaFaFaF  22,17
43      aaFcFaaFaFcFccFccFaFaFccFaFaaFaFcFccFaaFaaFaaFcFccFccFaFaaFccFcFaFaFcFaaFcFcFcFccFccFaaFcFcFaFccFccFccFaaFcFaaFcF       14,5
44      cFcFaFccFaaFaFccFaFccFaaFaFccFaaFaaFccFaaFccFaaFccFaFaaFaFaFaaFaaFccFaFcFaaFcFcFaFaFcFcFcFaFaaFcFaFcFaaFccFccFcFaaFaFccF        10,1
45      ccFaFcFaaFcFccFaFccFaaFccFaaFaaFcFaaFccFaaFccFccFcFaaFaaFcFaaFccFaaFcFcFaaFaFaFccFcFaFaFaFccFccFccFccFccFccFcFcFccFccFcF        25,13
46      aFccFaFcFaFcFaaFaaFcFaaFccFaFaaFaFcFaFaaFaaFaaFccFaaFaaFccFccFccFccFccFaaFaFcFaFaFccFaFccFcFccFcFcFccFcFccFccFccFccFccFaF       18,8
47      cFaaFcFaaFaFcFccFaaFcFccFcFaFccFaaFaaFccFccFccFaFcFccFcFaaFcFcFccFcFccFaFaFccFccFcFaFaFaaFcFaFcFccFccFccFaaFaFaFccFcFccFccF     25,22
48      aaFcFccFcFaFcFaFaFcFccFaFaaFaFcFccFccFaaFccFccFaaFaaFccFaaFaaFccFaaFccFcFaaFaFcFaFcFccFaaFccFaFaFccFaaFcFaaFaFccFaaFaaFccFccFcFaF       -
49      aFaaFccFccFaaFaaFccFccFaaFaaFaFcFccFaFcFaaFaFccFaaFccFaFcFaFccFaaFaaFaFccFaFaaFaaFcFaaFccFaaFcFaFccFccFaaFaaFaaFaaFccFcFccFaaFaFaaFaaF  -
50      aaFcFccFccFaFccFaFccFaaFaaFaaFccFaaFaaFccFaaFccFaFaaFccFccFaaFcFccFaFccFcFaaFaFccFccFccFaaFaFccFccFaFaaFccFccFccFaaFccFccFaFaFcFaFccFccF        -").
```