Count in octal: Difference between revisions
Content deleted Content added
add Ruby |
No edit summary |
||
Line 369: | Line 369: | ||
} |
} |
||
}</lang> |
}</lang> |
||
=={{header|Liberty BASIC}}== |
|||
Terminate these ( essentially, practically) infinite loops by hitting <CTRL<BRK> |
|||
<lang lb> |
|||
'the method used here uses the base-conversion from RC Non-decimal radices/Convert |
|||
'to terminate hit <CTRL<BRK> |
|||
global alphanum$ |
|||
alphanum$ ="01234567" |
|||
i =0 |
|||
while 1 |
|||
print toBase$( 8, i) |
|||
i =i +1 |
|||
wend |
|||
end |
|||
function toBase$( base, number) ' Convert decimal variable to number string. |
|||
maxIntegerBitSize =len( str$( number)) |
|||
toBase$ ="" |
|||
for i =10 to 1 step -1 |
|||
remainder =number mod base |
|||
toBase$ =mid$( alphanum$, remainder +1, 1) +toBase$ |
|||
number =int( number /base) |
|||
if number <1 then exit for |
|||
next i |
|||
toBase$ =right$( " " +toBase$, 10) |
|||
end function |
|||
</lang> |
|||
As suggested in LOGO, it is easy to work on a string representation too. |
|||
<lang lb> |
|||
op$ = "00000000000000000000" |
|||
L =len( op$) |
|||
while 1 |
|||
started =0 |
|||
for i =1 to L |
|||
m$ =mid$( op$, i, 1) |
|||
if started =0 and m$ ="0" then print " "; else print m$;: started =1 |
|||
next i |
|||
print |
|||
for i =L to 1 step -1 |
|||
p$ =mid$( op$, i, 1) |
|||
if p$ =" " then v =0 else v =val( p$) |
|||
incDigit = v +carry |
|||
if i =L then incDigit =incDigit +1 |
|||
if incDigit >=8 then |
|||
replDigit =incDigit -8 |
|||
carry =1 |
|||
else |
|||
replDigit =incDigit |
|||
carry =0 |
|||
end if |
|||
op$ =left$( op$, i -1) +chr$( 48 +replDigit) +right$( op$, L -i) |
|||
next i |
|||
wend |
|||
end |
|||
</lang> |
|||
Or use a recursive listing of permutations with the exception that the first digit is not 0 (unless listing single-digit numbers). For each digit-place, list numbers with 0-7 in the next digit-place. |
|||
<lang lb> |
|||
i = 0 |
|||
while 1 |
|||
call CountOctal 0, i, i > 0 |
|||
i = i + 1 |
|||
wend |
|||
sub CountOctal value, depth, startValue |
|||
value = value * 10 |
|||
for i = startValue to 7 |
|||
if depth > 0 then |
|||
call CountOctal value + i, depth - 1, 0 |
|||
else |
|||
print value + i |
|||
end if |
|||
next i |
|||
end sub |
|||
</lang> |
|||
=={{header|Logo}}== |
=={{header|Logo}}== |