Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(shunt).
- -import(list,[position/2,take/2,drop/2,append/2]).
- -export([find/2]).
- -export([split/2]).
- -export([few/2]).
- find([],[]) -> [];
- find(Xs,Ys)-> {Hs,Ts}=split(Xs,hd(Ys)),
- State = append(Ts,Hs),
- Lone = length(Ts)+1,
- Ltwo = length(Hs),
- [{one,Lone},{two,Ltwo},{one,-Lone},{two,-Ltwo}|find(State,tl(Ys))].
- split(Train,E) ->
- N = position(Train,E), {take(Train,N-1),drop(Train,N)}.
- few([],[]) -> [];
- few(Xs,Ys)->
- if
- hd(Xs) == hd(Ys) ->
- find(tl(Xs),tl(Ys));
- hd(Xs) /= hd(Ys) ->
- {Hs,Ts}=split(Xs,hd(Ys)),
- State = append(Ts,Hs),
- [{one,length(Ts)+1},{two,length(Hs)},{one,-(length(Ts)+1)},{two,-length(Hs)}|find(State,tl(Ys))]
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement