106
\$\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
  • 3
    \$\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

345 Answers 345

1
3 4
5
6 7
12
2
\$\begingroup\$

Braingolf, 18 bytes

8V9R#*[.]#
[R&!@v]

Try it online!

Explanation:

8V9R#*[.]#\n[R&!@v]
8                    Push 8
 V                   Create stack2 and switch to it
  9                  Push 9
   R                 Return to stack1
    #*               Push codepoint of *
      [.]            Do-while loop, will run 9 times due to the 8 pushed at the start
       .             Duplicate last item on stack
         #\n         Push codepoint of newline
            [R...v]  Do-while loop, uses stack2 for loop counting
                     Will run 10 times due to the 9 pushed at the start
              &!@    Print entire stack1 without popping
\$\endgroup\$
1
2
\$\begingroup\$

Marbelous, 81 bytes

@0
0A
>0\/
--
&0@1
&10B
@0&0
@1/\@2
@3@2
--/\\\..@4
>0&1&1/\&2
&2\/--@4/\s*
@3
:s*
2A
{0

Marbelous is a language based on marble machines

this program is composed of 4 subparts :

the main loop

a while loop going from 10 to 0, realease &0, and wait for &1 to be released before continuing

@0
0A
>0 \/
--
&0
&1
@0

the 11(0B) generator

a structure sending 11 (0B) to the portal @2 when the synchroniser group &0 is released

.. @1
.. 0B
.. &0
@1 /\ @2

the printer

a while loop waiting for something in @2 it then print that value minus 1 asterisk finish by printing the ascii value of @2-1 (which is 10(\n) here) and release synchroniser &1

@3 @2
-- /\ \\ .. @4
>0 &1 &1 /\ &2
&2 \/ -- @4 /\ s*
@3

asterisk creator

board transforming the inputted marble into a 2A (ascii value of *)

:s*
2A
{0

used language built-in are :

  • .. is a noop
  • 00-FF initiate a marble with this value
  • @n (n from 0 to Z) is a portal which teleport the marble to another portal with the same value
  • &n (n from 0 to Z) is a synchroniser, hold the marble until all corresponding synchroniser (same n) are full
  • \/ is a trash can
  • /\ create a duplicate passing marble to it's left and right
  • marbles going out of the machine from the bottom are implicitly outputed
  • -- is a decrement
  • \\ is a right deflector, the marble go right
  • >n (n from 0 to Z) is a conditional, if marble > n then noop else go right

boards

it also uses a board, boards are created with :name at the start of a new line with name being anything you want, they have special built-in

  • }n (n from 0 to Z) input argument
  • {n (n from 0 to Z) returned output

Boards execution pause the caller execution until finished

interpretor

\$\endgroup\$
2
\$\begingroup\$

CJam, 8 bytes

'*A*N+A*

My first CJam answer!

Explanation:

'*          Push an asterisk
  A*        Multiply by 10
    N+      Add a newline
      A*    Multiply by 10
            Implicitly output
\$\endgroup\$
2
\$\begingroup\$

Notepad++, 15 13 keystrokes

*<Ctrl-Shift-R><Ctrl-A><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-A><Ctrl-D><Ctrl-Shift-R><End><Enter><Ctrl-Shift-P>

Saved two keystrokes by using a macro. Explanation to come.

Original code and explanation

*****<Ctrl-D><Del><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-A><Ctrl-D>→<Enter>

We start by inserting five asterisks. CtrlD duplicates this line, leaving the cursor at the end of the first line. Del removes the newline, so now we have a line of ten asterisks.

Four applications of CtrlD give us five lines of asterisks. Next, CtrlA CtrlD duplicates all five lines at once, but it doesn't include a newline between the copies:

**********
**********
**********
**********
********************
**********
**********
**********
**********

Fortunately, the first half is still selected, so if we press , the cursor will be immediately after the tenth asterisk on the too-long line, and we can add the missing newline with Enter.

\$\endgroup\$
2
\$\begingroup\$

GNU nano, 14 keystrokes

<C-6>*<C-K><M-:><C-U><C-U><C-U><C-U><C-U><M-:><M-;><C-K><M-;><M-;>

<C-X> refers to CTRL+X, <M+X> refers to META+X.

Explanation

<C-6>         Start a selection block
*             Type an asterisk (typing does not affect the selection by default)
              At this point, '*' is selected.
<C-K>         Delete the selection and put it into the cutbuffer. '*'
<M-:>         Start recording a macro
  <C-U> (5x)  Paste 5 times, text is now '*****'
<M-:>         Stop macro recording. Macro pastes 5 times now.
<M-;>         Run the macro, pasting 5 more '*'s. Text is now '**********'
<C-K>         Delete the current line and put it in the cutbuffer. '**********\n'
<M-;><M-;>    Run the macro twice, pasting '**********\n' 10 times

Betcha didn't know nano had macros?

Video demo (done in Termux because of visible keyboard, --ignorerc just ignores any RC files that may alter the behavior)

\$\endgroup\$
2
\$\begingroup\$

Batch, 42 bytes

@for /l %%a in (1,1,10) do echo **********
\$\endgroup\$
2
\$\begingroup\$

vJASS (Warcraft 3), 100 76 bytes

Using //! import zinc "<code_path>" command to exclude //! zinc and //! endzinc.


library q{real w;function onInit(){for(0<=w<10){BJDebugMsg("**********");}}}

Warcraft 3

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Would you mind slowing down a bit on updating your answers, maybe wait for an hour or so before doing some more? The recently active page is getting flooded with older questions because of the edits, and it'd be good to let it settle down a bit \$\endgroup\$ – caird coinheringaahing Mar 11 at 22:44
  • \$\begingroup\$ @ChartZBelatedly oh, okay. Sorry for my unintentional spam. \$\endgroup\$ – noise Mar 11 at 22:47
  • \$\begingroup\$ No worries, just thought it'd be worth letting you know :) \$\endgroup\$ – caird coinheringaahing Mar 11 at 22:48
2
\$\begingroup\$

Python 3, 23 bytes

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

Try it online!

\$\endgroup\$
2
\$\begingroup\$

R, 39 bytes

cat(c("*","\n")[(0:219)%%21/10],sep='')

Don't know if R coercing indices to integer is commonly used, so thought it worth posting in case someone can do something extra with it!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Sure, navigating among so many answers is a nightmare, but different variations of doing this in R were extensively discussed here. \$\endgroup\$ – Kirill L. Mar 15 at 9:55
  • \$\begingroup\$ Fair point @KirillL. and I would have posted a comment but didn't have the reputation yet - ironically, posting the new answer has given me some of the reputation I need to do it... \$\endgroup\$ – Nick B Mar 15 at 21:17
2
\$\begingroup\$

05AB1E, 7 bytes

'*T×TF,

Try it online!

'*T×TF,  # full program
'*T×     # push "**********"
    TF   # repeat 10 times...
      ,  # output top of stack to STDOUT
         # (implicit) exit loop

05AB1E, 7 bytes

'*т×Tä»

Try it online!

'*т×Tä»  # full program
      »  # join....
  т×     # 100...
'*       # asteriks...
     ä   # split into...
    T    # 10...
     ä   # pieces...
      »  # by newlines
         # implicit output
\$\endgroup\$
2
\$\begingroup\$

CSASM v2.3.0.1, 50 bytes

func main:
push "**********\n"
push 10
mul
print
ret
end

mul duplicates a <str> value by a given <i32> amount, concatenating the copies together

\$\endgroup\$
2
\$\begingroup\$

GFortran, 31 29 bytes

print'(10A)',('*',j=0,99)
end

The loop ('*',j=0,99) spits out 100 *s. Formatting directive '(10(A))' '(10A)' wraps it.

try it online!

31 bytes

\$\endgroup\$
2
  • \$\begingroup\$ this shows that (fortran.ge.javascript) \$\endgroup\$ – roblogic Mar 15 at 1:22
  • 1
    \$\begingroup\$ FWIW Gnu f95 doesn't is happy with this print'(10A)',('*',j=0,99) as the print line, meaning it does the right thing with 10A instead of 10(A), which drops 2 more characters. \$\endgroup\$ – cnamejj Mar 24 at 6:39
2
+200
\$\begingroup\$

Factor, 30 bytes

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

Try it online!

Okay, is there a factor vocabulary to print string \$n\$ times? I couldn't find a documentation?

\$\endgroup\$
2
\$\begingroup\$

Excel, 10 8 keystrokes

In a fresh empty sheet,

Ctrl+GJ10EnterCtrl+Shift+Home*Ctrl-Shift-Enter

Explanation:

  • Ctrl+G is a shortcut for the GoTo dialog
  • Entering J10 goes to that cell
  • Enter closes the dialog
  • Ctrl+Shift+Home expands the selection to A1, making a grid of 10x10 cells
  • Then we put in the asterisk
  • Ctrl+Shift+Enter (instead of plain Enter) fills in the input over all selected cells
\$\endgroup\$
2
\$\begingroup\$

PHP, 69 Bytes

<?for($i=1;$i<101;$i++){if($i%10!=0){echo('*');}else{echo('*<br>');}}
\$\endgroup\$
1
2
\$\begingroup\$

Vyxal, 8 bytes

\*₀*¶+₀*

Try it Online!

-1 due to cairdcoinheringaahing

Later I reduced another one

\$\endgroup\$
4
  • 1
    \$\begingroup\$ -1 byte \$\endgroup\$ – caird coinheringaahing Apr 25 at 17:19
  • \$\begingroup\$ @cairdcoinheringaahing thax! \$\endgroup\$ – wasif Apr 25 at 17:20
  • \$\begingroup\$ here's how to do it in 4 bytes. But I recommend you keep this because it is flagless \$\endgroup\$ – lyxal Apr 26 at 2:36
  • \$\begingroup\$ Flagless, ₀(\*₀*, \$\endgroup\$ – A username May 14 at 8:54
2
\$\begingroup\$

Barrel, 14 13 bytes

^42#10(#10p¶

Explanation:

^42          // push 42 to the accumulator
   #10       // do 10 times...
      (      // defines a code block which becomes a single instruction
             // (the parenthesis is self-closing)
       #10p  // print the accumulator as an ASCII character 10 times
           ¶ // print a newline

EDIT: removed the closing parenthesis, saving 1 byte, since I found the reason hadn't been able to get it to work right (I had added a newline at the end of my test file! *sigh*).

\$\endgroup\$
2
\$\begingroup\$

Vyxal, jH, 6 5 4 3 bytes

×*²

Try it Online!

Explained

×*²
×*      # Push 100 asterisks onto the stack (as a single string) // the H flag initalises the stack with 100
  ²     # Split into pieces of 10 and use the j flag to join on newlines. 
\$\endgroup\$
1
\$\begingroup\$

Racket, 52 bytes

(display(string-join(make-list 10"**********")"\n"))

If you're fine with just returning the string and not printing it, you can forego the (display) for a score of 41 bytes.

An alternate answer (longer at 73 bytes, but I like it better personally):

(display(build-string 110(λ(n)(if(eq?(remainder n 10)0)#\newline #\*))))
\$\endgroup\$
1
\$\begingroup\$

Batch, 41 bytes

@for /l %%i in (0,1,9)do @echo **********
\$\endgroup\$
8
  • \$\begingroup\$ You can shave off 1 byte by removing the first @ \$\endgroup\$ – SomethingDark Aug 6 '16 at 3:44
  • \$\begingroup\$ @SomethingDark But then it would print for /l %%i in (0,1,9)do @echo **********... \$\endgroup\$ – Neil Aug 6 '16 at 9:39
  • \$\begingroup\$ It didn't when I tested it \$\endgroup\$ – SomethingDark Aug 6 '16 at 9:39
  • \$\begingroup\$ @SomethingDark You mean as an immediate command? As it's a single line, you might be on to something there. \$\endgroup\$ – Neil Aug 6 '16 at 9:45
  • \$\begingroup\$ As both an immediate command (in which case you could save an additional byte by using %i instead, but I need to double-check the rules for this language) and in a script. \$\endgroup\$ – SomethingDark Aug 6 '16 at 9:46
1
\$\begingroup\$

BASH, 46 bytes

for((n=0;n<10;n++));do echo "**********"; done
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Or for n in {0..9};{ echo "**********";} \$\endgroup\$ – manatwork Aug 4 '16 at 12:43
  • \$\begingroup\$ Or seq -f%10g 10|tr -c \\n \* in Bash + coreutils. \$\endgroup\$ – manatwork Aug 4 '16 at 14:52
1
\$\begingroup\$

Frink, 40 39 Bytes

for r=0 to 9
  println[repeat["*",10]]

-1 Byte @LeakNun

\$\endgroup\$
1
  • 4
    \$\begingroup\$ You can probably use 0 to 9 \$\endgroup\$ – Leaky Nun Aug 4 '16 at 11:18
1
\$\begingroup\$

Maple 30 bytes

printf(cat("**********\n"$10))
\$\endgroup\$
1
\$\begingroup\$

C, 84 bytes

#include<stdio>
int main(){int i;for(i=0;i<10;i++){printf("**********\n");return 0;}

If anyone can improve the answer, I'd appreciate it. I'm not trying to compete, it's just been simply ages since I've coded C or C++ and this challenge looked fun.

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

Sprects, 22 bytes

#eeep#eppp#pqqq*
#q***

Note: The interpreter uses U+0020 instead of U+0010.

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

C, 47 bytes

main(i){while(i<111)putchar(10|!!(i++%11)<<5);}

Try it online.

Not as compact as the other C answer (putchar is such a long name!), but I don't use the asterisk character in my program. It treats the output as a 11 by 10 grid, where the 11th character is the newline. It then computes the ASCII for '*' (10 + 32 = 42) or '\n' (10) for each position.

I could save one byte with this approach if I were to change the character expression to: 42-!(i++%11)*32, but that would require an asterisk.

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

EXCEL, 26 bytes.

=REPT("**********[ae]",10)

Can go into any cell.

\$\endgroup\$
1
  • \$\begingroup\$ What is [ae]? Is that Alt+Enter (the means to input a line break in Excel)? You can include the line break in the code here. It would be 23 bytes total. \$\endgroup\$ – Engineer Toast May 4 '17 at 13:03
1
\$\begingroup\$

tinyAll, 17 bytes

The current version (untouched for a LONG time), is extremelly broken, but works enough for this challenge.

P'*Ra_P"
[:;]"R9_

Basically:

  • Pass * to the R(repeat) function
  • Repeat it a (10) times
  • Output it (_)
  • Pass the output (;), through string interpolation, prefixed by a newline
  • To the R function
  • And repeat 9 more times
  • And display the result

A boring alternative, with the same byte count:

P"**********
"Ra_

Translating:

  • Pass "********** (newline)
  • To the R function, to repeat a (10) times
  • And output the result (_)

Try it:

// Commit https://github.com/ismael-miguel/tinyall/commit/2589837678f4b6556d1bd22f163255e2e058808e#diff-65af36bb0dc600cbc7a54816dcda57fd
(function(window, undefined) {
	var funcs = {
		//echo
		'_':function(value, data){
			var tmp = data.out + (value === undefined ? data.last : value);
			data.vars[';'] = data.out = tmp;
			return tmp;
		},
		//array
		A:function(value, data){
			var split_value = (value || '').split(/(\-?\d+(?:\.\d*)?(?:[eE][\-+]?\d+)?|'(?:\\'|[^']*)*'),?/);
			var final_value = [];
			for(var i = 0, l = split_value.length; i<l; i++)
			{
				if(split_value[i][0] == '\'')
				{
					final_value[final_value.length] = split_value[i].replace(/^'(.*)'$/,'$1').replace(/\\'/g,'\'');
				}
				else if(split_value[i]/1 || split_value[i] == '0')
				{
					final_value[final_value.length] = +split_value[i];
				}
			}
			
			return final_value;
		},
		//comparison functions
		C:function(value, data){
			
		},
		D:function(value, data){
			
			var debug = {
				value: value,
				type: typeof value,
				memory: data
			}
			
			if(console && console.log)
			{
				console.log(debug);
			}
			
			return value;
		},
		//eval
		E:function(value, data){
			run_code(value, data);
		},
		//flip the value around
		F:function(value, data){
			if(('object' === typeof value) && value.reverse)
			{
				return value.reverse();
			}
			else
			{
				return value.toString().split('').reverse().join('');
			}
		},
		//hello worlds
		H:function(value) {
			return 'hH'[value&1]
				+'ello'
				+(value&2?',':'')
				+' '
				+('wW'[+!!(value&4)])
				+'orld'
				+(value&8?'!':'')
				+(value&16?'\n':'');
		},
		//math functions
		M:function(value, data){
			
		},
		//not (inverts values/casing)
		N:function(value) {
			switch(typeof value)
			{
				case 'boolean':
					return !value;
				case 'number':
					return -value;
				case 'string':
					var tmp = '';
					for(var i = 0, l = value.length; i < l; i++)
					{
						if(value[i] >= 'a' && value[i] <= 'z')
						{
							tmp += String.fromCharCode(value.charCodeAt(i) - 32);
						}
						else if(value[i] >= 'A' && value[i] <= 'Z')
						{
							tmp += String.fromCharCode(value.charCodeAt(i) + 32);
						}
						else
						{
							tmp += value[i];
						}
					}
					return tmp;
				default:
					return 0;
			}
		},
		//passthrough
		P:function(value) {
			return value;
		},
		//repeat
		R:function(value, data){
			var tmp = '';
			
			if(value > 0)
			{
				while(value--)
				{
					tmp += data.last;
				}
			}
			
			return tmp;
		},
		//string functions
		S:function(value, data){
			var methods = {
				t:function(value){
					return value.replace(/^\s+/,'').replace(/\s+$/,'');
				},
				u:function(value){
					return value.toUpperCase();
				},
				T:function(value ){
					
				},
				R:function(value){
					
				}
			};
			
			var tmp = data.last.toString();
			for(var i = 0, l = value.length; i < l; i++)
			{
				tmp = value[i] in methods ? methods[value[i]](tmp, value, i) : '';
			}
		
			return tmp;
		},
		//clears output
		Z:function(value, data) {
			return data.vars[';'] = data.out = 0;
		}
	};
	
	var expand_string = function(value, data){
		
		return value.replace(
			/\[:(?:([A-Z_])(.)?|([^A-Z_'"]))\]/g,
			function(_, func, arg, value){
				if(func)
				{
					return funcs[func](get_value(arg, data, true), data);
				}
				else
				{
					return get_value(value, data, true);
				}
			}
		);
		
	};
	
	var get_value = function(value, data, recursion) {
		
		if(value === null || value === undefined || value === ' ')
		{
			return undefined;
		}
		
		var x = (value || '').toString();
		
		if(/^\-?\d+(?:\.\d*)?(?:[eE][\-+]?\d+)?$/.test(x))
		{
			//returns a number
			return +x;
		}
		else if(/^[a-z]$/.test(x))
		{
			//returns a number between 10-43
			return (x in data.vars) ? data.vars[x] : x.charCodeAt(0) - 87;
		}
		else if(x[0] == '\'')
		{
			return x[1];
		}
		else if(x[0] == '"' && x.length >= 2)
		{
			var sub = x.substr(1, x.length - 2);
			
			return recursion ? sub : expand_string(sub, data);
		}
		else
		{
			return data.vars[x];
		}
	};
	
	var run_code = function(code, memory){
		
		if(!code || /^[a-z\d]$/.test(code))
		{
			memory.out = funcs.H(get_value(code, memory));
		}
		else
		{
			code.toString().replace(
				// /(?:([^A-Z_:'"])=)?([A-Z_])(?::('.|"[^"]*"|-?\d+|.))?/g,
				/(?:([^A-Z_'"])=)?([A-Z_])(?:('.|"[^"]*"|-?\d+|[^A-Z_'"]))?/g,
				function(_, name, func, value){
					
					memory.vars[name || ':'] = memory.last = (funcs[func] || noop)( value ? get_value(value, memory) : memory.last, memory);
					
					return '';
				}
			);
		}
	}
	
	var noop = function(){};
	
	window.tinyAll=function(code, input) {
		var data = {
			out: '',
			last: 0,
			input: input || 0,
			vars: {
				//version
				'|':'0.3',
				//input
				':':input || 0,
				//output
				';':0,
				//code
				'.':(code || '').toString()
			}
		};
		
		run_code(data.vars['.'], data);
		
		return data.out || 0;
	};
})(Function('return this')());



//RUN THE CODE!!!
//\n instead of a real newline, but works the same
console.log(tinyAll('P\'*Ra_P"\n[:;]"R9_'));
console.log(tinyAll('P"**********\n"Ra_'));

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

PostgreSQL, 39 bytes

select repeat('**********'||chr(13),10)
\$\endgroup\$
1
\$\begingroup\$

99, 137 bytes

99999 9 9
9999 99999 9
999 99 9
999999 99 9




99 99 9 99 9 99 9 99 9999
99
99
99
99
99
99
99
99
99
99
999999
999 999 9
 99 999
 9 99999

Try it online!

\$\endgroup\$
1
3 4
5
6 7
12

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.