111
\$\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
  • 2
    \$\begingroup\$ you say trailing new lines are acceptable. Are leading newlines acceptable too? \$\endgroup\$ Feb 10 '17 at 2:34

375 Answers 375

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

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

Malbolge, 271 bytes

Generated here (linear generator). I tried other methods too but it took me pretty long time so I could not wait for completion.

D'`_:pon}}kXyxx5R-,s0Npn9+k#(EgDU0zyba+u)]xwvunV3210/.-,+*hg`H^c\"`_AW\UyxwvutsrqpJIHMLEDCg*@E>ba`_^]\[ZY9y765.-,+O/.nmJIHGFEDCBAya}|{ts9wvunV3210/.-,+*hg`H^c\"`_AW\UyxwvutsrqpJIHMLEDCg*@E>ba`_^]\[ZY9y765.-,+O/.nmJIHGFEDCBAya}|{ts9wvunV3210/.-,+*hg`H^c\"`_AW\Uyxwvutsrqp]

Try it online!

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

Arduino, 101 bytes

int i=0;void setup(){Serial.begin(300);}void loop(){if(i++<10)Serial.println("**********");else i--;}

The else case is there to prevent i from overflowing and becoming negative, since the loop() function is called indefinitely.

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

Ulpia, 41 bytes

"n*\n"for 0_?(0 0_1-=0_11%1<1+_->up)[hlt]

Explanation:

; counter == 'n' == 110 == 10 * 10 asterisks + 10 newlines and...
; ..."array" of characters to-be used, (starts at index = 1)
"n*\n"
for 0_ ?(  ; while the counter is not zero...
    0 (0_ 1 -) =  ; decrement it
    ; if counter is divisible by 11, the condition returns 1 and we get "\n"
    ; from the array, otherwise we get an "*"
    (((0_ 11 %) 1 <) 1 +) _ ->
up)  ; go up the nearest `for`
; when loop ends we halt
[hlt]
\$\endgroup\$
1
\$\begingroup\$

Python 3, 34 bytes

for i in range(10):
 print("*"*10)

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Code Golf! I've edited your answer to make it a bit clearer and added a link to try it. There's a couple similar Python answers, but nice first answer! \$\endgroup\$ Oct 1 at 16:09
  • \$\begingroup\$ You can save some bytes by inlining the for block, so it can be one line like for i in range(10):print("*"*10) \$\endgroup\$
    – hyper-neutrino
    Oct 1 at 16:09
  • \$\begingroup\$ Also, make sure to check out our Tips for golfing in Python to see if there are any other ways to golf your code. \$\endgroup\$ Oct 1 at 16:10
1
\$\begingroup\$

Subleq (8 bit), 18 bytes

 2 -1 42
 1 17  0
15 -1 -9
15 17 12
 1  8  0
10 10 -9

Explanation

 2 -1 42 Print [2]                               // [2] = 42, ASCII(42) = "*"
 1 17  0 [17] = [17] - [1]  if [17] <= 0 goto 0  // Loop 10 times
15 -1 -9 Print [15]                              // [15] = 10 ASCII(10) = <line feed> 
15 17 12 [17] = [17] - [15] if [17] <= 0 goto 12 // Set [17] back to -9
 1  8  0 [8]  = [8]  - [1]  if [8]  <= 0 goto 0  // Loop 10 times
10 10 -9 [10] = [10] - [10] if [10] <= 0 Exit    // Exit program
\$\endgroup\$
1
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 43 bytes

Outputs two trailing LFs.

 output =dupl(dupl('*',10) char(10),10)
end

Try it online!

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

jq, 16 bytes

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

Try it online!

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

C++, 76 bytes

I don't know if this could be golfed further, but just.

#include <iostream>
void a(){for(int i=0;i++<10;)std::cout<<"**********\n";}
\$\endgroup\$
4
  • \$\begingroup\$ No, I tried that. \$\endgroup\$
    – user54200
    Aug 4 '16 at 10:30
  • 5
    \$\begingroup\$ You can save a few bytes by using puts from cstdio instead of cout (save in header name, function name, plus line terminator for free). Also one byte by making i global (which gets zero initialized for free). \$\endgroup\$
    – Mat
    Aug 4 '16 at 12:23
  • 1
    \$\begingroup\$ This isn't a whole program (no main) so do you need the include? \$\endgroup\$ Jul 2 '18 at 0:07
  • \$\begingroup\$ tio.run/##S9ZNT07@/z/… Here is a version with Mat's suggestions \$\endgroup\$ Oct 14 '20 at 21:07
0
\$\begingroup\$

C# - 88 bytes

class P{static void Main(){int i=0;while(i++<10)System.Console.Write("**********\n");}}
\$\endgroup\$
2
  • \$\begingroup\$ You can reduce this a bit by using a for look, putting int i inside it for(int i=10;i-->0;) (There is never a reason to use a straight while loop in C# code golf, a for loop is never more expensive) \$\endgroup\$ Aug 4 '16 at 17:24
  • \$\begingroup\$ I know, but then I would have been copying and pasting an already existing answer. \$\endgroup\$
    – pay
    Aug 4 '16 at 17:28
0
\$\begingroup\$

Perl, 24 bytes

print((("*"x10).$/)x10);

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

Javascript (using external library - Enumerable) (41 bytes)

_.From("**********\n").Cycle(120).Write()

Link to lib: https://github.com/mvegh1/Enumerable/

Code explanation: This runs right in the console. Load the string into the library, which parses it to a char array enumerable. Create a new enumerable from that sequence, which is generated by cycling from start to finish 120 times (because the string length is 12, and we want 10 of them..12*10=120). I.e [1,2,3].Cycle(10) would be 1,2,3,1,2,3,1,2,3,1. Finally, join everything into a string with "" as delimiter

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ OH, .length lied to me ahah...I thought it would count "\" and "n" as separate characters..fixed! \$\endgroup\$ Aug 4 '16 at 17:58
  • \$\begingroup\$ Next time use mothereff.in/byte-counter \$\endgroup\$ Aug 5 '16 at 0:01
  • \$\begingroup\$ @PatrickRoberts Got it, thanks! \$\endgroup\$ Aug 5 '16 at 0:07
0
\$\begingroup\$

Ruby, 18 bytes

puts (?**10+$/)*10

Alternative version (+3 bytes)

10.times {puts ?**10}

Ungolfed (first version)

puts ('*' * 10 + '\n') * 10
\$\endgroup\$
1
0
\$\begingroup\$

Swift 2, 45 Bytes

func a(){for _ in 0...9{print("**********")}}
\$\endgroup\$
0
\$\begingroup\$

Wolfram, 22 bytes

Grid[Table["*",10,10]]
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Welcome to PPCG! I can't test right now, but I don't think this is a full program (it only displays correctly when used in Mathematica's notebook front end, which constitutes a snippet by this community's standards). If you put this in a source file and call it with wolfram -script file.m I don't think it'll print anything. I think the shortest way to get around that would be Print@@@Table["*",10,10]. Still, nice solution! :) \$\endgroup\$ Aug 4 '16 at 20:11
  • \$\begingroup\$ You are correct. Also, your solution works and is 24 bytes long. \$\endgroup\$ Aug 4 '16 at 20:29
0
\$\begingroup\$

R

matrix(rep("*",100), nrow = 10)

Probably faster way in R, but fun utilization of matrix

Explanation

rep: repeats first argument as many times as second argument.

matrix: creates matrix from vector (first argument), and nrow is the number rows desired in matrix.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Hi, and welcome to PPCG! However, we require all code to be golfed, which this isn't. Please golf it. \$\endgroup\$ Aug 5 '16 at 0:07
  • 1
    \$\begingroup\$ To make it print the actual desired output you would need to loop cat over it, one way or another. In addition, because of vector recycling, matrix("*",nr=10,nc=10) or array("*",c(10,10)) would be more concise to get the same matrix as the one you generate. \$\endgroup\$
    – plannapus
    Aug 5 '16 at 7:12
  • \$\begingroup\$ You are right in all regards. This works :for(i in 1:10){for (j in 1:10){cat("*");if(j == 10){cat("\n")}}} \$\endgroup\$
    – cgage1
    Aug 5 '16 at 16:54
0
\$\begingroup\$

Javascript, 45 bytes

for(i=0;i<10;i++) {console.log('**********')}

even better, ES6 Javascript, 38 bytes

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

open console and copy paste to test

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

Python 3 (22 bytes)

print(('*'*10+'\n')*10)
\$\endgroup\$
1
  • \$\begingroup\$ 23 bytes - I believe '\n' is two bytes of code, but if you measured with len it will have said 22. \$\endgroup\$ Aug 7 '16 at 6:16
0
\$\begingroup\$

Japt, 10 bytes

'*pA +R pA

Prints * ten times, then \n, then repeat from the beginning ten times.

Demo.

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

Arcyóu, 21 bytes

(* "**********\n" 10)

Try it online!

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

Gema, 31 characters

\A=@repeat{10;**********\n}@end

Sample run:

bash-4.3$ gema '\A=@repeat{10;**********\n}@end'
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
2
  • \$\begingroup\$ Can you provide a link to anywhere? \$\endgroup\$
    – Leaky Nun
    Aug 5 '16 at 11:01
  • \$\begingroup\$ Linkified the title, but I know about no on-line interpreter. :( \$\endgroup\$
    – manatwork
    Aug 5 '16 at 11:06
0
\$\begingroup\$

Groovy, 23 characters

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

Sample run:

bash-4.3$ groovy -e 'print(("*"*10+"\n")*10)'
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
0
0
\$\begingroup\$

Lua, 30 bytes

Full program outputting via its return value.

return("**********\n"):rep(10)
\$\endgroup\$
8
  • \$\begingroup\$ I'm afraid this is not a full program, just a snippet. It produces no output by its own, relies on Lua REPL's functionality. \$\endgroup\$
    – manatwork
    Aug 5 '16 at 12:11
  • 1
    \$\begingroup\$ @manatwork it is a full program, and is also outputting by itself. All lua program are encapsulated in function inside the VM, thus they can all return a value and it is a legit way of outputing \$\endgroup\$
    – Katenkyo
    Aug 6 '16 at 0:35
  • \$\begingroup\$ @manatwork Oh also, you just have to read this to know it's legit. \$\endgroup\$
    – Katenkyo
    Aug 6 '16 at 8:11
  • \$\begingroup\$ Are you referring to the “... if and only if the challenge requires an integer as output, obviously.” part? \$\endgroup\$
    – manatwork
    Aug 6 '16 at 9:05
  • \$\begingroup\$ @manatwork this part only refer to the case you use an exit code, because an exit code is always an integer. I was refering to "If functions can output using their return values, it makes sense that programs should be able to do the same", which is what I've done: using the return value of my program \$\endgroup\$
    – Katenkyo
    Aug 6 '16 at 10:28
0
\$\begingroup\$

Bc, 26 characters

for(;i++<10;)"**********
"

Sample run:

bash-4.3$ bc <<< 'for(;i++<10;)"**********
"'
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
0
\$\begingroup\$

JavaScript (115 106 81 chars)

o='';
for(i=0;i<10;i++){l='';for(j=0;j<10;j++){l+='*';}o+=l+"\n";}
console.log(o);

\$\endgroup\$
1
  • \$\begingroup\$ make the program all one line, instead of using "\n", just use a literal newline by hitting enter inside two empty quotes. that should save you 4 bytes. Also, do you need a semicolon after `l+='*'? \$\endgroup\$ Aug 8 '16 at 1:38
1
9
10
11 12 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.