Find palindromic numbers in both binary and ternary bases: Difference between revisions
Content added Content deleted
(→Functional Python: Updated primitives and output, pylinted for Python 3, added {works with tag}) |
|||
Line 2,005: | Line 2,005: | ||
see "wait for done..." + nl |
see "wait for done..." + nl |
||
while true |
while true |
||
binpal = |
binpal = basedigits(nr,2) |
||
terpal = |
terpal = basedigits(nr,3) |
||
bool1 = ispalindrome(binpal) |
bool1 = ispalindrome(binpal) |
||
bool2 = ispalindrome(terpal) |
bool2 = ispalindrome(terpal) |
||
Line 2,020: | Line 2,020: | ||
see "done..." + nl |
see "done..." + nl |
||
func |
func basedigits(n,base) |
||
if n = 0 |
if n = 0 |
||
return "0" |
return "0" |
||
Line 2,026: | Line 2,026: | ||
result = "" |
result = "" |
||
while n > 0 |
while n > 0 |
||
result = string(n % |
result = string(n % base) + result |
||
n = floor(n/ |
n = floor(n/base) |
||
end |
|||
return result |
|||
func ter(n) |
|||
if n = 0 |
|||
return "0" |
|||
ok |
|||
result = "" |
|||
while n > 0 |
|||
result = string(n % 3) + result |
|||
n = floor(n/3) |
|||
end |
end |
||
return result |
return result |
||
Line 2,055: | Line 2,044: | ||
return 0 |
return 0 |
||
ok |
ok |
||
</lang> |
</lang> |
||
{{out}} |
{{out}} |