111
\$\begingroup\$

Background

This is a standard textbook example to demonstrate for loops.

This is one of the first programs I learnt when I started learning programming ~10 years ago.

Task

You are to print this exact text:

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

Specs

  • You may have extra trailing newlines.
  • You may have extra trailing spaces (U+0020) at the end of each line, including the extra trailing newlines.

Scoring

This is . Shortest answer in bytes wins.

\$\endgroup\$
10
  • 3
    \$\begingroup\$ @DylanMeeus "You are to print this exact text:" \$\endgroup\$
    – Leaky Nun
    Aug 4 '16 at 12:56
  • 14
    \$\begingroup\$ @DylanMeeus Since that is to do with the dev tools hiding repeated console outputs, and isn't native to JavaScript consoles as a whole and is not in the JavaScript spec - as well as the fact that feature can be turned off - i think it should be acceptable. Not all browsers will collapse it like that. \$\endgroup\$
    – James T
    Aug 4 '16 at 12:58
  • 7
    \$\begingroup\$ @LeakyNun Leaderboard snippet please! \$\endgroup\$
    – anna328p
    Aug 4 '16 at 22:08
  • 4
    \$\begingroup\$ One of the most interesting things about this challange is that depending on your language ********** can be shorter then a loop. Makes me wonder when it's better for a given language to switch between 1 or 2 loops. \$\endgroup\$
    – dwana
    Aug 5 '16 at 9:14
  • 3
    \$\begingroup\$ you say trailing new lines are acceptable. Are leading newlines acceptable too? \$\endgroup\$ Feb 10 '17 at 2:34

377 Answers 377

1
9 10 11
12
13
0
\$\begingroup\$

RProgN 2, 8 bytes, Noncompeting

Noncompeting because Language Postdates challenge

°{°`**}*

I decided to take another stab at this, with a much better version of RProgN.

Explained

°{°`**}*
°      *    # Run the contained function Ten (Which ° is a constant for) times.
 {°  *}     # Repeat the referenced string 10 times.
   `*       # Asterisk Literal.
            # This results in 10 strings of 10 `*`s on the stack, which prints as expected.

Try it online!

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

Fourier, 22 bytes

10(10(~X42aX^~X)aN^~N)

Try it on FourIDE!

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

OCTAVE, 36 bytes

strrep(num2str(ones(10,10)),"1","*")

Makes a 10 by 10 matrix of ones, converts these to strings and then changes the ones to *'s.

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

OIL, 55 44 41 bytes, noncompeting

Annotated here for better understanding; remove everything after each ‌# in each line to make it work.

**********# asterisk storage
10#if what's in
14#line 14 (marked with $)
1#is identical to 10 (line 1)
13#jump to line 13 (marked with &)
6#else to line 6; the next line
4#print what's in line 0; 10 asterisks

11#print a newline
8#increment line 14 (marked with $)
14
6#jump to the beginning (line '' == line 0)

3#exit &
0#counter $
\$\endgroup\$
0
\$\begingroup\$

Syms 1.4, 12 bytes (noncompeting)

$
$*10*+10*>

Try it online!

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

C#, 96 bytes

static class P{static void Main(){for(int i=1;i<11;i++)System.Console.WriteLine("**********");}}

Try it online

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to PPCG! Firstly, you should specify the language and byte count; secondly, this isn't a full program or function, so doesn't meet the standard requirements; thirdly, you can save a bunch of bytes by removing unnecessary whitespace and changing the comparison symbol, like so: for(int i=1;i<11;i++)Console.WriteLine("**********\n"); \$\endgroup\$
    – F1Krazy
    Jun 9 '17 at 7:54
  • \$\begingroup\$ If this is C#, read this post to learn what your answer should be like. Also, have a look at the other answers to see what the standard format is (header with language name and bytecount, then code...). \$\endgroup\$
    – Dada
    Jun 9 '17 at 8:15
0
\$\begingroup\$

Micro, 15 bytes

"*"10*10c+10*:/
\$\endgroup\$
1
  • \$\begingroup\$ incidentally, the ascii code for newline is 10, so: 10c \$\endgroup\$
    – raddish0
    Jun 9 '17 at 12:34
0
\$\begingroup\$

k, 12 bytes

`0:10 10#"*"

Try it online.

Explanation:

   10 10#"*" /make 10 by 10 matrix of asterisk characters
`0:          /output each row as a line
\$\endgroup\$
0
\$\begingroup\$

4, 56 bytes

4, 5, 6!

3.600426011060310604018016021080250010202049503101010494

Try it online!

For explanation see verbose mode in the tio link - quite straightforward initialization of cells and nested 10x10 loop.

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

Crystal, 21 bytes

puts ("*"*10+"\n")*10
How does it work?
"*" * 10            = "**********" 
"**********" + "\n" = "**********\n"
"**********\n" * 10 = "**********\n**********\n[...]"
\$\endgroup\$
0
\$\begingroup\$

SOGL V0.12, 6 bytes

LL **∙

Try it Here!

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

Google Sheets, 22 Bytes

Anonymous worksheet function that takes no input and outputs a 10 x 10 grid of *s to the calling worksheet cell.

=REPT("**********
",10
\$\endgroup\$
0
\$\begingroup\$

ABCR, 36 bytes

)))))))BAAAAA4*xAb)))B(7OOOOOOOOOOP(x

Pushes 42 (the character code for *) to queue A, 10 (\n) to B, and then for each value from 9 to 0 print out ten copies of A as a character and one copy of B.

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

Acc!!, 68 bytes

Count i while i-10 {
	Count v while v-10 {
		Write 42
	}
	Write 10
}

Try it online!

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

dc, 41 bytes

[1-d0!>C]sR[42Pd10%0=NlRx]sC[10P]sN100lRx

Try it online!

I know there's dc answer, just wanna do it without dumping stack)

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

FALSE, 34 33 26 23 bytes

11[1-$]["**********
"]#
\$\endgroup\$
0
\$\begingroup\$

Momema, 44 bytes

a000b0-9 42 0+1*0b=+-10*0-9 10 1+1*1a=+-10*1

Try it online!

Explanation

                                                                     #  b = 0
a   0        #  label a0: jump past label a0 (no-op)                 #  do {
0   0        #            [0] = 0                                    #    a = 0
b   0        #  label b0: jump past label b0 (no-op)                 #    do {
-9  42       #            output chr 42                              #      print '*'
0   +1*0     #            [0] = 1 + [0]                              #      a += 1
b   =+-10*0  #  label b1: jump past label b((1 + !!([0] - 10)) % 2)  #    } while (a - 10 != 0)
-9  10       #            output chr 10                              #    print '\n'
1   +1*1     #            [1] = 1 + [1]                              #    b += 1
a   =+-10*1  #  label a1: jump past label a((1 + !!([1] - 10)) % 2)  #  } while (b - 10 != 0)
\$\endgroup\$
0
\$\begingroup\$

Micrsocript II, 13 bytes

{"*"s10*P}s9*
\$\endgroup\$
0
\$\begingroup\$

Python 3, 43 34 31 28 bytes

for i in[1]*10:print(10*'*')

Saved 9 bytes thanks to Simon

Saved 3 bytes thanks to Wheat Wizard

Just sprints ten asterisks and in a loop.

\$\endgroup\$
4
  • \$\begingroup\$ There is no need to print \n since each print starts with a new line. Also you can shorten 10*'*'. If you swap to Python 2, you can save another byte by removing a bracket. 31 bytes \$\endgroup\$
    – Simon
    Feb 6 '18 at 8:18
  • \$\begingroup\$ 30 bytes \$\endgroup\$
    – Simon
    Feb 6 '18 at 8:22
  • \$\begingroup\$ You can use something other than a range for example [1]*10 \$\endgroup\$
    – Grain Ghost
    Feb 6 '18 at 22:45
  • \$\begingroup\$ If you do [1]*10 you don't need the space after in. \$\endgroup\$
    – Grain Ghost
    Feb 12 '18 at 3:55
0
\$\begingroup\$

Whitespace, 91 bytes

[S S S T    T   S S T   S S N
_Push_100][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T  S S T   _Subtract][S N
S _Duplicate][N
T   T   S N
_If_negative_Jump_to_Label_EXIT][S S S T    S T S T S N
_Push_42_*][T   N
S S _Print_as_character][S N
S _Duplicate][S S S T   S T S N
_Push_10][T S T T   _Modulo][N
T   S T N
_If_0_Jump_to_Label_NEWLINE][N
S N
N
_Jump_to_Label_LOOP][N
S S T   N
_Create_Label_NEWLINE][S S S T  S T S N
_Push_10][T N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Integer i = 100
Start LOOP:
  i = i - 1
  If(i < 0)
    Exit program
  Print "*"
  If(i modulo-10 == 0)
    Print new-line
  Go to next iteration of LOOP
\$\endgroup\$
0
\$\begingroup\$

Charm, 50 bytes

f := 10 repeat i
[ [ " * " pstring ] f newline ] f

Try it online!

Funnily enough, this doesn't use loops at all, just repeated code.

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

SNOBOL4 (CSNOBOL4), 56 50 bytes

O	OUTPUT =DUPL('*',10)
	X =LT(X,9) X + 1 :S(O)
END

Try it online!

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

C, gcc 36 bytes

recursive solution. One downside is you need to pass 2 when you call the function to get 10 rows. f(a){a<puts("**********")?f(a+1):0;}

This alternative addresses that issue and you don't have to call the function from main since main is now the recursive function:

main(a){a<puts("**********")-1?main(a+1):0;}

gcc also resolves #include "stdio.h" missing and variable a is implicitly set to an int and initialized to 0.

\$\endgroup\$
5
  • 3
    \$\begingroup\$ You're not supposed to take input, I believe. \$\endgroup\$ May 26 '18 at 1:56
  • \$\begingroup\$ The second one addresses that. The second one is the entire .c file and takes no arguments when you run the executable. \$\endgroup\$
    – Geo
    May 26 '18 at 2:04
  • 2
    \$\begingroup\$ I see. You need to make that clear then(put the correct code in a code block under the header). \$\endgroup\$ May 26 '18 at 2:07
  • 2
    \$\begingroup\$ The solution you have at the top is an entirely invalid solution, so chuck it and just leave the valid one. \$\endgroup\$
    – LyricLy
    May 26 '18 at 4:55
  • \$\begingroup\$ Try it online! \$\endgroup\$ Jul 2 '18 at 15:16
0
\$\begingroup\$

Prolog (SWI), 62 59 55 54 bytes

t.
b:-between(0,9,_).
?-b,(b,write(*),1=0;t),nl,1=0;t.

Try it online!

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

Pari/GP, 31 bytes

for(i=1,10,print("**********"))

Try it online!

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

Python 3, 28 bytes

print(*['*'*10]*10,sep='\n')

Try it online!

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

PHP, 60 45 Bytes

Try it online (original answer)

Try it online (saved 15 Bytes thanks to @Titus)

Code (Original)

<?=strtr(str_repeat(base_convert("1ku",36,2),10),["
","*"]);

Code (Titus suggestions)

<?=strtr(str_repeat(11111111110,10),10,"*\n");

About the edit

The change is, using str_repeat(base_convert("1ku",36,10),10) actually uses more bytes than str_repeat(11111111110,10) and the use of string for replacements on strtr instead of an array.

Explanation, Why "1ku"?`

The solution is repeat the string "**********", lets take the base 2 number 11111111110

base 10 = 2046
base  2 = 11111111110
base 36 = 1ku

Basically is repeat a compressed string, and with strtr replace each 1 with a "*" and 0 with a \n

\$\endgroup\$
3
  • \$\begingroup\$ Why don´t You just take a string with the bits instead of the packed number, and use strings instead of array for translation? 45 bytes: <?=strtr(str_repeat(11111111110,10),10,"*\n"); (decbin(2046) is one byte longer than that.) Nice idea though. \$\endgroup\$
    – Titus
    Jun 2 '18 at 11:46
  • 1
    \$\begingroup\$ (and while you´re at it, you can fix **strtr** to strtr ;-) \$\endgroup\$
    – Titus
    Jun 2 '18 at 11:48
  • \$\begingroup\$ I just realize that yeah, it's less bytes by using 11111111110 instead of base_convert("1ku", 36,10), i was trully focused on compress the string rather than check the byte count, gonna edit the answer, ty @Titus \$\endgroup\$ Jun 2 '18 at 18:14
0
\$\begingroup\$

Python 2, 21 bytes

exec'print"*"*10;'*10

Try it online!

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

Glee, 17 bytes

('*'%%10\)%%10,,\

Explanation:

('*'                          create '*'
    %%10                      reshape to length 10
        \)                    monadic segment with CRLF
          %%10                reshape to sequence length 10
              ,,\             expose with LF separators
\$\endgroup\$
0
\$\begingroup\$

Python 3, 22 bytes

print(("*"*10+"\n")*10)

Felt like entering a Python 3 program too.

\$\endgroup\$
1
9 10 11
12
13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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