112
\$\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

380 Answers 380

1
7 8
9
10 11
13
1
\$\begingroup\$

W d, 7 4 bytes

°♣∩x

Uncompressed

T:s*E

Explanation

T     % Push a 10 onto the stack
 :    % Copy the top of stack
  s*  % Generate 10 asterisks
    E % Foreach in the range 1 .. 10,
      % Print 10 asterisks following a newline
\$\endgroup\$
1
\$\begingroup\$

Scratch 3.0, 4 blocks/65 bytes

SB Syntax:

when gf clicked
delete all of[o v
repeat(10
add[**********]to[o v

Picture:

enter image description here

Try it online Scratch!

I'm quite proud of the block count here, because it matches the byte counts of the winning answers. But SB Syntax ruined things for me. (´• ╭╮ •`)

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

Plain TeX, 35 bytes

\def~{**********\par}~~~~~~~~~~\bye

Try this Code at Overleaf

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

Set, 79 bytes

set A (A+1)
set ! 42
[A/K] set ? 1
set A 65
set B (B+1)
set ! 10
[B/L] set ? 1

There's a newline at the start.

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

Integral, 6 Bytes

v*)f)☼

Try it!

Explanation

v*     "*"
  )    Push 10
   f   Repeat string 10 times
    )☼ Push 10 copies onto the stack

Stack is joined with newlines & implicitly outputted
\$\endgroup\$
1
\$\begingroup\$

Keg, -pn, 9 bytes

`*`
*(9|⑩

Try it online!

1 shorter than the current answer.

\$\endgroup\$
5
  • \$\begingroup\$ Good, but no competition with 1+. \$\endgroup\$
    – null
    Aug 17 '20 at 5:08
  • \$\begingroup\$ Yes, very competition with 1+ if you outgolf MAWP \$\endgroup\$
    – lyxal
    Aug 17 '20 at 5:09
  • \$\begingroup\$ Such rubbish, so pointless, wow \$\endgroup\$
    – null
    Aug 17 '20 at 5:12
  • \$\begingroup\$ It's also funny seeing you hate it so much. ;P \$\endgroup\$
    – lyxal
    Aug 17 '20 at 5:13
  • \$\begingroup\$ ... (15 chars!) \$\endgroup\$
    – null
    Aug 17 '20 at 5:17
1
\$\begingroup\$

JavaScript (V8), 52 bytes

console.log((f=(c,i=10)=>i?c+f(c,--i):'\n')(f('*')))

Try it online!

JavaScript (V8), 45 bytes

console.log((f=c=>c.repeat(10))(f('*')+'\n'))

Try it online!

JavaScript (V8), 45 bytes

console.log(('*'.repeat(10)+'\n').repeat(10))

Try it online!

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

Pip -l, 5 bytes

'*MCt

Try it online!

Four years ago, I wrote a 7-byte Pip solution and said, "Kinda disappointed that the simple way was the shortest." Fear not, previous me: It's not the shortest anymore!

(Though technically, given our current consensus about flags, Pip and Pip -l aren't the same language... oh, whatever.)

Explanation

    t  Variable, preset to 10
  MC   Take that as the size of a grid of coordinate pairs and map a function to each pair
'*     Given a value rather than a function, MC puts that value at every location instead
       The result is a list of 10-element lists of asterisks, which we autoprint with
       every sublist on a new line thanks to the -l flag
\$\endgroup\$
2
  • \$\begingroup\$ hmm, isn't the flag added to the code length? \$\endgroup\$
    – Razetime
    Sep 4 '20 at 3:34
  • \$\begingroup\$ @Razetime That used to be the case (and Pip's flag system was designed with that rule in mind), but it's not anymore. \$\endgroup\$
    – DLosc
    Sep 4 '20 at 3:40
1
\$\begingroup\$

Rutger, 64 bytes

r=Repeat["*"];
o=Concat[r[10]];
o=Repeat[o["\n"]];
Print[o[10]];

Try it online!

Kinda self-explanatory, I hope.

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

Rust, 39 bytes

||for _ in 0..10{print!("{:*>11}","
")}

Try it online!

This uses * as a fill character to pad a newline. The result is printed 10 times.

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

Desmos, 30 bytes

29sign(mod([1,...,110],11))+13

View it online! (kinda)

Desmos doesn't have string support, so instead we output a list of 110 character codes. If you don't want a trailing newline, you can change the 110 to a 109 with no issues. Desmos also doesn't support loops properly, but if you apply operations to arrays, it applies them to each element in the array. Explanation:

           [1,...,110]           Generate array containing numbers 1 to 110
       mod(           ,11)       Find index mod 11 (0 corresponds to end of row)
  sign(                   )      Coerce to 0/1 instead of 0/1/2/...
29                         +13   Convert 0s to 13s (\n in ASCII) and 1s to 42s (* in ASCII)
\$\endgroup\$
1
\$\begingroup\$

GolfScript, 10 bytes

10."*"*n+*

Try it online!

10.         # Puts 10 on the stack and makes a copy of it
   "*"*     # Puts the asterisk on the stack and multiplies it by the 10 to get "**********"
       n+   # Adds a newline to the string
         *  # Multiplies by that first 10
\$\endgroup\$
1
\$\begingroup\$

Bubblegum, 8 bytes

00000000: d382 035e 2e7a b201

Try it online!

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

JAISBaL 3.0.1, 9 bytes

h**A10«

Verbose:

# \# enable verbose parsing #\
ten            \# [0] push ten onto the stack #\
push1 *        \# [1] push * onto the stack #\
mul            \# [2] multiply the top two values of the stack #\
dupmany 10     \# [3] duplicate the top value of the stack 10 times #\
popoutallln    \# [4] pop off every value in the stack and print each one with a new line #\

Conventional 10 byte version (using actual for loops):

˖˖S*˄P

Verbose:

# \# enable verbose parsing #\
ten                 \# [0] push ten onto the stack #\
for                 \# [1] start for loop #\
    ten             \# [2] push ten onto the stack #\
    for             \# [3] start for loop #\
        print1 *    \# [4] print * #\
    end             \# [5] end current language construct #\
    ln              \# [6] print a new line #\

intepreter

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

Check, 15 bytes

"*">10:r*R]+R*o

Pushes the string * and repeats it ten times, while also storing 10 in the register. Then adds 10 to the end of the string (a newline), then repeats the whole thing 10 times.

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

x86-16 machine code, IBM PC DOS, 17 bytes

00000000: b10a 8bd1 b82a 0acd 1088 c8cd 294a 75f4  .....*......)Ju.
00000010: c3                                       .

Listing:

B1 0A       MOV  CL, 10             ; repeat '*' 10 times per line 
8B D1       MOV  DX, CX             ; counter for 10 line loop 
        LINE_LOOP: 
B8 0A2A     MOV  AX, 0A2AH          ; AL = '*', AH = 0AH 
CD 10       INT  10H                ; print '*' 10 times 
88 C8       MOV  AL, CL             ; AL = LF char (0xA) 
CD 29       INT  29H                ; write to screen 
4A          DEC  DX                 ; dec counter 
75 F4       JNZ  LINE_LOOP          ; loop for 10 lines 
C3          RET                     ; return to DOS

Uses PC BIOS INT 10H function 0AH (write char at current position CX number of times) for each row. Since this function doesn't actually advance the cursor only a line feed/LF (0xA) char is needed to move to the next line.

enter image description here

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

Bound, 13 12 bytes

10:c42:d*@RS

Thanks to Razetime for the -1 byte
Explanation:

1 # Put 1 onto the stack [1]
0 # Put 0 onto the stack [1, 0]
: # Combine the top two elements [10]
c # Copies the top element [10, 10]
4 # Put 4 onto the stack [10, 10, 4]
2 # Put 2 onto the stack [10, 10, 4, 2]
: # Combine the top two elements [10, 10, 42]
d # Convert the top element into a char [10, 10, '*']
* # Multiply the top two elements [10, '**********']
@ # Sorts the stack ['**********', 10]
R # Repeat the next command n times, where n is top element (10) ['**********']
S # Print the top char/string (creates newlines)

Try it online!

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Welcome to the site and nice first answer! \$\endgroup\$ Oct 14 '20 at 15:51
  • \$\begingroup\$ 12 bytes: 10:c42:d*@RS \$\endgroup\$
    – Razetime
    Oct 14 '20 at 16:03
  • \$\begingroup\$ @cairdcoinheringaahing thank you! excited to be here \$\endgroup\$
    – HoofedEar
    Oct 14 '20 at 16:13
  • \$\begingroup\$ @Razetime nice! \$\endgroup\$
    – HoofedEar
    Oct 14 '20 at 16:14
1
\$\begingroup\$

Brian & Chuck, 23 bytes

*{-?
{..........>-.+?

Try it online!

The is the ascii code 11.

Brian:
*      "*" 11
  {-    Restart Chuck's code and subtract 1
    ?   Go to Chuck's code while the first byte is not 0

Chuck:
                    11 (This will be decremented by 1 each line)
  {                  Restart Brian's code
   ..........        Print the "*" 10 times
             >-.+    Print the newline
                 ?   Go back to Brian's code
\$\endgroup\$
1
\$\begingroup\$

Python 3, 67 bytes

print('\n'.join(''.join('*' for x in range(10))for y in range(10)))

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to the site, and nice first answer! \$\endgroup\$ Dec 1 '20 at 20:10
  • \$\begingroup\$ 62 bytes by saving range(10) as a variable and removing the space after '*' \$\endgroup\$
    – Stephen
    Dec 1 '20 at 21:42
  • \$\begingroup\$ Don't forget to check out existing Python solutions to this problem. The current record is 20 bytes (Python 2) / 22 bytes (Python 3). \$\endgroup\$
    – Bubbler
    Dec 1 '20 at 23:24
1
\$\begingroup\$

Zsh -F, 19 bytes

yes **********|head

Try it online!

Edit: just saw this exact answer was already posted for bash :(

\$\endgroup\$
1
  • \$\begingroup\$ alt approach (22 bytes): jot -b'**********' 10 \$\endgroup\$
    – roblogic
    Mar 15 '21 at 1:55
1
\$\begingroup\$

Java 11, 48 chars

Method String.repeat​(int)

for(int i=0;i++<10;out.println("*".repeat(10)));

Try it online!


Java 5, 53 chars

Static imports

for(int i=0;i++<100;out.print("*"+(i%10>0?"":"\n")));

Try it online!


Java 3, 60 chars

Plain old Java

for(int i=0;i++<100;System.out.print("*"+(i%10>0?"":"\n")));

Try it online!

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

C (gcc), 41 bytes

main(n){++n<puts("**********")&&main(n);}

Try it online!

Or if you don't have any problem using a function that would work only the first time it's called (because to make it work again you should reset the value of n)

C (gcc), 38 bytes

n=9;f(){puts("**********");n&&f(--n);}

Try it online!

And a 38 bytes dupe

n;f(){++n+1<puts("**********")&&f(n);}

Try it online!

Note that even the first code works only one time, it doesn't reset anything, you need to run the program again to have another 10x10 grid. However for some (questionable) reason they allow printing the grid just once per program run when using main, but not when using another function.

\$\endgroup\$
13
  • 2
    \$\begingroup\$ This prints a 10*n grid of asterisks. Taking extra input (the 10 in this case) is not allowed \$\endgroup\$ Jan 19 '21 at 3:51
  • \$\begingroup\$ @ppery fixed it, thank you so much \$\endgroup\$ Jan 19 '21 at 4:30
  • 1
    \$\begingroup\$ Nope, your answer is now a non-reusable function, so still not allowed. \$\endgroup\$ Jan 19 '21 at 4:42
  • \$\begingroup\$ Omg I am learning a lot from you! I will fix even this one \$\endgroup\$ Jan 19 '21 at 5:01
  • \$\begingroup\$ @ppery resetting the global variable at the end of the function requires too much unnecessary code and I just want you to notice that this so upvoted answer codegolf.stackexchange.com/a/88695/100356 doesn't reset anything either, it requires a new run for every 10x10 block. And most probably the same thing happens in most codes here and in any codegolf question. I don't see any reason why we should use double standards. \$\endgroup\$ Jan 19 '21 at 17:37
1
\$\begingroup\$

Lua, 31 bytes

print(("**********\n"):rep(10))

Try it online!

Not very impressive but I think simpler is shorter in this case.

\$\endgroup\$
1
  • \$\begingroup\$ can't seem to beat this :) \$\endgroup\$
    – Riptide
    Nov 1 '21 at 18:21
1
\$\begingroup\$

Python 3, 26 24 bytes

print((10*'*'+'\n')*10)
\$\endgroup\$
2
  • \$\begingroup\$ I'm new to coding and even newer to competitive programming, so don't go too hard on me :D \$\endgroup\$ Jan 23 '21 at 5:01
  • \$\begingroup\$ Oh of course, multiplication has priority over addition. Thanks dude. \$\endgroup\$ Jan 23 '21 at 5:09
1
\$\begingroup\$

Whispers v3, 38 bytes

> "**********"
>> Output 1
>> Each 2 1

Try it online!

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

BRASCA, 26 24 20 17 bytes

l:[{$[{'*o]xllo$]

Try it online!

Explanation

l:                   - Initialize stack
  [             ]    - Do 10 times:
   {$                -   Decrement and swap
     [    ]          -   Do 10 times:
      {'*o           -     Decrement and print *
           xllo$     -   Reset and print a newline
\$\endgroup\$
1
\$\begingroup\$

Python - 40 20 23 bytes

 print(("*"*10+"\n")*10) # prints a row of 10 *s then a new line, 10 times

This (freshly optimised) code prints an asterisk 10 times, then a newline (should be fixed now), then repeats that 10 times.

\$\endgroup\$
9
  • 2
    \$\begingroup\$ Well, a quick save would be with the asterisks, instead of print("**********"), try print("*"*10) and save 6 bytes. Online example here: tio.run/##K6gsycjPM/7/Py2/… \$\endgroup\$
    – steenbergh
    Mar 1 '21 at 14:14
  • 1
    \$\begingroup\$ You can also probably add a newline to the "*"*10, and then multiply that be ten as well \$\endgroup\$ Mar 1 '21 at 14:23
  • \$\begingroup\$ Fixed now - thanks for the help. \$\endgroup\$ Mar 1 '21 at 14:59
  • \$\begingroup\$ You don't define the variable n anywhere. \$\endgroup\$ Mar 1 '21 at 16:54
  • 1
    \$\begingroup\$ Um, it doesn't work like that for me. I get NameError: name 'n' is not defined running this code on both Python 2 and Python 3 \$\endgroup\$ Mar 2 '21 at 15:09
1
\$\begingroup\$

Templates Considered Harmful, 89 bytes

Ap<Fun<If<A<1>,Cat<St<42,42,42,42,42,42,42,42,42,42,10>,Ap<A<0>,Sub<A<1>,T>>>,LF>>,I<10>>

Try it online!

Pretty standard "10 stars 10 times" answer, in the form of a tail-recursive anonymous function.

Ap<
  Fun<
    If<A<1>,
       Cat<
         St<42,42,42,42,42,42,42,42,42,42,10>,
         Ap<A<0>,
            Sub<A<1>,I<1>>>>,
       LF>>,
  I<10>
>
\$\endgroup\$
1
\$\begingroup\$

naz, 44 40 bytes

crossed out 44 is still regular 44 :(

1x1f6a7m9o1o4d1o0m0x1f1f1f1f1f1f1f1f1f1f

This is another one of those cases where a truly recursive definition would actually use more bytes than just repeating the f instruction.

Saved 4 bytes by using division instead of subtraction!

Try it online!

Explanation (with 0x instructions removed)

1x1f                   # Function 1
    6a7m9o1o           # Output 10 asterisks
            4d1o       # Output a newline
                0m     # Reset the register
1f1f1f1f1f1f1f1f1f1f   # Call function 1 ten times
\$\endgroup\$
1
\$\begingroup\$

JavaScript (V8), 31 bytes

write(`**********
`.repeat(10))

Try it online!

\$\endgroup\$
1
7 8
9
10 11
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.