Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun {AndG X Y}
- case X#Y of (H|T)#(I|V)
- then H*I|{AndG T V}
- [] nil#nil then nil
- else X*Y
- end
- end
- fun {OrG X Y}
- case X#Y of (H|T)#(I|V)
- then H+I-(H*I)|{OrG T V}
- [] nil#nil then nil
- else X+Y-(X*Y)
- end
- end
- fun {XorG X Y}
- case X#Y of (H|T)#(I|V)
- then H+I-2*H*I|{OrG T V}
- [] nil#nil then nil
- else X+Y-2*Y*X
- end
- end
- proc {FullAdder X Y Z C S}
- local
- A
- B
- D
- E
- F
- in
- A={AndG X Y}
- B={AndG Y Z}
- D={AndG X Z}
- E={XorG X Y}
- F={OrG B D}
- C={OrG A F}
- S={XorG Z E}
- end
- end
- fun {NFullAdder S1 S2}
- local
- fun{Reverse L Acc}
- case L of H|T then
- if Acc==nil then {Reverse T H|nil}
- else {Reverse T H|Acc}
- end
- else Acc
- end
- end
- fun{Listo L1 L2 Prev LSol}
- local
- X
- Y
- in
- case L1#L2 of (I|T)#(J|V) then
- {FullAdder I J Prev X Y}
- {Listo T V X Y|LSol}
- else LSol#Prev
- end
- end
- end
- fun{NListo L1 L2}
- case L1#L2 of (H|T)#(I|V) then
- {Listo {Reverse H nil} {Reverse I nil} 0 nil}|{NListo T V}
- else nil
- end
- end
- in
- {NListo S1 S2}
- end
- end
- SA SB S5 S6 SC
- S1 = [1 1 1 1 1]|[0 0 0 0 0]|[1 1 1 1 0]|S5
- S2 = [1 1 1 1 1]|[0 0 0 0 0]|[0 0 0 0 1]|S6
- thread SA=S1 end
- thread SB=S2 end
- thread SC = {NFullAdder SA SB} end
- thread {Browse SC} end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement