First perfect square in base n with n unique digits: Difference between revisions

m
(Added Wren)
Line 3,185:
<lang python>'''Perfect squares using every digit in a given base.'''
 
from itertools import (count, dropwhile, repeat)
from math import (ceil, sqrt)
from time import time
 
Line 3,196:
'''
bools = list(repeat(True, base))
return next(dropwhile(missingDigitsAtBase(base, bools), count(
dropwhile(
max(above, ceil(sqrt(int('10' + '0123456789abcdef'[2:base], base))))
missingDigitsAtBase(base, bools),
)))
count(
max(
above,
ceil(sqrt(int(
max(above, ceil(sqrt(int( '10' + '0123456789abcdef'[2:base], base))))
base
)))
)
)
)
)))
 
 
# missingDigitsAtBase :: Int -> [Bool] -> Int -> Bool
def missingDigitsAtBase(base, bools):
'''Fusion of representing the square of integer N at a given base
given base with checking whether all digits of that base contribute to N^2.
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:
 
 
# TEST --------------------------- TEST -------------------------
# 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:
 
 
# GENERIC ------------------------- GENERIC ------------------------
 
# enumFromTo :: (Int, Int) -> [Int]
Line 3,253 ⟶ 3,266:
 
 
# showIntAtBase :: Int -> (Int -> String) -> Int -> String -> String
# 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>
</lang>
{{Out}}
<pre>Smallest perfect squares using all digits in bases 2-16:
9,655

edits