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

311 Answers 311

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

ORK, 185 bytes

When this program starts:
I have a scribe called W
W is to write "**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********"

Try it online!

ORK does everything (even I/O and basic math) with objects. As far as this question goes, looping does not have to be one of them.

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

ESOPUNK, 167 78 77 bytes

MARK L
@REP 10
COPY 42 #STDO
@END
COPY 10 #STDO
TEST X = 9
ADDI X 1 X
FJMP L

I haven't been bothered to implement the preprocessor, but this should work when I do.

\$\endgroup\$
  • \$\begingroup\$ would it be possible to do an inner repetition? i.e. @REP 10 / @REP 10 / COPY 42 #STDO / @END / COPY 10 #STDO / @END \$\endgroup\$ – ETHproductions Sep 28 '18 at 17:55
  • \$\begingroup\$ (also, does this language exist online anywhere?) \$\endgroup\$ – ETHproductions Sep 28 '18 at 17:56
  • \$\begingroup\$ @ETHproductions Nesting @rep is explicitly not allowed in the game's docs. Link added in header. \$\endgroup\$ – SIGSTACKFAULT Sep 28 '18 at 18:34
0
\$\begingroup\$

Julia 1.0, 23 bytes

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

Try it online!

\$\endgroup\$
  • \$\begingroup\$ You can change the \n for a literal newline \$\endgroup\$ – H.PWiz Dec 23 '18 at 13:54
0
\$\begingroup\$

A0A0, 145 bytes

A0A0
A0C3G1G1G1G1G1G1G1G1G1G1G1A0
A0P42P42P42P42P42P42P42P42P42P42G3P10A0
A0A1G-3G-3G-3G-3G-3G-3G-3G-3G-3G-3G-3A0
G-3
G-2G-2G-2G-2G-2G-2G-2G-2G-2

The top five lines are for the loop construction. A0A0 deletes instructions whenever it runs them, so those lines ensure that the loop keeps running. On line 3 are ten P42 instructions which print * (42 is the ascii code for an asterisk). The P10 instruction prints a new line.

The bottom line acts as a counter. For every execution of the loop it jumps to there and then jumps back to the loop. This consumes an instruction on that line. There are exactly nine instructions, so when it tries to go there when it has already printed ten lines the program will halt execution (since an empty line swill stop execution in A0A0).

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

Pascal (FPC), 57 bytes

var i:word;begin for i:=0to 9do writeln('**********')end.

Try it online!

This is probably the best one as I don't see how this can be improved in 9 characters or less which could be gained by removing *s.

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

Assembly (NASM, 32-bit, Linux), 122 bytes

mov ecx,10
n:push 0xa202a2a
push '****'
push '****'
loop n
mov edx,120
mov ecx,esp
mov ebx,1
mov eax,4
int 128
add esp,120

Try it Online!

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

Brian & Chuck, 23 bytes

*{-?
{..........>-.+?

Try it online!

The is the ascii code 11.

Brian:
*      "*" 11
  {-    Restart Chuck's code and subtract 1
    ?   Go to Chuck's code while the first byte is not 0

Chuck:
                    11 (This will be decremented by 1 each line)
  {                  Restart Brian's code
   ..........        Print the "*" 10 times
             >-.+    Print the newline
                 ?   Go back to Brian's code
\$\endgroup\$
0
\$\begingroup\$

C (gcc), 38 bytes

n=9;f(){puts("**********");n&&f(--n);}

Try it online!

And another 38 bytes

n;f(){++n+1<puts("**********")&&f(n);}

Try it online!

\$\endgroup\$
  • 2
    \$\begingroup\$ This prints a 10*n grid of asterisks. Taking extra input (the 10 in this case) is not allowed \$\endgroup\$ – pppery 2 days ago
  • \$\begingroup\$ @ppery fixed it, thank you so much \$\endgroup\$ – Davide 2 days ago
  • \$\begingroup\$ Nope, your answer is now a non-reusable function, so still not allowed. \$\endgroup\$ – pppery 2 days ago
  • \$\begingroup\$ Omg I am learning a lot from you! I will fix even this one \$\endgroup\$ – Davide 2 days ago
  • \$\begingroup\$ @ppery resetting the global variable at the end of the function requires too much unnecessary code and I just want you to notice that this so upvoted answer codegolf.stackexchange.com/a/88695/100356 doesn't reset anything either, it requires a new run for every 10x10 block. And most probably the same thing happens in most codes here and in any codegolf question. I don't see any reason why we should use double standards. \$\endgroup\$ – Davide yesterday
0
\$\begingroup\$

Zsh -F, 19 bytes

yes **********|head

Try it online!

Edit: just saw this exact answer was already posted for bash :(

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

Java 11, 48 chars

Method String.repeat​(int)

for(int i=0;i++<10;out.println("*".repeat(10)));

Try it online!


Java 5, 53 chars

Static imports

for(int i=0;i++<100;out.print("*"+(i%10>0?"":"\n")));

Try it online!


Java 3, 60 chars

Plain old Java

for(int i=0;i++<100;System.out.print("*"+(i%10>0?"":"\n")));

Try it online!

New contributor
lorem.ipsum is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
-3
\$\begingroup\$

HTML, 136 bytes

**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********
\$\endgroup\$
  • 2
    \$\begingroup\$ You can use <pre> \$\endgroup\$ – Leaky Nun Aug 5 '16 at 16:45
  • \$\begingroup\$ I can use <p> too \$\endgroup\$ – Skxrda Aug 5 '16 at 16:46
  • 8
    \$\begingroup\$ This answer is valid and allowed, but it's also extremely boring and unimaginative. \$\endgroup\$ – James Aug 5 '16 at 17:08
  • \$\begingroup\$ Ok, Can I post it in Markdown? \$\endgroup\$ – Skxrda Aug 5 '16 at 17:08
  • 3
    \$\begingroup\$ You can easily get this to 114 bytes with <pre> followed by the 109-byte text... \$\endgroup\$ – Timtech Aug 27 '16 at 21:43
1
7 8 9 10
11

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.