First perfect square in base n with n unique digits: Difference between revisions
First perfect square in base n with n unique digits (view source)
Revision as of 15:31, 17 April 2021
, 3 years ago→{{header|Python}}: Tidied.
(Added Wren) |
m (→{{header|Python}}: Tidied.) |
||
Line 3,185:
<lang python>'''Perfect squares using every digit in a given base.'''
from itertools import
from math import
from time import time
Line 3,196:
'''
bools = list(repeat(True, base))
return next
dropwhile(
max(above, ceil(sqrt(int('10' + '0123456789abcdef'[2:base], base))))▼
missingDigitsAtBase(base, bools),
)))▼
count(
max(
above,
ceil(sqrt(int(
base
)))
)
)
)
# missingDigitsAtBase :: Int -> [Bool] -> Int -> Bool
def missingDigitsAtBase(base, bools):
'''Fusion of representing the square of integer N at a
given base with checking whether all digits of
that base contribute to N^2.
Clears the bool at a digit position to False when used.
True if any positions remain uncleared (unused).
Line 3,223 ⟶ 3,235:
#
# main :: IO ()
def main():
Line 3,236 ⟶ 3,248:
print(
str(b).rjust(2, ' ') + ' -> ' +
showIntAtBase(b)(digit)(q)('').rjust(8, ' ')
' -> ' +
showIntAtBase(b)(digit)(q * q)('')
)
Line 3,245 ⟶ 3,258:
#
# enumFromTo :: (Int, Int) -> [Int]
Line 3,253 ⟶ 3,266:
# showIntAtBase :: Int -> (Int -> String) -> Int ->
# String -> String
def showIntAtBase(base):
'''String representation of an integer in a given base,
Line 3,275 ⟶ 3,289:
# MAIN ---
if __name__ == '__main__':
main()
</lang>
{{Out}}
<pre>Smallest perfect squares using all digits in bases 2-16:
|