Now that we know how to Square a Number my Way, we need an inverse operation, a way to Square Root a Number my Way. To square a number my way, you simply stack it on top of itself a number of times equal to the number of digits it contains, and then take read off every number that is formed both vertically and horizontally, and then add them together. More information about squaring a number in this manner can be found here. To square root a number my way, you simply take the number that has the least decimal digits that squares (my way) to make the number you are square rooting. For example, since 12 can be formed by squaring 6, and there are no numbers with fewer decimal digits that can be squared to form 12, the square root of 12 is 6.

Your Task:

Write a program or function that takes an integer and square roots it as outlined above.


An integer or string


A float or string square rooted as outlined above.

Test Cases:

1263 -> 125
57   -> 12


This is , lowest score in bytes wins!

  • \$\begingroup\$ Not sure if there may be multiple solutions, but in case there are, which one should we output? \$\endgroup\$
    – user72349
    Aug 9, 2017 at 21:31
  • \$\begingroup\$ The output can be float, but why does this apply to the input too? Shouldn't the input be an integer? \$\endgroup\$
    – Mr. Xcoder
    Aug 9, 2017 at 21:34
  • \$\begingroup\$ "... has the least decimal digits ..." - what does it mean? How do you count decimal digits of non-integer numbers? Can you post test cases which include non-integer inputs/outputs? \$\endgroup\$
    – user72349
    Aug 9, 2017 at 21:38
  • \$\begingroup\$ I think the first test case is 1263 -> 125. \$\endgroup\$
    – Mr. Xcoder
    Aug 9, 2017 at 21:45
  • 1
    \$\begingroup\$ This just feels like a dupe of the other challenge, like the answers will be (Range)(Port of answer to last challenge)(index). Most of the initial ones seem to follow that pattern anyway. \$\endgroup\$
    – nmjcman101
    Aug 10, 2017 at 14:13

5 Answers 5


Python 2, 101 bytes

Ports from my answer to square the numbers my way.

while sum(float(i*len(z))for z in[[i for i in`x`if"/"<i]]for i in[x]+z)!=z:x+=1
print x

Try it online!


Python 3, 112 bytes

f=lambda x,k=0:k if(lambda x:int(x)*len(x)+sum(map(int,map(''.join,zip(*[x]*len(x))))))(str(k))==x else f(x,k+1)

Try it online!

  • 3
    \$\begingroup\$ Name of outer lambda should be counted, as you use it recursively \$\endgroup\$ Aug 10, 2017 at 9:29
  • \$\begingroup\$ @DeadPossum Ah, yes, forgot about that. Thanks! \$\endgroup\$
    – hyper-neutrino
    Aug 10, 2017 at 15:40

Mathematica, 130 bytes


other test cases

5994 -> 999
79992 -> 9999
999990 -> 99999


Pyth, 20 bytes


Test Suite.

As all the other answers, this assumes the input is a "perfect square (my way)". This also uses the fact that the square (my way) of an integer is always higher than or equal to itself. Also, this is a port of Erik's solution to that challenge. Porting my solution from that challenge would result in a longer submission.


PHP, 92 90 89 84+1 bytes

brute force (assuming that the input is a perfect square)
using my solution from Square a Number my Way:


Run as pipe with -nR or try it online.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.