| Bytes | Lang | Time | Link |
|---|---|---|---|
| 052 | Swift 6 | 250428T144514Z | macOSist |
| 004 | Vyxal 3 | 250324T213822Z | Themooni |
| 022 | Raku Perl 6 rakudo | 250425T152300Z | xrs |
| 025 | AWK | 250312T202953Z | xrs |
| 069 | SAKO | 250324T170647Z | Acrimori |
| 027 | Tcl | 170619T113228Z | sergiol |
| nan | 230102T115226Z | The Thon | |
| nan | 161014T222018Z | user6011 | |
| 005 | 05AB1E | 200924T232622Z | Makonede |
| 003 | Vyxal j | 220602T211206Z | naffetS |
| 084 | tinylisp | 220204T043401Z | Razetime |
| 003 | Regenerate | 210627T045402Z | wasif |
| 047 | Rockstar | 200925T093109Z | Shaggy |
| 008 | Actually | 161010T200059Z | user4594 |
| 011 | Add++ | 200924T222802Z | caird co |
| 088 | Flurry | 200924T220938Z | Esolangi |
| 008 | J | 200713T040917Z | Moonchil |
| 008 | Dyalog APL | 200713T030244Z | Moonchil |
| 065 | C++ gcc | 200315T151958Z | S.S. Ann |
| 020 | PowerShell | 161010T123206Z | AdmBorkB |
| 024 | Powershell | 200308T083733Z | wasif |
| 050 | Erlang escript | 200307T122552Z | user9206 |
| 008 | Keg | 200307T011359Z | lyxal |
| 061 | C++ gcc | 200307T001435Z | S.S. Ann |
| 031 | JavaScript ES6 | 161010T124644Z | Arnauld |
| 011 | GolfScript | 191213T125305Z | Pseudo N |
| 052 | SNOBOL4 CSNOBOL4 | 171228T220520Z | Giuseppe |
| 004 | MathGolf | 191212T141817Z | Kevin Cr |
| 064 | W n | 191212T084948Z | user8505 |
| 041 | Wren | 191210T130949Z | user8505 |
| 004 | Japt R | 170225T031533Z | Oliver |
| 033 | R | 180719T151519Z | JayCe |
| 058 | Java | 161010T123743Z | Kevin Cr |
| 014 | Noether | 180719T142805Z | Beta Dec |
| 004 | Japt R | 180112T161703Z | Shaggy |
| 004 | Stax | 180411T044109Z | recursiv |
| 012 | k | 170226T070257Z | zgrep |
| 042 | brainfuck | 180113T084701Z | Jo King |
| 003 | Canvas | 180114T111558Z | dzaima |
| 007 | APL Dyalog Unicode | 180113T215121Z | ngn |
| 008 | Dyalog APL | 161026T100026Z | Adá |
| 017 | Pyt | 180113T144555Z | mudkip20 |
| 069 | Windows batch | 180113T042039Z | stevefes |
| 013 | Julia 0.6 | 180112T164258Z | gggg |
| 077 | Commodore 64/VIC20 BASIC and compatible C= 8bits | 170306T173630Z | Shaun Be |
| 013 | Underload | 170209T100528Z | Esolangi |
| 011 | J | 171228T230356Z | Bolce Bu |
| 171 | LaTeX | 171228T215533Z | Thiago O |
| 032 | Excel VBA | 171228T204240Z | Taylor R |
| 037 | Excel VBA | 170917T175026Z | Taylor R |
| 016 | QBIC | 161010T140642Z | steenber |
| 038 | 8th | 170918T182832Z | Chaos Ma |
| 005 | RProgN 2 | 170918T054815Z | ATaco |
| 022 | TIBasic | 161012T150629Z | Timtech |
| 041 | Common Lisp | 170209T130143Z | user6516 |
| 044 | JavaScript ES6 | 170619T115443Z | Shaggy |
| 027 | Perl 6 | 170501T233922Z | bb94 |
| 101 | Forte | 170308T164308Z | Leo |
| nan | GNU sed | 161010T131057Z | seshouma |
| 029 | Röda 0.12 | 170306T184803Z | user4180 |
| 016 | K | 170304T024735Z | Chromozo |
| 028 | PHP | 161010T141958Z | aross |
| 067 | Terrapin logo | 170226T041518Z | adrian |
| 033 | dc | 170225T051113Z | Mitchell |
| 026 | Bash + Unix utilities | 170224T212746Z | Mitchell |
| 028 | AutoHotkey | 170224T182534Z | Engineer |
| 017 | Perl 6 | 170222T171515Z | smls |
| 018 | k | 170222T162418Z | Paul Ker |
| 032 | Rebol | 170220T154136Z | draegtun |
| 080 | SQL | 170220T142842Z | grabthef |
| 117 | Sinclair ZX81/Timex TS1000/1500 | 170220T121551Z | Shaun Be |
| 036 | Haskell 36 Bytes | 170211T173724Z | brander |
| 030 | SmileBASIC | 170209T161931Z | 12Me21 |
| 037 | Python 2 | 161101T035624Z | James Mu |
| 004 | Pushy | 161223T124353Z | FlipTack |
| 047 | ><> | 161223T153046Z | redstarc |
| 057 | python3 | 161030T213754Z | Moonchil |
| 010 | CJam | 161010T144730Z | Luis Men |
| 022 | Cubix | 161031T163145Z | ETHprodu |
| 146 | ForceLang | 161030T220915Z | SuperJed |
| 8853 | C | 161031T154220Z | user6138 |
| 043 | C | 161011T154400Z | cleblanc |
| 005 | Dip | 161026T192933Z | acrolith |
| 005 | Jelly | 161010T121825Z | Jonathan |
| 031 | Crystal | 161026T210454Z | Zatherz |
| 086 | Swift 3 | 161026T195558Z | JAL |
| 153 | SQL | 161026T133845Z | Pete Ard |
| 063 | C++ | 161026T093959Z | anatolyg |
| 065 | C++ 11 | 161025T115923Z | Karl Nap |
| 016 | Element | 161025T023252Z | PhiNotPi |
| 075 | BrainFlak 75 Bytes | 161010T163458Z | Riley |
| 011 | 05AB1E | 161024T154837Z | Geno Rac |
| 041 | Scala | 161014T093827Z | corvus_1 |
| 129 | Brainfuck | 161020T181826Z | Anonymou |
| 008 | 05AB1E | 161020T154722Z | Oliver N |
| 196 | Python 3 | 161019T204543Z | penalosa |
| 076 | Perl | 161019T163237Z | Gabriel |
| 018 | Vim | 161015T234158Z | DJMcMayh |
| 027 | Braingasm | 161015T180617Z | daniero |
| 096 | C++ 96 Bytes | 161010T170351Z | Anedar |
| 011 | 2sable | 161013T201325Z | Geno Rac |
| 007 | Pyth | 161010T162639Z | Dignissi |
| nan | RProgN | 161013T234132Z | ATaco |
| 006 | 05AB1E | 161010T122112Z | Emigna |
| 032 | Haskell | 161013T181530Z | xnor |
| 008 | Pyth | 161010T202645Z | Connor D |
| 114 | F# | 161013T155853Z | magumbas |
| 081 | Elixir | 161013T133037Z | adrianmp |
| 056 | Prolog | 161012T162802Z | Sijmen S |
| 031 | MoonScript | 161012T153624Z | manatwor |
| 068 | GameMaker Language | 161012T151033Z | Timtech |
| 071 | Common Lisp Lispworks | 161012T050806Z | sadfaf |
| 110 | Java | 161012T024017Z | 416E6472 |
| 078 | C++ | 161011T211034Z | Cody |
| 084 | VBA | 161011T191248Z | krish KM |
| 036 | Lua | 161011T191211Z | IDid |
| 008 | Vim | 161011T111615Z | udioica |
| 029 | Ruby | 161011T050636Z | anna328p |
| 2724 | Ruby | 161010T204718Z | Level Ri |
| nan | Javascript | 161010T171040Z | Esteru |
| 058 | PHP | 161011T151218Z | ʰᵈˑ |
| 005 | Charcoal | 161011T130102Z | ASCII-on |
| 109 | Excel VBA | 161011T123650Z | tjb1 |
| 032 | Ruby | 161011T093151Z | IMP1 |
| 019 | jq | 161011T110137Z | manatwor |
| 027 | Groovy | 161011T105205Z | manatwor |
| 7270 | Java 7 | 161011T075205Z | Numberkn |
| 023 | Matlab | 161010T131805Z | mathause |
| 008 | J | 161011T002907Z | Conor O& |
| 047 | Racket | 161010T133504Z | rnso |
| 041 | RProgN | 161011T021421Z | ATaco |
| 008 | Befunge93 | 161010T213446Z | Demur Ru |
| 007 | Jolf | 161011T003450Z | Conor O& |
| 006 | Pyth | 161011T000222Z | Luis Men |
| 059 | Clojure | 161010T223438Z | Carcigen |
| 081 | BrainFlak | 161010T195003Z | DJMcMayh |
| 070 | Brainfuck | 161010T164835Z | Sean McB |
| 019 | Perl | 161010T154032Z | Dada |
| 006 | Pyke | 161010T171720Z | Blue |
| 035 | Haskell | 161010T135902Z | Craig Ro |
| 020 | Perl 5 | 161010T142218Z | simbabqu |
| 026 | Ruby | 161010T152740Z | Lee W |
| 016 | Vitsy | 161010T143023Z | Addison |
| 108 | C++ | 161010T142837Z | John Doe |
| 045 | R | 161010T143202Z | Billywob |
| 023 | Perl 6 | 161010T142604Z | Brad Gil |
| 035 | Bash | 161010T135713Z | manatwor |
| 008 | MATL | 161010T125751Z | Suever |
| 039 | Forth | 161010T134315Z | mbomb007 |
| 034 | Python 2 | 161010T122740Z | Jonathan |
| 069 | Batch | 161010T131144Z | Neil |
| 009 | Jellyfish | 161010T123648Z | Martin E |
| 012 | Brachylog | 161010T124404Z | Fatalize |
| 042 | C# | 161010T123735Z | adrianmp |
| 034 | JavaScript ES6 | 161010T123546Z | Huntro |
| 036 | Gema | 161010T122913Z | manatwor |
| 008 | V | 161010T122812Z | DJMcMayh |
| 014 | Retina | 161010T122553Z | Martin E |
Swift 6, 52 bytes
let s={(1...$0).map{print({String.init}()("*",$0))}}
Vyxal 3, 4 bytes
-1 byte: remembered ★ exists
ƛ★×,
ƛ★×,
ƛ # map over implicit range
★× # "*" times n
, # print with newline
💎
Created with the help of Luminespire.
<script type="vyxal3">
ƛ★×,
</script>
<script>
args=[["5"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>
AWK, 26 25 bytes
{for(;$1--;)print s=s"*"}
Shaved a byte.
{for(;$1--;print s)s=s"*"}
{for(;$1--; # decrement input till 0
print s) # print string s with new line
s=s"*"} # concat an asterisk each loop
SAKO, 69 bytes
PODPROGRAM:F(N)
**)TEKST
*
POWTORZ:J=1(1)I
LINIA
POWTORZ:I=1(1)N
WROC
Sometimes the simplest solutions are the shortest.
Full programme version, 71 bytes
CZYTAJ:N
**1)TEKST
*
POWTORZ:J=1(1)I
LINIA
POWTORZ:I=1(1)N
STOP1
KONIEC
Tcl, 27 bytes
time {puts [append s *]} $n
time {puts [string repe * [incr i]]} $n
while {[incr i]<=$n} {puts [string repe * $i]}
Thunno d, \$9\log_{256}(96)\approx\$ 7.41 bytes
R{1+'**ZK
Attempt This Online! The slight misallignment on the third line of output is just ATO's formatting.
Explanation:
R{1+'**ZK # Implicit input
R{ # Loop through range(0, input)
1+ # Add one
* # Multiply this
'* # With the string "*"
ZK # Print
# The d flag stops the implicit print at the end
Since the course is taught in C++, I'm eager to see solutions in C++.
C++, 123 bytes
(the joke here is to deliver a 'pure' c++ answer)
#include<string>
class X:public std::string{public:X(int i):std::string(i*(i+1)/2,'*'){for(;i--;)insert(i*(i+1)/2,"\n");}};
Vyxal j, 3 bytes
×*¦
How?
×*¦
×* # Repeat an asterisk the implicit input amount of times
¦ # Prefixes
# j flag joins on newlines
tinylisp, 84 bytes
(load library
(d Q(q((A)(join(map string(map* repeat-val(repeat-val 42 A)(1to A)))nl
tinylisp, 89 bytes
(d P(q((A N)(i(s N 1)(i(disp(string A))A(P(c 42 A)(s N 1)))(string A
(d Q(q((N)(P(q(42))N
the length of the library functions makes this surprisingly close to the library based one.
Regenerate, 3 bytes
\*+
You need to pass the input using -l flag.
Example run:
wasif@wasif:~/Downloads/Regenerate$ python3 regenerate.py -l 5 '\*+'
*
**
***
****
*****
wasif@wasif:~/Downloads/Regenerate$
Rockstar, 47 bytes
listen to N
X's0
while N-X
let X be+1
say "*"*X
Try it here (Code will need to be pasted in)
Actually, 8 bytes
R`'**`Mi
Explanation:
R`'**`Mi
R range(1, n+1) ([1, 2, ..., n])
`'**`M for each element: that many asterisks
i flatten and implicitly print
5 bytes
R'**i
Add++, 11 bytes
L,R"*"€*BFn
A function that returns the string given an argument \$n\$.
A full program is 17 bytes:
y:?
Ey,x:"*",*i,O
How they work
L, ; Define "anonymous" function
; It takes one argument, e.g 5
R ; Range STACK = [[1 2 3 4 5]]
"*" ; Push "*" STACK = [[1 2 3 4 5] "*"]
€ ; For each i:
* ; Repeat "*" i times STACK = [["*" "**" "***" "****" "*****"]]
BF ; Flatten STACK = ["*" "**" "***" "****" "*****"]
n ; Join by newlines STACK = ['*\n**\n***\n****\n*****']
; Return the top value
y:? ; y = input()
Ey, ; for i in range(y):
x:"*", ; x = "*"
*i, ; x *= i
O ; print(x)
Flurry, 88 bytes
{}{()[<><<>()>({})]({}{(){}(((<><<>()>){})[{}{<({}){}>}])}{<(<({})(<({}){}>){}>){}>})}{}
Can be run with the interpreter as follows:
$ ./Flurry -bnn -c "$pgm" 5
*
**
***
****
*****
This is heavily based on my answer to "Print a 10 by 10 grid of asterisks". In particular, I'm reusing my derivations of succ, and push_star, and the number 10.
push_star is a function that pushes 42 to the stack and returns its argument unchanged:
push_star := {(){}(((<><<>()>){})[{}{<({}){}>}])}
A function that takes a number n and pushes 42 to the stack n times, then pushes 10, and returns n+1:
push_row = λn. (n push_star (); push 10; succ n)
= λn. (push (n push_star 10); succ n)
= λn. K (succ n) (push (n push_star 10))
= λn. K (succ (push n)) (push (pop push_star 10))
:= { () [succ ( {})] ( {} push_star 10)}
:= { () [succ ( {})] ( {} push_star {<(<({})(<({}){}>){}>){}>})}
:= { () [succ ( {})] ( {} {(){}(((<><<>()>){})[{}{<({}){}>}])}{<(<({})(<({}){}>){}>){}>})}
:= {()[<><<>()>({})]({}{(){}(((<><<>()>){})[{}{<({}){}>}])}{<(<({})(<({}){}>){}>){}>})}
The number 1:
1 = λf n. f n
= λf. f
:= { {} }
Pop a number from the stack and apply push_row that many times to 1:
main = pop push_row 1
:= {}{()[<><<>()>({})]({}{(){}(((<><<>()>){})[{}{<({}){}>}])}{<(<({})(<({}){}>){}>){}>})}{{}}
Since popping from an empty stack returns 1, we can replace the final {{}} with {}, yielding:
{}{()[<><<>()>({})]({}{(){}(((<><<>()>){})[{}{<({}){}>}])}{<(<({})(<({}){}>){}>){}>})}{}
J, 8 bytes
[\@$&'*'
Explanation:
$&'*': Reshape*according to.
$: Reshape.&: Bound with (partial application).'*': Character literal*.
@: Function composition.[\: Each prefix of.
[: Identity.\: Apply the preceding verb to each prefix of the right argument.
Dyalog APL, 8 bytes
'*'/⍤0⍨⍳
Explanation:
'*': Literal character*./⍤0⍨: Select each 0-ranked vector (scalar) according to.
/: Select from the right argument according to the left.⍤0: Apply the preceding function to each scalar in the left and right arguments.⍨: Apply the preceding function, but with the left and right arguments switched (so we select now from the left argument according to the right).
⍳: Generate integers from 1 to the argument (inclusive)
C++ (gcc), 65 bytes
#include<ios>
int f(int n){for(n&&f(n-1);~n;putchar(n--?42:10));}
Including the #include in the byte count.
PowerShell, 21 20 bytes
1.."$args"|%{'*'*$_}
Loops from 1 to input $args, each iteration using string multiplication to construct a string of that many $_ asterisks. Default behavior for the implicit Write-Output at the end is with a newline for separator, so we get that for free.
PS C:\Tools\Scripts\golfing> .\draw-asterisk-pattern.ps1 5
*
**
***
****
*****
PS C:\Tools\Scripts\golfing> .\draw-asterisk-pattern.ps1 2
*
**
PS C:\Tools\Scripts\golfing> .\draw-asterisk-pattern.ps1 7
*
**
***
****
*****
******
*******
-1 byte thanks to Veskah.
Powershell, 24 bytes
1.."$args"|%{$a+="*";$a}
Erlang (escript), 50 bytes
s(0)->"";s(N)->s(N-1)++string:copies("*",N)++"~n".
Explanation
s(0)->""; % If the current item is 0, return the empty string.
s(N)-> % Otherwise:
s(N-1) % Return the N-1 string.
++string:copies("*",N).
% Append "*" N times.
++"~n" % Append a newline.
Keg, -pn, 8 bytes
Ï^⑷`*`*,
Explanation
Ï^
In the first part of the program, we push a range from 0 to n onto the stack. Then we reverse it because otherwise, the triangle is upside down.
⑷
We then start a mapping to the entire stack with the following:
`*`*,
Which says to multiply the string * by the number being mapped and print it.
C++ (gcc), 61 bytes
int f(int n){for(n&&f(n-1);~n;__builtin_putchar(n--?42:10));}
Uses ASCII char codes and builtins to shorten another solution.
JavaScript (ES6), 31 bytes
This one includes both a leading and a trailing line-break.
We start with a string s containing only a line-break. Then we process n recursive calls, adding an asterisk on the left side of this string at each iteration. The concatenation of all intermediate strings leads to the expected result.
f=(n,s=`
`)=>n?s+f(n-1,'*'+s):s
Without asterisk, 36 bytes
f=(n,s=`
`)=>n?s+f(n-1,atob`Kg`+s):s
GolfScript, 11 bytes
~,{)"*"*n}%
Explanation:
~, Create list [0...input-1]
{ }% Map over list:
)"*"*n Increment, push that many "*"s, push newline
MathGolf, 4 bytes
╒⌂*n
Try it online or verify some more test cases.
Explanation:
╒ # Push a list in the range [1, (implicit) input]
⌂ # Builtin for the asterisk character "*"
* # Map each value to that amount of asterisk characters (similar as in Python)
n # And join this list of strings by newlines
# (after which the entire stack joined together is output implicitly as result)
W n, 6 4 bytes
'**M
Explanation
M % Map every item in the implicit input with...
% (There's an implicit range from 1)
'** % asterisks input times
n % Join the result with a (n)ewline
How do I use the n flag?
... W.py filename.w [input-list] n
Wren, 41 bytes
Fn.new{|i|(1..i).map{|n|"*"*n}.join("
")}
Explanation
Fn.new{|i| // New function with the parameter i
(1..i) // Generate a range from 1 to i
.map{|n|"*"*n} // Replace the numbers with asterisks
.join("
")} // Join with newline
R, 33 bytes
cat(strrep("*",1:scan()),sep="
")
I hope it's not a dupe - I was able to find only one other R answer.
Leverages strrep and vectorization to build the vector "*","**",...,"******" and prints with cat using newline as a separator.
Java 7 11, 88 73 58 bytes
String c(int n){return(n<2?"":c(n-1)+"\n")+"*".repeat(n);}
-15 bytes by converting to Java 11.
Try it online. (NOTE: String#repeat(int) is emulated as repeat(String,int) for the same byte-count, because TIO doesn't contain Java 11 yet.)
Explanation:
String c(int n){ // Recursive method with integer parameter and String return-type
return(n<2? // If `n` is 1:
"" // Start with an empty String
: // Else:
c(n-1) // Start with a recursive call with `n-1`
+"\n") // and a trailing new-line
+"*".repeat(n);} // And append `n` amount of '*'
k, 16 12 bytes
4 bytes removed thanks to ngn! :)
{`0:,\x#"*"}
{ } /function(x)
x#"*" /reshape "*" by x
,\ /scan concatenation through the list
`0: /print line by line
brainfuck, 42 bytes
++++++++++<<,[>>[>]>--[<+>++++++]<-[.<]<-]
Takes the number as the char code of the input. Add two to avoid using negative cells, four to avoid wrapping.
How It Works:
Tape Format: Input 0 10 * * * *...
++++++++++ Creates the newline cell
<<, Gets input
[ While input
>>[>] Go to the end of the line of asterisks
>--[<+>++++++]<- Add an asterisk to the end of the line
[.<] Print the line including the newline
<- Subtract one from the input
]
Dyalog APL, 8 bytes
↑'*'⍴⍨¨⍳
↑ matrify the list consisting of
'*' the string "*"
⍴⍨ reshaped by
¨ each of
⍳ the integers 1 through the argument.
Pyt, 17 bytes
←ř↔0⇹Á`⑴67**Ƈǰƥłŕ
Explanation:
← Get input
ř↔ Push [input,input-1,...,1] onto stack
0⇹ Push 0, and flip the top two items on the stack
Á Push contents of array onto stack
` ł While top of stack is not 0, loop:
⑴ Create an array of 1s with length equal to the top of the stack
67** Multiply each element in the array by 42
Ƈǰƥ Convert to ASCII, join, and print; if top of stack is 0, exit loop
ŕ Pop the 0
Windows batch, 69 bytes
@set v=
@for /l %%G in (1,1,%1)do @call set v=*%%v%%&call echo %%v%%
Just putting an extra asterisk after each line.
Julia 0.6, 13 bytes
n->"*".^(1:n)
^ is used for exponentiation and string repeating in Julia. This follows from the choice of '*' for string concatenation, which was chosen over '+' because addition is supposed to be commutative, and string concatenation is not. A function or operator preceded by . is "broadcasted", which in this case mean it is applied elementwise.
Outputs an array of strings. Depending on how the rules are interpreted it may need println.("*".^(1:n)) (23 bytes, meets any interpretation) or display("*".^(1:n)) (22 bytes, prints exact desired output plus an additional line about the array type) or "*".^(1:x).*"\n" (19 bytes, array of strings with newlines). Example of each in TIO.
Commodore 64/VIC-20 BASIC (and compatible C= 8-bits), ~77 tokenized BASIC bytes
0 INPUT"NUMBER OF *";A:ON-(A<1)GOTO1:J=1:FORI=1TOA:FORX=1TOJ:PRINT"*";:NEXTX:J=J+1:PRINT:NEXTI
1 :
Technically line 1 isn't required, but I'm mis-using the ON...GOTO command as a conditional GOTO in line zero so I added in the shortest possible line 1 to end it gracefully.
You will need to use Commodore keyword abbreviations to fit line zero on a C64, see the screen shot below (Note that the C128 in 128 mode might have different keyword abbreviations, but then you can enter more characters so you probably won't need it):
Underload, 15 13 bytes
-2 or -3 bytes thanks to @ØrjanJohansen
(
)((*)~*:S)^
Input is a Church numeral inserted between the ) and ^ on the second line. For example:
(
)((*)~*:S)::*:**^
If printing a leading newline is allowed, the following solution works by ommiting the ~, for 12 bytes:
(
)((*)*:S)^
J, 11 Bytes
$&'*'@>:@i.
Includes trialing spaces on every line.
Explanation:
$&'*'@>:@i. | Full program
@ @ | Verb conjunction characters, make sure it isn't executed as a hook
i. | Integers 0 to n-1
>: | Increment (Integers 1 to n)
$&'*' | Reshape the array '*' to the size of each item by repeating it cyclically
Note that normally the dyadic ranks of $ are 1 _, so that $&'*' 1 2 3 would create a 1 by 2 by 3 array of '*'s. However, the @ cunjunction ensures that $&'*' is applied to each cell of it's argument.
LaTeX, 171 bytes
I had to use LaTeX instead of plain TeX for the \typein macro...
Here it is, as golfed as I could:
\documentclass{book}\begin{document}\typein[\n]{}\newcount\i\newcount\a\i=0\loop{\a=0\loop*\advance\a by1\ifnum\i>\a\repeat}
\advance\i by1
\ifnum\n>\i\repeat\enddocument
Explanation:
\documentclass{book}% Book because it is shorter than article ;)
\begin{document}% Mandatory...
\typein[\n]{}% User inputs \n
\newcount\i% Create a line counter
\newcount\a% And an asterisk counter
\i=0% Initializes the line number to zero
\loop{% Line number loop
\a=0% Sets the number of asterisks to zero
\loop% Asterisk loop
*% Prints the asterisk
\advance \a by 1% Adds one to \a
\ifnum\i>\a% If the line number is smaller than the number of asterisks
\repeat% Then repeat
}% Otherwise prints a new line
\advance\i by 1% And add 1 to the line counter
\ifnum\n>\i% If input number is less than the number of lines then
\repeat% Repeat
\enddocument% And finish LaTeX
Excel VBA, 32 Bytes
Anonymous VBE immediate window function that takes input from range A1 and outputs to the VBE immediate window.
For i=1To[A1]:?String(i,42):Next
Excel VBA, 37 Bytes
Anonymous VBE immediate window function that takes input from cell [A1] and outputs to range [B:B]
[B1].Resize([A1])="=Rept(""*"",Row())
QBIC, 16 bytes
:#*|[1,a|B=B+A?B
Explanation:
: Gets a cmd line param as number called 'a'
#*| Define A$ as '*'
[1,a| FOR b = 1 to a
B=B+A Extend B$ with another astrix
?B Print B$
<FOR LOOP implicitly closed>
QBIC's seen a few updates since this answer was posted. This could now be done with these 12 bytes:
[:|B=B+@*`?B
8th, 38 bytes
Code
( ( "*" . ) swap times cr ) 1 rot loop
SED (Stack Effect Diagram) is: n --
Example
ok> 5 ( ( "*" . ) swap times cr ) 1 rot loop
*
**
***
****
*****
RProgN 2, 5 bytes
²`**S
Outputs a stack of strings.
Explained
²`**S
² # Define the function with the next two concepts, `* and * in this case.
S # Create a stack from 1 to the input, and execute the previous function on each element.
* # Multiply the element by
`* # The string "*", which repeats it. Output is implicit.
TI-Basic, 28 22 bytes
Prompt A
"*
For(B,1,A
Disp Ans
Ans+"*
End
Common Lisp, SBCL, 69 66 61 45 44 41 bytes
full program:
(dotimes(i(read))(format t"~v{*~}*
"i 1))
Explanation
(dotimes(i(read)) <-- loop from i=0 to i=INPUT-1
(format t"~v{*~}*
"i 1)) <-- loop, displaying i+1 asterisks per line
Ideas for improvement are welcomed.
JavaScript (ES6), 44 bytes
n=>[...Array(n)].map(_=>s+="*",s="").join`
`
If outputting as an array is permitted then subtract 8 bytes.
n=>[...Array(n)].map(_=>s+="*",s="")
Try it
f=
n=>[...Array(n)].map(_=>s+="*",s="").join`
`
oninput=_=>o.innerText=f(+i.value)
o.innerText=f(i.value=5)
<input id=i min=1 type=number><pre id=o>
Perl 6 (27)
{.say for '*' <<x<<(1..$_)}
Forte, 101 bytes
1INPUT0
2LET4=(0*(0+1))*5
4END
6PUT42:LET7=6+1
7LET6=6+10
8PUT10:LET9=((9+9)+14)-3:LET3=8+5
3LET8=9-1
I've been wanting to try Forte for a while, and this seemed like a fine challenge for it. It was quite an effort writing the program, then golfing it and making it fit in one-digit numbered lines. It was also quite fun :) Kudos to ais523 for inventing this and many more incredible languages.
Since I'm in the mood I'll write an explanation in details, covering also the basis of the language.
Explanation
First, a very brief introduction for those who don't know this language, you can find the full specification and guide on its esolang page.
The syntax of Forte is similar BASIC, with line numbers prepended to each line, only that in Forte you dont GOTO 10, you make 10 come to you!
With the command LET, you can assign a number to... another number. If the command LET 10=20 is executed, from now on every time the number 10 is referenced, directly or indirectly (5+5 counts too), it is replaced by 20 instead. This affects line numbers too, so if we were on line 19 when executing that instruction, the next line to be executed will be our old line 10, now line 20.
Now, the actual code (with spaces added for clarity):
1 INPUT 0
This is practically LET 0=<a number taken from stdin>, in this program 0 is used like a variable, and only in line number 2
2 LET 4=(0*(0+1))*5
4 END
Line 4 is the one that terminates the program, so we want to put it at the position where we are done printing asterisks. How many of them do we need to print, though? As fitting for a "draw a triangle" challenge, the answer is given by triangular numbers!
The formula to calculate the nth triangular number is n*(n+1)/2. We will print an asterisk every 10 lines, so we multiply it by 10 and get n*(n+1)*5. Use 0 instead of n, add parentheses for every operation (always mandatory in Forte), and you get line 2.
6 PUT 42:LET 7=6+1
7 LET 6=6+10
Here we print the asterisks. The ASCII code for * is 42, so you get what PUT 42 does. The colon separates multiple instructions on the same line, so we then execute LET 7=6+1. What use do we have in redefining 7 as 6+1? Isn't it the same thing? Let's see what happens next.
Line 7 redefines 6 as 6+10, so 16. Ignoring for a moment the rest of the code, this means that when we reach line 16 we will print another asterisk, and then redefine 7 as 6+1. But now 6 is 16, so we are redefining it as 16+1! Line 7 is now line 17 and is the next one to be executed, changing 6 to 6+10, which means changing 16 to 16+10, so on line 26 we will print another asterisk, and so on.
Since in Forte a line cannot change its own number, this is the simplest structure for a loop, two lines changing each other's numbers repeatedly. I know this can be quite confusing, but that's kind of the point of the whole language ;)
8 PUT 10:LET 9=((9+9)+14)-3:LET 3=8+5
3 LET 8=9-1
Ok, that line 3 put here may seem out of place, but in Forte line order doesn't matter, only line numbering. I've chosen to put this line at the end because this pair of lines forms again a cycle, redefining each other's numbers, so it's easier to see them together. Moreover, the first time line 3 is executed (when 3 is still equal to 3 and nothing else), it has no effect on the program, redefining 8 as 8.
As you probably have guessed PUT 10 prints a newline, then the hard part comes. We want each line to have one more asterisk than the one before, so to know where to put the next newline we need to know where the previous one was. To do this, we use another "variable": the number 9. In practice, when we are about to print a newline on line 8, line 3 will be positioned (near) where the previous newline was printed, we'll use it to calculate where the next newline must be printed and move 9 (near) there. (Remember that line 8 can't move itself). Then we move line 3 a bit further than the current position, and use it to move line 8 to our 9.
These three numbers (3,8, and 9) were chosen in order not to conflict with any other redefinition of a number, and to be easy to use together (since neither 5 nor 1 will ever be redefined by this program we can do LET 3=8+5 and LET 8=9-1).
All of these numbers will always be redefined as themselves+10n. This means that 8 will only ever be redefined to numbers ending with an 8 (28,58,98...). This same property is valid for any other number redefinintion in this program (except 0), because this helped greatly my reasoning while writing the code (if you are crazy enough you can try to golf some bytes by using a smaller step, but I doubt there is much room for golfing without completely changing approach).
So, the actual difficult part of this program: LET 9=((9+9)+14)-3. This operation can be better explained if expanded to LET 9=(9+(9-(3-4)))+10, where 4 and 10 represent their respective actual numerical values (in the code they are grouped as 14, 4 wouldn't actually be usable because it was redefined in line 2). As we said before 3 is still placed near the previous newline; we subtract 4 from it to get the previous position of 9 (if 3 is 63, our previous 9 was 59), then we compute the difference between the current and the previous 9 to know how many program-lines have passed since the last newline was printed. We add this value to the current 9, plus 10 because the next time we will want to print one more asterisk. Our 9 is now where we want to print the next newline, so we move 3 to the current position, it will then move 8 to where it's needed, just before 9.
Phew, that was long. And hard. No dirty jokes, please
GNU sed, 25 24 20 + 1(n flag) = 21 bytes
Edit: 4 bytes less based on Riley's comments
x;G;:;P;s:\n.:*\n:;t
Run example: the input is in unary format, which for sed is allowed based on this consensus
me@LCARS:/PPCG$ sed -nf draw_triangle.sed <<< "0000"
*
**
***
****
A leading newline is present in the output, but this is allowed by the OP.
Explanation:
x;G # prepend a newline to unary string
: # start loop
P # print first line only
s:\n.:*\n: # shift one unary char from 2nd line to 1st, converted to a '*'
t # repeat
Röda 0.12, 30 29 bytes, non-competing
h i{seq 1,i|{|j|print"*"*j}_}
This is my first try in this scripting language created by fergusq :D
This is a function. To run, use this:
h i{seq 1,i|{|j|print"*"*j}_}
main {
h(5)
}
Ungolfed
h i{ /* Define a function h with parameter i */
seq 1,i /* Generate a sequence of numbers from 1 to i */
|{ }_ /* and pipe it to a for-loop */
|j| /* where j is the number in the sequence*/
print"*"*j /* and print an asterisk duplicated j times*/
}
K, 16 Bytes
{-1(1+!x)#'"*"};
{-1(1+!x)#'"*"}10;
*
**
***
****
*****
******
*******
********
*********
**********
EDIT BELOW - adding explanation)
/Code ---> explanation (pretend x is 3)
1+!x ---> Numbers from 1 to 3
1 2 3#"*" ---> Take left many items of right ==> ("*";"**";"***")
-1x ---> Print x to the console, if x is a list, each item is printed to a new line
example(notice the -1 printed at the bottom).
-1("*";"**";"***")
*
**
***
-1
To silence the output(-1), put a semicolon after the expression e.g.
-1("Hello");
Hello
PHP, 43 34 31 28 bytes
Note: uses IBM 850 encoding (old favorite reinvented recently)
for(;$argn--;)echo$o.=~ı,~§;
Run like this:
echo 5 | php -nR 'for(;$argn--;)echo$o.=~ı,~§;';echo
> *
> **
> ***
> ****
> *****
Explanation
Iterates from N down to 0. Add an asterisk to $o for each iteration, then outputs $o and a newline.
Tweaks
- Add an asterisk to
$ofor each iteration, and then output$o. Saves 9 bytes - Combined adding an asterisk to
$owith outputting, saves 3 bytes - Saved 3 bytes by using
$argn
Terrapin logo, 67 bytes
to a :a
make "b 1 repeat :a[repeat :b[type "*]make "b b+1 pr "]
end
Bash + Unix utilities, 26 bytes
seq -f10^%f-1 $1|bc|tr 9 *
Output to stderr should be ignored.
The code above works on TIO since the working directory there has no visible files. If this needs to run in a directory that contains a visible file, change * to \* at the cost of one byte (27 bytes):
seq -f10^%f-1 $1|bc|tr 9 \*
AutoHotkey, 28 bytes
Loop,%1%
Send,{* %A_Index%}`n
%1% is the first argument passed in
%A_Index% is the current iteration in the loop
Send sends a keystroke multiple times if it's followed by a number
Perl 6, 17 bytes
put(\*x++$)xx get
Full program that prints to stdout.
How it works:
\* # a Capture object that stringifies to the asterisk,
x # string-repeated by
++$ # a counter that starts at 1,
put( ) # and printed followed by a newline.
xx get # Do all of that n times.
Invokes the put statement n times, each time printing the asterisk repeated by the counter variable ++$.
Perl 6, 21 bytes
{.put for \*Xx 1..$_}
A lambda that prints to stdout.
How it works:
{ } # A lambda.
\* # A Capture object that stringifies to the asterisk.
1..$_ # Range from 1 to n.
X # Cartesian product of the two,
x # with the string repetition operator applied to each result.
.put for # Iterate over the strings, and print each followed by a newline.
k, 18 bytes
{-1@(1+!x)#\:"*";}
Explanation:
-1@ // prints to console
1+!x //returns list from 1 to x (implicit input)
#\: //for each item in the prefixed list, "take" this many
"*" //asterisk string
Rebol, 32 bytes
loop do input[print append{}"*"]
Ungolfed:
loop do input [
print append {} "*"
]
SQL, 80 bytes
DECLARE @i INT=1,@ INT=5WHILE @i<>@ BEGIN PRINT REPLICATE('*',@i)SET @i=@i+1 END
ungolfed:
DECLARE @index INT=1,
@rows INT=5
WHILE @index<>@rows
BEGIN
PRINT REPLICATE('*',@index)
SET @index=@index+1
END
Sinclair ZX81/Timex TS1000/1500, 117 bytes (listing)
1 PRINT "NUMBER OF * TO SHOW?"
2 INPUT A
3 IF A<1 THEN STOP
4 LET J=A/A
5 FOR I=1 TO A
6 FOR X=1 TO J
7 PRINT "*";
8 NEXT X
9 LET J=J+1
10 PRINT
11 NEXT I
Note that because the screen scroll isn't handled in this program listing, you may only enter a number between 0 and 22 because as soon as the ZX81 hits the bottom of the screen it will halt the program. You can see the missing * by using CONT when this happens, but also note that the ZX81 only has 32 columns text by default in BASIC.
Haskell 36 Bytes
Here is a version using map.
f="*":map('*':)f;g=unlines.(`take`f)
Input g 10
Output "*\n**\n***\n****\n*****\n******\n*******\n********\n*********\n**********\n"
Alternatives of interest might be:
38 Bytes
g n=id=<<scanl(\x y->'*':x)"*\n"[2..n]
38 Bytes
f="*\n":map('*':)f;g n=id=<<(n`take`f)
36
g n=id=<<(take n$iterate('*':)"*\n")
SmileBASIC, 30 bytes
INPUT N
FOR I=1TO N?"*"*I
NEXT
Python 2, 38 37 bytes
There are only 36 characters shown, but a trailing newline is needed to avoid an EOF-related error raised by the interpreter. 1 byte knocked off for Flp.Tkc's observation.
for n in range(input()+1):print'*'*n
Output for n=5
# leading newline here
*
**
***
****
*****
Python 3, 45 bytes
The actual list comprehension is never assigned or printed, but if it were, it would be full of Nones, as None is the default return value of print().
[print('*'*n)for n in range(int(input())+1)]
Pushy, 4 bytes
:42"
This method takes advantages of Pushy's automatic int/char conversion:
\ Implicit: Input on stack
: \ Input times do: (this consumes input)
42 \ Push 42 (char '*')
" \ Print whole stack
Because each iteration adds a new * char, this outputs a triangle. For example, with n=4:
* \ Stack: [42]
** \ Stack: [42, 42]
*** \ Stack: [42, 42, 42]
**** \ Stack: [42, 42, 42, 42]
><>, 47 bytes
<v[1:$-1;!?:$+10
0\:&
$>:@=?v1+&:&"*"o
0f]oa~<.
This was fun to write, though a bit more bytes than I expected.
python3, 58 57 bytes
print('\n'.join(['*'*(p+1)for p in range(int(input()))]))
Ungolfed:
rownums = int(input())
output = []
for i in range(rownums):
currrow = "*" * (i+1) # 'i' * 5 == 'iiiii'
output.append(currrow)
print('\n'.join(output))
CJam, 13 11 10 bytes
Thanks to @MartinEnder for removing two bytes, and @Linus for removing one more!
ri{)'**N}%
Explanation
ri e# Read input as an integer n
{ }% e# Run this block for each k in [0 1 ... n-1]
) e# Add 1 to the implicitly pushed k
'* e# Push asterisk character
* e# Repeat the character k+1 times
N e# Push newline
e# Implicitly display
Cubix, 22 bytes
?(.;I:^;/-.@o;(!\>'*oN
Test it online! Outputs a trailing newline.
At first I wasn't sure I could get this to fit on a 2-cube, but in the end it worked out fine:
? (
. ;
I : ^ ; / - . @
o ; ( ! \ > ' *
o N
. .
I'll add an explanation when I have time, hopefully later today.
ForceLang, 146 bytes
def S set
def G goto
S a io.readnum()
S b 0
label 0
if a=b
G 1
if b
io.writeln()
S b 1+b
S c 0
label b
io.write "*"
S c 1+c
if b=c
G 0
G b
label 1
C, 88 bytes / 53 bytes
Using C89.
g(a){a&&g(a-1);a<2||puts("");while(a--)putchar('*');}main(int a,char**v){g(atoi(v[1]));}
With whitespace for clarity:
g(a) {
a && g(a-1);
a<2 || puts("");
while (a--) putchar('*');
}
main(int a, char** v) {
g(atoi(v[1]));
}
Without main, this function is 53 bytes:
g(a){a&&g(a-1);a<2||puts("");while(a--)putchar('*');}
C, 47 46 45 43 bytes
Takes input from the command line
f(n){for(n&&f(n-1);~n;putchar(n--?42:10));}
Basically if n is not 0 recurse on n-1. at the top of the recursion where n is 0 it just prints a newline, the for loop terminates when n is -1 or ~n is zero, otherwise it prints ASCII 42 which is '*'. Try it on ideone
C++ 58 Bytes + 19 for including iostream is 77
#include<iostream>
int f(int n){for(n&&f(n-1);~n;std::cout<<(n--?"*":"\n"));}
main(c,v)char**v;
{
f(atoi(v[1]));
}
a.exe 3
*
**
***
Dip, 6 5 bytes
`**En
-1 byte thanks to Oliver
Explanation:
`** Push "*" repeated input times
E Prefixes
n Join by newlines
Jelly, 6 5 bytes
”*ẋþY
How?
”*ẋþY - Main link: n
”* - literal string "*"
þ - form outer product with the dyadic function:
ẋ - repeat list (right input is an implicit range(n), Jelly defaults to 1-based)
so the outer product is like:
[[i*'*' for i in range(1,len("*")+1)] for x in range(1,n+1)]
Y - join with line feeds
- implicit print
Bounty:
I'm not sure what the no ordinals clause is, since a character is a lookup of an ordinal.
Direct lookup would just be 42Ọẋþ³Y for 7 bytes - where the ³ gets us the input)
A short slightly indirect method would be, for 8 bytes, “)’Ọẋþ³Y - where we lookup ')' in jelly's code page, which is 1-indexed so “)’ yields 42.
Crystal, 31 bytes
n=5;(1..n).each{|x|puts "*"*x}
Output:
*
**
***
****
*****
Really demonstrates the beauty of Crystal/Ruby. n is the integer input, (1..n) is an inclusive range from 1 to n ([1, n]). .each is a method on Range that runs the provided block for every integer in the range.
Swift 3, 86 bytes
for i in 1...Int(CommandLine.arguments[1])!{print(String(repeatElement("*",count:i)))}
Yuck. If I can drop the Int and String initializers I might be able to get this shorter than Java. Open to any optimizations.
Ungolfed:
import Foundation
guard CommandLine.argc > 1, let a = Int(CommandLine.arguments[1]) else {
fatalError("Invalid or nonexistent argument")
}
for i in 1...a {
print(String(repeatElement("*", count: i)))
}
Usage:
➜ ~ swift asterisk.swift 5
*
**
***
****
*****
SQL, 153 Bytes
Golfed:
CREATE PROCEDURE P @n INT AS BEGIN DECLARE @a INT;SET @a=0;DECLARE @o VARCHAR(1000);SET @o='*'WHILE @a<@n BEGIN PRINT @o;SET @o=@o+'*'SET @a=@a+1;END;END
Ungolfed:
CREATE PROCEDURE P
@n INT
AS
BEGIN
DECLARE @a INT;
SET @a=0;
DECLARE @o VARCHAR(1000);
SET @o='*'
WHILE @a<@n
BEGIN
PRINT @o;
SET @o=@o+'*'
SET @a=@a+1;
END;
END
Testing:
EXEC P '6'
Output:
*
**
***
****
*****
******
C++, 63 bytes
void s(int n){if(n)s(n-1),cout<<setfill('*')<<setw(n+1)<<"\n";}
Usage:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
s(5);
}
Overrides the filling character (which is usually a space), and outputs an empty string (or actually a newline).
One weird thing about this code is the usage of if (...) - I cannot find a way to replace it by a conditional operator ... ? ... : ....
C++ 11, 65 bytes
Not including the include in the byte count.
#include<string>
using S=std::string;S g(int n){return n?g(n-1)+S(n,'*')+'\n':"";}
Usage:
std::cout << g(n) << std::endl;
Element, 16 bytes
_'[1+'[\*`]\
`"]
Explanation:
This is a pretty simple nested-loop approach. Let N represent the newline in the source code.
_'[1+'[\*`]\N`"]
_' take input and move it to the control stack
[ ] a FOR loop, each iteration = 1 line of output
[1+ ] increment the top of the stack, as a counter
[ ' ] move that value to the control stack
[ [ ] ] another FOR loop, for the current line
[ [\*`] ] output a literal asterisk
[ \N` ] output a literal newline
[ "] move the counter from control to main stack
Brain-Flak 75 Bytes
Includes +3 for -A
{(({})[()]<{({}[()]<(((((()()()){}()){})){}{})>)}{}((()()()()()){})>)}{}
Explanation:
{(({})[()]< >)}
#reduce the top element by one until it is 0 after doing the following
#Push this element back on to act as a counter for the next step.
#(counts down from input to 0 we'll call this counter)
{({}[()]< >)}
#reduce the top element by one until it is 0 after doing the following
#(counts down from counter to 0)
(((((()()()){}()){})){}{})
#push 42 (the ASCII code for *)
{}
#pop the counter used to push
#the right number of *s
((()()()()()){})
#push a 10 (newline)
{}
#pop the null byte
05AB1E, 11 bytes
'*×.pD¦`r`»
Explanation: (Prints hourglass)
Implicit input - 5
'* Asterisk character - stack = '*'
× Repeat input times - stack = '*****'
.p Get prefixes - stack = ['*', '**', '***', '****', '*****']
D Duplicate last element
STACK = ['*', '**', '***', '****', '*****'] , ['*', '**', '***', '****', '*****']
¦ Remove first element from final list
STACK = ['*', '**', '***', '****', '*****'] , ['**', '***', '****', '*****']
`r` Reverse 1 list and flatten both
STACK = '*****','****','***','**','*','**','***','****','*****'
» Join by newlines and implicitly print
For input 5, prints:
*****
****
***
**
*
**
***
****
*****
Scala, 44 30 bytes (51 45 without asterisk, 41 for hourglass)
With asterisk in code (30 bytes):
(i:Int)=>(i to(1,-1))map("*"*) //create a range from i to 1 and map each number to that number of asterisks
Without asterisk (45 bytes):
(i:Int)=>(i to(1,-1))map(((41+1).toChar+"")*) //same as above, but without a literal asterisk
Without asterisk and easy ways of calculating 42 (57 bytes):
(i:Int)=>(i to(1,-1))map(((math sqrt("7G"##)).toChar+"")*)
## is the hashcode method, which returns 1764 for the string "7G", the square root of 1764 is 42, the ascii code for *
Hourglass:
(& :Int)=>((&to(1,-1))++(2 to&))map("*"*)
(& :Int)=> //define an anonymus function with an int parameter called &
(
(& to (1,-1)) //a range from & to 1, counting by -1, aka downwards
++ //concat
(2 to&) //a range from 2 to &
)
map( //map each number to
"*" * //the string "*" repeated x times
)
Brainfuck, 129 bytes
I know there's already a shorter answer in brainfuck, however I wanted to create a program which could handle a multi-digit number input rather than either a single-digit input or a single ascii character input unlike the previous one posted.
,[>+++[->++++[-<<---->>]<]+>,]<-<<[<<]>>[<[->>++++++++++<<]>>>]+>>++++++++++>>++++++[-<+++++++>]<<<<<[>[->+>>.<<<]>>.<[-<+>]<+<-]
This is my first ever brainfuck program and it will work for any input between 0 and the maximum size of a single cell (traditionally 8 bits or 255) entered using the characters '0' to '9' (corresponding to ascii-values 048-057)
Explanation
The first part of this program, ,[>+++[->++++[-<<---->>]<]+>,], takes the input numbers as char values and removes 48 from each to make them equal to the numbers 0 to 9 rather than the char values of the numbers 0 to 9. It stores these in separate cells with a 1 in between each of them so that the start and end points can be found again.
The second part, <-<<[<<]>>[<[->>++++++++++<<]>>>], consolidates the separate values into one cell. This is why the maximum size of a cell controls how high a number can be.
The third section, +>>++++++++++>>++++++[-<+++++++>]<<<<<, is used to set up the other cells needed: one with the number of asterisks per line, one with the code for a linefeed and one with the code for an asterisk. There is also a blank cell left for working with later.
The remainder of the code, [>[->+>>.<<<]>>.<[-<+>]<+<-], is used to:
- Output as many asterisks as necessary
- Output a linefeed
- Reset the value of the cell controlling the asterisks
- Increment the control cell
- Decrement the cell with the number until it equals 0
05AB1E, 8 bytes
TžQè×.p»
Explanation coming soon
Python 3, 196 Bytes
import contextlib as b,io;q=io.StringIO()
with b.redirect_stdout(q):import this
n=int(input());c=q.getvalue()[655];print(''.join([''.join([c for z in range(n)][:i+1])+'\n' for i in range(n)]))
This is probably counted as a cheat, but it uses the asterisk character in the import this string rather than explicitly writing an asterisk in the program code. It also doesn't use any asterisk multiplication operators. It temporarily rerouts stdout so as not to print the Zen of Python when run.
Perl, 83 76 bytes (no asterisk)
print substr((split("\n",`perldoc perlre`))[55],48,1)x$_."\n"foreach(1..<>);
(Faster version for large input, 83 characters):
$r=`perldoc perlre`;print substr((split("\n",$r))[425],11,1)x$_."\n"foreach(1..<>);
Explanation:
The statement perldoc perlre executes the shell command to display the Perl documentation on regular expressions, which contains an asterisk as the 11th character on line 425. Split the resulting output by line, then extract that character and print in triangular format.
Edited to save 6 characters by not saving the output of the shell command, and instead just running it every time. It increases the runtime, though, but we only care about bytes, not runtime :) Another byte was saved (for a total of -7) by finding an earlier asterisk in the perldoc output.
Vim, 22, 18 keystrokes
O <esc>J:h r<cr>lyEZZ<C-v>{@"
Huge credit to @Udioica for coming up with an awesome vim answer that I expanded on. This answer does not contain any asterisks, in hopes of winning the bounty.
Explanation:
Input is typed before the rest of the program. Udioica came up with this awesome trick. Typing <n>O <esc> will create a pyramid of spaces and one empty line, as long as you have :set autoindent enabled. This option comes on by default in vim 8 and neovim, though not older versions of vim. Since this also creates an extra line, we use J to join this line with the next one, which effectively just removes the line below us.
Now at this point, we need to replace all of these spaces with asterisks. If I was not worried about using asterisks in my code, I would just visually select the whole thing <C-v>{ and type r*, which replaces each character of the selection with an asterisk. But I can't do that.
So we open up the help pages to :h r. The interesting thing about this is that in the vim-window, this page is displayed as:
r
r{char} Replace the character under the cursor with {char}.
...
With the cursor on the first 'r'. However, the file itself actually contains this text:
*r*
r{char} Replace the character under the cursor with {char}.
...
Pretty convenient. So we move over one character with l, and yank the text r* with yE ([y]ank to the [E]nd of this word).
To close this buffer, we use the shortcut to save a file ZZ. Now, we visually select our spaces, and run the yanked text as if we had typed it by doing @". This works because "@" runs the following register as vim-keystrokes, and " is the default register for yanking.
Braingasm, 27 bytes
Braingasm is a brainfuck variant with just a few more instructions and options. And this task would've been so much easier if I had bothered implementing that as many times as the value in the current cell thing yet..
;[->+[->+42.<]10.>[-<+>]<<]
Here's how it works:
; Read an integer from stdin and write it to cell#1
[ ] While the value of cell#1 is not zero,
->+ < substract one from cell#1 and add one to cell#2.
[->+ <] Each time, do the same between cell#2 and cell#3,
42. but also print an asterix on the way.
10. Then print a newline.
>[-<+>]< Move the value from cell#3 back to cell#2
C++ - 92 96 Bytes
#include<string>
int main(){int n;std::string s;scanf("%d",&n);for(;n--;)puts((s+="*").data());}
Ungolfed:
//this one hurts, but c++ strings are mutable
#include<string>
int main(){
int n;
//this one hurts as well
std::string s;
//read input to n
//longer than 'std::cin>>n', but no #include<iostream> needed
scanf("%d",&n);
// same as 'while(n--)', also characterwise, but way cooler
for(;n--;)
//add a '*' the string
//data() does the same as c_str()
//puts automatically adds an '\n'
puts((s+="*").data());
}
2sable, 24 11 bytes
>G')Ç>çJN×,
And no sign of any asterisks! Golfed from 24 to 11 thanks to @Emigna.
Explanation:
>G')Ç>çJN×,
> Push input+1
G For N in range (1,input+1)
')Ç>çJ Push '*' by getting ascii code for ')' and adding 1
Nx, Print '*' repeated N times
Pyth, 7 Bytes
VQ*\*hN
Knocked off a byte thanks to @ETHproductions Try it online
using @PIetu1998's Technique
6, bytes
j*L*\*S
RProgN, 42 Bytes, Competing only for the Bounty
Q L c 's' =
►3'rep'º'R'=]¿]s\R\1-]} [
The length of the script is used as the character code for *.
05AB1E, 7 6 bytes
Uses CP-1252 encoding.
'*×.p»
8 byte no-asterisk version:
žQTè×.p»
Explanation
Example using input n = 5
'* # push "*"
# STACK: "*"
× # repeat input number times
# STACK: "*****"
.p # get prefixes of string
# STACK: ['*', '**', '***', '****', '*****']
» # join by newlines
# implicit print
Haskell, 32 bytes
unlines.(`take`iterate('*':)"*")
The expression iterate('*':)"*" generates the infinite list ["*","**","***","****","*****",...]. The function then takes the first n elements and joins them with newlines.
The more direct
concat.(`take`iterate('*':)"*\n")
is one byte longer.
F#, 114 chars
[<EntryPoint>]
let main a =
for i = 1 to System.Int32.Parse(a.[0]) do
printfn "%s" <| String.replicate i "*"
0
Elixir, 81 bytes
&Enum.reduce(Enum.to_list(1..&1),"",fn(x,r)->r<>String.duplicate("*",x)<>"\n"end)
Anonymous function using the capture operator. Enum.reduce will iterate a list (the list is obtained by calling Enum.to_list on the range 1..n) and concatenate the return string r (which has been initialized with "") with a string made of x asterisks and a newline.
Full program with test case:
s=&Enum.reduce(Enum.to_list(1..&1),"",fn(x,r)->r<>String.duplicate("*",x)<>"\n"end)
IO.write s.(5)
Try it online on ElixirPlayground !
Prolog, 60 58 56 bytes
g(N):-N<=0,put(*),g(N-1);!.
f(N):-N<=0,f(N-1),g(N),nl;!.
I'm not that familiar with Prolog, but I just gave it a shot. I'm sure it can be a lot shorter.
Put the code into a file, then load that file into swipl and run f(25). (or some other number).
EDIT: quotes can be left out in put statement
EDIT 2: changing =:= to <= saves 2 bytes. I tried inverting it, but that'd make it wait for a return for some reason.
MoonScript, 31 bytes
(n)->for i=1,n
print "*"\rep i
Sample call:
_ 5
GameMaker Language, 68 bytes
a="*"for(i=2;i<=argument0;i++){a+="#"for(j=0;j<i;j++)a+="*"}return a
Common Lisp (Lispworks), 71 bytes
(defun f(n)(dotimes(i n)(dotimes(j(1+ i))(format t"*"))(format t"~%")))
Usage:
CL-USER 170 > (f 5)
*
**
***
****
*****
NIL
Ungolfed:
(defun f (n)
(dotimes (i n)
(dotimes (j (1+ i))
(format t "*"))
(format t "~%")))
Java, 110 bytes
Not that short, but I really like having empty for loops.
String f(int n){String s="";for(int i=0;i<n;i++,s+=new String(new char[i]).replace("\0","*")+"\n"){}return s;}
C++, 78 bytes
I don't know how there are 2 C++ answers that don't just do it with for loops. Very short and sweet this way:
void T(int n){for(int i=1;i<=n;i++){for(int j=0;j<i;j++)cout<<'*';cout<<'\n';}}
Full program
#include <iostream>
using namespace std;
void T(int n)
{
for(int i = 1; i <= n; i++)
{
for(int j = 0; j < i; j++)
cout << '*';
cout << '\n';
}
}
int main()
{
T(5);
}
Edit: it is unclear to me whether to count the #include<iostream>, using namespace std, and/or std::whatever in calls. C/C++ answers all over this site seem to use both, and for the most part no one seems to care except for the occasional comment. If I need the std::, then +10. If I need the #include<iostream>, +18 (although GCC allows me to do without the basic includes, so maybe not that one)
VBA, 84 bytes
taking advantage of recursive coding. it generates x times * as the line/round
Function f(x)
If x<=1 Then f="*" Else f=f(x-1) & vbCrLf & String(x,"*")
End Function
results:
?f(10)
*
**
***
****
*****
******
*******
********
*********
**********
?f(2)
*
**
?f(5)
*
**
***
****
*****
Lua, 36 bytes
for i=1,...do print(("*"):rep(i))end
Takes input from the command line.
Vim, 8 bytes
o <Esc><C-V>{r*J
Takes input in the readahead buffer, so if input is 15, you would type that and then the code above. This is a silly rule, but seems to be allowed. If you got input in a register like "a, you'd just stick @a in front (10). If you got it from the start file, you'd prepend D@" instead (11).
Relies on abuse of :set autoindent, which is default in vimgolf.com rules and default in Vim 8 (and everyone uses it anyway).
o <Esc>: With its number argument, if your text starts with whitespace, and you have:set autoindent, Vim glitches out and creates a cascade of indent.<C-V>{r*: Turn all those spaces into*s. I'm using block visual so that, even if your lousy indent settings silently group your spaces into tabs, you'll still get the right number of*s.J: Starting withounfortunately left a blank line at the top. This removes it.
Ruby, 29 bytes
->n{n.times{|i|puts'*'*i+?*}}
Call with ->n{n.times{|i|puts'*'*i+?*}}[number].
Ruby, 27 (or 24) bytes
(Thanks to m-chrzan for pointing out the miscounting.)
Returns a string.
->n{(1..n).map{|i|?**i}*$/}
the map makes an array of strings of * of increasing length. The *$/ takes the array and joins the elements to make a newline-separated string. If an array of strings is acceptable, these three bytes can be saved, scoring 24.
In test program
f=->n{(1..n).map{|i|?**i}*$/}
puts f[5]
Javascript, 71 bytes 48 Bytes, thanks ETHproductions!
(n,c)=>{while(c<=n)console.log("*".repeat(c++))}
PHP, 66 58 bytes
Just a simple loop, really.
I'm new to golfing, so might not be the shortest way.
for($i=fgets(STDIN);$x++<$i;)echo str_repeat("*",$x)."\n";
Thanks to manatwork for byte-saving.
Charcoal, 5 bytes
G↓→N*
It's the same length as Jelly, which is really bad for an ASCII-art oriented language. At least it's readable, I guess
Explanation
G Polygon
↓→ Down, then right
N Input number
* Fill with '*'
Excel VBA, 109 bytes
This function returns to cell, requires text wrapping be turned on.
Function a(b)
For i = 1 To b
For c = 1 To i
d = "*" & d
Next c
a = a & d & Chr(10)
d = ""
Next i
End Function
99 Bytes - Alternative that runs as a function but prints to immediate.
Function f(b)
For i = 1 To b
For c = 1 To i
Debug.Print "*";
Next c
Debug.Print
Next i
End Function
94 Bytes - One more that is just a sub with hard coded value, prints to immediate.
Sub k()
r = 5
For i = 1 To r
For c = 1 To i
Debug.Print "*";
Next c
Debug.Print
Next i
End Sub
Ruby, 32 bytes
1.upto($*[0].to_i){|i|puts"*"*i}
The $* is an array of arguments.
foo.rb 5 will print the following:
*
**
***
****
*****
jq, 19 characters
(18 characters code + 1 character command line option.)
range(1;.+1)|"*"*.
Sample run:
bash-4.3$ jq -r 'range(1;.+1)|"*"*.' <<< 5
*
**
***
****
*****
On-line test (Passing -r through URL is not supported – check Raw Output yourself.)
Groovy, 27 characters
{1.upto(it){println"*"*it}}
Sample run:
groovy:000> ({1.upto(it){println"*"*it}})(5)
*
**
***
****
*****
===> null
Java 7,72 70 bytes
Thanks to @kevin for shave it off by 2 bytes.
String f(int n,String s,String c){return n<1?c:f(--n,s+"*",c+s+"\n");}
Output
*
**
***
****
*****
******
Matlab, 26 23 bytes
Good old Matlab...
@(n)tril(repmat('*',n))
Has trailing whitespaces. tril gives you the lower triangular matrix.
edit: saved 2 bythes thanks to Luis Mendo
J, 11 8 bytes
Saved 3 bytes thanks to miles!
]\@#&'*'
Here is a decomposition:
(]\@#&'*') x
x (]\@#) '*'
]\ (x # '*')
Now, this last one reads as "the prefixes (]\) of the string consisting of x copies of '*'". Observe:
5 ]\@# '*'
*
**
***
****
*****
]\ 5# '*'
*
**
***
****
*****
]\ 5 # '*'
*
**
***
****
*****
]\@#&'*' 5
*
**
***
****
*****
Test case
f =: ]\@#&'*'
f 3
*
**
***
f 5
*
**
***
****
*****
f 1
*
f 2
*
**
f &. > ;/1+i.10
+-+--+---+----+-----+------+-------+--------+---------+----------+
|*|* |* |* |* |* |* |* |* |* |
| |**|** |** |** |** |** |** |** |** |
| | |***|*** |*** |*** |*** |*** |*** |*** |
| | | |****|**** |**** |**** |**** |**** |**** |
| | | | |*****|***** |***** |***** |***** |***** |
| | | | | |******|****** |****** |****** |****** |
| | | | | | |*******|******* |******* |******* |
| | | | | | | |********|******** |******** |
| | | | | | | | |*********|********* |
| | | | | | | | | |**********|
+-+--+---+----+-----+------+-------+--------+---------+----------+
Older, 11-byte solutions
'*'#~"+1+i.
This is equivalent
'*' #~"0 1 + i.
1 + i. is the range [1, x]. Then, '*' #~"0 applied to this range shapes (element) copies of '*'.
Bonus program:
[:#&'*'\#&1
This is a capped fork #&'*'\ applied to the result of #&1 of the input. #&1 gives an array of x ones, and #&'*'\ shapes '*' to the prefixes of this array.
Test cases
f1 =: '*'#~"+1+i.
f2 =: [:#&'*'\#&1
f1 1
*
f2 2
*
**
f1 3
*
**
***
f2 4
*
**
***
****
f2 5
*
**
***
****
*****
f1 5
*
**
***
****
*****
(f1;f2)3
+---+---+
|* |* |
|** |** |
|***|***|
+---+---+
f1;f2
f1 ; f2
(f1;f2)5
+-----+-----+
|* |* |
|** |** |
|*** |*** |
|**** |**** |
|*****|*****|
+-----+-----+
(f1;f2)10
+----------+----------+
|* |* |
|** |** |
|*** |*** |
|**** |**** |
|***** |***** |
|****** |****** |
|******* |******* |
|******** |******** |
|********* |********* |
|**********|**********|
+----------+----------+
Racket 47 bytes
(for((i(+ 1 n)))(displayln(make-string i #\*)))
Ungolfed:
(define (f n)
(for ((i (+ 1 n))) ; (i 5) in 'for' produces 0,1,2,3,4
(displayln (make-string i #\*)))) ; #\* means character '*'
Testing:
(f 5)
Output:
*
**
***
****
*****
RProgN, 41 Bytes.
24 of these bytes are just assigning R and s, so that we can use a spaceless segment.
'rep' º 'R' = '*' 's' = ►]¿]s\R\1-]}[
Explination
'rep' º 'R' = # Get the function for 'rep' (Replace), associate 'R' with it.
'*' 's' = # Associate 's' with the string literal '*'
► # Begin spaceless segment.
] # Push a copy of the top of the stack (The input)
¿ # While truthy, popping the top of the stack.
] # Push a copy...
s \ R # Push an *, swap the two top values giving "i, *, i", Repeat the *, i times, giving "i, ****", or whatever.
\ 1 - # Swap the top values, giving "****, i", decrement the top value by 1.
] # Push a copy of the top value.
}[ # End the while, after processing, pop the top value (Which would be 0). Implcititly print.
Try it!
<style>
#frame{
width:60em;
height:60em;
border:none;
}
</style>
<iframe id='frame' src="https://tehflamintaco.github.io/Reverse-Programmer-Notation/RProgN.html?rpn=%27rep%27%20%C2%BA%20%27R%27%20%3D%20%27*%27%20%27s%27%20%3D%20%E2%96%BA%5D%C2%BF%5Ds%5CR%5C1-%5D%7D%5B&input=5">Sorry, You need to support IFrame. Why don't you..?</iframe>
Befunge93, 31 chars (3 spaces, 8 pure directionals)
&>:#v_@
-^ : >$55+,1
,"*"<_^#:-1
Befunge98, 28 chars
&>:#v_@
-^ : >$a,1
1,*'<_^#:-
Jolf, 7 bytes
This time, the builtin didn't let me win. Oh well.
―t0jj'*
Explanation
―t0jj'*
―t0 pattern: left-corner-base triangle
j with <input> height
j and <input> width.
'* comprised of asterisks
Pyth, 6 bytes
j._*"*
Explanation
j Join by newlines
._ all prefixes of
* the result of repeating
"* the string "*"
as many times as the implicit input
Clojure, 59 bytes
#(doseq[m(range 1(inc %))](println(apply str(repeat m\*))))
Basically, just uses doseq to loop over the range, printing the corresponding number of stars.
It's really unfortunate that the shortest way I've been able to repeat a character in Clojure is (apply str (repeat m \*)). That's hardly competitive here. Some good ol' python string multiplication would have been awesome.
Ungolfed:
(defn tri [n]
(doseq [m (range 1 (inc n))]
(println (apply str (repeat m \*)))))
Should be fairly self-explanatory.
Brain-Flak, 81 bytes
78 bytes but three for the -A flag, which enables ASCII output.
{(({}[()])<>()){({}[()]<(((((()()()){}())){}{}){})>)}{}((()()()()()){})<>}<>{}
Brain-flak isn't the greatest language for ASCII-art, but it still managed to be somewhat short. Ish. Kinda.
Explanation:
While True:
{
(
Decrement counter
({}[()])
And move copy to other stack
<>())
Push N '*'s
{({}[()]<(((((()()()){}())){}{}){})>)}
Pop 0
{}
Push newline
((()()()()()){})
Move back to counter
<>
Endwhile
}
Move to other stack
<>
Pop an extra newline
{}
Brainfuck, 70 bytes
,>++++++[<-------->>>+++++++<<-]<[>+[->+>.<<]>[-<+>]++++++++++.[-]<<-]
I'm sure this could be golfed a little bit. This version only works for single-digit numbers; feel free to modify it to work on larger numbers too.
Edit: If it's allowed to use a single character's ASCII value as the input, the resulting code is below. Only 60 bytes.
,>++++++[>>+++++++<<-]>[>+[->+>.<<]>[-<+>]++++++++++.[-]<<-]
Explanation:
,>++++++[<-------->>>+++++++<<-] [this gets a single character from
input into the first cell, subtracts 48 to convert it to an integer
representation, and puts 42 in the 3rd cell (ASCII '*').]
<[ while the first cell is not zero do
>+ add 1 to 2nd cell (empty when we start)
[->+>.<<] [while 2nd cell is not empty subtract 1 and print an *.
Make a copy in 3rd cell.]
>[-<+>] copy 3rd cell value back to 2nd cell
++++++++++.[-] [put '\n' in 3rd cell, print, clear]
<<-
] loop
Edit: Here is a version that works for numbers up to 255, reading the text representation of the number followed by EOF. If your favorite interpreter has unbounded cells it will work up to 999.
>>,[----------
[
>++++++[<------>-]<--
>],]
[
Pointer is one past the end of a run of digits containing input.
Assumption: input < 256.
Add ten times most significant digit to second and ten times the
second to the third to get it in one cell.
]
<<<[>++++++++++<-]>[>++++++++++<-]>
Store 42 '*' in the cell 3 to the right
>>++++++[>+++++++<-]<<
[ While first cell is not empty
>+ Add 1 to 2nd cell
[->+>.<<] [make a copy in 3rd cell, print '*']
>[<+>-] copy 3rd back to 2nd
++++++++++.[-] print newline and clear 3rd
<<- subtract 1 from 1st and continue
]
Perl, 19 bytes
-4 bytes thanks to @Ton Hospel and his rework of the solution!
eval"s//*/;say;"x<>
Needs free -E (or -M5.010) flag to run. Takes a number from input :
perl -E 'eval"s//*/;say;"x<>' <<< "5"
Haskell, 35 38 bytes
List comprehension thanks to nimi:
f x=unlines[[1..n]>>"*"|n<-[1..x]]
Old version:
f 0=""
f n=f(n-1)++([1..n]>>"*")++"\n"
Alternate version:
g n=([1..n]>>"*")++"\n"
f n=[1..n]>>=g
Perl 5, 22 20 bytes
say"*"x$_ for 1..pop
Run it with the -E switch to get say.
$ perl -E 'say"*"x$_ for 1..pop' 5
*
**
***
****
*****
Written out as a full program it would look like this:
use strict;
use feature 'say';
# get the argument
my $limit = pop @ARGV;
foreach my $i (1 .. $limit) {
say "*" x $i;
}
shiftandpopimplicitly work on@ARGV(the list of arguments) outside of subs..is the range operatorsayincludes a newlinexis an operator to repeat strings and is explained in perlop
Ruby, 26 bytes
->n{s='';n.times{p s+=?*}}
Vitsy, 19 16 bytes
Yeah this needs some reducing. I'm out of practice!
D1H}\[\['*'O]aO]
(implicit input)
D Peek n, push n.
1 Push 1.
H Pop x, pop y, push range(x, y)
} Reverse, pop n, reverse, push n.
\[ ] Pop n, do bracketed items n times.
\[ ] Pop n, do bracketed items n times.
'*'O Output the character *.
aO Output a newline.
Think of it as though I'm iterating through a list (1 through n) and popping out the number of *s according to the currently selected list item.
Explanation soon.
C++, 108 chars
#import<iostream>
main(){int n;std::cin>>n;for(int i=1;i<=n;++i){for(int j=i;j--;)std::cout<<"*";puts("");}}
Straightforward.
R, 45 bytes
For loop approach:
for(i in 1:scan())cat(rep("*",i),"\n",sep="")
Perl 6, 23 bytes
{.put for [\~] '*'xx$_}
( If the output is allowed to be a list of "lines" without newlines .put for can be removed )
Explanation:
# bare block lambda with implicit parameter 「$_」
{
.put # print with trailing newline
for # for every one of the following
[\~] # produce using concatenation operator
'*' xx $_ # list repeat '*' by the input
}
( See documentation for produce if you don't understand what [\~] ... is doing )
Bash, 35 characters
for((;i++<$1;));{ s+=\*;echo "$s";}
Sample run:
bash-4.3$ bash draw-an-asterisk-triangle.sh 5
*
**
***
****
*****
Forth, 39 bytes
Quite simple, with a couple of nested loops. ASCII 42 is an asterisk.
: f 0 do I -1 do 42 emit loop CR loop ;
Prints a trailing newline.
Python 2, 37 34 bytes
i=1;exec"print'*'*i;i+=1;"*input()
i is initialised to 1;
then exec commands to execute the following string of code, so it must be constructed;
the string is "print'*'*i;i+=1;" but the * following the string takes precedence over the exec and instructs to first repeat the string input() times;
the exec command now executes the long string which acts like a loop, printing another string of increasing length, again using * to repeat the character '*', then incrementing i with i+=1.
Python 3, 41 bytes:
def f(n):i=1;exec("print('*'*i);i+=1;"*n); or
lambda n,i=1:exec("print('*'*i);i+=1;"*n)
Batch, 69 bytes
@set s=
@for /l %%i in (1,1,%1)do @call set s=*%%s%%&call echo %%s%%
Jellyfish, 12 11 9 bytes
\P$'*
i
Explanation
The above program is equivalent to the following functional pseudocode:
\ P $ i '*
map_prefixes(print, reshape(input(), '*'))
The $ (reshape) creates a string of N asterisks. \P creates a function which takes a list (or string) and passes each of its prefixes to P (print). Hence, this successively prints strings of 1 to N asterisks.
Brachylog, 12 bytes
yke:"*"rj@w\
This assumes that a trailing new line is acceptable
Explanation
yk The range [0, …, Input - 1]
e Take one element I of that range
:"*"rj Juxtapose "*" I times to itself
@w Write that string followed by a new line
\ False: backtrack to another element of the range
No trailing new line, 15 bytes
-:"*"rj:@[f~@nw
This one works by taking all prefixes of "*" × Input.
C#, 42 bytes
f=n=>n<1?"":f(n-1)+"\n"+new string('*',n);
Full program with test case:
using System;
namespace DrawAnAsteriskPattern
{
class Program
{
static void Main(string[] args)
{
Func<int,string>f= null;
f=n=>n<1?"":f(n-1)+"\n"+new string('*',n);
Console.WriteLine(f(5));
}
}
}
JavaScript (ES6), 34 bytes
f=x=>x?f(x-1)+`
`+'*'.repeat(x):''
Gema, 36 characters
*=@repeat{*;@append{s;\*}@out{$s\n}}
Sample run:
bash-4.3$ gema '*=@repeat{*;@append{s;\*}@out{$s\n}}' <<< 5
*
**
***
****
*****
Retina, 14 bytes
Byte count assumes ISO 8859-1 encoding.
.+
$**
.
$`$&¶
Explanation
.+
$**
Turn the input N into N asterisks.
.
$`$&¶
Replace each asterisk with everything up to and including that asterisk (this is the $`$&) and a linefeed (this the ¶).
