Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/Gray-code/SenseTalk/gray-code.sensetalk
Normal file
37
Task/Gray-code/SenseTalk/gray-code.sensetalk
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
function BinaryToGray param1
|
||||
set theResult to ""
|
||||
repeat for each character in param1
|
||||
if the counter is equal to 1
|
||||
put it after theResult
|
||||
else
|
||||
if it is equal to previousCharacter
|
||||
put "0" after theResult
|
||||
else
|
||||
put "1" after theResult
|
||||
end if
|
||||
end if
|
||||
set previousCharacter to it
|
||||
end repeat
|
||||
return theResult
|
||||
end BinaryToGray
|
||||
|
||||
function GrayToBinary param1
|
||||
set theResult to param1
|
||||
repeat for each character in param1
|
||||
if the counter is equal to 1
|
||||
next repeat
|
||||
end if
|
||||
set currentChar to it
|
||||
set lastCharInd to the counter - 1
|
||||
repeat for lastCharInd down to 1
|
||||
if currentChar is equal to character it of param1
|
||||
set currentChar to "0"
|
||||
else
|
||||
set currentChar to "1"
|
||||
end if
|
||||
end repeat
|
||||
set character the counter of theResult to currentChar
|
||||
end repeat
|
||||
|
||||
return theResult
|
||||
end GrayToBinary
|
||||
Loading…
Add table
Add a link
Reference in a new issue