Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
9
Task/Gray-code/Nim/gray-code-1.nim
Normal file
9
Task/Gray-code/Nim/gray-code-1.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
proc grayEncode(n: int): int =
|
||||
n xor (n shr 1)
|
||||
|
||||
proc grayDecode(n: int): int =
|
||||
result = n
|
||||
var t = n
|
||||
while t > 0:
|
||||
t = t shr 1
|
||||
result = result xor t
|
||||
4
Task/Gray-code/Nim/gray-code-2.nim
Normal file
4
Task/Gray-code/Nim/gray-code-2.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import strutils, strformat
|
||||
|
||||
for i in 0 .. 32:
|
||||
echo &"{i:>2} => {toBin(grayEncode(i), 6)} => {grayDecode(grayEncode(i)):>2}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue