jq -rn
, 76 65 60 59 bytes
-6 bytes thanks to ovs and another -6 (plus -5 more indirectly) thanks to Michael Chatiskatzi
def r:range(9),7-range(8);r|[8-.-r|"\(" "*.//1-.)"[:1]]|add
Try it online!
Explanation
The -n
flag specifies that there is no input; the -r
flag outputs the result strings, each on its own line, without quotes.
def r: Define a helper function r
range(9), which generates the numbers 0 through 8, followed by
7 - range(8); the numbers 7 through 0
Main program:
r | Start with the results of r
[ For each of those numbers, put the following in a list:
8 - . - r | 8, minus the current number, minus the results of calling r again
"\( For each of those numbers, interpolate the following into a string:
" " * . Try to repeat a space that many times
// and if the result is null (i.e. the number was less than 1),
1 - . subtract the number from 1 instead
)"
[:1] Take the first character of each resulting string
] | Take each resulting list of strings and
add concatenate it together
To help visualize what's going on, here's what just the r|[8-.-r]
part does:
[8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8]
[7,6,5,4,3,2,1,0,-1,0,1,2,3,4,5,6,7]
[6,5,4,3,2,1,0,-1,-2,-1,0,1,2,3,4,5,6]
[5,4,3,2,1,0,-1,-2,-3,-2,-1,0,1,2,3,4,5]
[4,3,2,1,0,-1,-2,-3,-4,-3,-2,-1,0,1,2,3,4]
[3,2,1,0,-1,-2,-3,-4,-5,-4,-3,-2,-1,0,1,2,3]
[2,1,0,-1,-2,-3,-4,-5,-6,-5,-4,-3,-2,-1,0,1,2]
[1,0,-1,-2,-3,-4,-5,-6,-7,-6,-5,-4,-3,-2,-1,0,1]
[0,-1,-2,-3,-4,-5,-6,-7,-8,-7,-6,-5,-4,-3,-2,-1,0]
[1,0,-1,-2,-3,-4,-5,-6,-7,-6,-5,-4,-3,-2,-1,0,1]
[2,1,0,-1,-2,-3,-4,-5,-6,-5,-4,-3,-2,-1,0,1,2]
[3,2,1,0,-1,-2,-3,-4,-5,-4,-3,-2,-1,0,1,2,3]
[4,3,2,1,0,-1,-2,-3,-4,-3,-2,-1,0,1,2,3,4]
[5,4,3,2,1,0,-1,-2,-3,-2,-1,0,1,2,3,4,5]
[6,5,4,3,2,1,0,-1,-2,-1,0,1,2,3,4,5,6]
[7,6,5,4,3,2,1,0,-1,0,1,2,3,4,5,6,7]
[8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8]
Any number that's greater than 0 gets turned into that many spaces (and then trimmed back to a single space). The other numbers gets subtracted from 1 (turning 0 .. -8 into 1 .. 9) and stringified.