|
Post by sarossell on Mar 4, 2020 5:29:05 GMT -5
I welcome your kind analysis and review for submission:
samples = 20 call zecklist samples print "Decimal","Zeckendorf" for n = 0 to samples print zecklist$(n) next n
Sub zecklist inDEC dim zecklist$(inDEC) do bin$ = str$(dec2bin(count)) inRevBin$ = reverse$(bin$) if instr(bin$,"11") = 0 then zecklist$(found) = using("###",found) + space$(12) + bin$ found = found + 1 end if count = count + 1 loop until found = inDEC + 1 End sub
Function reverse$(inSTG$) for n = 1 to len(inSTG$) reverse$ = mid$(inSTG$,r,1) + reverse$ next n End Function
function dec2bin(inDEC) do bin$ = str$(inDEC mod 2) + bin$ inDEC = int(inDEC/2) loop until inDEC = 0 dec2bin = val(bin$) end function
|
|
|
Post by tsh73 on Mar 4, 2020 7:08:31 GMT -5
Removed some unused stuff (never heard of Zeckendorf numbers before)
samples = 20 call zecklist samples
print "Decimal","Zeckendorf" for n = 0 to samples print n, zecklist$(n) next n
Sub zecklist inDEC dim zecklist$(inDEC) do bin$ = dec2bin$(count) if instr(bin$,"11") = 0 then zecklist$(found) = bin$ found = found + 1 end if count = count+1 loop until found = inDEC + 1 End sub
function dec2bin$(inDEC) do bin$ = str$(inDEC mod 2) + bin$ inDEC = int(inDEC/2) loop until inDEC = 0 dec2bin$ = bin$ end function
|
|
|
Post by sarossell on Mar 4, 2020 7:32:00 GMT -5
Ah, right. Good catch taking out the reverse function. I forgot to remove that part. I had originally written this code to generate Fibonacci CODING which uses Zeckendorf representation of Fibonacci numbers in REVERSE followed by an appended "1". This provides a communications protocol that easily corrects transmission errors with multiple passes due to the nature of the Zeckendorf representation (there are never consecutive 1 digits). By reversing the Zeckendorf to ensure the most significant digit is to the right and then appending another 1 to it, each number is delineated by two consecutive 1 digits. For example, 10 Decimal = 10010 Zeck = 010011 Fib Coding.
And that's why we review these things! Awesome! Thanks!
:@)
|
|