Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Gray-code/Elixir/gray-code.elixir
Normal file
15
Task/Gray-code/Elixir/gray-code.elixir
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
defmodule Gray_code do
|
||||
use Bitwise
|
||||
def encode(n), do: bxor(n, bsr(n,1))
|
||||
|
||||
def decode(g), do: decode(g,0)
|
||||
|
||||
def decode(0,n), do: n
|
||||
def decode(g,n), do: decode(bsr(g,1), bxor(g,n))
|
||||
end
|
||||
|
||||
Enum.each(0..31, fn(n) ->
|
||||
g = Gray_code.encode(n)
|
||||
d = Gray_code.decode(g)
|
||||
:io.fwrite("~2B : ~5.2.0B : ~5.2.0B : ~5.2.0B : ~2B~n", [n, n, g, d, d])
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue