Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Gray-code/Logo/gray-code-1.logo
Normal file
13
Task/Gray-code/Logo/gray-code-1.logo
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
to gray_encode :number
|
||||
output bitxor :number lshift :number -1
|
||||
end
|
||||
|
||||
to gray_decode :code
|
||||
local "value
|
||||
make "value 0
|
||||
while [:code > 0] [
|
||||
make "value bitxor :code :value
|
||||
make "code lshift :code -1
|
||||
]
|
||||
output :value
|
||||
end
|
||||
29
Task/Gray-code/Logo/gray-code-2.logo
Normal file
29
Task/Gray-code/Logo/gray-code-2.logo
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
to format :str :width [pad (char 32)]
|
||||
while [(count :str) < :width] [
|
||||
make "str word :pad :str
|
||||
]
|
||||
output :str
|
||||
end
|
||||
|
||||
; Output binary representation of a number
|
||||
to binary :number [:width 1]
|
||||
local "bits
|
||||
ifelse [:number = 0] [
|
||||
make "bits 0
|
||||
] [
|
||||
make "bits "
|
||||
while [:number > 0] [
|
||||
make "bits word (bitand :number 1) :bits
|
||||
make "number lshift :number -1
|
||||
]
|
||||
]
|
||||
output (format :bits :width 0)
|
||||
end
|
||||
|
||||
repeat 32 [
|
||||
make "num repcount - 1
|
||||
make "gray gray_encode :num
|
||||
make "decoded gray_decode :gray
|
||||
print (sentence (format :num 2) ": (binary :num 5) ": (binary :gray 5) ":
|
||||
(binary :decoded 5) ": (format :decoded 2)) ]
|
||||
bye
|
||||
Loading…
Add table
Add a link
Reference in a new issue