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

338 Answers 338

1
3 4
5
6 7
12
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\$

Perl 5, 17 bytes

say'*'x10for 0..9

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ need to print * not x \$\endgroup\$ – roblogic Mar 15 at 1:03
  • 1
    \$\begingroup\$ @roblogic: Thanks for your hint. It was only a small change, of course. \$\endgroup\$ – Donat Mar 15 at 9:04
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\$

Vyxal, jH, 6 5 4 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\$
2
\$\begingroup\$

PHP, 69 Bytes

<?for($i=1;$i<101;$i++){if($i%10!=0){echo('*');}else{echo('*<br>');}}
New contributor
Dominic F is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
1
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
\$\begingroup\$

jq, 24 18 characters

(16 characters code + 2 characters command line option.)

range(10)|"*"*10

Thanks to:

  • Leaky Nun for suggesting to use string multiplication (-6 characters)

Sample run:

bash-4.3$ jq -nr 'range(10)|"*"*10'
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********

On-line test (Passing -r through URL is not supported – check Raw Output yourself.)

\$\endgroup\$
2
  • \$\begingroup\$ range(10)|"*"*10 \$\endgroup\$ – Leaky Nun Aug 5 '16 at 10:58
  • \$\begingroup\$ Thank you, @LeakyNun. No idea why I left with the idea that string*number not works. (array*string is the one that not works.) \$\endgroup\$ – manatwork Aug 5 '16 at 11:02
1
\$\begingroup\$

Pyke, 6 bytes

TVT\**

Try it here!

       - (T = 10)
TV     - repeat(10):
  T\** -  10*"*"
\$\endgroup\$
1
\$\begingroup\$

Go, 84 characters

package main;import"fmt";func main(){for j:=0;j<10;j++{fmt.Println("**********");}}

Sample run:

bash$ go build && ./golf
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
2
  • \$\begingroup\$ Print ten asterisks without using a loop \$\endgroup\$ – Leaky Nun Aug 5 '16 at 15:26
  • \$\begingroup\$ removed inner loop per @LeakyNun \$\endgroup\$ – Tom Scanlan Aug 6 '16 at 2:10
1
\$\begingroup\$

Gibberish, 29 bytes

56ea1[[**********]eo1su1fu]gw

Explanation:

56ea1[[**********]eo1su1fu]gw |
56                            | push 5 and 6
  e                           | switch to first instruction set
   a                          | add a, b
    1                         | push 1
     [[**********]eo1su1fu]   | push string
                           g  | switch to set 3
                            w | while a is 1 execute string as code
      [**********]            | push ten asterisks
                  e           | switch to set 1
                   o          | print a
                    1s        | subtract one
                      u       | duplicate a
                       1      | push 1
                        f     | switch to set 2
                         u    | pop a, b push 1 if a > b else push 0
\$\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.