# Square Root a Number my Way

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.

## Input:

An integer or string

## Output:

A float or string square rooted as outlined above.

## Test Cases:

1263 -> 125
57   -> 12


## Scoring:

This is , lowest score in bytes wins!

• Not sure if there may be multiple solutions, but in case there are, which one should we output?
– user72349
Aug 9, 2017 at 21:31
• The output can be float, but why does this apply to the input too? Shouldn't the input be an integer? Aug 9, 2017 at 21:34
• "... 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?
– user72349
Aug 9, 2017 at 21:38
• I think the first test case is 1263 -> 125. Aug 9, 2017 at 21:45
• 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. Aug 10, 2017 at 14:13

# Python 2, 101 bytes

Ports from my answer to square the numbers my way.

x,z=1,input()
while sum(float(i*len(z))for z in[[i for i inxif"/"<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!

• Name of outer lambda should be counted, as you use it recursively Aug 10, 2017 at 9:29
• @DeadPossum Ah, yes, forgot about that. Thanks! Aug 10, 2017 at 15:40

# Mathematica, 130 bytes

(For[i=1,(t=Length[s=#&@@RealDigits[#]//.{a___,0}:>{a}];If[IntegerPart@#==0,t++];t#+Tr[FromDigits@Table[#,t]&/@s])&[i]!=#,i++];i)&


other test cases

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

# Pyth, 20 bytes

xms+RdsM*RF_lB@jkUT


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:

while((0|$k/=10)||$s-$argn&&$k=++$n+$s=0)$s+=$n+str_repeat($k%10,strlen($n));echo\$n;


Run as pipe with -nR` or try it online.