86
\$\begingroup\$

Background

This is a standard textbook example to demonstrate for loops.

This is one of the first programs I learned 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.

Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

/* Configuration */

var QUESTION_ID = 88653; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });  
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];
  
  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });
    
    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });
    
  });
  
  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;
    
    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/<a/.test(lang)) lang = jQuery(lang).text();
    
    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.lang > b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}
body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">

    </tbody>
  </table>
</div>
<div id="language-list">
  <h2>Winners by Language</h2>
  <table class="language-list">
    <thead>
      <tr><td>Language</td><td>User</td><td>Score</td></tr>
    </thead>
    <tbody id="languages">

    </tbody>
  </table>
</div>
<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>

\$\endgroup\$
  • 2
    \$\begingroup\$ @DylanMeeus "You are to print this exact text:" \$\endgroup\$ – Leaky Nun Aug 4 '16 at 12:56
  • 13
    \$\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
  • 6
    \$\begingroup\$ @LeakyNun Leaderboard snippet please! \$\endgroup\$ – dkudriavtsev Aug 4 '16 at 22:08
  • 2
    \$\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

278 Answers 278

1
6 7
8
9 10
0
\$\begingroup\$

Prolog (SWIPl), 64 / 69 bytes (depending on how to count)

-1*_.
A*0:-writeln(*),C is A-1,C*9.
A*B:-write(*),C is B-1, A*C.

Query with

9*9.

Online Example

Try it online, but take note that since writeln/1 has a bug in Swish, causing it to print a new line before as well as after. I've replaced it with write/1,nl/0 which should be (according to documentation) its equivalent. This raised the byte count of the example.

On the Byte Count

I'm not sure how to count the query, but if it is to be counted towards the total byte count, it's 5 bytes (including an Enter).

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

D2, 11 bytes

!7;//.|a:|a

Explanation:

!7 is expanded to 7 +, so it set the current cell to 7.
; switch to the second shift state (7 is *) /code|digit repeat code digit times (digit is base 36).
. print the character in the current shift state (so here, * is printed).
: print a newline in shift mode 2.

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

Stuck, 10 Bytes

Very simple implementation here, no tricks ;)

'*10*N+10*

Explanation:

'*           # Enter char mode, puts '*' on the stack
  10*        # Multiply string by 10, puts '**********' on the stack
     N+      # Push a newline to the stack and append to the asterisks
       10*   # Multiply that string by 10 and implicitly print.
\$\endgroup\$
0
\$\begingroup\$

memes, 17 bytes

d5+5’{p

Needs ********** as input, therefore +10.

d      Don't print result
5+5    10 times
’      loop
{p     Print input
\$\endgroup\$
0
\$\begingroup\$

Bash + coreutils + X11 term - 7 keystrokes

Exact keys to hit:

  • <Alt>+1
  • 0
  • 0
  • * (<Shift>+8)
  • <Return>

Requirements:

  • Your terminal window must be exactly 10 characters wide.
  • Your terminal prompt (PS1) should be empty.
  • Your working dir must be empty.
\$\endgroup\$
  • \$\begingroup\$ We count submissions like this in keystrokes, not bytes. So this would be 2 more keystrokes because of alt and shift. \$\endgroup\$ – Rɪᴋᴇʀ Dec 27 '16 at 16:04
0
\$\begingroup\$

8th, 28 bytes

( "*" 10 s:* . cr ) 10 times
\$\endgroup\$
0
\$\begingroup\$

Scala, 23 bytes

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

Almost the same as python solution.

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

C++ 83 bytes 82 Thanks to matthew roh!

#include <iostream>
int main(){for(int i;i++<10;){std::cout<<"**********"<<"\n";}}

Try Me Online!

\$\endgroup\$
  • \$\begingroup\$ Maybe i++<10 would help? \$\endgroup\$ – Matthew Roh Feb 6 '17 at 7:06
  • \$\begingroup\$ Unfortunately It seems to returns an invalid syntax error :\ \$\endgroup\$ – GCaldL Feb 9 '17 at 1:57
  • \$\begingroup\$ Hm? It works for me. \$\endgroup\$ – Matthew Roh Feb 9 '17 at 7:27
  • \$\begingroup\$ Amateur Mistake... As the last argument in a for statement I didn't expect ; was required etc. for(int i;i<10;i++) returns an error expected ')' before ';' when written as for(int i;i<10;i++;) \$\endgroup\$ – GCaldL Feb 9 '17 at 23:29
0
\$\begingroup\$

Perl, 22 bytes

print"**********\n"x10
\$\endgroup\$
0
\$\begingroup\$

QC 41 bytes

&FF002A2A2A2A2A2A2A2A2A2A0D0AFF##########

&FF00 Write hex to memory at address 00 until FF is reached
2A2A2A2A2A2A2A2A2A2A0D0AFF 10 asterisks with a new line and the terminator at the end
########## Print contents of memory 10 times until first 00 is reached

Could be made shorter if loops were used.

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

Z80 TI-83+, 53 bytes

.nolist
#include "ti83plus.inc"
#define    ProgStart    $9D95

.list
.org    ProgStart - 2
    .db    t2ByteTok, tAsmCmp
    bcall(_homeup)
    ld A, 0
    ld (PenCol), A
Do:
    inc A
    ld hl, msg
    bcall(_PutS)
    bcall(_NewLine)
    cp 10
    jr NZ, Do
    ret
msg:
    .db "**********", 0
.end
.end

Compiled with SPASM.

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

Sinclair ZX81/Timex TS1000/1500

Simple enough I think

Method 1, 55 bytes (listing):

 1 LET A=0
 2 PRINT "**********"
 3 LET A=A+1
 4 GOTO 2+((A=9)*3)

Method 2, 30 bytes (listing)

 1 FOR I=0 TO 9
 2 PRINT "**********"
 3 NEXT I
\$\endgroup\$
  • \$\begingroup\$ The ZX81 has a 1-byte ** (which is shift and H); this will save 5 bytes from each listing and might even be a bit quicker. ** is used for to the power of. \$\endgroup\$ – Shaun Bebbers Feb 17 '17 at 12:29
0
\$\begingroup\$

Japt, 9 bytes

Ao@'*pA÷

Try it online!

Non-competitive solutions using the new flag features in Japt:

-R flag.

-x flag.

-Sx flags.

-P flag.

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

Cardinal, 41 bytes

%++=tt*=>"*******" v
        ^~?-~,"***"<

Try it online!

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

Syms, 24 bytes

{*}10;*[[[[[[[[[{~>[)}[)

The interpreter as provided errors immediately, but changing line 2 to if True: fixes it. (Is this allowed? Seems like it.)

Explanation:

{*}10;*[[[[[[[[[{~>[)}[)
{*}                       Add '*' to the stack.
   10;*                   Repeat it 10 times.
       [[[[[[[[[          Duplicate 9 times (there are now 10 copies on the stack)
                {~>[)}    Swap, output, duplicate, run (prints element below tos (top of stack) and then executes tos, stack is now (copies, this))
                      [)  Duplicate and run (causes infinite loop, exits when '*'*10 copies run out)
\$\endgroup\$
0
\$\begingroup\$

Python 3 (35 bytes)

for x in range(1,11):print("*"*10)
\$\endgroup\$
  • \$\begingroup\$ range(10) works. \$\endgroup\$ – CalculatorFeline Mar 2 '17 at 22:13
0
\$\begingroup\$

RProgN 2, 8 bytes, Noncompeting

Noncompeting because Language Postdates challenge

°{°`**}*

I decided to take another stab at this, with a much better version of RProgN.

Explained

°{°`**}*
°      *    # Run the contained function Ten (Which ° is a constant for) times.
 {°  *}     # Repeat the referenced string 10 times.
   `*       # Asterisk Literal.
            # This results in 10 strings of 10 `*`s on the stack, which prints as expected.

Try it online!

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

Fourier, 22 bytes

10(10(~X42aX^~X)aN^~N)

Try it on FourIDE!

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

OCTAVE, 36 bytes

strrep(num2str(ones(10,10)),"1","*")

Makes a 10 by 10 matrix of ones, converts these to strings and then changes the ones to *'s.

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

OIL, 55 44 41 bytes, noncompeting

Annotated here for better understanding; remove everything after each ‌# in each line to make it work.

**********# asterisk storage
10#if what's in
14#line 14 (marked with $)
1#is identical to 10 (line 1)
13#jump to line 13 (marked with &)
6#else to line 6; the next line
4#print what's in line 0; 10 asterisks

11#print a newline
8#increment line 14 (marked with $)
14
6#jump to the beginning (line '' == line 0)

3#exit &
0#counter $
\$\endgroup\$
0
\$\begingroup\$

05AB1E, 7 bytes

'*т×Tô»

Try it online!

An alternate solution to the 05AB1E one already provided.

Explanation:

'*т×Tô» 
'*      Push an asterisk
  т×    Repeat the asterisk 100 times: "***********..."
    Tô  Split it into pieces of 10.
      » Join with newlines.
        Implicit print.
\$\endgroup\$
0
\$\begingroup\$

Syms 1.4, 12 bytes (noncompeting)

$
$*10*+10*>

Try it online!

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

C#, 96 bytes

static class P{static void Main(){for(int i=1;i<11;i++)System.Console.WriteLine("**********");}}

Try it online

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to PPCG! Firstly, you should specify the language and byte count; secondly, this isn't a full program or function, so doesn't meet the standard requirements; thirdly, you can save a bunch of bytes by removing unnecessary whitespace and changing the comparison symbol, like so: for(int i=1;i<11;i++)Console.WriteLine("**********\n"); \$\endgroup\$ – F1Krazy Jun 9 '17 at 7:54
  • \$\begingroup\$ If this is C#, read this post to learn what your answer should be like. Also, have a look at the other answers to see what the standard format is (header with language name and bytecount, then code...). \$\endgroup\$ – Dada Jun 9 '17 at 8:15
0
\$\begingroup\$

Micro, 15 bytes

"*"10*10c+10*:/
\$\endgroup\$
  • \$\begingroup\$ incidentally, the ascii code for newline is 10, so: 10c \$\endgroup\$ – raddish0 Jun 9 '17 at 12:34
0
\$\begingroup\$

Check, 15 bytes

Non-competing as language postdates the challenge

"*">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\$
  • \$\begingroup\$ Forgot to do that, sorry. \$\endgroup\$ – Esolanging Fruit Jun 15 '17 at 1:12
0
\$\begingroup\$

k, 12 bytes

`0:10 10#"*"

Try it online.

Explanation:

   10 10#"*" /make 10 by 10 matrix of asterisk characters
`0:          /output each row as a line
\$\endgroup\$
0
\$\begingroup\$

q/kdb+, 19 13 bytes

Solution:

-1(2#10)#"*";

Example:

q)-1(2#10)#"*";
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********

Explanation:

-1(2#10)#"*"; / solution
         "*"  / the asterisk
        #     / take or reshape
  (2#10)      / list (10;10), 10 rows, 10 columns
-1           ; / print to stdout
\$\endgroup\$
0
\$\begingroup\$

Pyth, 6 bytes

Bet there's going to be a shorter Charcoal answer

VT*T"*

Explanation:

VT     Ten times
 *T"*  Output ten asterisks followed by a newline

Try it online!

\$\endgroup\$
  • \$\begingroup\$ ---nope :|--- yep \$\endgroup\$ – ASCII-only Sep 7 '17 at 1:55
  • \$\begingroup\$ @ASCII-only why am i alive \$\endgroup\$ – Stan Strum Sep 7 '17 at 2:11
0
\$\begingroup\$

4, 56 bytes

4, 5, 6!

3.600426011060310604018016021080250010202049503101010494

Try it online!

For explanation see verbose mode in the tio link - quite straightforward initialization of cells and nested 10x10 loop.

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

Crystal, 21 bytes

puts ("*"*10+"\n")*10
How does it work?
"*" * 10            = "**********" 
"**********" + "\n" = "**********\n"
"**********\n" * 10 = "**********\n**********\n[...]"
\$\endgroup\$
1
6 7
8
9 10

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.