83
\$\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.

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

270 Answers 270

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

Lua, 30 bytes

Full program outputting via its return value.

return("**********\n"):rep(10)
\$\endgroup\$
  • \$\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\$
  • \$\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\$ – Bald Bantha Aug 8 '16 at 1:38
0
\$\begingroup\$

ListSharp, 73 bytes

[FOREACH NUMB IN 1 TO 10 AS k]
{
STRG p=p+"**********"+<newline>
}
SHOW=p
\$\endgroup\$
0
\$\begingroup\$

3var, 27 26 bytes

1 byte thanks to Business Cat

iisiia+<*>aaaF[PPPPPPPPPPO]
aaamaiis*>iiF[PPPPPPPPPPO]

I don't how do nested loops marked by F.

Try it online!

\$\endgroup\$
  • \$\begingroup\$ 26 bytes aaamaiis*>iiF[PPPPPPPPPPO] \$\endgroup\$ – Business Cat Aug 5 '16 at 20:12
  • \$\begingroup\$ @BusinessCat Thanks, do you know why this and this produce different results? \$\endgroup\$ – Leaky Nun Aug 6 '16 at 4:05
  • \$\begingroup\$ I don't know. I don't see anything in the docs about needing to put loops on a new line, though they do in their examples. Maybe it's an interpreter error? \$\endgroup\$ – Business Cat Aug 6 '16 at 5:03
0
\$\begingroup\$

Mumps, 26 Bytes.

F J=0:1:9 W "**********",!

As loops are fairly efficient (space-wise) in Mumps, I thought I'd see if the loop within a loop was shorter, but it was not; weighing in at 31 bytes:

F I=0:1:9{F J=0:1:9{W "*"} W !}

The braces are allowable loop delimiters in the InterSystems Cache version of Mumps that I use; at times they may save a byte or two golfing, but mostly they're just handy to have nested loops in a one-line routine.

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

Befunge '98, 31 bytes

a>:|>1++:9`#@_a,
v*'[^
>,v1
-v>
\$\endgroup\$
0
\$\begingroup\$

Factor, 30

10 [ "**********"print ] times

So verbose...

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

MSM, 19 bytes

.;;.;...;.;;.;..␍**

where is a newline.

. concatenates the two rightmost characters and ; appends a copy of the rightmost element to the end, so the first commands .;;.;... create one line **********␍ and the next commands ;.;;.;.. make 10 lines out of it.

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

Oracle SQL 11.2, 44 bytes

SELECT'**********'FROM v$bh WHERE rownum<11;
\$\endgroup\$
0
\$\begingroup\$

Pip, 7 bytes

LtP'*Xt

Straightforward: Loop 10 times. Print string of 10 asterisks each time. Kinda disappointed that the simple way was the shortest...

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

Jade & CSS, 41 36 bytes

- for (x=0;x++<10;)
  **********<br>

Jade is a HTML pre-processor. I'm unsure if using this is breaking any rule or if I have to include something else in the byte count. This also beats my previous entry of 60 bytes.

See it on Codepen: http://codepen.io/409/pen/ZOPgdJ

Thanks to Business Cat for saving 5 bytes.

\$\endgroup\$
  • \$\begingroup\$ You can save 1 byte by doing x++<11; instead of x<11;x++. I think you can also omit the var. Also this makes a 10x11 grid, you need to change the 11 to 10. \$\endgroup\$ – Business Cat Aug 18 '16 at 12:45
  • \$\begingroup\$ Hey, thanks for the improvements @BusinessCat \$\endgroup\$ – ʰᵈˑ Aug 18 '16 at 13:10
0
\$\begingroup\$

Lua, 29 Bytes. Non-competing

(("*"):rep(10).."\n"):rep(10)

Forgot to make this print, and with print, it's identical to another answer. So I'm not competing, instead of trying to think up an entirely new short approach.

\$\endgroup\$
  • \$\begingroup\$ This is snippet which prints nothing. Unless the challenge explicitly specifies, the solutions are expected to be either full program of function which either print or return the result. If you make it print, will be duplicate of Seeseemelk's answer, posted 13 days earlier. \$\endgroup\$ – manatwork Aug 19 '16 at 8:00
  • \$\begingroup\$ Didn't notice the specification to print. Although this is my own work, it does work out to be identical to the other lua answer. Redacting my competing status. \$\endgroup\$ – ATaco Aug 21 '16 at 23:25
0
\$\begingroup\$

Groovy, 23 characters

10.times{println'*'*10}
\$\endgroup\$
  • \$\begingroup\$ Please use code block markup (indent each line with 4 spaces or enclose it between <pre> and </pre> tags) for your code, so scripts like Code Golf UserScript Enhancement Pack can insert the length beside the code. \$\endgroup\$ – manatwork Aug 22 '16 at 7:24
  • \$\begingroup\$ @manatwork Done. I'm new here; had no idea that was a thing. \$\endgroup\$ – M. Justin Aug 22 '16 at 7:26
0
\$\begingroup\$

Stata, 49 bytes

loc i=1
wh `i'<11 {
di "**********"
loc i=`i'+1
}

Output

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

ISOLADOS, 131 bytes

ISOLAADOOOOOOOOOOOS ISOLAAAAAAADOS ISOLAADOOOOOOOOOOS ISOLAAADOOOS ISOLAAAAAAAADOS ISOLAADOOOOOOOOOOS ISOLAAADOOOS ISOLAAAAAAAAADOS

ISOLAADOOOOOOOOOOOS    push 11
ISOLAAAAAAADOS         chr(a + 31)
ISOLAADOOOOOOOOOOS     push 10
ISOLAAADOOOS           push a * b
ISOLAAAAAAAADOS        push [a]
ISOLAADOOOOOOOOOOS     push 10
ISOLAAADOOOS           push a * b
ISOLAAAAAAAAADOS       join list by new lines
\$\endgroup\$
0
\$\begingroup\$

Racket 36 bytes

(for((j 10))(displayln"**********"))
\$\endgroup\$
0
\$\begingroup\$

Groovy 46 Bytes

(1..10).collect{''.center(10,'*')}.join('\n')

https://groovyconsole.appspot.com/script/5102912250314752

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

SX, 21 bytes

和(0,10):我('*'*10)

Actually: this compiles (technically, it just becomes Python) directly to Python. It is the same as:

for i in range(0,10):print('*'*10)

\$\endgroup\$
  • \$\begingroup\$ The SX code is 21 bytes long, and please split your answer in multiple answers for multiple submissions \$\endgroup\$ – TuxCrafting Sep 12 '16 at 8:37
  • \$\begingroup\$ Generally is better to post solutions in different languages in different answers, so they can be upvoted / downvoted separately. For example your Ruby solution is essentially identical with John Ramos's Ruby answer, so that may attract some downvotes. \$\endgroup\$ – manatwork Sep 12 '16 at 8:38
  • \$\begingroup\$ 11 bytes off: print(("*"*10+"\n")*10) \$\endgroup\$ – TuxCrafting Sep 12 '16 at 8:39
  • \$\begingroup\$ @TùxCräftîñg, that would be duplicate of helloworld922's Python 3 answer (or if you make it Python 2, then duplicate of shooqie's answer). \$\endgroup\$ – manatwork Sep 12 '16 at 8:53
  • \$\begingroup\$ I'm so sorry. I didn't even read any of the answers. I just answered. I'll delete my answers for Python and Ruby. \$\endgroup\$ – XiKuuKy Sep 12 '16 at 12:39
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\$

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.