Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Gray-code/Picat/gray-code.picat
Normal file
26
Task/Gray-code/Picat/gray-code.picat
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
go =>
|
||||
foreach(I in 0..2**5-1)
|
||||
G = gray_encode1(I),
|
||||
E = gray_decode1(G),
|
||||
printf("%2d %6w %2d %6w %6w %2d\n",I,I.to_binary_string,
|
||||
G, G.to_binary_string,
|
||||
E.to_binary_string, E)
|
||||
end,
|
||||
nl,
|
||||
println("Checking 2**1300:"),
|
||||
N2=2**1300,
|
||||
G2=gray_encode1(N2),
|
||||
E2=gray_decode1(G2),
|
||||
% println(g2=G2),
|
||||
% println(e2=E2),
|
||||
println(check=cond(N2==E2,same,not_same)),
|
||||
nl.
|
||||
|
||||
gray_encode1(N) = N ^ (N >> 1).
|
||||
gray_decode1(N) = P =>
|
||||
P = N,
|
||||
N := N >> 1,
|
||||
while (N != 0)
|
||||
P := P ^ N,
|
||||
N := N >> 1
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue