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
2
3 4 5
13
6
\$\begingroup\$

Unary, 3584048336806633376708256331142263836115215 bytes

Can't post it here for obvious reasons.

But it's literally just 3584048336806633376708256331142263836115215 zeroes.

\$\endgroup\$
5
\$\begingroup\$

Retina, 12 bytes

Byte count assumes ISO 8859-1 encoding. The leading linefeed is significant.


10$**
.
$_¶

The first stage writes a string of ten asterisks, the second stage replaces each asterisk with the entire string and a linefeed. This prints two trailing linefeeds.

\$\endgroup\$
5
\$\begingroup\$

J, 10 9 bytes

1 byte thanks to @Adám.

10 10$'*'

Online interpreter.

Explanation

10 10 specifies the dimension to the operator $ which builds an array with the specified dimensions.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Also 9 bytes: '*'$~,~10 \$\endgroup\$ Aug 4 '16 at 18:26
5
\$\begingroup\$

Mathematica, 24 bytes

Print@"**********"~Do~10

It's kinda unfortunate that StringRepeat alone is 12 characters long...

\$\endgroup\$
5
\$\begingroup\$

///, 25 bytes

/a/**********
/aaaaaaaaaa

Try it online!

A simple replace command.

\$\endgroup\$
1
  • 6
    \$\begingroup\$ It's screaming! \$\endgroup\$
    – user42643
    Aug 5 '16 at 14:08
5
\$\begingroup\$

Julia, 23 22 bytes

print(("*"^10*"
")^10)

See here to test on an online interpreter. Thanks @Dennis for the tip!

\$\endgroup\$
1
  • \$\begingroup\$ Try changing your code to function output. \$\endgroup\$ Aug 12 '16 at 23:06
5
\$\begingroup\$

Sesos, 11 bytes

With many thanks to Leaky Nun for his help, and credit to his Brainf*ck answer, which inspired this one. Golfing suggestions welcome. Try It Online!

0000000: A8 24 BE EC CB 82 06 BD A7 EC 0E    .$.........

How it works

The binary file above has been generated by assembling the following SASM code.

add 42,fwd 1,add 10,fwd 1,add 10  # puts 42, 10, 10 in the register
jmp,sub 1,rwd 1                   # starts the first loop
jmp,sub 1,rwd 1,put,fwd 1,jnz     # second loop prints 42 or "*"
add 10,put,fwd 1                  # resets first loop, prints 10 or "\n"
                                  # first loop ends implicitly
\$\endgroup\$
1
  • \$\begingroup\$ Congratulations! \$\endgroup\$
    – Leaky Nun
    Aug 5 '16 at 13:45
5
\$\begingroup\$

T-SQL, 35 bytes

I used a hard carriage return in the string, which is why it wraps to the next line.

select replicate('**********
',10)
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Save 1 byte by using PRINT instead of SELECT \$\endgroup\$
    – BradC
    Jan 30 '18 at 21:30
5
\$\begingroup\$

DOG, 22 bytes

10 bark "**********\n"

Prints out ********** and a newline 10 times.

Try it online! (you'll have to manually copy the code since I don't have permalink functionality yet ;_;)

\$\endgroup\$
3
  • 2
    \$\begingroup\$ A cat posting in DOG language... interesting, could have sworn you were sworn enemies of the household \$\endgroup\$
    – ʰᵈˑ
    Aug 9 '16 at 7:59
  • \$\begingroup\$ @ʰᵈˑHe's learning the enemy language to become a spy. \$\endgroup\$
    – user47018
    Aug 9 '16 at 18:03
  • \$\begingroup\$ @Midnightas ahaha yes! \$\endgroup\$
    – ʰᵈˑ
    Aug 10 '16 at 8:24
5
\$\begingroup\$

Perl 6,  19 17  16 bytes

say '*'x 10 for ^10
put '*'x 10 for ^10
put('*'x 10)xx 10
put(\*x 10)xx 10

Try it

Explanation:

put(       # print with trailing newline
  '*' x 10 # 「*」 string repeated 10 times
) xx 10    # list repeat the above 10 times

Apparently \* or \(*) which is short for Whatever.new.list.Capture when coerced to a Str turns into just *.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ I've recently discovered that \* (a Capture containing one Whatever) stringifies to the asterisk, at one less byte than '*'. \$\endgroup\$
    – smls
    Mar 3 '17 at 7:18
5
\$\begingroup\$

Common Lisp, SBCL, 39 38 35 32 31 29 28 bytes

(format t"~10{~10@{*~}
~}"1)

Ideas for improvement are welcomed.

~10{...~} ;loops 10 times, doing inside loop and printing newline
~10@{*~}  ;loops 10 times, displaying ten "*"
\$\endgroup\$
3
  • \$\begingroup\$ In this form it gives me an error, maybe '(1) instead of 1 ? \$\endgroup\$
    – Renzo
    Sep 28 '17 at 18:44
  • \$\begingroup\$ @Renzo Are you sure you tried it in SBCL? It works for me both when written to REPL and when loaded from file. It is true however that it does not work in TIO - they use Clisp implementation I think. \$\endgroup\$
    – user65167
    Sep 30 '17 at 15:19
  • 1
    \$\begingroup\$ You are right, I tried it in CCL and in TIO, where it does not work. But, it works in SBCL. \$\endgroup\$
    – Renzo
    Sep 30 '17 at 19:13
5
\$\begingroup\$

Lost, 152 116 114 105 95 91 60 57 54 bytes

66 bytes saved thanks to Jo King

v%<@(<<<<<<<<<<<<<<
\?\<>"**********h^"
/<>9v+^?:)-1+-

Try it online!

This program is unbelievably convoluted. I might explain it when I finished golfing it. For now here is a rough overview.

Explanations

To the left we have

v%
\?\<

which catches and cleans the ip. It exits when ? fails to jump over \ pushing the ip down to

  (
  >
>9v

which puts a counter set at 9 into the scope.

Then we push the string "**********h^". The ip wraps around to the other side and back down onto the next line moving backwards. The +- combines the last two characters to turn the h^ to a newline.

From here +^?:)-1 subtracts one from the counter or deflects the counter up to the top row if it is already zero. On its way to the top row * combines the two junk values we have lying around once on the top row we get rid of the last value with ( and exit with @.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ 62 bytes \$\endgroup\$
    – Jo King
    Feb 6 '18 at 9:28
  • \$\begingroup\$ @JoKing Nice! I'll add that as soon as I have a chance to fully digest all of your changes. \$\endgroup\$
    – Wheat Wizard
    Feb 6 '18 at 14:12
  • 1
    \$\begingroup\$ Sorry, but 60 bytes \$\endgroup\$
    – Jo King
    Feb 6 '18 at 22:13
  • \$\begingroup\$ @JoKing Ok I've updated the answer. Thanks \$\endgroup\$
    – Wheat Wizard
    Feb 6 '18 at 22:37
5
\$\begingroup\$

TSQL, 24bytes

PRINT'**********'
GO 10

My first submission, please be kind with any help :)

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

vim, 8 bytes

10a*<ESC>Y9p

<ESC> is 0x1b.

Annotated

10a*<ESC>  # append * 10 times
Y          # copy line into default register
9p         # paste 9 times

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Congrats on posting in the Language of the Month! \$\endgroup\$
    – Makonede
    Apr 14 '21 at 22:37
5
\$\begingroup\$

Python 3, 22 bytes

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

Try it online!

thanks to - hyper-neutrino, for tips!

\$\endgroup\$
6
  • 3
    \$\begingroup\$ Welcome to CGCC! You seem to have an extra trailing newline - your code is actually only 25 bytes because you don't need to count that. Additionally, you have an extra space after print that you don't need. \$\endgroup\$
    – hyper-neutrino
    Jun 20 '21 at 7:58
  • \$\begingroup\$ thanks for your tip(s) @hyper-neutrino, I didn't notice that haha! I guess I shouldn't edit that now, it might be cheating :/ \$\endgroup\$ Jun 21 '21 at 16:40
  • \$\begingroup\$ Why would it be? You can edit your answer to save bytes any time, and it's very common for people to suggest tips in comments; it's part of the game :) it's a competition, but more importantly we're all here to have fun and enjoy golfing. \$\endgroup\$
    – hyper-neutrino
    Jun 21 '21 at 17:07
  • 1
    \$\begingroup\$ Oh, thanks! I'll do it then haha \$\endgroup\$ Jun 25 '21 at 8:10
  • \$\begingroup\$ you should update the byte count and the TIO link as well \$\endgroup\$
    – MarcMush
    Jun 25 '21 at 15:09
5
\$\begingroup\$

Unreadable, 337 319 bytes

'""""""'""'"""'""""""'"""'""'""'""'""'""'""'""'""'""'"""'"""""'""'""""""'""'"""'""""""""'"""""""'""'"""'""""'""""'""""""'""'""'"""'"""""""'"""'"""""'""'""""""'""'""'"""'""""""""'"""""""'""'""'"""'"'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'"""""""'"""'"'"""""""'"""

Try it online!

That is quite ... unreadable, have some pseudocode:

Set 2 Set 1 10

While (Increment Set 2 Decrement Get 2)
  Second Second
  Set 3 Get 1
  While (Increment Set 3 Decrement Get 3)
    Print Increment*32 Get 1
  Print Get 1

Transpile it online!

\$\endgroup\$
5
\$\begingroup\$

Elixir 53 bytes 50 bytes 48 bytes 40 bytes

IO.puts List.duplicate "**********\n",10

Run it online

Beginner to Elixir, any thoughts? :D

50 bytes thanks to Underslash

48 bytes thanks to Dom Hastings

40 bytes thanks to Jo King

\$\endgroup\$
8
  • 1
    \$\begingroup\$ Couple of things, usually for answers its standard practice to include a link to some way to run it. A good website for this is TIO and if you look youll find Elixir there. Also, some basic things regarding your answer is always try to remove whitespace (in your case the " = " can be "=") but even better is doing this which comes out at 43 bytes. Good luck on future answers! \$\endgroup\$
    – Underslash
    Aug 12 '21 at 8:27
  • \$\begingroup\$ Oh, something else, whitespace is counted in the bytecount, but websites like TIO automatically count bytes. \$\endgroup\$
    – Underslash
    Aug 12 '21 at 8:28
  • 1
    \$\begingroup\$ Building on @JoKing's suggestion, you can also use List.duplicate instead of String for another -2: Try it online! \$\endgroup\$ Aug 12 '21 at 14:13
  • 2
    \$\begingroup\$ A different approach entirely for 35: Try it online! \$\endgroup\$ Aug 12 '21 at 14:16
  • 2
    \$\begingroup\$ Thanks Guys! :D I'll use what @DomHastings said about the List.duplicate. and oh yea they should be asterisks my bad :). I'll correct those! Thanks again! \$\endgroup\$ Aug 13 '21 at 10:03
5
\$\begingroup\$

Tagscript, 45 bytes

{replace(a,\*\*\*\*\*\*\*\*\*\*
):aaaaaaaaaa}

I don't know where you can run this lang except through carlbot so heres a link to that

Does this count? haha

EDIT: Potentially controversial, but I can shave off 10 bytes if I don't escape the asterisks:

{replace(a,**********
):aaaaaaaaaa}

Carlbot doesn't actually parse asterisks as a special character, it's Discord's markdown system that displays the text as modified. The exact text context of the output would be

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

If this 35 byte solution is valid, I also argue that the original 45 byte solution is invalid, as while only the 10x10 of asterisks is displayed by Discord, the actual text context of Carlbot's message would be

\*\*\*\*\*\*\*\*\*\*
\*\*\*\*\*\*\*\*\*\*
\*\*\*\*\*\*\*\*\*\*
\*\*\*\*\*\*\*\*\*\*
\*\*\*\*\*\*\*\*\*\*
\*\*\*\*\*\*\*\*\*\*
\*\*\*\*\*\*\*\*\*\*
\*\*\*\*\*\*\*\*\*\*
\*\*\*\*\*\*\*\*\*\*
\*\*\*\*\*\*\*\*\*\*

Which would be incorrect.

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

Python 2, 21 Bytes

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

Works in a similar way to Destructible Watermelon's Python 3 solution.

\$\endgroup\$
4
  • 9
    \$\begingroup\$ Yay I inspired someone! \$\endgroup\$ Aug 4 '16 at 9:46
  • \$\begingroup\$ Unfortunately, it only ties with the other Python 2 solution. :( \$\endgroup\$
    – Steven H.
    Aug 4 '16 at 9:48
  • \$\begingroup\$ Well, at least it is relevant in Python 2 \$\endgroup\$ Aug 4 '16 at 9:49
  • \$\begingroup\$ Same length: exec"print'*'*10;"*10 \$\endgroup\$
    – mbomb007
    Sep 20 '16 at 19:43
4
\$\begingroup\$

CJam, 9 8 bytes

Thanks to Lynn for saving 1 byte.

'*A*N]A*

Try it online!

Explanation

'*A*    e# Create a string of 10 asterisks.
N       e# Push a linefeed.
]       e# Wrap both in a list.
A*      e# Repeat 10 times.
\$\endgroup\$
1
  • 1
    \$\begingroup\$ '*A*N]A* is 8 bytes. \$\endgroup\$
    – Lynn
    Aug 4 '16 at 11:55
4
\$\begingroup\$

><>, 28 bytes

av
->:?!;av>~1ao
:-1o*76<^!?

Try it online!

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

Befunge, 39 bytes

52*>52* v
,1-:!#v_>67*
#@_v  >$52*,1-:!

Try it here!

\$\endgroup\$
3
  • 3
    \$\begingroup\$ This is 39 bytes; you don't need to count the trailing newline \$\endgroup\$
    – Justin
    Aug 4 '16 at 17:54
  • \$\begingroup\$ Thanks, I guess my text editor put a trailing newline somewhere and added to the file size. \$\endgroup\$
    – user55852
    Aug 4 '16 at 18:02
  • \$\begingroup\$ Shorter version by switching the movement direction to be left instead of right: (36 bytes) ideone.com/GZi1PG \$\endgroup\$
    – Justin
    Aug 4 '16 at 18:03
4
\$\begingroup\$

Actually, 7 bytes

9u;'**n

Try it online!

Explanation:

9u;'**n
9u;      push two copies of 10
   '*    push "*"
     *   multiply by one of the copies, yielding "**********"
      n  push 10 total copies of the string
\$\endgroup\$
4
\$\begingroup\$

PowerShell, 14 bytes

0..9|%{'*'*10}

Items exiting the pipeline are automatically printed on individual lines by the default PowerShell host.

Hooray for * doing string repetition.

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

Fuzzy Octo Guacamole, 15 bytes

'*'25**25*!_[X]

Explanation:

'*'              # Push '*'
   25*           # Push 10
      *          # Multiply, leaves '**********' ('*'*10)
       25*!_     # Sets the for-loop counter to 10 (2*5)
            [X]  # Iterates 10 times and prints '********' each time
\$\endgroup\$
4
\$\begingroup\$

Lua 36 bytes

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

There is already a Lua answer, but his was however not a full program that would print output and this one is shorter.

I wanted to post it as a comment to that one, but I don't have the reputation yet.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ On which interpreter does this print output? \$\endgroup\$
    – Leaky Nun
    Aug 6 '16 at 4:02
  • \$\begingroup\$ @LeakyNun Whoops, my bad. I tested it with the Lua 5.3 interpreter but I started it in interactive mode. I fixed the code so that it also runs in non interactive mode. \$\endgroup\$
    – Seeseemelk
    Aug 8 '16 at 10:08
4
\$\begingroup\$

Chef, 252 bytes

Was purely for fun trying to learn Chef.

Try it online!

a.

Ingredients.
42 b
10 c
10 d
13 e

Method.
Put e into mixing bowl.
F the c.
Put b into mixing bowl.
F the c until fed.
Liquefy contents of the mixing bowl.
G the d.
Pour contents of the mixing bowl into the baking dish.
G the d until ged.

Serves 1.
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Nice answer! Welcome to the site :) \$\endgroup\$
    – DJMcMayhem
    Dec 20 '17 at 21:10
4
\$\begingroup\$

TSQL, 45 bytes

SELECT TOP 10 REPLICATE('*',10) FROM systypes 

Above query use TSQL REPLICATE function to replicate * 10 times and systypes is a system view in SQL Server which list out system specified and user defined data types.

Try it here

This is my answer on Code Golf and I hope I am doing it correctly.

\$\endgroup\$
4
  • \$\begingroup\$ Welcome to PPCG! I would say you need to count those spaces in your bytecount, since they are required to execute your code \$\endgroup\$ Aug 4 '16 at 15:30
  • \$\begingroup\$ @applejacks01 Thanks for your input. I have modified it. \$\endgroup\$ Aug 4 '16 at 15:32
  • 2
    \$\begingroup\$ Couldn't you just do Select top 10 '**********' from systypes? \$\endgroup\$ Aug 6 '16 at 14:41
  • \$\begingroup\$ Didn't see there was already a TSQL answer. You can do it in 24 bytes by just using Print and "Go 10" \$\endgroup\$
    – Paul
    Feb 12 '18 at 11:25
4
\$\begingroup\$

Backhand, 28 bytes

aH~0}|{:& [a ^v&v"*******" ^

Try it online!

It may seem weird that the quotes only contain 7 asterisks, but there's a reason for it.

Explanation:

Note that the pointer usually moves in steps of 3

a         Push 10 as the counter
   0 |{   Push 0 to not get reflected and enter the loop
        &           Store the counter in the register
           a        Push a newline
               v v  Decrease the step value to 1
                  "*******"    Push 7 asterisks
                            ^  Increase the step value to 2 and reflect
                  " * * * "    Push 3 asterisks
                &   Restore the counter
             ^      Increase the step counter to 3
          [         Decrement the counter
       :    Duplicate the counter
    }|      Repeat the loop if the counter is not zero
  ~     Otherwise, pop the excess copy of the counter
 H      And terminate, printing the contents of the stack
\$\endgroup\$
4
\$\begingroup\$

Charcoal, 4 bytes

G+α*

Try it online!

The code translates as: draw a filled polygon (); give it four equal sides going in the four cardinal directions (+); each side should be 10 characters (α, a variable preinitialized to 10); use asterisks (*).

\$\endgroup\$
1
1
2
3 4 5
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.