111
\$\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
  • 4
    \$\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
  • 2
    \$\begingroup\$ you say trailing new lines are acceptable. Are leading newlines acceptable too? \$\endgroup\$ Feb 10 '17 at 2:34

376 Answers 376

1 2 3
4
5
13
3
\$\begingroup\$

K (ngn/k), 16 14 13 bytes

` 0:10 10#"*"

Try it online!

Thanks to @Bubbler in the k tree for helping me out with this.

¯2 bytes thanks to @Bubbler

¯1 byte thanks to @Bubbler

\$\endgroup\$
3
\$\begingroup\$

Elixir, 35 bytes

for _<-0..9,do: IO.puts"**********"

Try it online!

Originally suggested to @Chester Lynn on their answer.

\$\endgroup\$
3
\$\begingroup\$

Commodore BASIC (C64/128, PET, VIC-20, C16/+4, THEC64/Mini, Ultimate64) ~35 tokenised BASIC bytes

0a$="**********":fori=.to9:?a$:next

Very simply, a string is created called a$; this is of 10 asterisks. This is printed to the screen in a for/next loop, which is from zero to nine inclusive. Each string is printed onto a new row on the screen.

A few tokenised BASIC bytes could be saved with:

0fori=.to9:?"**********":next

Though I think this would be less performant (not that performance will matter with such a trivial BASIC listing).

Commodore 64 running the 10 x 10 challenge

\$\endgroup\$
2
  • \$\begingroup\$ A minor tweak and it's also valid Applesoft Basic 0a$="**********":fori=0to9:?a$:next \$\endgroup\$
    – roblogic
    Aug 26 at 2:55
  • \$\begingroup\$ You can also do 0?"**********":a=a+1:ifa<10thengoto in Commodore BASIC; without a line number following the goto command, Commodore BASIC will goto 0 as long as there is a line zero \$\endgroup\$ Aug 26 at 12:58
3
\$\begingroup\$

Python 3, 25 24 23 bytes

Newest answer

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

I'm an idjot, I don't need so many parentheses.


2nd answer

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

I shaved off a byte doing it more simply.


1st answer

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

Python can multiply strings, but most of your saving are eaten by print(), so it goes like this:

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

print(                    # Print to console
      (('*'*10)           # Put 10 '*' in a row
               +'\n'      # Append a new line character at the end of the 10 '*'
                    )*10) # Now do it 10 more times
\$\endgroup\$
1
3
\$\begingroup\$

V (vim), -v 11 bytes

i*<esc>yl9pyy9p

Try it online!

Insert a * and copy it 9 times towards left and copy the line and paste it nine times.

Also I am a sock of someone :P

-4 as I am an idot.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Ooh nice, a fellow sockpuppet \$\endgroup\$ Oct 1 at 15:32
  • \$\begingroup\$ 9i*<esc>yy9p? \$\endgroup\$
    – pxeger
    Oct 15 at 11:50
  • 1
    \$\begingroup\$ Also, this is 11 bytes, not 15 bytes, because <esc> is one byte \$\endgroup\$
    – pxeger
    Oct 15 at 11:56
  • \$\begingroup\$ dom!!!e @pxeger \$\endgroup\$
    – Milk
    Oct 16 at 7:52
3
\$\begingroup\$

Cascade, 32 27 bytes

"
*
*
*
*@
*}
*|
*/
*
*.
*/

Try it online!

Aha! It turns out just printing ten asterisks ten times does beat out my more complex answer. Unfortunately though, writing this program exposed not one, but two bugs in my interpreter. Below is my longer, but higher effort solution:

Cascade, 32 bytes

_9'2
 ^*|
\ !]
(.n
n?\
\%!|
n)+\

Try it online!

One of my more compact Cascade programs. I'm still not sure if it would be shorter to just print 10 asterisks 10 times instead of using a counter, but I'm satisfied with this, especially how the bottom intersects with the top.

Explanation

The easiest way to understand the code is know the basic structure. Each instruction can take up to three inputs, each one below it.

 +
lcr

These are the left, center and right arguments. In this case, the + instruction is dyadic, meaning it takes the left and right arguments. Most instructions are either dyadic or monadic (taking one argument, the center one). The /\| instructions take only the argument they are pointing to, and the ! instructions skips over the center and takes the argument two below it. Each of these arguments can themselves be code instructions, meaning they chain together in a prefix like notation. For example, this code could be represented by the recursive Lisp-like code:

code = (if (0==(n=dec n))
         doboth
           (print (
              if (% n (+9 2)) ('*')
              else (inc 9)
           ))
           (code)
       )

If that doesn't make sense, here's an expanded look at the code, which is still a little confusing, but it at least has an idea of which parts are connected to each other through the |/\Xs. Note that the top and bottom rows are the overlap between the two (and same with the left and right).

\  |/|\ \
 _ 9 ' 2
/ \  |  /
   ^ * |
  / \  | 
 \   ! ]
\ \  \/ \
 ( . n/
 | | |   
 n ? \
  /|\ \  
 \ % ! |
  X \\ | 
 n ) +/\
\  |/|\ \

Starting from the top left corner, we have the first check (_) which executes the right branch only if the left is successful. The left goes down to the ], which sets the n variable (initially 110) to the decrement (() of n, i.e. n=n-1. The check then takes the result of this (the new value of n) and continues if it is positive. This moves onto the branch instruction on the right (^), which executes both the left and right branches.

The left prints (.) the value given by the choice instruction (?). This branches depending on the center value, which is the modulo (%) of n and the addition (+) of 9 and 2. Note that this wraps around to the top again for those digits. If n%(9+2) is 0, then we branch left, which navigates around the % and returns the increment ()) of 9, printing a newline. If it is not divisible by 11, then we go right, skip over the + with a !, and return the character (') of * to print.

Now the right branch of the ^ skips over the n, then goes right, down, and right again, wrapping around both the right edge and the bottom edge to loop back to the _ in the top left. This now loops over the exact same code until n has reached 0, printing ten asterisks and then a newline.

\$\endgroup\$
3
\$\begingroup\$

Minim, 42 37 35 Bytes

New solution halts by checking if [0] > 99.

$<42._^++[0]%10.$<10._^[0]>99.C=-1.

With whitespace and comments:

$< 42.         ; Print 42 as unicode '*'
_^ ++[0] % 10. ; Increment index 0 and skip next stmt if index 0 mod 10 is nonzero
    $< 10.     ; Print 10 as unicode '\n'
_^ [0] > 99. ; Skip next stmt if index 0 is greater than 99
    C = -1.    ; Set program counter to -1 (advances to 0 afterwards)

Old solutions halted by checking [0] == 100...

$<42._^++[0]%10.$<10._^[0]==100.C=-1.

... or used labels and gotos.

_>1.$<42._^++[0]%10.$<10._<?([0]-100)._>0.

GitHub Repository

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Nice answer! Did you make this language? (Also, welcome to Code Golf!) \$\endgroup\$ Aug 13 at 3:27
  • \$\begingroup\$ @RedwolfPrograms Thank ya kindly~ Yes indeed! This is an old esolang (2017) that I resurrected last month, and have been in the process of finishing. I didn't do too bad for my first entry, I suppose! And thank you~ \$\endgroup\$ Aug 13 at 3:37
  • \$\begingroup\$ Also just realized that my program's size is the ASCII value of the asterisk! How serendipitous~ \$\endgroup\$ Aug 13 at 4:11
  • 1
    \$\begingroup\$ When I went to the esolangs article, I instantly recognised this as being from Truttle server. Welcome to the wonderful world of Code Golf! \$\endgroup\$
    – lyxal
    Aug 13 at 11:17
2
\$\begingroup\$

Python 3, 29 23 bytes

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

Thanks to orlp for shaving off 6 bytes.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ We require either a full program or a function. An expression is not sufficient. \$\endgroup\$
    – orlp
    Aug 4 '16 at 9:35
  • \$\begingroup\$ Yes, I'm referring to your second paragraph. \$\endgroup\$
    – orlp
    Aug 4 '16 at 9:36
  • 1
    \$\begingroup\$ print((10*"*"+"\n")*10) is shorter. \$\endgroup\$
    – orlp
    Aug 4 '16 at 9:37
  • \$\begingroup\$ darnit we had the same answer :( \$\endgroup\$ Aug 4 '16 at 9:50
  • \$\begingroup\$ Changing print to exit will save 1 byte and still output the result, there wasn't specified if it should be printed on standard output. \$\endgroup\$ Aug 4 '16 at 13:50
2
\$\begingroup\$

Golisp, 34 bytes

for[range@10{(_)writeln@*["**"5]}]

Due to a "bug", I can't concatenate strings...

\$\endgroup\$
5
  • \$\begingroup\$ Congratulations! \$\endgroup\$
    – Leaky Nun
    Aug 4 '16 at 10:29
  • \$\begingroup\$ @LeakyNun For what? \$\endgroup\$ Aug 4 '16 at 10:30
  • \$\begingroup\$ For developing a language. \$\endgroup\$
    – Leaky Nun
    Aug 4 '16 at 10:30
  • \$\begingroup\$ @LeakyNun Just look at my GitHub repos... \$\endgroup\$ Aug 4 '16 at 10:35
  • 7
    \$\begingroup\$ I didn't say "for developing your first language" \$\endgroup\$
    – Leaky Nun
    Aug 4 '16 at 10:35
2
\$\begingroup\$

SpecBAS - 18 bytes

?(("*"*10)+#13)*10

? is shorthand for PRINT, #13 is the equivalent of \n in other languages.

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

C#, 79 bytes

class P{void Main(){for(int i=0;i++<10;)System.Console.Write("**********\n");}}
\$\endgroup\$
2
  • \$\begingroup\$ This won't run without static void right? \$\endgroup\$
    – pay
    Aug 4 '16 at 15:49
  • \$\begingroup\$ @pay has void already not sure if it needs static will check later when I have chance \$\endgroup\$ Aug 4 '16 at 15:59
2
\$\begingroup\$

golflua, 22 characters

~@i=0,9 w"**********"$

Sample run:

bash-4.3$ golflua -e '~@i=0,9 w"**********"$'
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
2
\$\begingroup\$

C++, 75 bytes

#include<cstdio>
int main(){for(int i=0;i<10;++i)std::puts("**********");}
\$\endgroup\$
7
  • 2
    \$\begingroup\$ Why the downvote? \$\endgroup\$
    – arnsong
    Aug 4 '16 at 13:00
  • \$\begingroup\$ I believe this was an automatic downvote from the community user. Your post was auto-flagged as low quality (since it only contained code) and Leaky Nun's edit caused an automatic unowned downvote. See meta.stackexchange.com/q/236883 \$\endgroup\$ Aug 4 '16 at 13:03
  • 2
    \$\begingroup\$ That's actually not true. I don't think it's fair to assume. \$\endgroup\$
    – arnsong
    Aug 4 '16 at 13:55
  • 1
    \$\begingroup\$ You can save 1 byte by changing the for-loop to: for(int i=0;++i<11;) \$\endgroup\$ Aug 4 '16 at 14:07
  • 2
    \$\begingroup\$ Use int main(i) and remove the int i=0. Then, replace i<10;++i with i++<10;. -7 \$\endgroup\$ Aug 4 '16 at 14:58
2
\$\begingroup\$

T-SQL, 50 bytes

print replicate(replicate('*',10)+char(10),10)
\$\endgroup\$
1
  • 1
    \$\begingroup\$ not an T-SQL expert but wouldn't 'print replicate('**********'+char(10),10)' be shorter? \$\endgroup\$
    – dwana
    Aug 5 '16 at 8:25
2
\$\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\$
2
\$\begingroup\$

Notepad++, ??? keystrokes

I have no idea how to score this, but I decided to give it a shot since there's an answer on Notepad.

Here's the sequence:

* * * * * CTRL (hold) A D D D D D D D D D D

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

Bash (pure), 30 bytes

printf '%.s**********
' {0..9}

Test it on Ideone.

How it works

Before calling the shell built-in printf, Bash expands the glob {0..9} to 0 1 2 3 4 5 6 7 8 9.

The format string

%.s**********
 

specifies a string whose first 0 characters are included in the output (%.s), followed by ten asterisks and a linefeed. printf repeats the format string as many times as needed to consume all arguments. Since .%s is an empty string, this results in the desired output.

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

MSX BASIC, 40 30 bytes

1FORR=1TO10:FORC=1TO10:?"*";:NEXT:?:NEXT

Update: D'oh... much shorter if I just print whole rows:

1FORR=1TO10:?"**********":NEXT
\$\endgroup\$
1
  • \$\begingroup\$ -1 byte: 1FORR=0TO9:?"**********":NEXT \$\endgroup\$
    – mazzy
    Jul 2 '18 at 9:55
2
\$\begingroup\$

Clojure, 38 bytes

(apply print(repeat 10"**********\n"))

Simple enough

\$\endgroup\$
2
  • \$\begingroup\$ I'm afraid, that should be 38 bytes. Currently it prints only 8 x 8. \$\endgroup\$
    – manatwork
    Aug 5 '16 at 13:17
  • \$\begingroup\$ You are completely right. I keep posting wrong cases this whole day. \$\endgroup\$
    – Michael M
    Aug 5 '16 at 13:52
2
\$\begingroup\$

Underload, 22 bytes

(*****):*(
)*:*::*:**S
\$\endgroup\$
0
2
\$\begingroup\$

Scheme, 51 Bytes

(map (lambda (n)(display "**********\n"))(iota 10))
\$\endgroup\$
2
\$\begingroup\$

Ruby, 26 20 bytes

10.times{puts'*'*10}

Try it online!

Explanation

Runs 10 times; each time, it prints * (10 times), with an automatic line break at the end.

Kudos to OrangeFlash81 for saving me 6 bytes.

\$\endgroup\$
1
  • \$\begingroup\$ I think 10.times{puts'*'*10} works as well and is shorter. \$\endgroup\$ Aug 7 '16 at 8:26
2
\$\begingroup\$

Xtend, 33 bytes

[for(_:0..9)print('**********
')]

... a Java dialect; [] is a lambda definition

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

Deadfish ~, 24 bytes

{{iiii}ii{c}{ddd}ddc{d}}

how it works:

{foo} does foo exactly ten times. first, it starts a ten loop, in this loop, it sets the counter to 42, prints it ten times (as char (asterisk)), decrements it to 10, prints it (newline), subtracts 10, then loops again, doing this 10 times.

\$\endgroup\$
1
  • \$\begingroup\$ 23 bytes by setting the counter to 10 initially \$\endgroup\$
    – ovs
    Sep 22 at 7:50
2
\$\begingroup\$

Google Sheets, 31 23 bytes

Code:

In cell A1 (12 bytes):

=REPT(B1,10)

In cell B1 (11 bytes):

**********        # Contains New Line
                  # <--

Result:

enter image description here

Previous Attempt #1 (31 bytes):

=REPT(REPT("*",10)&CHAR(10),10)

Previous Attempt #2 (also 31 bytes):

=REPT("**********"&CHAR(10),10)
\$\endgroup\$
2
\$\begingroup\$

S.I.L.O.S 45 bytes

All whitespace necessary due to my poor interpreter design.

a = 10
lbla
printLine **********
a - 1
if a a

Try it Online!

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

Lua, 34 bytes

for i=1,10 do print"**********"end
\$\endgroup\$
2
\$\begingroup\$

Befunge-93 (PyFunge), 28 bytes

#<90v0-1_@#:,
#^_ >1+"*",:9`

Try it online!

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

Javascript (REPL), 27 bytes, Old is 32 bytes. Thanks to @Peter

('**********\n').repeat(10)
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Welcome to PPCG! Please note that we count REPL submissions differently from full-program solutions, so this should be marked as "Javascript (REPL)". \$\endgroup\$
    – user45941
    Feb 13 '18 at 2:32
  • \$\begingroup\$ @Mego Thank you, I will remember this! \$\endgroup\$
    – NTCG
    Feb 13 '18 at 2:49
  • \$\begingroup\$ ('**********\n').repeat(10) is shorter :) \$\endgroup\$
    – Peter
    Feb 13 '18 at 21:27
  • \$\begingroup\$ Welcome to PPCG :) Note that this solution already exists: codegolf.stackexchange.com/a/88660/58974. However, you can remove the brackets around the string and use a template literal with a literal newline to save 3 bytes: tio.run/##y0osSyxOLsosKNHNy09J/Z@cn1ecn5Oql5OfrvE/… \$\endgroup\$
    – Shaggy
    Feb 15 '18 at 11:54
2
\$\begingroup\$

Kotlin (script), 32 bytes

print("**********\n".repeat(10))

Try it online!

Run this locally as a standalone program by

  • installing Kotlin
  • saving the source to a .kts file
  • run with kotlinc -script myfile.kts

This does not seem to work on TIO, for whatever reason, which is why I had to include the header/footer.

\$\endgroup\$
3
  • \$\begingroup\$ You could run this as a standalone program using the -script command line switch on kotlin. This doesn't work in TIO/kotlinc though. \$\endgroup\$
    – snail_
    May 25 '18 at 19:01
  • \$\begingroup\$ I wasn't aware this is possible. If you want to link the script version on TIO, you could do it this way. \$\endgroup\$
    – ovs
    May 25 '18 at 19:35
  • \$\begingroup\$ {print("**********\n".repeat(10))} \$\endgroup\$
    – mazzy
    Jul 2 '18 at 8:18
1 2 3
4
5
13

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.