107
\$\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
  • 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

346 Answers 346

1 2 3
4
5
12
2
\$\begingroup\$

Underload, 22 bytes

(*****):*(
)*:*::*:**S
\$\endgroup\$
0
2
\$\begingroup\$

Scheme, 51 Bytes

(map (lambda (n)(display "**********\n"))(iota 10))
\$\endgroup\$
2
\$\begingroup\$

Ruby, 26 20 bytes

10.times{puts'*'*10}

Try it online!

Explanation

Runs 10 times; each time, it prints * (10 times), with an automatic line break at the end.

Kudos to OrangeFlash81 for saving me 6 bytes.

\$\endgroup\$
1
  • \$\begingroup\$ I think 10.times{puts'*'*10} works as well and is shorter. \$\endgroup\$ – Aaron Christiansen Aug 7 '16 at 8:26
2
\$\begingroup\$

Xtend, 33 bytes

[for(_:0..9)print('**********
')]

... a Java dialect; [] is a lambda definition

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

Deadfish ~, 24 bytes

{{iiii}ii{c}{ddd}ddc{d}}

how it works:

{foo} does foo exactly ten times. first, it starts a ten loop, in this loop, it sets the counter to 42, prints it ten times (as char (asterisk)), decrements it to 10, prints it (newline), subtracts 10, then loops again, doing this 10 times.

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

Google Sheets, 31 23 bytes

Code:

In cell A1 (12 bytes):

=REPT(B1,10)

In cell B1 (11 bytes):

**********        # Contains New Line
                  # <--

Result:

enter image description here

Previous Attempt #1 (31 bytes):

=REPT(REPT("*",10)&CHAR(10),10)

Previous Attempt #2 (also 31 bytes):

=REPT("**********"&CHAR(10),10)
\$\endgroup\$
2
\$\begingroup\$

S.I.L.O.S 45 bytes

All whitespace necessary due to my poor interpreter design.

a = 10
lbla
printLine **********
a - 1
if a a

Try it Online!

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

Lua, 34 bytes

for i=1,10 do print"**********"end
\$\endgroup\$
2
\$\begingroup\$

Befunge-93 (PyFunge), 28 bytes

#<90v0-1_@#:,
#^_ >1+"*",:9`

Try it online!

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

Javascript (REPL), 27 bytes, Old is 32 bytes. Thanks to @Peter

('**********\n').repeat(10)
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Welcome to PPCG! Please note that we count REPL submissions differently from full-program solutions, so this should be marked as "Javascript (REPL)". \$\endgroup\$ – user45941 Feb 13 '18 at 2:32
  • \$\begingroup\$ @Mego Thank you, I will remember this! \$\endgroup\$ – NTCG Feb 13 '18 at 2:49
  • \$\begingroup\$ ('**********\n').repeat(10) is shorter :) \$\endgroup\$ – Peter Feb 13 '18 at 21:27
  • \$\begingroup\$ Welcome to PPCG :) Note that this solution already exists: codegolf.stackexchange.com/a/88660/58974. However, you can remove the brackets around the string and use a template literal with a literal newline to save 3 bytes: tio.run/##y0osSyxOLsosKNHNy09J/Z@cn1ecn5Oql5OfrvE/… \$\endgroup\$ – Shaggy Feb 15 '18 at 11:54
2
\$\begingroup\$

Kotlin (script), 32 bytes

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

Try it online!

Run this locally as a standalone program by

  • installing Kotlin
  • saving the source to a .kts file
  • run with kotlinc -script myfile.kts

This does not seem to work on TIO, for whatever reason, which is why I had to include the header/footer.

\$\endgroup\$
3
  • \$\begingroup\$ You could run this as a standalone program using the -script command line switch on kotlin. This doesn't work in TIO/kotlinc though. \$\endgroup\$ – snail_ May 25 '18 at 19:01
  • \$\begingroup\$ I wasn't aware this is possible. If you want to link the script version on TIO, you could do it this way. \$\endgroup\$ – ovs May 25 '18 at 19:35
  • \$\begingroup\$ {print("**********\n".repeat(10))} \$\endgroup\$ – mazzy Jul 2 '18 at 8:18
2
\$\begingroup\$

Kotlin, 62 bytes

fun main(a:Array<String>){for(i in 0..9)println("**********")}

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ your golfed version 37 bytes: {for(i in 0..9)println("**********")}. -3 byte version {print("**********\n".repeat(10))} ))) \$\endgroup\$ – mazzy Jul 2 '18 at 8:15
2
\$\begingroup\$

05AB1E, 9, 8 bytes

Tƒ,TF'*+

my first golfing answer so any tips are welcome

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ That's a grid of 10x9, not 10x10 \$\endgroup\$ – mbomb007 Jul 2 '18 at 14:34
  • \$\begingroup\$ didn't notice that, fixed it @mbomb007 \$\endgroup\$ – Tomb Jul 2 '18 at 14:41
2
\$\begingroup\$

Java (OpenJDK 8), 61 bytes

static{for(int i=0;i++<10;)System.out.println("**********");}

Try it online!

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

MathGolf, 6 bytes

⌂♀*♂/n

Try it online!

Explanation

⌂       Push "*"
 ♀*     Multiply by 100
   ♂/   Divide into chunks of 10
     n  Join with newline

With an output control flag this could be 5 bytes, but I don't have that yet.

\$\endgroup\$
2
  • \$\begingroup\$ Out of curiosity, why is there a single-byte builtin to push the * character? Or are there builtins for *, +, -, and / and some kind of eval functionality for a mathematical expression in string format? \$\endgroup\$ – Kevin Cruijssen Sep 20 '18 at 15:26
  • 2
    \$\begingroup\$ When I made the language, I wanted one single printable character to satisfy printing challenges where any character is valid. Luckily enough, I chose the asterisk! I also have a space character as a single command. \$\endgroup\$ – maxb Sep 20 '18 at 19:01
2
\$\begingroup\$

Shakespeare Programming Language, 387 bytes

,.Ajax,.Ford,.Act I:.Scene I:.[Exeunt][Enter Ajax and Ford]Ford:You be twice the sum ofa cat twice twice the sum ofa cat a big big cat.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.You be twice the sum ofa cat a big big cat.Speak thy.Ajax:You be the sum ofyou a cat.Be you nicer the sum ofa cat a big big big cat?If notlet usScene I.

Try it online!

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

Stax, 4 bytes

╪n│╔

Run and debug it

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

R 33 bytes

cat(rep('**********',10),sep='
')

Try it online

I believe this is shorter than the other R answers on this question.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I believe this is shorter than yours, but Mamie's answer on the first page (sorted by oldest) is something like 26 bytes if the comments are to be believed. \$\endgroup\$ – Giuseppe Feb 19 '19 at 22:14
  • \$\begingroup\$ Ah, I'd missed that one, thanks @Giuseppe. \$\endgroup\$ – CT Hall Feb 19 '19 at 22:31
2
\$\begingroup\$

Gol><>, 9 bytes

aFa:R`*|H

There is a trailing newline, but the specs say it is okay. Below is a version that doesn't have a trailing new line, but adds on 2 extra bytes.

aFaR`*a|~rH

Try it online!

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

C# (.NET Core), 53 bytes

Brand new to code golf, is this type of format allowed to be used (Usage of the header section / footer section)?

for(int i=0;i<10;i++){Console.Write("**********\n");}

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ Welcome to PPCG, and Great First Answer \$\endgroup\$ – Taylor Scott Feb 19 '19 at 22:46
  • \$\begingroup\$ You can get it down to 49 bytes by moving the i++ into the conditional expression, and moving the block body into the increment statement: for(int i=0;i++<10;Console.Write("**********\n")); (try it online) \$\endgroup\$ – mgthomas99 Feb 20 '19 at 14:47
  • 1
    \$\begingroup\$ This is not valid since it's neither a function (lambdas count) nor is it a full program. With a few adjustments though, 42 \$\endgroup\$ – ASCII-only Feb 20 '19 at 16:29
  • \$\begingroup\$ @mgthomas99 btw that's 50 bytes, and it makes no difference whether the write is inside or outside \$\endgroup\$ – ASCII-only Feb 20 '19 at 16:30
2
\$\begingroup\$

Perl 5, 18 Bytes

say'*'x10for 1..10

Requires the -E flags, as in:

perl -E "say'*'x10for 1..10"
\$\endgroup\$
2
\$\begingroup\$

Forth (gforth), 36 34 bytes

: f 9 for ." **********" cr next ;

Try it online!

-2 bytes thanks to @bubbler

Explanation

 10 0            \ put 10 and 0 on the stack
 do              \ begin a loop from 0 to 10 (0 inclusive 10 exclusive)
 ." **********"  \ print the string literal ********** (the initial space is required because forth words are space separated, and ." is not an exception)
 cr              \ print out a new line character
 loop            \ end the loop
\$\endgroup\$
1
  • \$\begingroup\$ Using for..next loop is 2 bytes shorter: Try it online! \$\endgroup\$ – Bubbler Oct 12 '19 at 8:13
2
\$\begingroup\$

Keg, 10 bytes

(
|(
|\*)
)

Explanation

(\n|           Start for loop iterating 10 times
    (\n|       Start for loop iterating 10 times
        \*     Push an asterisk
          )    End loop
           \n  Push a newline

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Apparently the final ) is not needed, only the newline in front of it. At least for the TIO version. \$\endgroup\$ – manatwork Oct 14 '19 at 14:20
2
\$\begingroup\$

JAPT, 12 bytes

'*
pA)+R
VpA

Japt sets vars automatically, so '* sets U to "*" pA)+R prints U out A(10) times. And adds a new line (+R). All this is set to V. VpA prints V out A times

In Regular JS is

U = "*";
V = (U.p(A)) + R;
V.p(A)
\$\endgroup\$
2
\$\begingroup\$

CSS, 157 109 bytes

Inspired by hd answer, probably 1:1 reproduced from OP question (except background color) - pure CSS solution (no additional HTML)

body:after,body:before{white-space:pre;content:'**********\A**********\A**********\A**********\A**********\A'

\$\endgroup\$
1
  • 4
    \$\begingroup\$ 103 bytes: *,:after{margin:0;white-space:pre;content:'**********\A**********\A**********\A**********\A**********\A (FireFox only, save it inside <style>...</style> in a totally empty file), the :after matches every element's after (in this case html and body) and * is used to remove the body margin. \$\endgroup\$ – Night2 Oct 15 '19 at 5:43
2
\$\begingroup\$

MAWP, 26 bytes

%25W[25W[~67W;~1A]%25W;1A]

This was interesting.

Try it!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You have no use for the % at the start and two stack reversals, essentially leading you to my answer codegolf.stackexchange.com/a/209467/92080 \$\endgroup\$ – Dion Aug 12 '20 at 18:20
  • \$\begingroup\$ Really should stop spamming the stack reversal everywhere. \$\endgroup\$ – Razetime Aug 13 '20 at 2:05
2
\$\begingroup\$

1+, 256 255 64 61 59 56 50 48 bytes

10
42
..(|(A|";";";";";)(A)^";^)(B|()()())(B)(B)

I'm lazy. Pushes a newline and an asterisk, then simply output them, without any tricks. No loops because creating terminating loops in 1+ is painful.

EDIT: -1 byte by reusing the constant 2.

EDIT: -191 bytes by using functions.

EDIT: -3 bytes by using another function.

EDIT: -2 bytes using one more function.

EDIT: -3 bytes.

EDIT: -6 bytes, although it probably doesn't quite follow the rules. It outputs number: followed by the correct output, but number: is a input prompt. If the input prompt have to be counted as output, then all answers with input is invalid as well.

This exploits a weird behaviour of the interpreter. When run in TIO with argument .input.tio, it reads from the input for the program source code and reads from the input again for the program input. So, yeah, the source code is fed into the input itself. 42 is a nope NOP because the only number literal 1+ recognises is 1. . pushes the input as an integer, which is 42.

If the character was something other than * it can be 46 bytes, by reading a character, not integer (* cannot precede the program due to the empty stack)

This will be completely valid after TwilightSparkle Edition is out. (TSE have a "-o" command line option that runs the original interpreter, except there are no prompts.)

EDIT: -2 bytes. Same trick with 10.

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

Rockstar, 53 51 41 37 35 bytes

X's10
while X
say "*"*10
let X be-1

Try it here (Code will need to be pasted in)

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

MAWP, 23 bytes

25W[25W[67W;1A]%52W;1A]

Try it!

Two nested loops doing almost the same thing

MAWP 2.0, 20 bytes

10[10["*":1-]`10;1-]

Try it!

Basically the same thing

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

Mornington Crescent, 1940 bytes

Take Northern Line to Euston
Take Victoria Line to Seven Sisters
Take Victoria Line to Euston
Take Victoria Line to Euston
Take Northern Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take District Line to Acton Town
Take Piccadilly Line to Heathrow Terminal 5
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Parsons Green
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Bakerloo Line to Paddington
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Bank
Take Northern Line to Mornington Crescent

Try it online!

// "*" = 42 = 6*7

// get 7
Take Northern Line to Euston
Take Victoria Line to Seven Sisters

// copy it
Take Victoria Line to Euston
Take Victoria Line to Euston
Take Northern Line to Bank

// add it until 42
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster

// get char "*"
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross

// concatenate it (shorter than with loop)
Take Northern Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington

// calculate a 10 for newline
// get 5 from Heathrow Terminal 5
Take District Line to Acton Town
Take Piccadilly Line to Heathrow Terminal 5
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Parsons Green

// add 5 + 5
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster

// get char "\n"
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross

// concatenate it with asterisks
Take Bakerloo Line to Paddington

// copy them
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington

// go home and print
Take Circle Line to Bank
Take Circle Line to Bank
Take Northern Line to Mornington Crescent
\$\endgroup\$
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.