Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Gray-code/BCPL/gray-code.bcpl
Normal file
22
Task/Gray-code/BCPL/gray-code.bcpl
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
get "libhdr"
|
||||
|
||||
let grayEncode(n) = n neqv (n >> 1)
|
||||
|
||||
let grayDecode(n) = grayDecodeStep(0, n)
|
||||
and grayDecodeStep(r, n) =
|
||||
n = 0 -> r,
|
||||
grayDecodeStep(r neqv n, n >> 1)
|
||||
|
||||
let binfmt(n) =
|
||||
n = 0 -> 0,
|
||||
(n & 1) + 10 * binfmt(n >> 1)
|
||||
|
||||
let printRow(n) be
|
||||
$( let enc = grayEncode(n)
|
||||
let dec = grayDecode(enc)
|
||||
writef("%I2: %I5 => %I5 => %I5 => %I2*N",
|
||||
n, binfmt(n), binfmt(enc), binfmt(dec), dec)
|
||||
$)
|
||||
|
||||
let start() be
|
||||
for i = 0 to 31 do printRow(i)
|
||||
Loading…
Add table
Add a link
Reference in a new issue