# root of root of root of root

This idea came to me when I saw my little brother playing with my calculator :D

Taking a integer as an input, print that many graphical square roots under each other, like this:

n = 1

___
\/ 1

n = 3
_______
/ _____
/ / ___
\/\/\/ 3

n = 5

___________
/ _________
/ / _______
/ / / _____
/ / / / ___
\/\/\/\/\/ 5

n = 10

______________________
/ ____________________
/ / __________________
/ / / ________________
/ / / / ______________
/ / / / / ____________
/ / / / / / __________
/ / / / / / / ________
/ / / / / / / / ______
/ / / / / / / / / ____
\/\/\/\/\/\/\/\/\/\/ 10


Each root consists of 4 parts, which I'm going to very scientifically name:

(s is the root size on the stack of roots, n is the input number, x is the number of digits)

1. The "tail", which is a single \
2. The "wall", which consists of / * s
3. The "roof", which consists of _ * 2 * s + x
4. And the number n under the smallest root, placed in the centre (leaving one empty space under the last _ in the smallest root)

# Input

You must take input of the number n, no hardcoding the n

# Output

This is a code-golf challenge, so lowest byte count for each language wins!

• Will the number exceed the digit 9?
– user92069
Commented May 9, 2020 at 8:36
• @Λ̸̸ good catch, will edit the rules. Yes, it can exceed the digit 9, updating the rules to clarify what to do
– Dion
Commented May 9, 2020 at 8:38
• Related (the same idea, but different art) Commented May 9, 2020 at 12:10
• Why does the input have to be from STDIN and out to STDOUT? That seems like an unnecessarily arbitrary restriction. Commented May 9, 2020 at 14:12
• @RossPresser Less interesting than you might think: with input s as a string, l = s.splitlines()[-1]; print(int(l[l.index(' '):]) ** (1 / l.count('/'))). Commented May 11, 2020 at 18:31

# Java (JDK), 139 171 bytes

String g(int k){return g(0,k);}String g(int i,int n){return i<n?" ".repeat(n-i+1)+"/ ".repeat(i)+"_".repeat((n-i)*2+(""+n).length())+"\n"+g(++i,n):"\\/".repeat(n)+" "+n;}


Try it online!

No for loop, recursion is used. Therefor I had to define the function as a method because I couldn't find a way to define it as a BiFunction lambda expression and call it recursively. The method has 2 inputs: zero as first argument, the integer input parameter as second. And thus added an overloaded method with only one parameter.

## Explained

String g(int i,int n) {                          // i is current index (start with 0), n is the input parameter value
return i<n?                                    // are we not yet at the end?
+"/ ".repeat(i)                        // add i times '/ '
+"_".repeat((n-i)*2+(""+n).length())   // add underscores, including extra for the length of the input value
+g(++i,n)                              // recursive call with i+1
:
"\\/".repeat(n)+" "+n                   // at last i=n, add \/ + input parameter value
;}                                               // what goes open, must be closed


Called as

System.out.println(g(10));


139 -> 171 : to make it acceptable with only 1 input parameter (@Razetime)

• I think you should overload the function to accept a single parameter like this: Try it online! That way it'd be valid. Commented Nov 3, 2020 at 16:20
• @Razetime, I'm afraid you're right :(. Added your suggestion to the answer. Thanks for the remark. Commented Nov 3, 2020 at 16:30
• Joys of golfing in a verbose language. You should check out this thread for some shortening methods. Commented Nov 3, 2020 at 16:45