Help us understand the problem. What is going on with this article?

第四回オフラインリアルタイムどう書くの解答例(Prolog)

More than 5 years have passed since last update.

根性で書いてみました。ぜーはーぜーはー。
ちょっとだけPrologがわかってきた気がします。

考え方はC++版 ( http://qiita.com/items/3d148710b250061f5dbc ) と同じです。

str2pos([X00, Y00, C, X01, Y01, C, X02, Y02, C, X03, Y03], [[X10, Y10], [X11, Y11], [X12, Y12], [X13, Y13]]) :-
    X10 is X00 - 48, Y10 is Y00 - 48,
    X11 is X01 - 48, Y11 is Y01 - 48,
    X12 is X02 - 48, Y12 is Y02 - 48,
    X13 is X03 - 48, Y13 is Y03 - 48.

normalize([[X00, Y00], [X01, Y01], [X02, Y02], [X03, Y03]], [[X10, Y10], [X11, Y11], [X12, Y12], [X13, Y13]]) :-
    min_member(Xmin, [X00, X01, X02, X03]), min_member(Ymin, [Y00, Y01, Y02, Y03]),
    X10 is X00 - Xmin, Y10 is Y00 - Ymin,
    X11 is X01 - Xmin, Y11 is Y01 - Ymin, 
    X12 is X02 - Xmin, Y12 is Y02 - Ymin, 
    X13 is X03 - Xmin, Y13 is Y03 - Ymin.
normalize([_,_,_], [ [0,0], [0,0], [0,0], [0,0] ]). 
normalize([_,_],   [ [0,0], [0,0], [0,0], [0,0] ]). 
normalize([_],     [ [0,0], [0,0], [0,0], [0,0] ]). 

tetromino([ [0, 0], [0, 1], [0, 2], [1, 2] ], 'L') :- !.
tetromino([ [0, 0], [0, 1], [1, 0], [2, 0] ], 'L') :- !.
tetromino([ [0, 0], [1, 0], [1, 1], [1, 2] ], 'L') :- !.
tetromino([ [0, 1], [1, 1], [2, 0], [2, 1] ], 'L') :- !.
tetromino([ [0, 0], [0, 1], [1, 1], [2, 1] ], 'L') :- !.
tetromino([ [0, 0], [0, 1], [0, 2], [1, 0] ], 'L') :- !.
tetromino([ [0, 0], [1, 0], [2, 0], [2, 1] ], 'L') :- !.
tetromino([ [0, 2], [1, 0], [1, 1], [1, 2] ], 'L') :- !.
tetromino([ [0, 0], [1, 0], [2, 0], [3, 0] ], 'I') :- !.
tetromino([ [0, 0], [0, 1], [0, 2], [0, 3] ], 'I') :- !.
tetromino([ [0, 0], [1, 0], [1, 1], [2, 0] ], 'T') :- !.
tetromino([ [0, 0], [0, 1], [0, 2], [1, 1] ], 'T') :- !.
tetromino([ [0, 1], [1, 0], [1, 1], [2, 1] ], 'T') :- !.
tetromino([ [0, 1], [1, 0], [1, 1], [1, 2] ], 'T') :- !.
tetromino([ [0, 0], [0, 1], [1, 0], [1, 1] ], 'O') :- !.
tetromino([ [0, 0], [0, 1], [1, 1], [1, 2] ], 'S') :- !.
tetromino([ [0, 1], [0, 2], [1, 0], [1, 1] ], 'S') :- !.
tetromino([ [0, 1], [1, 0], [1, 1], [2, 0] ], 'S') :- !.
tetromino([ [0, 0], [1, 0], [1, 1], [2, 1] ], 'S') :- !.
tetromino(_,                        '-') :- !.

solve([]).
solve([S0|SS]) :- str2pos(S0, P0), sort(P0, P1), normalize(P1, P2), tetromino(P2, R2), writeln(R2), solve(SS).

result :- see('testpattern.txt'), read(SS), seen, solve(SS).
testpattaern.txt
[ "55,55,55,55",
  "07,17,06,05",
  "21,41,31,40",
  "62,74,73,72",
  "84,94,74,75",
  "48,49,57,47",
  "69,89,79,68",
  "90,82,91,92",
  "13,23,03,24",
  "24,22,25,23",
  "51,41,21,31",
  "64,63,62,65",
  "49,69,59,79",
  "12,10,21,11",
  "89,99,79,88",
  "32,41,43,42",
  "27,16,36,26",
  "68,57,58,67",
  "72,62,61,71",
  "25,24,15,14",
  "43,54,53,42",
  "95,86,76,85",
  "72,73,84,83",
  "42,33,32,23",
  "66,57,67,58",
  "63,73,52,62",
  "76,68,77,67",
  "12,11,22,01",
  "05,26,06,25",
  "03,11,13,01",
  "11,20,00,21",
  "84,95,94,86",
  "36,56,45,35",
  "41,33,32,43",
  "75,94,84,95",
  "27,39,28,37",
  "45,34,54,35",
  "24,36,35,26",
  "27,27,27,27",
  "55,44,44,45",
  "70,73,71,71",
  "67,37,47,47",
  "43,45,41,42",
  "87,57,97,67",
  "49,45,46,48",
  "63,63,52,72",
  "84,86,84,95",
  "61,60,62,73",
  "59,79,69,48",
  "55,57,77,75" ].
emattsan
ソフトウェアエンジニア、言語オタク
http://d.hatena.ne.jp/E_Mattsan/
esm
We build applications which work well and make customers happy.
http://www.esm.co.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした