Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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 ).

View 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).