RosettaCodeData/Task/Gray-code/SenseTalk/gray-code.sensetalk

38 lines
836 B
Plaintext

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