A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
9
Task/Gray-code/Erlang/gray-code-1.erl
Normal file
9
Task/Gray-code/Erlang/gray-code-1.erl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
-module(gray).
|
||||
-export([encode/1, decode/1]).
|
||||
|
||||
encode(N) -> N bxor (N bsr 1).
|
||||
|
||||
decode(G) -> decode(G,0).
|
||||
|
||||
decode(0,N) -> N;
|
||||
decode(G,N) -> decode(G bsr 1, G bxor N).
|
||||
11
Task/Gray-code/Erlang/gray-code-2.erl
Normal file
11
Task/Gray-code/Erlang/gray-code-2.erl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
-module(testgray).
|
||||
|
||||
test_encode(N) ->
|
||||
G = gray:encode(N),
|
||||
D = gray:decode(G),
|
||||
io:fwrite("~2B : ~5.2.0B : ~5.2.0B : ~5.2.0B : ~2B~n", [N, N, G, D, D]).
|
||||
|
||||
test_encode(N, N) -> [];
|
||||
test_encode(I, N) when I < N -> test_encode(I), test_encode(I+1, N).
|
||||
|
||||
main(_) -> test_encode(0,32).
|
||||
Loading…
Add table
Add a link
Reference in a new issue