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

375 Answers 375

1
9 10 11 12
13
0
\$\begingroup\$

Haskell, 34 bytes

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

λ> putStr$[0..9]>>([0..9]>>"*")++"\n"
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
5
  • \$\begingroup\$ Since the question stipulates you have to print the text your likely need a main=. I'd also point out that "*********\n" is shorter than ([0..9]>>"*")++"\n". \$\endgroup\$
    – Wheat Witch
    Jul 2 '18 at 0:21
  • 1
    \$\begingroup\$ @CatWizard No need for main. Your proposal is already taken. \$\endgroup\$ Jul 2 '18 at 0:24
  • \$\begingroup\$ @CatWizard I am running GHCi on my terminal. Isn't that allowed? \$\endgroup\$ Jul 2 '18 at 0:39
  • \$\begingroup\$ GHCi is allowed. It is generally considered a different language from Haskell. If other people are not using main and no one has done anything I think you will fine though. \$\endgroup\$
    – Wheat Witch
    Jul 2 '18 at 0:42
  • \$\begingroup\$ @CatWizard I added a demo so that readers know this is to be used in an interpreter. \$\endgroup\$ Jul 2 '18 at 0:46
0
\$\begingroup\$

Powershell, 12 bytes

@('*'*10)*10

Explanation

  '*'*10      create a string with 10 '*'
@('*'*10)     create an array with one element of string with 10 '*'
@('*'*10)*10  repeat elements of this array 10 times
\$\endgroup\$
1
0
\$\begingroup\$

Ahead, 21 18 bytes

~oK:k9*'N@k=11:+1~

Try it online!

\$\endgroup\$
0
\$\begingroup\$

ORK, 185 bytes

When this program starts:
I have a scribe called W
W is to write "**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********"

Try it online!

ORK does everything (even I/O and basic math) with objects. As far as this question goes, looping does not have to be one of them.

\$\endgroup\$
0
\$\begingroup\$

ESOPUNK, 167 78 77 bytes

MARK L
@REP 10
COPY 42 #STDO
@END
COPY 10 #STDO
TEST X = 9
ADDI X 1 X
FJMP L

I haven't been bothered to implement the preprocessor, but this should work when I do.

\$\endgroup\$
3
  • \$\begingroup\$ would it be possible to do an inner repetition? i.e. @REP 10 / @REP 10 / COPY 42 #STDO / @END / COPY 10 #STDO / @END \$\endgroup\$ Sep 28 '18 at 17:55
  • \$\begingroup\$ (also, does this language exist online anywhere?) \$\endgroup\$ Sep 28 '18 at 17:56
  • \$\begingroup\$ @ETHproductions Nesting @rep is explicitly not allowed in the game's docs. Link added in header. \$\endgroup\$ Sep 28 '18 at 18:34
0
\$\begingroup\$

Julia 1.0, 23 bytes

print(("*"^10*"\n")^10)

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can change the \n for a literal newline \$\endgroup\$
    – H.PWiz
    Dec 23 '18 at 13:54
0
\$\begingroup\$

A0A0, 145 bytes

A0A0
A0C3G1G1G1G1G1G1G1G1G1G1G1A0
A0P42P42P42P42P42P42P42P42P42P42G3P10A0
A0A1G-3G-3G-3G-3G-3G-3G-3G-3G-3G-3G-3A0
G-3
G-2G-2G-2G-2G-2G-2G-2G-2G-2

The top five lines are for the loop construction. A0A0 deletes instructions whenever it runs them, so those lines ensure that the loop keeps running. On line 3 are ten P42 instructions which print * (42 is the ascii code for an asterisk). The P10 instruction prints a new line.

The bottom line acts as a counter. For every execution of the loop it jumps to there and then jumps back to the loop. This consumes an instruction on that line. There are exactly nine instructions, so when it tries to go there when it has already printed ten lines the program will halt execution (since an empty line swill stop execution in A0A0).

\$\endgroup\$
0
\$\begingroup\$

Pascal (FPC), 57 bytes

var i:word;begin for i:=0to 9do writeln('**********')end.

Try it online!

This is probably the best one as I don't see how this can be improved in 9 characters or less which could be gained by removing *s.

\$\endgroup\$
0
\$\begingroup\$

Assembly (NASM, 32-bit, Linux), 122 bytes

mov ecx,10
n:push 0xa202a2a
push '****'
push '****'
loop n
mov edx,120
mov ecx,esp
mov ebx,1
mov eax,4
int 128
add esp,120

Try it Online!

\$\endgroup\$
2
  • \$\begingroup\$ If you're scoring by assembler code and not machine code, use some NASM magic \$\endgroup\$
    – EasyasPi
    Jan 22 at 20:56
  • \$\begingroup\$ @EasyasPi I try to make it portable \$\endgroup\$ Jan 25 at 15:32
0
\$\begingroup\$

Java 11, 48 chars

Method String.repeat​(int)

for(int i=0;i++<10;out.println("*".repeat(10)));

Try it online!


Java 5, 53 chars

Static imports

for(int i=0;i++<100;out.print("*"+(i%10>0?"":"\n")));

Try it online!


Java 3, 60 chars

Plain old Java

for(int i=0;i++<100;System.out.print("*"+(i%10>0?"":"\n")));

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Lua, 31 bytes

print(("**********\n"):rep(10))

Try it online!

Not very impressive but I think simpler is shorter in this case.

\$\endgroup\$
0
\$\begingroup\$

x86_16 machine code - 37 bytes

B4 0E            MOV AH, 0EH
B9 000A          MOV CX, 10
8B D1            MOV DX, CX
8B D9            MOV BX, CX

             .LOOP:
B0 2A            MOV AL, "*"
CD 10            INT 10H
E3 02            JCXZ .NEWLINE
E2 F8            LOOP .LOOP

             .NEWLINE:
B0 0A            MOV AL, 10
CD 10            INT 10H
B0 0D            MOV AL, 13
CD 10            INT 10H

8B CB            MOV CX, BX
4A               DEC DX
74 02            JZ .EXIT
75 E9            JNZ .LOOP

             .EXIT:
B8 004C          MOV AX, 4C00H
CD 21            INT 21H

Running using DOSBox :

10-GRID Screenshoot

\$\endgroup\$
0
\$\begingroup\$

Java, 46 bytes

$->System.out.print("**********\n".repeat(10))

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Twue, 31 bytes

a::~**********\n
::=
aaaaaaaaaa

Try it on the website!

Simply defines the replacement a which maps to printing 10 asterisks. The main body consists of 10 as. Trying a secondary replacement b::=aa or b::=aaaaa both yield 33 bytes, which is unfortunately longer.

Whereas in some Thue interpreters, outputting implicitly outputs a newline, that is not the case in Twue, which must manually insert the newline.

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

HTML, 136 bytes

**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********
\$\endgroup\$
6
  • 2
    \$\begingroup\$ You can use <pre> \$\endgroup\$
    – Leaky Nun
    Aug 5 '16 at 16:45
  • 10
    \$\begingroup\$ This answer is valid and allowed, but it's also extremely boring and unimaginative. \$\endgroup\$
    – DJMcMayhem
    Aug 5 '16 at 17:08
  • 1
    \$\begingroup\$ Ok, Can I post it in Markdown? \$\endgroup\$
    – Skxrda
    Aug 5 '16 at 17:08
  • 3
    \$\begingroup\$ You can easily get this to 114 bytes with <pre> followed by the 109-byte text... \$\endgroup\$
    – Timtech
    Aug 27 '16 at 21:43
  • 2
    \$\begingroup\$ I was hoping to join in on this one but unfortunately do not have the reputation for here yet. I'm not sure if this is an applicable method, but using html/emmet you can get this down to 20 bytes. ({**********}+br)*10 Alternatively p{**********}*10 is 16 bytes. New user to this site, so I'm unsure if the tab character counts. \$\endgroup\$
    – N.J.Dawson
    Sep 1 '16 at 16:12
1
9 10 11 12
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.