Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Notifications
Mark all as read
Challenges

Looping counter

+5
−0

Looping counter

Create an infinite loop that outputs lines of asterisks, with each line containing one more asterisk. Instead of the asterisk, any printable, non-whitespace character can be used. However all lines need to use the same character.

The beginning of the output looks like this:

*
**
***
****
*****
******
*******
********
*********
**********
***********
************

An ungolfed Python implementation:

from itertools import count

for i in count(1):
    print('*'*i)
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

13 answers

+3
−0

Lua, 31 bytes

_=''::_::_=_..'*'print(_)goto _

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

You can shorten your loop by using goto. As a bonus, this makes your code look even more cryptic (: ... (2 comments)
+3
−0

Ruby, 18 bytes

loop{$><<$/=?*+$/}

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+2
−0

Haskell, 35 bytes

main=mapM putStrLn$iterate('*':)"*"

Attempt This Online!

55 -> 39, with orthoplex's idea.

39 -> 35 from orthoplex.

Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Neat solution, but that import is quite expensive. Maybe try something like ```haskell x="*":map('*... (3 comments)
+1
−0

Bash, 17 bytes

echo x$1;./$0 x$1

Try it online!

Thanks to celtschk‭ for spotting my mistake :)

Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Wrong output (1 comment)
+1
−0

brainfuck, 31 bytes

++++++++++[[>]>-[<+>---]<[.<]>]

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

dc, 13 bytes

[r1+pA*rdx]dx

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

JavaScript (Node.js), 31 bytes

for(i='';;console.log(i+='*'));

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

Python 2, 26 bytes

_=1
while 1:_*=10;print~-_

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

MATL, 16 bytes

1`1yh1$lZctDwQt]

Try it online!

The TIO output fetch will likely fail, so make sure to click the run button to stop the execution.

1`1yh1$lZctDwQt]
1`             ] - Push 1 onto stack, enter do-while
  1              - Push 1 onto stack
   y             - duplicate n-th level of stack, default is 2
    h            - horzcat, 1 10h -> [1;10]
     1$l         - ones, specifying arguments with 1$
        Zc       - strjoin
          t      - duplicate top of stack
           D     - display
            w    - swap
             Q   - increment by 1
              t  - duplicate

Matlab can loop infinitely using k=1:inf, but MATL cannot perform [1:Y] where Y is shorthand for inf.

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

Python 3, 28 bytes

_=""
while 1:_+="*";print(_)

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

Embed ESCR, about 32 characters depending on how you count

loop
  append s "*"
  show s
  endloop

The indentation is not required, but shown for clarity. Declaring the variable S is also not included, since similar stuff doesn't seem to be included in other examples.

S is a string variable. In ESCR, storage for a string can grow dynamically at run time as needed. The string initialially starts empty, with one "*" appended to it each iteration.

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

C (gcc), 47 bytes

i,n;f(){for(i=n+++2;i--;)putchar(i?42:13);f();}

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

><>, 10 bytes

1:naoa*1+!

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!

Like what we're doing? Support us! Donate