Comment detail

あみだくじ (Nested Flatten)
 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
| | |-| |
|-| | |-|
| |-| |-|
|-| |-| |
|-| | | |').

タグ書き間違えました,SWI-Prologです.

Index

Feed

Other

Link

Pathtraq

loading...