Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/Gray-code/Prolog/gray-code-1.pro
Normal file
10
Task/Gray-code/Prolog/gray-code-1.pro
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
to_gray(N, G) :-
|
||||
N0 is N >> 1,
|
||||
G is N xor N0.
|
||||
|
||||
from_gray(G, N) :-
|
||||
( G > 0
|
||||
-> S is G >> 1,
|
||||
from_gray(S, N0),
|
||||
N is G xor N0
|
||||
; N is G ).
|
||||
31
Task/Gray-code/Prolog/gray-code-2.pro
Normal file
31
Task/Gray-code/Prolog/gray-code-2.pro
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
:- use_module(library(apply)).
|
||||
|
||||
to_gray(N, G) :-
|
||||
N0 is N >> 1,
|
||||
G is N xor N0.
|
||||
|
||||
from_gray(G, N) :-
|
||||
( G > 0
|
||||
-> S is G >> 1,
|
||||
from_gray(S, N0),
|
||||
N is G xor N0
|
||||
; N is G ).
|
||||
|
||||
make_num(In, Out) :-
|
||||
atom_to_term(In, Out, _),
|
||||
integer(Out).
|
||||
|
||||
write_record(Number, Gray, Decoded) :-
|
||||
format('~w~10|~2r~10+~2r~10+~2r~10+~w~n',
|
||||
[Number, Number, Gray, Decoded, Decoded]).
|
||||
|
||||
go :-
|
||||
setof(N, between(0, 31, N), Numbers),
|
||||
maplist(to_gray, Numbers, Grays),
|
||||
maplist(from_gray, Grays, Decodeds),
|
||||
format('~w~10|~w~10+~w~10+~w~10+~w~n',
|
||||
['Number', 'Binary', 'Gray', 'Decoded', 'Number']),
|
||||
format('~w~10|~w~10+~w~10+~w~10+~w~n',
|
||||
['------', '------', '----', '-------', '------']),
|
||||
maplist(write_record, Numbers, Grays, Decodeds).
|
||||
go :- halt(1).
|
||||
Loading…
Add table
Add a link
Reference in a new issue