Triangular code, triangular output

For this challenge, submissions should be a program or function shaped like a right triangle, which produces a right triangle of the same size.

What is a right triangle?

For this challenge, a right triangle consists of 1 or more lines, each containing a number of characters (assume all non-newline characters are the same width) equal to that line number:

.
..
...
....


Trailing newlines are allowed.

The challenge:

Your code should form a right triangle, and output a right triangle with the same height made up of any non-newline characters.

As this is code golf, shortest answer in bytes per language wins.

• So, to be clear, 1 byte solutions outputting a single character are valid? Also, for longer solutions, must all characters in the output be the same, as in your example? And why are functions disallowed? – Shaggy Apr 4 '20 at 21:19
• @Shaggy Yes, 1 byte solutions would be valid (though for most golfing languages this is probably trivial anyway), characters do not need to be the same, and I actually think I'll revise the rules to allow functions. – Redwolf Programs Apr 4 '20 at 21:21
• Based on "made up of any non-newline characters", a null byte is allowed, right? – S.S. Anne Apr 4 '20 at 21:41
• @S.S.Anne Yes, I'd say the only bytes not allowed would be \n and \r (0x0a and 0x0d) – Redwolf Programs Apr 4 '20 at 21:52
• I have the feeling this challenge would have been better as a code-bowling challenge tbh :) – Kevin Cruijssen Apr 6 '20 at 8:42

R, 34 bytes

#
d=
cat
d(9^
(1:7)
,sep="
")#####


Try it online!

Outputs $$\9^1\$$ to $$\9^7\$$:

9
81
729
6561
59049
531441
4782969

• Nice answer! It appears the decimal representation of 9^n is n digits long up to n=21. – Redwolf Programs Apr 5 '20 at 14:28

brainfuck, 1 byte

.


Outputs a single null byte.

Try it online!

• The fun thing with brainfuck is you can do this with nothing but dots over any number of lines! – Hand-E-Food Apr 5 '20 at 22:49
• @Hand-E-Food Not quite. You'll need a 10 for the newline, so you can do it with +, <, >, and . – S.S. Anne Apr 6 '20 at 15:54
• It still won't work without loops, because if you have to print more bytes than you have dots, you will inevitably need to reuse them. – the default. Apr 9 '20 at 15:18

C (gcc), 53 bytes

Fixed error pointed out by @S.S. Anne

\
m\
ain
(n){
9<pr\
intf(\
"%d\n",
n*=9)||\
main(n);}


Try it online!

JavaScript (ES7),  43  34 bytes

A triangle of 7 rows, filled with 0's.

f
=(
s=
)=>
s[7]?
'':0+s
+f(0+s)


Try it online!

Commented

f   // f is a recursive function
=(   // taking
s=   // a string s initialized to
)=>   // a linefeed
s[7]?   // if s has more than 7 characters,
'':0+s   // stop recursion; otherwise append a 0, followed by s,
+f(0+s)   // followed by the result of a recursive call with 0 + s

• Different method (still 34 bytes), full program – Redwolf Programs Apr 5 '20 at 19:47
• 19 byte quine? Is this valid? – tsh Jul 24 '20 at 5:45
• @tsh There's apparently no consensus anymore about that kind of quines. – Arnauld Jul 24 '20 at 15:26
• @Arnauld But this question does not require a proper quine. – tsh Jul 25 '20 at 13:33
• @tsh You're right, I did not remember this challenge accurately. Your solution looks valid indeed. I think you should post it as a new answer. – Arnauld Jul 25 '20 at 13:37

Perl 5, 665453 19 bytes

#
##
use
####
Quine


I am submitting this as a joke because I did not even bother trying to write some optimized code. Instead, I am using a module from CPAN that causes the program to print itself.

The Quine.pm module can be found on CPAN and was released in January 2001, long before this question was posted here. So I assume that it is acceptable, as it seems to be the tradition in other Code Golf questions.

Edit 1: Saved 12 bytes by removing the semicolon after the use statement.

Edit 2: Thanks to Arnauld for pointing out that I did not need the final newline character, saving one byte.

Edit 3: Thanks to petStorm who made a great improvement by putting the use statement and the module name on separate lines, reducing the program to only 19 bytes. This exercise that started as a joke is now a very competitive entry. It would be difficult to do better in a non-obscure language (insert joke about Perl's readability here).

• So, can this work? I tried it and it didn't throw a syntax error. – user92069 Apr 5 '20 at 4:41
• It does work and it produces the expected output without errors. Thanks a lot for the suggestion! – RaphaelQuinet Apr 5 '20 at 7:13

Python 2, 53 43 bytes

I think we are allowed to output different characters. Because of this, I simply printed $$\10^i\$$ at every iteration.

#
##
###
i=1;
exec\
"prin\
t i;i*\
=10;"*8\


Try it online!

Bash, 26 bytes

The dc command turns out to be quite useful in code-golfing.

\
d\
c \
-e{\
5..1\
0}*p \


Try it online!

u
=
(9
^)
++<8;
)echo(
10**$i- 1)."\n";  Try it online! Not that bad for PHP.. displays a triangle of "9" Java 10, 76 bytes (11 rows) v -> {// var r=""; long i =0,s=1; for(;++i <12;r+=(s *=9)+"\n") ;return r;}  Inspired by all the other answers. Try it online. • I wonder why Java doesn't support backslash line continuers. – S.S. Anne Apr 7 '20 at 14:47 • @S.S.Anne I'm actually wondering why other languages do support backslash line continues. What's the purpose of it in regular programming, apart from benig able to split long strings to multiple lines without using "\n+"? – Kevin Cruijssen Apr 8 '20 at 15:45 • C has macros that can't take up multiple lines without them. If you want to have a big macro, it won't be readable unless you use the backslash like continuation. The same applies to line-based languages, too. I guess Java is neither of those, so it doesn't need them. – S.S. Anne Apr 8 '20 at 16:30 05AB1E, 1 bytes 0  Try it online. Not much to say I guess.. If this was instead, we could do something like this (can be made as arbitrary large as you'd want it to, as long as the last three bytes are ₄*»): 1 11 111 1111 11111 111111 1111111 11111111 111111111 1111111₄*»  Try it online. Explanation: 1\n11\n111\n... # Push all these numbers one by one to the stack 111...111 # Push the number of the last line ₄* # Multiply it by 1000 to increase its size by 3 » # Join everything on the stack by newlines # (after which it is output implicitly as result)  Wolfram Language (Mathematica), 43 bytes \ "\ "<\ >".\ "~Ta\ ble~#\ &/@Ran\ ge [8*1]  Try it online! Canvas, 1 byte Boring solution, just like everyone else. :) \  Try it here! Canvas, 4 bytes Non-trivial attempt. ＼ ２＼  Try it here! Explanation ＼ # Draw a diagonal, with nothing on the stack # Errors silently # Newline: A character not in the code page. # It basically does nothing. ２ # 2: Push 2 onto the stack ＼ # Draw a diagonal with a length of 2 # Implicit output  • I think the new-line might be equivalent to the pilcrow at byte 10 of the code-page, ¶, try it – Jonathan Allan Apr 5 '20 at 15:39 Bash + GNU utilities, 43 bytes \ s\ eq\ -f\ 'seq\ -s "\ " %f' \$[+8]|sh


Try it online!

I couldn't quite get this down to 7 rows; I needed to pad it by 4 bytes to fill out the 8-row triangle (that's why I have \$[+8] in the code instead of just 8).

BSD Challenge!

If you take the same idea as the GNU solution above but use the BSD utility jot instead of seq, it's just one byte too long for a 7-row solution (which would be 34 bytes):

    \
j\
ot\
-w\
'jot\
-s "\
" ' 7|sh
# This is one byte too long for 7 rows :( .


If someone can see how to shave just 1 byte off this BSD version, that would get it down to a 7-row 34-byte solution.

Here's a TIO link to the BSD version if anybody wants to try their hand at eliminating that one last byte! This also works under OS X, if you have a Macintosh.

(Obviously this version, like the GNU version in my main answer above, can be padded to be another 8-row 43-byte solution, but that's not as interesting.)

• I have a 26-byte solution if you want. – dingledooper Apr 5 '20 at 19:20
• @dingledooper That's a nice one. It's completely different from mine; go ahead and post it yourself. – Mitchell Spector Apr 5 '20 at 19:23
• Ok thanks, that's what I'll do. – dingledooper Apr 5 '20 at 19:26
• I love the smooth edge on your triangle! – Hand-E-Food Apr 6 '20 at 23:07
• @Hand-E-Food Thank you\ – Mitchell Spector Apr 7 '20 at 3:33

Clojure, 10389 76 bytes

(
;;
;;;
loop
[i 9]
(when(
* i;;;;
99999999
)(println
i)(recur(*
i 9))));;;;


Try it online!

Prints the first 11 powers of 9. Exits with an ArithmeticException: integer overflow when trying to multiply $$\9^{12}\$$ by $$\99999999\$$.

C (gcc), 53 bytes

;
m\
ain
(n){
9/pr\
intf(\
"%d\n",
n)&&mai\
n(n*10);}


Prints powers of 10.

Try it online!

SQL (Oracle)88 76 Bytes

;
/*
ABC
DEFG
HIJ*/
SELECT
LEVEL,1)
FROM DUAL
CONNECT BY
LEVEL < 12;


Try it out

Output:

1
11
111
1111
11111
111111
1111111
11111111
111111111
1111111111
11111111111


Edit: Thanks @Math Junkie, by following the rules I actually cut off 12 bytes.

• This is an interesting post, but unfortunately, it misses the point of the challenge. The triangle formed by the source code should be increasing in size, the same way as the output – math junkie Apr 8 '20 at 15:28
• @mathjunkie I read the question like 3 times, it doesn't state that it needs to be increasing size, just that the code form a right triangle. It also doesn't specify that the output be the same direction as the code, only that it be the same height. The code and output triangles are the same (Just reflected across the X-axis) – Del Apr 8 '20 at 15:33
• In the section of the description describing a right triangle, it mentions that the number of characters on a line should be "equal to that line number" – math junkie Apr 8 '20 at 15:50
• @mathjunkie You are definitely correct, I missed that. Shoot and I thought I found a loophole. – Del Apr 8 '20 at 16:03
• @mathjunkie Actually thank you for pointing out my error. When I reformatted, I was actually able to save 1 line and therefore 12 bytes. – Del Apr 8 '20 at 16:21

Bash, 64 bytes

\
d\
at\
e +\
d%n%\
m%n%j\
%n%Y%n\
%R%n%:z\
%n%7Y%n%\
T%n%N%n%F\


Try it online!

Not the shortest but kind of fancy. Displays current date in convinient format. Tried to do it locales intependent. Last byte for fancy too.

SmileBASIC 4, 3 bytes

\
?0


0
OK


Erlang (escript), 76 bytes

f
()
->[
%%%%
%%%%%
string
:copies
("!", X)
++"\n"||X
<- lists :
seq(1,11)].


Try it online!

dc, 4 bytes

B
1f


Try it online!

Explanation:

B   Push 11 on the stack.
1   Push 1 on the stack.
f   Print the items on the stack, starting at the top, each one with a terminal newline.


Python 3, 53 bytes

#
##
###
for\
i in\
range(
9):####
print(#
10**i)###


Try it online! Similar to dingledooper's submission. I was also going to submit:

brainfuck, 1 byte!!

.


Try it online! But S.S.Anne beat me by a couple of hours :)

HQ9+, 1 byte

Q


Try it online!

Io, 43 bytes

A lot more "content" than my previous submissions.

\
\
\
for(
i,1,8
,(9**i
)     \
println)


Try it online!

• Readability improvement: Try it online! – the default. Apr 6 '20 at 10:51
• @mypronounismonicareinstate Nice modification. However, I'm not going to accept it, because in my opinion, a one-liner in a case like this is much more readable than a line-breaked program. – user92069 Apr 6 '20 at 10:58

dirt, 43 bytes

x
xx
xx|
|'a'
(a*'a
)**{1|
}.*|"11
11111"|x


run with with empty string as input:

>dirt triangle.dirt -i ""
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaaaaaa
aaaaaaaa


C (gcc), 53 bytes

\
m\
ain
(n){
for(;
9/n;n=
printf(
"%0*d\n"
,n,0));;}


Try it online!

C (gcc), 53 bytes

\
m\
ain
(n){
9/n&&
main(\
printf(
"%0*d\n"
,n,0));;}


Try it online!

Stax, 4 bytes

2
mR


Run and debug it at staxlang.xyz!

Nontrivial solution. Prints "\x01\n\x01\x02", so you won't see any output, but it's there. One byte is easy but boring.

2     Push 2
mR    For n in [1,2], print [1..n] as a string


Another 4-byter that feels like cheating:

0     Do nothing
|?    Source of program, implicit print.