122
\$\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
    Commented Aug 4, 2016 at 12:56
  • 16
    \$\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
    Commented Aug 4, 2016 at 12:58
  • 9
    \$\begingroup\$ @LeakyNun Leaderboard snippet please! \$\endgroup\$
    – anna328p
    Commented Aug 4, 2016 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
    Commented Aug 5, 2016 at 9:14
  • 3
    \$\begingroup\$ you say trailing new lines are acceptable. Are leading newlines acceptable too? \$\endgroup\$ Commented Feb 10, 2017 at 2:34

413 Answers 413

1
8 9
10
11 12
14
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\$

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\$ Commented Oct 14, 2020 at 15:51
  • \$\begingroup\$ 12 bytes: 10:c42:d*@RS \$\endgroup\$
    – Razetime
    Commented Oct 14, 2020 at 16:03
  • \$\begingroup\$ @cairdcoinheringaahing thank you! excited to be here \$\endgroup\$
    – HoofedEar
    Commented Oct 14, 2020 at 16:13
  • \$\begingroup\$ @Razetime nice! \$\endgroup\$
    – HoofedEar
    Commented Oct 14, 2020 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\$ Commented Dec 1, 2020 at 20:10
  • \$\begingroup\$ 62 bytes by saving range(10) as a variable and removing the space after '*' \$\endgroup\$
    – Stephen
    Commented Dec 1, 2020 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
    Commented Dec 1, 2020 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
    Commented Mar 15, 2021 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\$ Commented Jan 19, 2021 at 3:51
  • \$\begingroup\$ @ppery fixed it, thank you so much \$\endgroup\$
    – anotherOne
    Commented Jan 19, 2021 at 4:30
  • 1
    \$\begingroup\$ Nope, your answer is now a non-reusable function, so still not allowed. \$\endgroup\$ Commented Jan 19, 2021 at 4:42
  • \$\begingroup\$ Omg I am learning a lot from you! I will fix even this one \$\endgroup\$
    – anotherOne
    Commented Jan 19, 2021 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\$
    – anotherOne
    Commented Jan 19, 2021 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
    Commented Nov 1, 2021 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\$ Commented Jan 23, 2021 at 5:01
  • \$\begingroup\$ Oh of course, multiplication has priority over addition. Thanks dude. \$\endgroup\$ Commented Jan 23, 2021 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
    Commented Mar 1, 2021 at 14:14
  • 1
    \$\begingroup\$ You can also probably add a newline to the "*"*10, and then multiply that be ten as well \$\endgroup\$ Commented Mar 1, 2021 at 14:23
  • \$\begingroup\$ Fixed now - thanks for the help. \$\endgroup\$ Commented Mar 1, 2021 at 14:59
  • \$\begingroup\$ You don't define the variable n anywhere. \$\endgroup\$ Commented Mar 1, 2021 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\$ Commented Mar 2, 2021 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
\$\begingroup\$

Java (JDK), 37 bytes

out.print("**********\n".repeat(10));

Try it online!

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

Clojure, 35 bytes

(dotimes[_ 10](print"**********
"))

Try it online!

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

Elixir, 35 bytes

for _<-0..9,do: IO.puts"**********"

Try it online!

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

VBScript, 39 bytes

For i=0 to 9
WSH.Echo "**********"
next

VBScript, 53 bytes

For i=0 to 9
WSH.Echo replace(space(10)," ","*")
next

The second solution is slightly more interesting......

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

ConTeXt (40 bytes)

Compile it here (note that the magic comment is only here for texlive.net and it's not needed in an offline compilation).

\let~\dorecurse\starttext~{10}{~{10}*\\}
\$\endgroup\$
1
\$\begingroup\$

Twue, 31 bytes

a::~**********\n
::=
aaaaaaaaaa

Try it on the website!

Simply defines the replacement a which maps to printing 10 asterisks. The main body consists of 10 as. Trying a secondary replacement b::=aa or b::=aaaaa both yield 33 bytes, which is unfortunately longer.

Whereas in some Thue interpreters, outputting implicitly outputs a newline, that is not the case in Twue, which must manually insert the newline.

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

Duocentehexaquinquagesimal, 18 bytes

hùyy₄āÆβUW:“ã¾8½ž+

Try it online!

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

BRASCA, 14 bytes

l[ll['*o{]xo{]

Try it online!

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

yuno (abandoned), 11 bytes

」*10リュ」ニュア10リュ

xxd using Jelly's codepage:

00000000: f8f6 e6e5 5bf8 5200 e6e5 5b              ẏẇȧẓ[ẏR¡ȧẓ[

Explanation

」*                push "*"
  10              push 10
    リュ            repeat "*" 10 times
      」ニュ         push "\n"
         ア        add / concatenate
          10      push 10
            リュ    repeat "**********\n" 10 times

Equivalently written as ]*10ryu]nyua10ryu

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

PPL, 33 bytes

loop10{
printLine("**********")
}

There is no concept of repeating strings, and the * operator is not overloaded with strings by numbers, so I hardcoded a string of 10 asterisks and printed it 10 times using the loop keyword.

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

Mathematica, 24 bytes

Print@@@Table["*",10,10]

A second (simple) Mathematica proposition, same length

\$\endgroup\$
1
8 9
10
11 12
14

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.