80
\$\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\$
  • \$\begingroup\$ I'm not that familiar with this. The chrome dev tools print repetition on one line. e.g, here it would print (10)********** is that acceptable, as we know it's a dev-tool 'optimisation'? \$\endgroup\$ – Dylan Meeus Aug 4 '16 at 12:37
  • 2
    \$\begingroup\$ @DylanMeeus "You are to print this exact text:" \$\endgroup\$ – Leaky Nun Aug 4 '16 at 12:56
  • 12
    \$\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
  • 1
    \$\begingroup\$ you say trailing new lines are acceptable. Are leading newlines acceptable too? \$\endgroup\$ – Albert Renshaw Feb 10 '17 at 2:34

264 Answers 264

72
\$\begingroup\$

Brainfuck, 47 bytes

++++++++++[->++++>+>+<<<]>++>[-<..........>>.<]

Try it online!

++++++++++[->++++>+>+<<<]   set the tape to 40 10 10
>++>                        set the tape to 42 10 10
[-<..........>>.<]          come on
\$\endgroup\$
  • 48
    \$\begingroup\$ +1 for emoticon in the code >.< \$\endgroup\$ – user48538 Aug 4 '16 at 11:27
  • 24
    \$\begingroup\$ +1 for the fish bones >++> \$\endgroup\$ – Beta Decay Aug 7 '16 at 23:56
68
\$\begingroup\$

C (gcc), 41 39 bytes

main(i){for(;++i<puts("**********"););}
\$\endgroup\$
  • \$\begingroup\$ what version of c? \$\endgroup\$ – Zaibis Aug 4 '16 at 12:51
  • \$\begingroup\$ @Zaibis Works fine on gcc: coliru.stacked-crooked.com/a/848cb22a00c35c29 . \$\endgroup\$ – orlp Aug 4 '16 at 13:28
  • 4
    \$\begingroup\$ looks good, good ol' ANSI C. \$\endgroup\$ – YSC Aug 4 '16 at 13:38
  • 4
    \$\begingroup\$ main(i){while(11-i++)puts("**********");} is an alternative, same length. \$\endgroup\$ – YSC Aug 4 '16 at 13:41
  • 6
    \$\begingroup\$ I like the clever use of the return from puts() (and of the initial value of i). \$\endgroup\$ – Toby Speight Aug 8 '16 at 14:17
65
\$\begingroup\$

Bash + coreutils, 19 bytes

I prefer to repeat stuff in Bash using 'yes'.

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

I saved 2 bytes by @Neil's suggestion. But when the directory where you are running this command does not only contain files starting with a '.' dot you need to enclose the stars * with ".

Bash + coreutils, 21 bytes

yes "**********"|head
\$\endgroup\$
  • 2
    \$\begingroup\$ Great idea to use yes. We usually label such solutions as “Bash + coreutils”. \$\endgroup\$ – manatwork Aug 4 '16 at 14:58
  • 8
    \$\begingroup\$ Nice that 10 lines coincidentally happens to be the default for head. \$\endgroup\$ – Digital Trauma Aug 4 '16 at 15:15
  • 3
    \$\begingroup\$ Can you save two bytes by requiring that any files in the current directory must begin with a .? \$\endgroup\$ – Neil Aug 4 '16 at 18:51
  • \$\begingroup\$ @Neil, is your comment ment for my answer? If so, I do not get it :) \$\endgroup\$ – CousinCocaine Aug 4 '16 at 18:57
  • 1
    \$\begingroup\$ You can also write yes \**********|head without the restriction on files. \$\endgroup\$ – Florian F Aug 10 '16 at 13:51
50
\$\begingroup\$

Vim, 13 8 bytes

Saved 5 bytes thanks to @Lynn

qqi*␛9.o␛q9@q 

10i*␛Y9p

10i*␛ insert 10 times *, and Y9p copy the line and paste it 9 times.

\$\endgroup\$
  • 8
    \$\begingroup\$ 10i*♥Y9p works. \$\endgroup\$ – Lynn Aug 4 '16 at 11:25
  • 1
    \$\begingroup\$ That's insane vi. \$\endgroup\$ – nbubis Aug 7 '16 at 6:53
  • \$\begingroup\$ I think you can count keystrokes instead of bytes for text editors, which means <ESC> would be shorter. \$\endgroup\$ – addison Aug 7 '16 at 14:55
  • 1
    \$\begingroup\$ Why ♥ and not ␛ ? \$\endgroup\$ – CL. Aug 8 '16 at 12:54
  • 1
    \$\begingroup\$ I would have used yy9p myself, but nice job using capitals to save a character! \$\endgroup\$ – Joe Z. Aug 12 '16 at 21:08
49
\$\begingroup\$

Pyth, 6 bytes

VT*T\*

T is 10 in Pyth, Vab executes statement b a times, \* is the asterisk character constant, and multiplying (*) a string and an integer repeats that string n times. Pyth's implicit printing with V means 10 lines are printed.

\$\endgroup\$
40
\$\begingroup\$

Hexagony, 37 35 34 31

10"+}(=${";<$<1}42/.0@_=<>\;>(_

Expanded:

   1 0 " +
  } ( = $ {
 " ; < $ < 1
} 4 2 / . 0 @
 _ = < > \ ;
  > ( _ . .
   . . . .

Try it online

Basically just has two for loops counting down from ten to zero, printing out an asterisk on the inner loop, and a newline on the outer loop.

Explanation:

This program consists of three main parts: initialisation of memory, a loop which prints ten asterisks and a loop which prints a newline. The loop which prints a newline also contains the loop which prints the asterisks.

First, the code runs the totally linear memory initialisation. The code works out to be: 10"+}42. This sets the memory of the nearby edges to look like:

10 \ / 10
    |
   42

42 is the ASCII code for the asterisk character, and the two tens will be used as our loop counters. Of note is that the memory pointer is currently pointing away from the two tens, so moving backwards will put us on one of the tens.

Next, we start the astersisk printing loop. Linearly, the code looks like: ;".._(. This prints out an asterisk, moves the memory pointer backwards and to the left and finally decrements the value there. After one iteration, the memory would look like:

10 \ / 9
    |
   42

Then we hit the loop condition: the bottom-leftmost >. If the edge we just decremented is still positive we bounce around and execute a { to move us back onto the 42. Then we hit a $ and return to the beginning of the printing loop, the ;, by skipping the <. If the value was zero, we head into the other loop.

The outer loop begins by resetting the recently zeroed memory edge to ten (this is the 10 in the code, going southwest). Then, we print out this ten as an ASCII character, which is a newline. Next, we move onto the other memory edge and decrement it with {( and then execute what amounts to a bunch of noops: =${_=. Now, after one iteration of this loop, memory would look like:

 9 \ / 10
    |
   42

This time, the memory is facing outwards from the edge storing a nine in the above diagram. Next we execute the < which acts as the loop condition for the outer loop. If the value was non-zero we bounce around off of some mirrors, then begin executing meaningful instructions again after entering the top of the hexagon at the " moving southwest. This causes us to move backwards and to the left, onto the 42 again, but facing inwards. Then the = flips our direction, resetting the state properly to begin the inner loop again. If the edge was set to zero, the instruction pointer goes on a little adventure which does nothing until it exits the program.

The adventure begins by the instruction pointer venturing northeast, perilously disregarding the safety of the cardinal directions. It bravely ignores a mirror that is aligned with its diretion (/) and heroically leaps off of a trampoline ($) entirely evading the deadly trap of another, totally identical trampoline. Staring out at the emptiness of uninitialised hexagon edges, the pointer, without faltering for a moment, adds the two blank edges it faces together, setting the current edge to their sum: 0 (the edge was actually zero beforehand, but the pointer likes to believe this was pretty important). Since the edge is zero, the pointer makes a left turn at the fork in the road, walking into a mysterious forest (of hexagons). There, it finds itself disoriented, moving forwards and backwards and forwards, until it winds up at the same place in memory as it started. Thinking that the problem must be that the current edge was set to zero last time, the pointer bravely plants a 1 into the current edge. Then, the noble pointer investigates another path, one laid with... a trap! The current edge is decremented and set back to zero! The pointer, dazed by the shocking turn of events, stumbles back into the trap setting the current edge to negative one. Infuriated, the pointer attempts to return to the comparatively pleasant forest, only to notice that since the current edge is not positive, the paths have yet again shifted and the pointer finds itself walking into a cave. And by a cave, I mean the mouth of a giant hexagonal worm. Helpless, the pointer curses the sexinity with its dying breath. Also, the program ends.

\$\endgroup\$
  • \$\begingroup\$ Golly, I hope the worm was OK with swallowing a pointer. Those things can hurt. \$\endgroup\$ – Joffan Aug 8 '16 at 4:01
  • 3
    \$\begingroup\$ +1 for writing the most interesting—the only—Hexagony explanation I've ever read. I felt so tense when the edge was decremented! \$\endgroup\$ – Joe Aug 28 '16 at 0:07
37
\$\begingroup\$

Emacs, 10 8 keystrokes

F3 C-1 0 * ENTER F4 C-9 F4

Explanation

F3             Starts a macro recording
C-1 0 *        Apply 10 times command '*': prints 10 asterix'
ENTER          Insert new line
F4             Stops the macro record
C-9 F4         Apply 9 times the macro

Thanks to Sean for saving two keystrokes, suggesting to replace C-udigit with C-digit.

\$\endgroup\$
  • 9
    \$\begingroup\$ +1, I always upvote text editor answers (even though I'm more of a vim guy myself) :) \$\endgroup\$ – DJMcMayhem Aug 4 '16 at 15:10
  • 1
    \$\begingroup\$ If C-u counts as just one keystroke, then you can shave off two strokes by typing C-1 C-0 (or M-1 M-0) instead of C-u 1 0 and C-9 instead of C-u 9. \$\endgroup\$ – Sean Aug 5 '16 at 14:45
  • 15
    \$\begingroup\$ +1 because you had to suffer through using emacs to write this. \$\endgroup\$ – addison Aug 7 '16 at 14:54
  • 1
    \$\begingroup\$ Alternatively (saves nothing) the line repetition can be done inside the macro: F3 C-1 0 * ENTER C-1 0 F4 \$\endgroup\$ – Jonathan Carroll Aug 9 '16 at 5:14
  • \$\begingroup\$ @JonathanCarroll yes it would save bytes if we were to print more than 10 lines ;) \$\endgroup\$ – YSC Aug 9 '16 at 8:28
29
\$\begingroup\$

Jelly, 7 bytes

”*x⁵Ṅ9¡

What's going on?

”*x⁵Ṅ9¡  - No arguments
”*       - character literal, *
  x      - multiply (dyadic operation)
   ⁵     - integer literal, 10 (we have now constructed the string '**********')
    Ṅ    - Print & linefeed (monadic operation)
     9   - integer literal, 9
      ¡  - Repeat n times (n is 9 as the first Ṅ is not a repeat)

Test it on tryitonline

\$\endgroup\$
  • 9
    \$\begingroup\$ I really like the Ṅ9¡. \$\endgroup\$ – Dennis Aug 7 '16 at 20:16
  • \$\begingroup\$ List version: ”*ẋ⁵Wẋ⁵. \$\endgroup\$ – Erik the Outgolfer Oct 1 '16 at 14:51
  • \$\begingroup\$ @EriktheGolfer you'd need a Y on the end to "print this exact text" \$\endgroup\$ – Jonathan Allan Oct 1 '16 at 14:54
  • \$\begingroup\$ @JonathanAllan It is a list on its own, though. It isn't meant to "print this exact text", but, if you want to work on it, you'll use it. \$\endgroup\$ – Erik the Outgolfer Oct 1 '16 at 14:55
26
\$\begingroup\$

PowerShell, 14 12 bytes

,('*'*10)*10

Constructs a string of asterisks of length 10 using string multiplication. Encapsulates that in parens and feeds that into the comma-operator to construct an array. We use array multiplication to construct a 10-element array consisting of that element (i.e., a 10-element array of asterisk strings). That's left on the pipeline, and output is implicit (since the default Write-Output for an array is newline-separated, we get that for free -- thanks to @Joey for the clarification).

Older, 14 bytes

0..9|%{'*'*10}

Full program. Loops from 0 to 9 through a ForEach-Object loop |%{...}. Each iteration, we use string multiplication to create a length-10 string of *. Those resulting strings are left on the pipeline, and output at the end is implicit (since the default Write-Output for an array is newline-separated, we get that for free -- thanks to @Joey for the clarification).

\$\endgroup\$
  • 5
    \$\begingroup\$ I like it, because powershell can get so verbose. Yet this is elegant and short. \$\endgroup\$ – dwana Aug 4 '16 at 13:25
  • \$\begingroup\$ Well, technically the array is never passed through a ToString, it's unrolled and passed element by element to Write-Output. In contexts where the array is converted to a string, you get its elements space-separated. \$\endgroup\$ – Joey Aug 9 '16 at 14:46
  • \$\begingroup\$ @Joey Ah, fair, that's a better way to put it. I'll edit the wording (and my answer template ;-)). \$\endgroup\$ – AdmBorkBork Aug 9 '16 at 14:58
  • 1
    \$\begingroup\$ I may be biased here because I'm involved with a PowerShell implementation so I had to learn a lot of what actually goes on inside the interpreter ;) \$\endgroup\$ – Joey Aug 9 '16 at 15:00
24
\$\begingroup\$

V, 7 bytes

10é*10Ä

Try it online!

About as straightforward as an answer can be.

Explanation:

10      "10 times:
  é*    "insert an asterisk
    10Ä "make 10 copies of the current line

Non-competing version (5 bytes):

10O±*

Explanation:

10O     " Insert the following on the next ten lines:
   ±    "   10 copies of
    *   "   an asterisk

This didn't work when the challenge was posted because of a bug.

\$\endgroup\$
  • \$\begingroup\$ Point of order: é and Ä are multibyte characters (at least in utf-8, as you have them here) so this program is 9 bytes long. \$\endgroup\$ – rob Aug 4 '16 at 19:35
  • 6
    \$\begingroup\$ @rob They are encoded in utf-8 here, because that's just the way the browser works. V uses "Latin1" encoding, where they are E9 and C4 respectively. \$\endgroup\$ – DJMcMayhem Aug 4 '16 at 19:41
21
\$\begingroup\$

Jellyfish, 12 10 bytes

Thanks to Zgarb for saving 2 bytes.

P$'*
 &;10

Try it online!

Explanation

Using more conventional notation, this program represents the following expression:

P( $( &;(10), '* ) )

&; takes a single value and creates a pair with two times that value, so &;(10) gives us [10 10]. Then $ is reshape which forms a 10x10 grid of asterisks. Finally, P prints the array in "matrix format" which prints each string on its own line.

\$\endgroup\$
20
\$\begingroup\$

HTML & CSS, 104 60 bytes

p::after{content:"**********"
<p><p><p><p><p><p><p><p><p><p>

I'm unsure if the byte count is correct (as I'm not counting the <style> tags for CSS. The HTML could also be shortened if I used a HTML preprocessor, but I'm unsure if that's breaking rules

Thanks to manatwork and Business Cat.

See my Jade entry of 36 bytes

\$\endgroup\$
  • \$\begingroup\$ You can leave out the self closing /s and write all tags in the same line. But better change the tags to <p> as it is shorter even if you need to add p{margin:0}. \$\endgroup\$ – manatwork Aug 5 '16 at 13:28
  • 2
    \$\begingroup\$ This is not valid css. You need the closing bracket! \$\endgroup\$ – Richard Hamilton Aug 5 '16 at 16:37
  • 25
    \$\begingroup\$ @RichardHamilton valid css and working css are not the same thing \$\endgroup\$ – undergroundmonorail Aug 7 '16 at 8:51
  • 1
    \$\begingroup\$ @ClementNerma Why should anyone put code after this? \$\endgroup\$ – Erik the Outgolfer Sep 13 '16 at 12:47
  • 2
    \$\begingroup\$ you can leave off the last > I believe \$\endgroup\$ – 12Me21 Feb 6 '17 at 14:47
16
\$\begingroup\$

Python 2, 22 21 bytes

print('*'*10+'\n')*10
\$\endgroup\$
  • \$\begingroup\$ print(("*"*10+'\n')*10) worked for me. \$\endgroup\$ – piepi Aug 7 '16 at 3:31
  • 6
    \$\begingroup\$ @piepi That's why you're usually better off golfing in Python 2 - you don't need parentheses when calling print. \$\endgroup\$ – shooqie Aug 7 '16 at 7:41
16
\$\begingroup\$

MATLAB, 14 bytes

repmat('*',10)
\$\endgroup\$
  • \$\begingroup\$ I don't have MATLAB to test this, so I'm unsure if this has spaces between the *s. \$\endgroup\$ – Erik the Outgolfer Oct 1 '16 at 15:59
  • \$\begingroup\$ @EriktheGolfer clearly not :) \$\endgroup\$ – PieCot Oct 1 '16 at 19:41
  • \$\begingroup\$ mat suggests a matrix, that's why I asked. \$\endgroup\$ – Erik the Outgolfer Oct 2 '16 at 6:23
  • 2
    \$\begingroup\$ @EriktheGolfer excuse me, I was rude. Mat, in fact, refers to a matrix, but in this case is a matrix of char, that is an array of strings (every row is like a string). So, the outupt matrix is printed one row for line, without spaces between elements of the same row. \$\endgroup\$ – PieCot Oct 2 '16 at 15:07
16
\$\begingroup\$

APL, 9 bytes

Works on all APLs ever made.

10 10⍴'*'

10 10 ten rows and ten column

 cyclically repeating

'*' a star

TryAPL online!

\$\endgroup\$
  • \$\begingroup\$ It's worth noting that this solution is not Dyalog-specific; it also works with GNU APL. \$\endgroup\$ – Arc676 Jun 15 '17 at 1:20
  • 3
    \$\begingroup\$ @Arc676 True. In fact, it works on all APLs ever made. \$\endgroup\$ – Adám Jun 15 '17 at 1:26
  • \$\begingroup\$ argh, I need just one more byte... I almost beat you with the "format" trick: ∘.⊢⍨⍕⍨,⍨5 \$\endgroup\$ – ngn Feb 6 '18 at 7:50
  • \$\begingroup\$ @ngn That's wonderfully horrible! \$\endgroup\$ – Adám Feb 6 '18 at 8:59
14
\$\begingroup\$

Java 7, 63 bytes

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

Just for kicks. I can't seem to find any tricks to make this shorter. Trying to add logic for a 100-loop or returning a String instead of printing just ends up worse.

\$\endgroup\$
  • 1
    \$\begingroup\$ You can shave it off by one byte if you declare i as a class variable (it defaults to 0): int i;void f(){for(;i++<10;)System.out.println("**********");} \$\endgroup\$ – shooqie Aug 4 '16 at 9:51
  • 1
    \$\begingroup\$ That would break reusability unless I did i=0 somewhere in the function, negating the savings. \$\endgroup\$ – Geobits Aug 4 '16 at 9:54
  • 3
    \$\begingroup\$ +1 Seems you're indeed right that this is the shortest.. Recursive is 65 bytes: int i=10;void f(){System.out.println("**********");if(i-->0)g();}; One by one recursive is 67 bytes: int i=99;void f(){System.out.print(i%10<1?"*\n":"*");if(i-->0)g();}; Using String-constructor with char-array is 82 bytes: void g(){System.out.print(new String(new char[10]).replace("\0","**********\n"));}; and a String.format is 81 bytes: void g(){System.out.print(String.format("%010d",0).replace("0","**********\n"));}. Ah well, we tried. ;) \$\endgroup\$ – Kevin Cruijssen Aug 4 '16 at 11:10
  • 2
    \$\begingroup\$ But does it count without having to add the class declaration itself? What is the shortest java7 full program that can do this? \$\endgroup\$ – jsbueno Aug 4 '16 at 12:54
  • 1
    \$\begingroup\$ You have to count the import statement, so it wouldn't work for savings here. \$\endgroup\$ – Geobits Aug 7 '16 at 19:09
14
\$\begingroup\$

Ruby, 15 characters

puts [?**10]*10

Sample run:

bash-4.3$ ruby -e 'puts [?**10]*10'
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
  • \$\begingroup\$ Can you explain ?**10? It does indeed create a string of ten asterisks, but I'm unclear how... \$\endgroup\$ – erich2k8 Aug 9 '16 at 0:05
  • 3
    \$\begingroup\$ The ? is the character literal notation, so ?* == '*'. The 2nd * is the String.* method, so ?**10 == '*'.*(10). \$\endgroup\$ – manatwork Aug 9 '16 at 7:26
  • \$\begingroup\$ Afraid I still don't understand why ? is the literal notation of anything, but perhaps some questions are better left unanswered. ;) \$\endgroup\$ – erich2k8 Aug 10 '16 at 9:09
  • \$\begingroup\$ Sorry, I can't find any reference on this. Is simply the Ruby syntax, which allows various string literal notations plus one in case the string is 1 character long: a ? mark followed by the character, without requiring a closing pair of the ? mark. \$\endgroup\$ – manatwork Aug 10 '16 at 9:53
  • 1
    \$\begingroup\$ I found it in the reference here: ruby-doc.org/core-2.3.0/doc/syntax/literals_rdoc.html There is also a character literal notation to represent single character strings, which syntax is a question mark (?) followed by a single character or escape sequence that corresponds to a single codepoint in the script encoding: \$\endgroup\$ – erich2k8 Aug 11 '16 at 22:53
13
\$\begingroup\$

Notepad, 34 31 keystrokes

**********
^A^C↓^V^A^C↓^V^V^V^V

^ denotes Ctrl-<following character> keypress, ↑↓ are up and down keys, respectively.

Props to Crypto for 3 saved keystrokes.

\$\endgroup\$
  • 2
    \$\begingroup\$ You should use keystrokes to count this. \$\endgroup\$ – Leaky Nun Aug 4 '16 at 16:08
  • 1
    \$\begingroup\$ That's Shift+Up. Ctrl+Up is something else. \$\endgroup\$ – Neil Aug 4 '16 at 18:53
  • 1
    \$\begingroup\$ 31 keystrokes **********↵^A^C↓^V^A^C↓^V^V^V^V \$\endgroup\$ – Crypto Aug 5 '16 at 5:52
  • 1
    \$\begingroup\$ 26 keystrokes *****^A^C^V^V↵^A^C^V^A^C^V^V^V^V^V \$\endgroup\$ – Andy Aug 8 '16 at 17:24
  • 5
    \$\begingroup\$ 23 keystrokes **^A^C^V^V^V^V^V↵^A^C^V^V^A^C^V^V^V^V^V \$\endgroup\$ – Andy Aug 8 '16 at 17:26
13
\$\begingroup\$

Emojicode, 54 bytes

🏁🍇🔂i⏩0 10🍇😀🔤**********🔤🍉🍉

Explanation:

🏁🍇                        👴 The beginning of program.
    🔂 i ⏩ 0 10 🍇          👵 This is called a "range".
                          It basically starts with i=0 and increments until i=10, then exits. 👵
        😀 🔤**********🔤    👵 😀 is printing class.
                          The 🔤s make the characters they surround string literals. 👵
    🍉                     👴 End of range
🍉                         👴 End of program
\$\endgroup\$
  • 2
    \$\begingroup\$ I count 54 utf-8 bytes. \$\endgroup\$ – Conor O'Brien Aug 29 '16 at 2:46
  • \$\begingroup\$ This language hates WIndows 7... \$\endgroup\$ – John Dvorak Dec 27 '16 at 16:11
10
\$\begingroup\$

05AB1E, 7 bytes

TF'*T×,

Explanation

TF      # 10 times do:
  '*T×  # repeat asterisk 10 times
      , # print with newline

Try it online

\$\endgroup\$
  • 1
    \$\begingroup\$ т'*×Tô» is another completely different one lol. \$\endgroup\$ – Magic Octopus Urn Feb 8 '18 at 15:28
  • \$\begingroup\$ TLú'*ζ» using the zip-filler was another idea... bad one though. \$\endgroup\$ – Magic Octopus Urn Feb 8 '18 at 15:40
10
\$\begingroup\$

R, 27 29 bytes

cat(rep('\r**********\n',10))

An alternate answer (34 bytes) is: cat(rep('**********',10),sep='\n')

\$\endgroup\$
  • \$\begingroup\$ This adds an extra space at the beginning of all lines except the first (see here ). \$\endgroup\$ – plannapus Aug 4 '16 at 16:14
  • \$\begingroup\$ Thanks, it works adding \r. \$\endgroup\$ – Mamie Aug 4 '16 at 19:48
  • 1
    \$\begingroup\$ Another alternative, too many (37) bytes: cat(matrix('*',10,10),fill=10,sep='') r-fiddle \$\endgroup\$ – Jonathan Carroll Aug 9 '16 at 4:48
  • \$\begingroup\$ Another alternative, also 29 bytes: write(rep("*",100),"",10,,"") \$\endgroup\$ – Giuseppe Feb 13 '18 at 16:14
  • \$\begingroup\$ Dropping \nfrom the above works for 27 bytes: \$\endgroup\$ – JayCe May 25 '18 at 16:07
8
\$\begingroup\$

MATL, 8 bytes

'*'10tX"

Try it online!

'*'   % Push '*' (string containing an asterisk)
10t   % Push 10 twice
X"    % Repeat the string 10×10 times. Implicitly display
\$\endgroup\$
8
\$\begingroup\$

Brainfuck, 46 43 bytes

+[[---<]+[-->]<]<<[--<<++..........-->>>.<]

Try it online! Requires an interpreter with a tape that is open on the left and has 8-bit cells.

The first part of this program +[[---<]+[-->]<] sets up the tape like so:

[255, 250, 245, ... 15, 10, 5, 0, 250, 240, 230, ..., 40, 30, 20, 10, 0]
                                                                      ^

This gives a 40 for outputting asterisks (*, ASCII 42), a 20 to use as a loop counter, and a 10 to use for outputting newlines.

\$\endgroup\$
8
\$\begingroup\$

PHP, 32 bytes

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

(variant 32 bytes - was written with echo)

<?=str_repeat("**********
",10);

(variant 33 bytes)

<?=str_pad("",110,"**********
");

(variant 33 bytes)

for(;$i++<110;)echo$i%11?"*":"
";

(variant 35 bytes)

for(;$i++<10;)printf("%'*10s
",'');

(variant 38 bytes)

<?=($a=str_repeat)($a("*",10)."
",10);
\$\endgroup\$
  • 3
    \$\begingroup\$ The second one can be golfed to 32 bytes as well: <?=str_repeat("**********↵",10); \$\endgroup\$ – insertusernamehere Aug 4 '16 at 13:41
  • 1
    \$\begingroup\$ As you already have a nice collection of alternatives, here is another for fun: echo chunk_split(str_repeat("*",100),10); The longest so far, just in my vision this is the PHP way to do it. \$\endgroup\$ – manatwork Sep 1 '16 at 7:37
  • \$\begingroup\$ Can be a byte shorter with WIN-1252 encoding: for(;++$i<111;)echo$i%11?~Õ:~õ; or for(;++$i<11;)echo~ÕÕÕÕÕÕÕÕÕÕõ; \$\endgroup\$ – aross Sep 29 '16 at 15:50
  • \$\begingroup\$ Another modulo variant for 33 bytes: for(;$i++<110;)echo"*↵"[$i%11<1];. And to add a 37 bytes solution to that collection: for(;$i++<110;)echo chr($i%11?42:10);. \$\endgroup\$ – Titus Jun 9 '17 at 8:50
6
\$\begingroup\$

JavaScript (ES6), 37 bytes

console.log(`**********
`.repeat(10))

A straightforward answer.

\$\endgroup\$
  • 5
    \$\begingroup\$ Cant you save 6 by using alert ? \$\endgroup\$ – Kevin L Aug 4 '16 at 12:45
  • 1
    \$\begingroup\$ Arguably you could save 13 bytes by removing the console.log() and specifying REPL in the title. \$\endgroup\$ – Patrick Roberts Aug 4 '16 at 23:56
6
\$\begingroup\$

Cheddar, 21 20 bytes

print('*'*10+'
')*10

Yet another straightforward answer.

\$\endgroup\$
  • 4
    \$\begingroup\$ Use a literal newline to save 1 byte \$\endgroup\$ – Leaky Nun Aug 4 '16 at 10:51
  • 2
    \$\begingroup\$ Make it a function using -> instead of print maybe? \$\endgroup\$ – Downgoat Aug 4 '16 at 19:00
6
\$\begingroup\$

Haskell, 29 bytes

putStr$[0..9]>>"**********\n"

<list1> >> <list2> makes (length <list1>) copies of <list2>.

\$\endgroup\$
6
\$\begingroup\$

R, 35 33 32 bytes

Ô R, you're so verbose sometimes.

for(i in 1:10)cat(rep("*",10),"\n")

Interestingly, the cat function has no value (it provides NULL to STDOUT), so you can't do somethig like rep(cat(rep))), which would have been funnier !

EDIT :
New solution proposed by @LeakyNun, -2 bytes.

for(i in 1:10)cat("**********\n")

EDIT : Shortening it just by -1 byte, by @user5957401

for(i in 0:9)cat("**********\n")
\$\endgroup\$
  • 3
    \$\begingroup\$ for(i in 1:10)"**********\n" \$\endgroup\$ – Leaky Nun Aug 4 '16 at 10:41
  • 1
    \$\begingroup\$ @LeakyNun : Simplicity is the key ! I had cat nonetheless, otherwise it produces nothing. \$\endgroup\$ – Frédéric Aug 4 '16 at 10:44
  • \$\begingroup\$ cat(rep("**********\n",10)) \$\endgroup\$ – Leaky Nun Aug 5 '16 at 3:56
  • \$\begingroup\$ @LeakyNun It wouldn't produce the desired output: see here. The default separator in cat is a space, hence this output. \$\endgroup\$ – plannapus Aug 5 '16 at 7:14
5
\$\begingroup\$

Retina, 12 bytes

Byte count assumes ISO 8859-1 encoding. The leading linefeed is significant.


10$**
.
$_¶

The first stage writes a string of ten asterisks, the second stage replaces each asterisk with the entire string and a linefeed. This prints two trailing linefeeds.

\$\endgroup\$
5
\$\begingroup\$

J, 10 9 bytes

1 byte thanks to @Adám.

10 10$'*'

Online interpreter.

Explanation

10 10 specifies the dimension to the operator $ which builds an array with the specified dimensions.

\$\endgroup\$
  • \$\begingroup\$ Also 9 bytes: '*'$~,~10 \$\endgroup\$ – Conor O'Brien Aug 4 '16 at 18:26

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.