Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sum([],0).
- sum([X|Xs],Total):- sum(Xs,Rest) , Total is X+Rest.
- add_N_spaces(Line, Line,0).
- add_N_spaces([' '|Line],RestLine,N) :-N>0, N1 is N-1,
- add_N_spaces(Line, RestLine,N1).
- add_N_stars(Line, Line,0).
- add_N_stars([*|Line],RestLine,N) :- N>0,N1 is N-1,
- add_N_stars(Line, RestLine,N1).
- vecLine2BitLine(X,[Y|Ys],N,BitLine):-
- LastSpace is Y-1,
- last(X,LastStarLoc),
- last([Y|Ys],LastStarLen),
- vecLine2BitLine_aux(X,[Y|Ys],N,Tmp,LastSpace),
- LastSpaces = N - LastStarLoc - LastStarLen + 1,
- add_N_spaces(ListOfSpaces,[],LastSpaces),
- append(Tmp,ListOfSpaces,BitLine).
- vecLine2BitLine_aux([],[],_,[],_).
- vecLine2BitLine_aux([X|Xs],[Y|Ys],N,BitLine,LastSpace):-
- NumOfSpaces is Y-LastSpace ,
- add_N_spaces(ListOfSpaces,[],NumOfSpaces),
- add_N_stars(ListOfStars,[],X),
- append(ListOfSpaces,ListOfStars,Tmp),
- length(Tmp,Size),
- NewN is N-Size,
- LastSpace2 is X+Y,
- vecLine2BitLine_aux(Xs,Ys,NewN,Tmp2,LastSpace2),
- append(Tmp,Tmp2,BitLine).
- insertBegining([Element|List],List,Element).
- makeListc([],_,[]).
- makeListc([M|Rest],Index,List):-
- nth1(Index,M,Element),
- insertBegining(AlmostList,[],Element),
- makeListc(Rest,Index,Temp),
- append(AlmostList,Temp,List).
- trans(Matrix,TransposedMatrix):-
- length(Matrix,Len),
- NLen is Len+1,
- trans_aux(Matrix,1,TransposedMatrix,NLen).
- trans_aux(_,Len,[],Len).
- trans_aux([M|Rest],Index,NewMatrix,Len):-
- makeListc([M|Rest],Index,Listi),
- IndexNew is Index + 1,
- trans_aux([M|Rest],IndexNew,Almost,Len),
- insertBegining(NewMatrix,Almost,Listi).
- trim(L,N,S) :- % to trim N elements from a list
- append(P,S,L) , % - split L into a prefix and suffix
- length(P,N) .
- starsInArow([' '|_],0).
- starsInArow([' '],0).
- starsInArow([],0).
- starsInArow([*|RestBit],N):-
- starsInArow(RestBit,C),
- N is C + 1.
- isBitLineLegal([],[]).
- isBitLineLegal([' '|[]],[]).
- isBitLineLegal([' '|RestBit],[LenLine|RestLine]):-
- isBitLineLegal(RestBit,[LenLine|RestLine]).
- isBitLineLegal([*|RestBit],[LenLine|RestLine]):-
- starsInArow([*|RestBit],N),
- N =:= LenLine ,
- trim([*|RestBit],LenLine,S),
- isBitLineLegal(S,RestLine).
- vecLineAll2BitLineAll([],[],_,[]).
- vecLineAll2BitLineAll([LenLineAll|RestL],[PosLineAll|RestP],N,BitLineAll):-
- vecLine2BitLine(LenLineAll,PosLineAll,N,Temp),
- vecLineAll2BitLineAll(RestL,RestP,N,Rest),
- insertBegining(BitLineAll,Rest,Temp).
- isBitLineLegalAll([],[]).
- isBitLineLegalAll([BitLineAll|RestBit],[LenLineAll|RestL]):-
- isBitLineLegal(BitLineAll,LenLineAll),
- isBitLineLegalAll(RestBit,RestL).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement