Looping counter
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)
Lua, 31 bytes ``` =''::::=.. …
2y ago
Vyxal, 5 4 bytes ``` ¤{‹… …
2y ago
[Ruby], 18 bytes lo …
2y ago
MATL, 16 bytes ``` 1`1yh1$ …
2y ago
Haskell, 35 bytes main=mapM …
2y ago
[brainfuck], 31 bytes + …
2y ago
[K (oK)], 9 bytes {x#0} …
3mo ago
C, 30 + 1-4 byte f(m){f …
1y ago
Fig, 5 bytes The actual score …
2y ago
Japt, 6 bytes ßOpP±Q …
2y ago
JavaScript, 25 bytes Could …
2y ago
J, 13 char ``` '',^:(<)'' ` …
2y ago
[C (gcc)], 47 bytes …
2y ago
[JavaScript (Node.js)], 31 byt …
2y ago
Embed ESCR, about 32 character …
2y ago
[><>], 10 bytes 1:naoa1 …
2y ago
[dc], 13 bytes [r1+pArd …
2y ago
[Bash], 17 bytes ec …
2y ago
[Python 2], 26 bytes …
2y ago
[Python 3], 28 bytes …
2y ago
[AWK], 26 24 bytes END{ …
6mo ago
21 answers
Vyxal, 5 4 bytes
¤{‹…
This is so stupid and I love it
Explained
¤{‹…
¤ # Push an empty string
{ # Forever:
‹ # Append a "-" to the top of the stack
… # And print it without popping
0 comment threads
Haskell, 35 bytes
main=mapM putStrLn$iterate('*':)"*"
55 -> 39, with orthoplex's idea.
39 -> 35 from orthoplex.
1 comment thread
MATL, 16 bytes
1`1yh1$lZctDwQt]
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
.
0 comment threads
C, 30 + 1-4 byte
f(m){f(printf("%0*i\n",m,0));}
Has this limitations:
- counter stops working at
INT_MAX
or at stack overflow. - Needs a input value to indicate on which line we start.
0
starts on the line with one character. - It uses
0
and not*
as output character
Because of the additional input number, i added the + 1 in the title. If you call the program, you need to write f(0)
, this is why the +4 in the title.
Fully working program, 36 byte:
main(m){main(printf("%0*i\n",m,0));}
0 comment threads
JavaScript, 25 bytes
Could be 21 but calling the function like that feels like cheating.
(f=s=>f(s+=8,print(s)))``
22 bytes
Didn't want to post this as my main solution as it's pretty much the same as Moshi's.
for(s=``;;)print(s+=8)
0 comment threads
J, 13 char
'*',^:(<_)'*'
How it works: What's in parenthesis indicates to the verb ^: that the verb to the left of ^: has to be performed to the object on the right of the ^: an infinite number of times and that it has to list each intermediate result. '_' is infinity, and '<' boxes it to force listing the intermediate results.
'*',^:(<4)'*'
*
**
***
****
0 comment threads
Fig, 5 bytes
The actual score is $5\log_{256}(96)\approx$ 4.116 bytes. The leaderboard only likes ints in the header.
(J,Q0
-1 char thanks to Seggan
Fractional byte lang created by Seggan. Is this even allowed here?
(J,Q0
,Q : Print and return last return value, initialized as 0
J 0 : Add 0 to end of result
( : Loop forever
1 comment thread
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.
0 comment threads
K (oK), 9 bytes
{x#0}'!10
!10 / pass range your arbitrary number
.' / treat those as a list, and evaluate each separately
{ } / main function
x / number passed from the list
# / will be 'counted' x many times
0 / printing the 0 each time
2 comment threads