yohei #4763(2007/12/11 18:06 GMT) [ Prolog ] Rating1/1=1.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
switch(['|'], [A], [A]). switch(['|','-','|'|S], [A,' ',B|L], [B,' ',C|L1]) :- switch(['|'|S], [A|L], [C|L1]). switch(['|',' ','|'|S], [A,' ',B|L], [A,' ',C|L1]) :- switch(['|'|S], [B|L], [C|L1]). amida_sub(Hs, []) :- atom_chars(H, Hs), writeln(H). amida_sub(Hs, [X|L]) :- writeln(X), atom_chars(X, Xs), switch(Xs, Hs, H1), amida_sub(H1, L). amida(A) :- concat_atom([H|L], '\n', A), writeln(H), atom_chars(H, Hs), amida_sub(Hs, L). :- amida('A B C D E | | |-| | |-| | |-| | |-| |-| |-| |-| | |-| | | |').
Rating1/1=1.00-0+
1 reply [ reply ]
yohei #4764(2007/12/11 18:08 GMT) Rating0/0=0.00
タグ書き間違えました,SWI-Prologです.
[ reply ]
yohei
#4763()
[
Prolog
]
Rating1/1=1.00
switch(['|'], [A], [A]). switch(['|','-','|'|S], [A,' ',B|L], [B,' ',C|L1]) :- switch(['|'|S], [A|L], [C|L1]). switch(['|',' ','|'|S], [A,' ',B|L], [A,' ',C|L1]) :- switch(['|'|S], [B|L], [C|L1]). amida_sub(Hs, []) :- atom_chars(H, Hs), writeln(H). amida_sub(Hs, [X|L]) :- writeln(X), atom_chars(X, Xs), switch(Xs, Hs, H1), amida_sub(H1, L). amida(A) :- concat_atom([H|L], '\n', A), writeln(H), atom_chars(H, Hs), amida_sub(Hs, L). :- amida('A B C D E | | |-| | |-| | |-| | |-| |-| |-| |-| | |-| | | |').Rating1/1=1.00-0+
1 reply [ reply ]