LoginSignup
0
0

More than 3 years have passed since last update.

オフラインどう書く第29回の解答

Last updated at Posted at 2019-08-17

問題はこちら->http://nabetani.sakura.ne.jp/hena/ord29devdice/

法則が見つかりませんでしたので、6の位置と向きのすべての場合を調べました。
展開図の下側は回転で上側と重なります。
入力のリストLとそれをrev/2で回転させたL2に該当するサイコロを、
diceの中からfind/2で集め、整形して表示しているだけです。

%SWI-Prolog version 7.4.2
%start.
%:-initialization(start). %ideone

dice([['6','4','1'],['D','3','5']]).
dice([['6','T','1'],['5','4','D']]).
dice([['T','6','4'],['2','1','5']]).
dice([['4','6','T'],['5','1','2']]).
dice([['1','T','6'],['D','4','5']]).
dice([['1','4','6'],['5','3','D']]).
dice([['S','5','1'],['4','D','3']]).
dice([['S','2','1'],['3','5','4']]).
dice([['2','S','5'],['4','1','T']]).
dice([['5','S','2'],['T','1','4']]).
dice([['1','2','S'],['4','5','3']]).
dice([['1','5','S'],['3','D','4']]).

sel(L,R):-find(L,L1),rev(L,L2),find(L2,L3),maplist(rev,L3,L4),append(L1,L4,R).

find(L,R):-findall(L,dice(L),R).

rev(L,R):-maplist(reverse,L,L1),reverse(L1,R).

tostr(L1,L2,R):-maplist(makes,L1,L2,R1),flatten(R1,R2),atomics_to_string(R2,",",R).

makes([],[],[]).
makes([H1|T1],[H2|T2],R):-
     makes(T1,T2,R1),atom_codes(H1,N),
     (N>118->(concat_atom([H1,H2],"=",S),R=[S|R1]);R=R1).

chan([],[]).
chan([H|T],R):-chan(T,R1),atom_codes(H,N),(N>118->R=[_|R1];R=[H|R1]).

solve(L,R):-
     maplist(chan,L,L1),sel(L1,L3),(L3=[]->R="none";(L3=[X]->tostr(L,X,R);R="many")).

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

pre([]).
pre([_,B,Q|T]):-
     atomics_to_string(L,"/",B),maplist(atom_chars,L,L1),solve(L1,R),disp(R,Q),pre(T).

disp(R,A):-(A==R->Str=" pass ";Str=" fail "),write(Str),writeln(R).

str("0  Tx4/5yz         x=1,y=S,z=2
1       14S/xyz         none
2       1w6/xyz         many
3       4w3/12S         w=5
4       4w3/S51         w=D
5       15S/wD4         w=3
6       54D/6Tw         w=1
7       S21/35w         w=4
8       w2x/354         w=S,x=1
9       wx1/54D         w=6,x=T
10      45w/12x         w=3,x=S
11      5w2/x14         w=S,x=T
12      Dw5/x41         w=3,x=6
13      w4x/1y6         w=D,x=5,y=T
14      15w/xy4         w=S,x=3,y=D
15      D35/wxy         w=6,x=4,y=1
16      4wx/51y         w=6,x=T,y=2
17      wTx/D4y         w=1,x=6,y=5
18      wxy/z3D         w=1,x=4,y=6,z=5
19      wx5/1yz         w=D,x=4,y=T,z=6
20      w53/xyz         w=4,x=1,y=2,z=S
21      wx1/yzD         w=6,x=T,y=5,z=4
22      wxS/3yz         w=1,x=5,y=D,z=4
23      wx2/y1z         w=5,x=S,y=T,z=4
24      4wx/2yz         w=1,x=T,y=S,z=5
25      T6w/xyz         w=4,x=2,y=1,z=5
26      Swx/yDz         w=5,x=1,y=4,z=3
27      wDx/yzS         w=3,x=4,y=1,z=5
28      wxy/5Sz         w=T,x=1,y=4,z=2
29      wSx/4yz         w=2,x=5,y=1,z=T
30      wxS/y5z         w=1,x=2,y=4,z=3
31      wxy/35z         w=S,x=2,y=1,z=4
32      wxy/T6z         w=2,x=1,y=5,z=4
33      wxD/yz1         w=5,x=4,y=6,z=T
34      1wx/yz5         w=T,x=6,y=D,z=4
35      wx3/y5z         w=4,x=D,y=S,z=1
36      6wx/y3z         w=4,x=1,y=D,z=5
37      5wx/4yz         w=1,x=2,y=6,z=T
38      wx4/Syz         w=3,x=5,y=2,z=1
39      w3D/xyz         w=5,x=1,y=4,z=6
40      w3x/6yz         w=D,x=5,y=4,z=1
41      wxy/z12         w=4,x=6,y=T,z=5
42      1wS/xyz         many
43      wxy/Dz5         many
44      3w4/xyz         many
45      wxy/5zD         many
46      wxy/Tz4         many
47      5wD/xyz         many
48      wDx/y5z         many
49      wxy/3z4         many
50      wxy/5z2         many
51      Dyz/S1x         none
52      w1z/xyS         none
53      15x/T6y         none
54      zy4/5x6         none
55      2xy/4Tz         none
56      xzS/y1w         none
57      Syx/4z5         none
58      xwS/Tzy         none
59      D5z/xwy         none
60      yxD/z35         none").
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0