104
\$\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
  • 2
    \$\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\$ – Trotski94 Aug 4 '16 at 12:58
  • 7
    \$\begingroup\$ @LeakyNun Leaderboard snippet please! \$\endgroup\$ – anna328p Aug 4 '16 at 22:08
  • 3
    \$\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
  • 1
    \$\begingroup\$ you say trailing new lines are acceptable. Are leading newlines acceptable too? \$\endgroup\$ – Albert Renshaw Feb 10 '17 at 2:34

338 Answers 338

1
2
3 4 5
12
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\$ – Conor O'Brien 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
  • 5
    \$\begingroup\$ It's screaming! \$\endgroup\$ – mınxomaτ 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\$ – Mama Fun Roll 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\$

Unary, 3584048336806633376708256331142263836115215 bytes

Can't post it here for obvious reasons.

But it's literally just 3584048336806633376708256331142263836115215 zeroes.

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

TSQL, 24bytes

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

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

\$\endgroup\$
2
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\$ – Destructible Lemon 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\$ – Destructible Lemon 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\$ – James 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\$ – applejacks01 Aug 4 '16 at 15:30
  • \$\begingroup\$ @applejacks01 Thanks for your input. I have modified it. \$\endgroup\$ – Anuj Tripathi Aug 4 '16 at 15:32
  • 2
    \$\begingroup\$ Couldn't you just do Select top 10 '**********' from systypes? \$\endgroup\$ – pinkfloydx33 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\$

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
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
3
\$\begingroup\$

Cheddar, 24 bytes

print(['*'*10]*10).vfuse

'*'*10 builds the string **********.

Then, ['**********']*10 creates 10 copies of that string.

Then, vfuse joins by newline.

\$\endgroup\$
3
\$\begingroup\$

Perl, 17 bytes

Requires -E at no extra cost.

say"*"x10for 0..9

Usage

perl -E 'say"*"x10for 0..9'
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********

Saved a byte thanks to @manatwork!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Keywords may touch the preceding digits. \$\endgroup\$ – manatwork Aug 4 '16 at 12:27
  • \$\begingroup\$ @manatwork Ahhh... I always forget that works, expecially as for0.. doesn't! Thanks! \$\endgroup\$ – Dom Hastings Aug 4 '16 at 12:29
  • 1
    \$\begingroup\$ I literally typed out the same program :) \$\endgroup\$ – simbabque Aug 4 '16 at 14:14
  • 1
    \$\begingroup\$ Try it online! \$\endgroup\$ – mik Mar 15 at 11:52
3
\$\begingroup\$

><>, 35 bytes

ab*1-:?!v:20.
>'*'o72.~
^?%b;!?l<oa

Try it online!

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

dc, 22 18 bytes

[**********]ddddff

Invoked in bash as

echo [**********]ddddff | dc

Explanation:

[**********] # This is dc's way of making a string, which is then pushed onto the stack
dddd         # d is for duplicate, so we duplicate it 4 times on the stack
ff           # print the whole stack twice, which contains 5 repetitions of 10 *'s (x2)

Thanks to LeakyNun for saving 5 4 bytes; Edited from 5 since I can't count.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Ah, right! f doesn't clear the stack. Alternatively, ...dfffff would accomplish it as well with the same byte count. Come to think, ...ddfffp would work just as well (3 sets of three and then just one). There are a lot of ways to get 10 reps with 6 bytes. \$\endgroup\$ – Delioth Aug 4 '16 at 17:45
3
\$\begingroup\$

C#, 53,122 108 bytes

Seeing that I'm seriously new to code golf... I'll give it a shot in c#

public class Program{public static void Main(){for (var i=0;i<10;i++)System.Console.Write("**********\n");}}

try it online

\$\endgroup\$
13
  • \$\begingroup\$ for(var i=0;i++<10;)Console.Write("**********\n"); is shorter, also, you need a full program or function. \$\endgroup\$ – ASCII-only Aug 4 '16 at 11:08
  • \$\begingroup\$ @MarsUltor - thanks for the feedback. As mentioned, I'm seriously new to this and not exactly sure what is allowed and what not. Could you please elaborate on full program? Would this include literary all the code, such as using, namespaces, main etc. Thanks! \$\endgroup\$ – Richard Bailey Aug 4 '16 at 11:12
  • 2
    \$\begingroup\$ class a{static void Main{for(var i=0;i++<10;)Console.Write("**********\n");}} is acceptable (not entirely sure it works though, you should test it, maybe you need System before Console) \$\endgroup\$ – ASCII-only Aug 4 '16 at 11:21
  • 1
    \$\begingroup\$ You can get rid of using System; and use System.Console.WriteLine("**********");. It saves you 6 bytes. Also, you can get rid of some spaces for extra savings - the ones around the for cycle. \$\endgroup\$ – auhmaan Aug 4 '16 at 17:23
  • 2
    \$\begingroup\$ It's a shame Enumerable.Repeat() is so many bytes... C# could move up a lot of these with a shorthand for that function. \$\endgroup\$ – Joel Coehoorn Aug 8 '16 at 19:28
1
2
3 4 5
12

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.