10
\$\begingroup\$

The looping counter is a challenge that prints an infinite number of lines. The first line has one *, the next line has one more * than this line. An example output is:

*
**
***
****
*****
******
*******
... (goes forever)

However, the question above is too simple and is a duplicate, so let's make it harder.

For every line, instead of printing *'s, print an uppercase English letter; also, the number of characters is not increased by one, but by the ASCII value of character in this line minus 64: the first line is one A, the second line is two B's, the third line is four C's, ..., the 26-th line is 326 Z's, the 27-th line is 352 A's, ...

A
BB
CCCC
DDDDDDD
EEEEEEEEEEE
FFFFFFFFFFFFFFFF
... (goes forever)

This is , so code in the fewest bytes.

Your output can be in any place (e.g.: Standard output, files, graphics, etc.), but must follow the format.

\$\endgroup\$
9
  • \$\begingroup\$ This is a duplicate of Count up forever because that task allows you to output in unary, which is essentially exactly this \$\endgroup\$ Commented Jun 6 at 13:19
  • \$\begingroup\$ Most solutions there which use decimal can be trivially modified to this by changing n=0;n+=1 to n='';n+='*' \$\endgroup\$ Commented Jun 6 at 13:25
  • \$\begingroup\$ The character edit is also still trivial. Perhaps the entire idea is not really suitable for a challenge. \$\endgroup\$
    – SanguineL
    Commented Jun 6 at 13:43
  • 1
    \$\begingroup\$ @None1 When you make a change to the challenge, please notify the writers of existing answers that their answer has become invalid \$\endgroup\$
    – Luis Mendo
    Commented Jun 6 at 16:44
  • 10
    \$\begingroup\$ I have left comments on invalid solutions, but next time open a new challenge instead of modifying an old one, the question was closed because it was a duplicate, doesn't mean you can't open a new one. Anyway what's been done has been done just keep that in mind for future challenges \$\endgroup\$ Commented Jun 6 at 17:22

14 Answers 14

5
\$\begingroup\$

Charcoal, 23 bytes

W¹«×⊕↨¹⁺¹﹪υ²⁶§αLυD⎚⊞υLυ

Try it online! Link is to verbose version of code. Explanation:

W¹«

Repeat forever.

×⊕↨¹⁺¹﹪υ²⁶§αLυ

Reduce all of the members of the list modulo 26, increment each, take the sum, then increment that, and use that to repeat the current letter.

D⎚

Output the string and clear the canvas. (Normally Charcoal doesn't output until it terminates, but that's not useful for infinite output challenges.)

⊞υLυ

Push the current count to the predefined empty list.

Note that works on empty lists in the newer version of Charcoal on ATO allowing it to replace ⁺¹ for a 1-byte saving.

If the number of lines was an input parameter and padded output was allowed then it would be possible in only 17 bytes (16 on ATO):

EN×⊕↨¹⁺¹﹪…⁰ι²⁶§αι

Try it online! Link is to verbose version of code. Explanation:

 N                  Input number
E                   Map over implicit range
               α    Predefined variable uppercase alphabet
              §     Indexed by
                ι   Current value
  ×                 Repeated by
         …          Range from
          ⁰         Literal integer `0`
           ι        To current value
        ﹪           Vectorised reduced modulo
            ²⁶      Literal integer `26`
      ⁺¹            Vectorised incremented
    ↨¹              Summed
   ⊕                Incremented
                    Implicitly print

The original challenge was possible in 5 bytes:

W¹«*D

Try it online! Link is to verbose version of code. Explanation:

W¹«

Repeat forever.

*

Append a * to the canvas.

Output the current contents of the canvas.

Note that Dump is throttled on TIO, making it take 5 seconds to fill the 128KB output buffer; it's about 10× faster if you Attempt This Online! with the --nt option.

\$\endgroup\$
1
  • \$\begingroup\$ @DLosc Finally got around to updating this; sorry for the delay. \$\endgroup\$
    – Neil
    Commented Jun 8 at 7:42
4
\$\begingroup\$

Nekomata, 15 bytes

Ňr26%→Ɔ64+$∑→řH

Attempt This Online!


the original challenge, 5 bytes

'*ŇPř

Attempt This Online!

'*ŇPř
'*      Push the character '*'
  Ň     Choose a natural number
   P    Check that it is positive
    ř   Repeat the character that many times

Without any command-line flags, Nekomata will print all possible results separated by newlines.

\$\endgroup\$
0
4
\$\begingroup\$

JavaScript (Node.js), 74 bytes

for(i=0,s=1;;s+=i,i%=26)console.log(String.fromCharCode(++i+64).repeat(s))

Try it online!

JavaScript (Node.js), 30 bytes

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

Try it online!

Can't find a dup

\$\endgroup\$
0
2
\$\begingroup\$

Python 3, 45 bytes

a=b=1
while[print(chr(b+64)*a)]:a+=b;b=b%26+1

A full program that prints forever.

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Retina 0.8.2, 46 bytes

$
@
{2=T`@L`L`(.)\1*
}2=`(.)\1*
$&$1
}:T`@L`LA

Try it online! Explanation:

$
@

Append an @.

2=T`@L`L`(.)\1*

Bump all of the characters up by one code point, but only in the second run of identical characters.

2=`(.)\1*
$&$1

Duplicate the last character, but only if there are two runs of identical characters.

{`
}`

Repeat until all of the letters are the same, at which point there is only one run of identical characters and so no substitutions are made.

:T`@L`LA

Bump all of the characters up by one code point, wrapping Z back around to A, and output the new string.

}`

Repeat forever, since the output keeps changing.

The original challenge was possible in 6 bytes:

+:`$
*

Try it online! Explanation:

+`

Repeat forever, since the output keeps changing.

:`

After performing the command, output the new value.

$
*

Append a * to the output.

This is a case where Retina 0.8.2 is golfier than Retina 1 where the * needs to be quoted with a $. (Retina 1 also uses \ instead of Retina 0.8.2's :.)

\$\endgroup\$
2
  • \$\begingroup\$ Challenge was updated, this is no longer valid \$\endgroup\$ Commented Jun 6 at 17:21
  • 1
    \$\begingroup\$ @noodleman Finally got around to updating this; sorry for the delay. \$\endgroup\$
    – Neil
    Commented Jun 8 at 14:40
2
\$\begingroup\$

Java (JDK), 88 87 84 bytes

v->{for(int j=1,s=1,a;;s+=j,j=j%26+1)for(a=0;a<=s;)System.out.write(a++<s?j+64:10);}

Try it online!

+1 credit to this answer for the idea to use System.out.write with the ternary operator and this Javascript answer for the algorithm.

\$\endgroup\$
2
  • \$\begingroup\$ -2 bytes: j%=26,s+=j++ \$\endgroup\$
    – corvus_192
    Commented Jun 7 at 15:46
  • \$\begingroup\$ @corvus_192 Impossible, if we put modulo operation before the assignment of s, we are getting s=s+j%26 instead of s=s+j. This gives incorrect string lengthes after the 26th letter (Z). But this 1-byte reduction can still be done j=j%26+1 ;) \$\endgroup\$ Commented Jun 7 at 18:21
2
\$\begingroup\$

Perl 5 + -M5.10.0 -061, 38 bytes

$/+=$-,$-%=26while say+(A..Z)[$-++]x$/

Try it online!

Explanation

-061 sets $/ to 1 which starts our repetition counter where we need it.

while we say (always returns truthy) the letter of the alphabet, at index $- (starts at 0 and post-incremented), repeated $/ times, we increment $/ by $-, then set $- to itself, modulo 26.

\$\endgroup\$
2
\$\begingroup\$

R, 51 bytes

while(T<-T+F)cat(strrep(LETTERS[F<-F%%26+1],T),"
")

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Python 3, 56 bytes

a,b=1,0
while 1:
 print(chr(b%26+65)*a)
 a+=b%26+1
 b+=1

Try it online!

\$\endgroup\$
0
1
\$\begingroup\$

PowerShell Core, 45 bytes

for(){([char]($c%26+65)+'')*++$i
$i+=$c++%26}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

05AB1E, 14 bytes

1[DN>.b×,N₂%>+

Try it online.

Or alternatively:

AuÞ∞<₂%>.¥>×€,

Try it online.

Original closed challenge (5 bytes):

'*[=Ć

Try it online.

Explanation:

1          # Start with 1
 [         # Loop indefinitely:
  D        #  Duplicate the current value
   N>      #  Push the 1-based loop-index
     .b    #  Convert it to an uppercase character (1→A,2→B,...,26→Z,27→A,...)
       ×   #  Repeat that letter the duplicated value amount of times
        ,  #  Pop and print it with trailing newline
  N        #  Push the 0-based loop index
   ₂%      #  Modulo-26
     >     #  Increase it by 1
      +    #  Increase the current value by this for the next iteration
A          # Push the lowercase alphabet
 u         # Uppercase it
  Þ        # Convert it to a list of characters, and cycle indefinitely
∞          # Push an infinite positive list: [1,2,3,...]
 <         # Decrease by 1 to make it non-negative: [0,1,2,...]
  ₂%       # Modulo-26 each
    >      # Then increase each back by 1
     .¥    # Prepend 0 and undelta
       >   # Increase each by 1
×          # Repeat the letters those values amount of times
 €         # Loop over each string:
  ,        #  Output it with trailing newline
'*        '# Push "*"
  [        # Loop indefinitely:
   =       #  Print the current string with trailing newline (without popping)
    Ć      #  Enclose; append its own first character
\$\endgroup\$
1
\$\begingroup\$

Google Sheets, 103 bytes

To be entered in A1:

=LET(R,LAMBDA(R,a,b,i,l,IF(i=ROWS(A:A),l,R(R,a+b,MOD(b,26)+1,i+1,{l;REPT(CHAR(b+64),a)}))),R(R,1,1,1,))

enter image description here

The formula prints until the last row of the sheet. It breaks after a few thousand rows because of the 32k max char limitation of the REPT function.

enter image description here

\$\endgroup\$
1
\$\begingroup\$

C++, 113 109 bytes

#include<iostream>
int i,p=1;int main(){while(p){std::cout<<std::string(p,char(i%26+65))<<'\n';p+=i++%26+1;}}

Try it online!

-4 bytes thanks to suggestions by Neil and ceilingcat.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Moving the i++ into the p+= expression saves 2 bytes, but you can save 5 more by using a for loop. \$\endgroup\$
    – Neil
    Commented Jun 8 at 7:32
  • 1
    \$\begingroup\$ 88 bytes \$\endgroup\$
    – ceilingcat
    Commented Jun 13 at 18:36
0
\$\begingroup\$

Arturo, 58 57 bytes

s:1i:0whileø->loop'A'..'Z'=>['s+i,[email protected]:s&|print'i+1]

enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.