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
  • 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\$ Feb 10 '17 at 2:34

367 Answers 367

1 2 3
4
5
13
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] == 100. ; Skip next stmt if index 0 is 100
    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\$

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

Kotlin, 62 bytes

fun main(a:Array<String>){for(i in 0..9)println("**********")}

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ your golfed version 37 bytes: {for(i in 0..9)println("**********")}. -3 byte version {print("**********\n".repeat(10))} ))) \$\endgroup\$
    – mazzy
    Jul 2 '18 at 8:15
2
\$\begingroup\$

05AB1E, 9, 8 bytes

Tƒ,TF'*+

my first golfing answer so any tips are welcome

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ That's a grid of 10x9, not 10x10 \$\endgroup\$
    – mbomb007
    Jul 2 '18 at 14:34
  • \$\begingroup\$ didn't notice that, fixed it @mbomb007 \$\endgroup\$
    – Tomb
    Jul 2 '18 at 14:41
2
\$\begingroup\$

Java (OpenJDK 8), 61 bytes

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

Try it online!

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

MathGolf, 6 bytes

⌂♀*♂/n

Try it online!

Explanation

⌂       Push "*"
 ♀*     Multiply by 100
   ♂/   Divide into chunks of 10
     n  Join with newline

With an output control flag this could be 5 bytes, but I don't have that yet.

\$\endgroup\$
2
  • \$\begingroup\$ Out of curiosity, why is there a single-byte builtin to push the * character? Or are there builtins for *, +, -, and / and some kind of eval functionality for a mathematical expression in string format? \$\endgroup\$ Sep 20 '18 at 15:26
  • 2
    \$\begingroup\$ When I made the language, I wanted one single printable character to satisfy printing challenges where any character is valid. Luckily enough, I chose the asterisk! I also have a space character as a single command. \$\endgroup\$
    – maxb
    Sep 20 '18 at 19:01
2
\$\begingroup\$

Shakespeare Programming Language, 387 bytes

,.Ajax,.Ford,.Act I:.Scene I:.[Exeunt][Enter Ajax and Ford]Ford:You be twice the sum ofa cat twice twice the sum ofa cat a big big cat.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.Speak thy.You be twice the sum ofa cat a big big cat.Speak thy.Ajax:You be the sum ofyou a cat.Be you nicer the sum ofa cat a big big big cat?If notlet usScene I.

Try it online!

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

Stax, 4 bytes

╪n│╔

Run and debug it

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

R 33 bytes

cat(rep('**********',10),sep='
')

Try it online

I believe this is shorter than the other R answers on this question.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I believe this is shorter than yours, but Mamie's answer on the first page (sorted by oldest) is something like 26 bytes if the comments are to be believed. \$\endgroup\$
    – Giuseppe
    Feb 19 '19 at 22:14
  • \$\begingroup\$ Ah, I'd missed that one, thanks @Giuseppe. \$\endgroup\$
    – CT Hall
    Feb 19 '19 at 22:31
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.