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 code-golf. Shortest answer in bytes wins.
-
3\$\begingroup\$ @DylanMeeus "You are to print this exact text:" \$\endgroup\$Leaky Nun– Leaky Nun2016年08月04日 12:56:25 +00:00Commented Aug 4, 2016 at 12:56
-
16\$\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– James T2016年08月04日 12:58:40 +00:00Commented Aug 4, 2016 at 12:58
-
9\$\begingroup\$ @LeakyNun Leaderboard snippet please! \$\endgroup\$anna328p– anna328p2016年08月04日 22:08:46 +00:00Commented Aug 4, 2016 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– dwana2016年08月05日 09:14:22 +00:00Commented Aug 5, 2016 at 9:14
-
3\$\begingroup\$ you say trailing new lines are acceptable. Are leading newlines acceptable too? \$\endgroup\$Albert Renshaw– Albert Renshaw2017年02月10日 02:34:47 +00:00Commented Feb 10, 2017 at 2:34
420 Answers 420
Brainfuck, 47 bytes
++++++++++[->++++>+>+<<<]>++>[-<..........>>.<]
++++++++++[->++++>+>+<<<] set the tape to 40 10 10
>++> set the tape to 42 10 10
[-<..........>>.<] come on
C (gcc), (削除) 41 (削除ここまで) 39 bytes
main(i){for(;++i<puts("**********"););}
-
\$\begingroup\$ what version of c? \$\endgroup\$Zaibis– Zaibis2016年08月04日 12:51:59 +00:00Commented Aug 4, 2016 at 12:51
-
\$\begingroup\$ @Zaibis Works fine on gcc: coliru.stacked-crooked.com/a/848cb22a00c35c29 . \$\endgroup\$orlp– orlp2016年08月04日 13:28:04 +00:00Commented Aug 4, 2016 at 13:28
-
4\$\begingroup\$ looks good, good ol' ANSI C. \$\endgroup\$YSC– YSC2016年08月04日 13:38:58 +00:00Commented Aug 4, 2016 at 13:38
-
4\$\begingroup\$
main(i){while(11-i++)puts("**********");}is an alternative, same length. \$\endgroup\$YSC– YSC2016年08月04日 13:41:06 +00:00Commented Aug 4, 2016 at 13:41 -
10\$\begingroup\$ I like the clever use of the return from
puts()(and of the initial value ofi). \$\endgroup\$Toby Speight– Toby Speight2016年08月08日 14:17:26 +00:00Commented Aug 8, 2016 at 14:17
Bash + coreutils, 19 bytes
I prefer to repeat stuff in Bash using 'yes'.
yes **********|head
I saved 2 bytes by @Neil's suggestion. But when the directory where you are running this command does not only contain files starting with a '.' dot you need to enclose the stars * with ".
Bash + coreutils, 21 bytes
yes "**********"|head
-
2\$\begingroup\$ Great idea to use
yes. We usually label such solutions as "Bash + coreutils". \$\endgroup\$manatwork– manatwork2016年08月04日 14:58:36 +00:00Commented Aug 4, 2016 at 14:58 -
13\$\begingroup\$ Nice that 10 lines coincidentally happens to be the default for
head. \$\endgroup\$Digital Trauma– Digital Trauma2016年08月04日 15:15:16 +00:00Commented Aug 4, 2016 at 15:15 -
3\$\begingroup\$ Can you save two bytes by requiring that any files in the current directory must begin with a
.? \$\endgroup\$Neil– Neil2016年08月04日 18:51:18 +00:00Commented Aug 4, 2016 at 18:51 -
\$\begingroup\$ @Neil, is your comment ment for my answer? If so, I do not get it :) \$\endgroup\$CousinCocaine– CousinCocaine2016年08月04日 18:57:39 +00:00Commented Aug 4, 2016 at 18:57
-
1\$\begingroup\$ You can also write
yes \**********|headwithout the restriction on files. \$\endgroup\$Florian F– Florian F2016年08月10日 13:51:39 +00:00Commented Aug 10, 2016 at 13:51
Vim, (削除) 13 (削除ここまで) 8 bytes
Saved 5 bytes thanks to @Lynn
(削除)
qqi*␛9.o␛q9@q
(削除ここまで)
10i*␛Y9p
10i*␛ insert 10 times *, and Y9p copy the line and paste it 9 times.
-
10\$\begingroup\$
10i*♥Y9pworks. \$\endgroup\$lynn– lynn2016年08月04日 11:25:33 +00:00Commented Aug 4, 2016 at 11:25 -
1\$\begingroup\$ That's insane vi. \$\endgroup\$Nathaniel Bubis– Nathaniel Bubis2016年08月07日 06:53:04 +00:00Commented Aug 7, 2016 at 6:53
-
\$\begingroup\$ I think you can count keystrokes instead of bytes for text editors, which means <ESC> would be shorter. \$\endgroup\$addison– addison2016年08月07日 14:55:40 +00:00Commented Aug 7, 2016 at 14:55
-
1\$\begingroup\$ Why ♥ and not ␛ ? \$\endgroup\$CL.– CL.2016年08月08日 12:54:30 +00:00Commented Aug 8, 2016 at 12:54
-
1\$\begingroup\$ I would have used
yy9pmyself, but nice job using capitals to save a character! \$\endgroup\$Joe Z.– Joe Z.2016年08月12日 21:08:35 +00:00Commented Aug 12, 2016 at 21:08
Pyth, 6 bytes
VT*T\*
T is 10 in Pyth, Vab executes statement b a times, \* is the asterisk character constant, and multiplying (*) a string and an integer repeats that string n times. Pyth's implicit printing with V means 10 lines are printed.
Hexagony, (削除) 37 (削除ここまで) (削除) 35 (削除ここまで) (削除) 34 (削除ここまで) 31
10"+}(=${";<$<1}42/.0@_=<>\;>(_
Expanded:
1 0 " +
} ( = $ {
" ; < $ < 1
} 4 2 / . 0 @
_ = < > \ ;
> ( _ . .
. . . .
Basically just has two for loops counting down from ten to zero, printing out an asterisk on the inner loop, and a newline on the outer loop.
Explanation:
This program consists of three main parts: initialisation of memory, a loop which prints ten asterisks and a loop which prints a newline. The loop which prints a newline also contains the loop which prints the asterisks.
First, the code runs the totally linear memory initialisation. The code works out to be: 10"+}42. This sets the memory of the nearby edges to look like:
10 \ / 10
|
42
42 is the ASCII code for the asterisk character, and the two tens will be used as our loop counters. Of note is that the memory pointer is currently pointing away from the two tens, so moving backwards will put us on one of the tens.
Next, we start the astersisk printing loop. Linearly, the code looks like: ;".._(. This prints out an asterisk, moves the memory pointer backwards and to the left and finally decrements the value there. After one iteration, the memory would look like:
10 \ / 9
|
42
Then we hit the loop condition: the bottom-leftmost >. If the edge we just decremented is still positive we bounce around and execute a { to move us back onto the 42. Then we hit a $ and return to the beginning of the printing loop, the ;, by skipping the <. If the value was zero, we head into the other loop.
The outer loop begins by resetting the recently zeroed memory edge to ten (this is the 10 in the code, going southwest). Then, we print out this ten as an ASCII character, which is a newline. Next, we move onto the other memory edge and decrement it with {( and then execute what amounts to a bunch of noops: =${_=. Now, after one iteration of this loop, memory would look like:
9 \ / 10
|
42
This time, the memory is facing outwards from the edge storing a nine in the above diagram. Next we execute the < which acts as the loop condition for the outer loop. If the value was non-zero we bounce around off of some mirrors, then begin executing meaningful instructions again after entering the top of the hexagon at the " moving southwest. This causes us to move backwards and to the left, onto the 42 again, but facing inwards. Then the = flips our direction, resetting the state properly to begin the inner loop again. If the edge was set to zero, the instruction pointer goes on a little adventure which does nothing until it exits the program.
The adventure begins by the instruction pointer venturing northeast, perilously disregarding the safety of the cardinal directions. It bravely ignores a mirror that is aligned with its diretion (/) and heroically leaps off of a trampoline ($) entirely evading the deadly trap of another, totally identical trampoline. Staring out at the emptiness of uninitialised hexagon edges, the pointer, without faltering for a moment, adds the two blank edges it faces together, setting the current edge to their sum: 0 (the edge was actually zero beforehand, but the pointer likes to believe this was pretty important). Since the edge is zero, the pointer makes a left turn at the fork in the road, walking into a mysterious forest (of hexagons). There, it finds itself disoriented, moving forwards and backwards and forwards, until it winds up at the same place in memory as it started. Thinking that the problem must be that the current edge was set to zero last time, the pointer bravely plants a 1 into the current edge. Then, the noble pointer investigates another path, one laid with... a trap! The current edge is decremented and set back to zero! The pointer, dazed by the shocking turn of events, stumbles back into the trap setting the current edge to negative one. Infuriated, the pointer attempts to return to the comparatively pleasant forest, only to notice that since the current edge is not positive, the paths have yet again shifted and the pointer finds itself walking into a cave. And by a cave, I mean the mouth of a giant hexagonal worm. Helpless, the pointer curses the sexinity with its dying breath. Also, the program ends.
-
\$\begingroup\$ Golly, I hope the worm was OK with swallowing a pointer. Those things can hurt. \$\endgroup\$Joffan– Joffan2016年08月08日 04:01:59 +00:00Commented Aug 8, 2016 at 4:01
-
8\$\begingroup\$ +1 for writing the most interesting—the only—Hexagony explanation I've ever read. I felt so tense when the edge was decremented! \$\endgroup\$juh– juh2016年08月28日 00:07:03 +00:00Commented Aug 28, 2016 at 0:07
Emacs, (削除) 10 (削除ここまで) 8 keystrokes
F3 C-1 0 * ENTER F4 C-9 F4
Explanation
F3 Starts a macro recording
C-1 0 * Apply 10 times command '*': prints 10 asterix'
ENTER Insert new line
F4 Stops the macro record
C-9 F4 Apply 9 times the macro
Thanks to Sean for saving two keystrokes, suggesting to replace C-udigit with C-digit.
-
9\$\begingroup\$ +1, I always upvote text editor answers (even though I'm more of a vim guy myself) :) \$\endgroup\$DJMcMayhem– DJMcMayhem2016年08月04日 15:10:35 +00:00Commented Aug 4, 2016 at 15:10
-
1\$\begingroup\$ If
C-ucounts as just one keystroke, then you can shave off two strokes by typingC-1 C-0(orM-1 M-0) instead ofC-u 1 0andC-9instead ofC-u 9. \$\endgroup\$Sean– Sean2016年08月05日 14:45:15 +00:00Commented Aug 5, 2016 at 14:45 -
23\$\begingroup\$ +1 because you had to suffer through using emacs to write this. \$\endgroup\$addison– addison2016年08月07日 14:54:27 +00:00Commented Aug 7, 2016 at 14:54
-
1\$\begingroup\$ Alternatively (saves nothing) the line repetition can be done inside the macro:
F3C-10*ENTERC-10F4\$\endgroup\$Jonathan Carroll– Jonathan Carroll2016年08月09日 05:14:37 +00:00Commented Aug 9, 2016 at 5:14 -
\$\begingroup\$ @JonathanCarroll yes it would save bytes if we were to print more than 10 lines ;) \$\endgroup\$YSC– YSC2016年08月09日 08:28:54 +00:00Commented Aug 9, 2016 at 8:28
Jelly, 7 bytes
"*x5Ṅ9¡
What's going on?
"*x5Ṅ9¡ - No arguments
"* - character literal, *
x - multiply (dyadic operation)
5 - integer literal, 10 (we have now constructed the string '**********')
Ṅ - Print & linefeed (monadic operation)
9 - integer literal, 9
¡ - Repeat n times (n is 9 as the first Ṅ is not a repeat)
Test it on tryitonline
-
10\$\begingroup\$ I really like the
Ṅ9¡. \$\endgroup\$Dennis– Dennis2016年08月07日 20:16:54 +00:00Commented Aug 7, 2016 at 20:16 -
\$\begingroup\$ List version:
"*ẋ5Wẋ5. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年10月01日 14:51:47 +00:00Commented Oct 1, 2016 at 14:51 -
\$\begingroup\$ @EriktheGolfer you'd need a
Yon the end to "print this exact text" \$\endgroup\$Jonathan Allan– Jonathan Allan2016年10月01日 14:54:19 +00:00Commented Oct 1, 2016 at 14:54 -
\$\begingroup\$ @JonathanAllan It is a list on its own, though. It isn't meant to "print this exact text", but, if you want to work on it, you'll use it. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年10月01日 14:55:59 +00:00Commented Oct 1, 2016 at 14:55
PowerShell, (削除) 14 (削除ここまで) 12 bytes
,('*'*10)*10
Constructs a string of asterisks of length 10 using string multiplication. Encapsulates that in parens and feeds that into the comma-operator to construct an array. We use array multiplication to construct a 10-element array consisting of that element (i.e., a 10-element array of asterisk strings). That's left on the pipeline, and output is implicit (since the default Write-Output for an array is newline-separated, we get that for free -- thanks to @Joey for the clarification).
Older, 14 bytes
0..9|%{'*'*10}
Full program. Loops from 0 to 9 through a ForEach-Object loop |%{...}. Each iteration, we use string multiplication to create a length-10 string of *. Those resulting strings are left on the pipeline, and output at the end is implicit (since the default Write-Output for an array is newline-separated, we get that for free -- thanks to @Joey for the clarification).
-
6\$\begingroup\$ I like it, because powershell can get so verbose. Yet this is elegant and short. \$\endgroup\$dwana– dwana2016年08月04日 13:25:13 +00:00Commented Aug 4, 2016 at 13:25
-
\$\begingroup\$ Well, technically the array is never passed through a
ToString, it's unrolled and passed element by element to Write-Output. In contexts where the array is converted to a string, you get its elements space-separated. \$\endgroup\$Joey– Joey2016年08月09日 14:46:08 +00:00Commented Aug 9, 2016 at 14:46 -
\$\begingroup\$ @Joey Ah, fair, that's a better way to put it. I'll edit the wording (and my answer template ;-)). \$\endgroup\$AdmBorkBork– AdmBorkBork2016年08月09日 14:58:13 +00:00Commented Aug 9, 2016 at 14:58
-
1\$\begingroup\$ I may be biased here because I'm involved with a PowerShell implementation so I had to learn a lot of what actually goes on inside the interpreter ;) \$\endgroup\$Joey– Joey2016年08月09日 15:00:03 +00:00Commented Aug 9, 2016 at 15:00
V, 7 bytes
10é*10Ä
About as straightforward as an answer can be.
Explanation:
10 "10 times:
é* "insert an asterisk
10Ä "make 10 copies of the current line
5 bytes:
10O±*
Explanation:
10O " Insert the following on the next ten lines:
± " 10 copies of
* " an asterisk
This didn't work when the challenge was posted because of a bug.
-
\$\begingroup\$ Point of order: é and Ä are multibyte characters (at least in utf-8, as you have them here) so this program is 9 bytes long. \$\endgroup\$rob– rob2016年08月04日 19:35:11 +00:00Commented Aug 4, 2016 at 19:35
-
8\$\begingroup\$ @rob They are encoded in utf-8 here, because that's just the way the browser works. V uses "Latin1" encoding, where they are
E9andC4respectively. \$\endgroup\$DJMcMayhem– DJMcMayhem2016年08月04日 19:41:40 +00:00Commented Aug 4, 2016 at 19:41
Jellyfish, (削除) 12 (削除ここまで) 10 bytes
Thanks to Zgarb for saving 2 bytes.
P$'*
&;10
Explanation
Using more conventional notation, this program represents the following expression:
P( $( &;(10), '* ) )
&; takes a single value and creates a pair with two times that value, so &;(10) gives us [10 10]. Then $ is reshape which forms a 10x10 grid of asterisks. Finally, P prints the array in "matrix format" which prints each string on its own line.
HTML & CSS, (削除) 104 (削除ここまで) 60 bytes
p::after{content:"**********"
<p><p><p><p><p><p><p><p><p><p>
I'm unsure if the byte count is correct (as I'm not counting the <style> tags for CSS. The HTML could also be shortened if I used a HTML preprocessor, but I'm unsure if that's breaking rules
Thanks to manatwork and Business Cat.
See my Jade entry of 36 bytes
-
\$\begingroup\$ You can leave out the self closing
/s and write all tags in the same line. But better change the tags to<p>as it is shorter even if you need to addp{margin:0}. \$\endgroup\$manatwork– manatwork2016年08月05日 13:28:32 +00:00Commented Aug 5, 2016 at 13:28 -
2\$\begingroup\$ This is not valid css. You need the closing bracket! \$\endgroup\$Richard Hamilton– Richard Hamilton2016年08月05日 16:37:59 +00:00Commented Aug 5, 2016 at 16:37
-
31\$\begingroup\$ @RichardHamilton valid css and working css are not the same thing \$\endgroup\$undergroundmonorail– undergroundmonorail2016年08月07日 08:51:10 +00:00Commented Aug 7, 2016 at 8:51
-
2\$\begingroup\$ @ClementNerma Why should anyone put code after this? \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年09月13日 12:47:13 +00:00Commented Sep 13, 2016 at 12:47
-
3\$\begingroup\$ you can leave off the last
>I believe \$\endgroup\$12Me21– 12Me212017年02月06日 14:47:04 +00:00Commented Feb 6, 2017 at 14:47
APL, 9 bytes
Works on all APLs ever made.
10 10⍴'*'
10 10 ten rows and ten column
⍴ cyclically repeating
'*' a star
-
\$\begingroup\$ It's worth noting that this solution is not Dyalog-specific; it also works with GNU APL. \$\endgroup\$Arc676– Arc6762017年06月15日 01:20:51 +00:00Commented Jun 15, 2017 at 1:20
-
4\$\begingroup\$ @Arc676 True. In fact, it works on all APLs ever made. \$\endgroup\$Adám– Adám2017年06月15日 01:26:28 +00:00Commented Jun 15, 2017 at 1:26
-
2\$\begingroup\$ argh, I need just one more byte... I almost beat you with the "format" trick:
∘.⊢⍨⍕⍨,⍨5\$\endgroup\$ngn– ngn2018年02月06日 07:50:40 +00:00Commented Feb 6, 2018 at 7:50 -
1\$\begingroup\$ @ngn That's wonderfully horrible! \$\endgroup\$Adám– Adám2018年02月06日 08:59:10 +00:00Commented Feb 6, 2018 at 8:59
Python 2, (削除) 22 (削除ここまで) 21 bytes
print('*'*10+'\n')*10
-
3\$\begingroup\$
print(("*"*10+'\n')*10)worked for me. \$\endgroup\$piepi– piepi2016年08月07日 03:31:43 +00:00Commented Aug 7, 2016 at 3:31 -
8\$\begingroup\$ @piepi That's why you're usually better off golfing in Python 2 - you don't need parentheses when calling
print. \$\endgroup\$shooqie– shooqie2016年08月07日 07:41:05 +00:00Commented Aug 7, 2016 at 7:41 -
\$\begingroup\$ @shooqie You can't beat a Python3 solution using Python2. Python2 and Python3 are different languages. You also wouldn't compare the Python2 solution to a specialized golf language like Pyth. \$\endgroup\$Alfe– Alfe2019年10月14日 13:41:10 +00:00Commented Oct 14, 2019 at 13:41
-
\$\begingroup\$ Original code prints TypeError: unsupported operand type(s) for *: 'NoneType' and 'int' #Edit didn't notice it was python 2. Piepi's code worked for me \$\endgroup\$Rivered– Rivered2021年03月14日 02:19:46 +00:00Commented Mar 14, 2021 at 2:19
Notepad, (削除) 34 (削除ここまで) 31 keystrokes
**********
^A^C↓^V^A^C↓^V^V^V^V
^ denotes Ctrl-<following character> keypress, ↑↓ are up and down keys, respectively.
Props to Crypto for 3 saved keystrokes.
-
2\$\begingroup\$ You should use keystrokes to count this. \$\endgroup\$Leaky Nun– Leaky Nun2016年08月04日 16:08:35 +00:00Commented Aug 4, 2016 at 16:08
-
1\$\begingroup\$ That's Shift+Up. Ctrl+Up is something else. \$\endgroup\$Neil– Neil2016年08月04日 18:53:14 +00:00Commented Aug 4, 2016 at 18:53
-
1\$\begingroup\$ 31 keystrokes
**********↵^A^C↓^V^A^C↓^V^V^V^V\$\endgroup\$Crypto– Crypto2016年08月05日 05:52:05 +00:00Commented Aug 5, 2016 at 5:52 -
1\$\begingroup\$ 26 keystrokes
*****^A^C^V^V↵^A^C^V^A^C^V^V^V^V^V\$\endgroup\$Andy– Andy2016年08月08日 17:24:21 +00:00Commented Aug 8, 2016 at 17:24 -
7\$\begingroup\$ 23 keystrokes
**^A^C^V^V^V^V^V↵^A^C^V^V^A^C^V^V^V^V^V\$\endgroup\$Andy– Andy2016年08月08日 17:26:27 +00:00Commented Aug 8, 2016 at 17:26
MATLAB, 14 bytes
repmat('*',10)
-
\$\begingroup\$ I don't have MATLAB to test this, so I'm unsure if this has spaces between the
*s. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年10月01日 15:59:16 +00:00Commented Oct 1, 2016 at 15:59 -
\$\begingroup\$ @EriktheGolfer clearly not :) \$\endgroup\$PieCot– PieCot2016年10月01日 19:41:50 +00:00Commented Oct 1, 2016 at 19:41
-
\$\begingroup\$
matsuggests a matrix, that's why I asked. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年10月02日 06:23:23 +00:00Commented Oct 2, 2016 at 6:23 -
3\$\begingroup\$ @EriktheGolfer excuse me, I was rude. Mat, in fact, refers to a matrix, but in this case is a matrix of char, that is an array of strings (every row is like a string). So, the outupt matrix is printed one row for line, without spaces between elements of the same row. \$\endgroup\$PieCot– PieCot2016年10月02日 15:07:35 +00:00Commented Oct 2, 2016 at 15:07
Java 7, 63 bytes
void f(){for(int i=0;i++<10;)System.out.println("**********");}
Just for kicks. I can't seem to find any tricks to make this shorter. Trying to add logic for a 100-loop or returning a String instead of printing just ends up worse.
-
1\$\begingroup\$ You can shave it off by one byte if you declare
ias a class variable (it defaults to0):int i;void f(){for(;i++<10;)System.out.println("**********");}\$\endgroup\$shooqie– shooqie2016年08月04日 09:51:16 +00:00Commented Aug 4, 2016 at 9:51 -
3\$\begingroup\$ That would break reusability unless I did
i=0somewhere in the function, negating the savings. \$\endgroup\$Geobits– Geobits2016年08月04日 09:54:44 +00:00Commented Aug 4, 2016 at 9:54 -
3\$\begingroup\$ +1 Seems you're indeed right that this is the shortest.. Recursive is 65 bytes:
int i=10;void f(){System.out.println("**********");if(i-->0)g();}; One by one recursive is 67 bytes:int i=99;void f(){System.out.print(i%10<1?"*\n":"*");if(i-->0)g();}; Using String-constructor with char-array is 82 bytes:void g(){System.out.print(new String(new char[10]).replace("0円","**********\n"));}; and a String.format is 81 bytes:void g(){System.out.print(String.format("%010d",0).replace("0","**********\n"));}. Ah well, we tried. ;) \$\endgroup\$Kevin Cruijssen– Kevin Cruijssen2016年08月04日 11:10:32 +00:00Commented Aug 4, 2016 at 11:10 -
2\$\begingroup\$ But does it count without having to add the class declaration itself? What is the shortest java7 full program that can do this? \$\endgroup\$jsbueno– jsbueno2016年08月04日 12:54:37 +00:00Commented Aug 4, 2016 at 12:54
-
1\$\begingroup\$ You have to count the import statement, so it wouldn't work for savings here. \$\endgroup\$Geobits– Geobits2016年08月07日 19:09:54 +00:00Commented Aug 7, 2016 at 19:09
Ruby, 15 characters
puts [?**10]*10
Sample run:
bash-4.3$ ruby -e 'puts [?**10]*10'
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
-
\$\begingroup\$ Can you explain
?**10? It does indeed create a string of ten asterisks, but I'm unclear how... \$\endgroup\$Eric Haynes– Eric Haynes2016年08月09日 00:05:34 +00:00Commented Aug 9, 2016 at 0:05 -
4\$\begingroup\$ The
?is the character literal notation, so?* == '*'. The 2nd*is theString.*method, so?**10 == '*'.*(10). \$\endgroup\$manatwork– manatwork2016年08月09日 07:26:46 +00:00Commented Aug 9, 2016 at 7:26 -
\$\begingroup\$ Afraid I still don't understand why
?is the literal notation of anything, but perhaps some questions are better left unanswered. ;) \$\endgroup\$Eric Haynes– Eric Haynes2016年08月10日 09:09:44 +00:00Commented Aug 10, 2016 at 9:09 -
\$\begingroup\$ Sorry, I can't find any reference on this. Is simply the Ruby syntax, which allows various string literal notations plus one in case the string is 1 character long: a
?mark followed by the character, without requiring a closing pair of the?mark. \$\endgroup\$manatwork– manatwork2016年08月10日 09:53:17 +00:00Commented Aug 10, 2016 at 9:53 -
1\$\begingroup\$ I found it in the reference here: ruby-doc.org/core-2.3.0/doc/syntax/literals_rdoc.html
There is also a character literal notation to represent single character strings, which syntax is a question mark (?) followed by a single character or escape sequence that corresponds to a single codepoint in the script encoding:\$\endgroup\$Eric Haynes– Eric Haynes2016年08月11日 22:53:11 +00:00Commented Aug 11, 2016 at 22:53
Emojicode, 54 bytes
🏁🍇🔂i⏩0 10🍇😀🔤**********🔤🍉🍉
Explanation:
🏁🍇 👴 The beginning of program.
🔂 i ⏩ 0 10 🍇 👵 This is called a "range".
It basically starts with i=0 and increments until i=10, then exits. 👵
😀 🔤**********🔤 👵 😀 is printing class.
The 🔤s make the characters they surround string literals. 👵
🍉 👴 End of range
🍉 👴 End of program
-
3\$\begingroup\$ I count 54 utf-8 bytes. \$\endgroup\$Conor O'Brien– Conor O'Brien2016年08月29日 02:46:07 +00:00Commented Aug 29, 2016 at 2:46
-
\$\begingroup\$ This language hates WIndows 7... \$\endgroup\$John Dvorak– John Dvorak2016年12月27日 16:11:09 +00:00Commented Dec 27, 2016 at 16:11
05AB1E, 7 bytes
×ばつ,
Explanation
TF # 10 times do:
×ばつ # repeat asterisk 10 times
, # print with newline
-
1\$\begingroup\$
т'*×Tô»is another completely different one lol. \$\endgroup\$Magic Octopus Urn– Magic Octopus Urn2018年02月08日 15:28:35 +00:00Commented Feb 8, 2018 at 15:28 -
\$\begingroup\$
TLú'*ζ»using the zip-filler was another idea... bad one though. \$\endgroup\$Magic Octopus Urn– Magic Octopus Urn2018年02月08日 15:40:14 +00:00Commented Feb 8, 2018 at 15:40
Brainfuck, (削除) 46 (削除ここまで) 43 bytes
+[[---<]+[-->]<]<<[--<<++..........-->>>.<]
Try it online! Requires an interpreter with a tape that is open on the left and has 8-bit cells.
The first part of this program +[[---<]+[-->]<] sets up the tape like so:
[255, 250, 245, ... 15, 10, 5, 0, 250, 240, 230, ..., 40, 30, 20, 10, 0]
^
This gives a 40 for outputting asterisks (*, ASCII 42), a 20 to use as a loop counter, and a 10 to use for outputting newlines.
R, (削除) 27 (削除ここまで) 29 bytes
cat(rep('\r**********\n',10))
An alternate answer (34 bytes) is: cat(rep('**********',10),sep='\n')
-
-
\$\begingroup\$ Thanks, it works adding
\r. \$\endgroup\$Mamie– Mamie2016年08月04日 19:48:17 +00:00Commented Aug 4, 2016 at 19:48 -
1\$\begingroup\$ Another alternative, too many (37) bytes:
cat(matrix('*',10,10),fill=10,sep='')r-fiddle \$\endgroup\$Jonathan Carroll– Jonathan Carroll2016年08月09日 04:48:24 +00:00Commented Aug 9, 2016 at 4:48 -
\$\begingroup\$ Another alternative, also 29 bytes:
write(rep("*",100),"",10,,"")\$\endgroup\$Giuseppe– Giuseppe2018年02月13日 16:14:45 +00:00Commented Feb 13, 2018 at 16:14 -
1\$\begingroup\$ And
write(rep("**",50),1,5,,"")is 27 bytes and avoids the first carriage return. \$\endgroup\$J.Doe– J.Doe2018年09月18日 08:57:37 +00:00Commented Sep 18, 2018 at 8:57
PHP, 32 bytes
for(;$i++<10;)echo"**********
";
(variant 32 bytes - was written with echo)
<?=str_repeat("**********
",10);
(variant 33 bytes)
<?=str_pad("",110,"**********
");
(variant 33 bytes)
for(;$i++<110;)echo$i%11?"*":"
";
(variant 35 bytes)
for(;$i++<10;)printf("%'*10s
",'');
(variant 38 bytes)
<?=($a=str_repeat)($a("*",10)."
",10);
-
3\$\begingroup\$ The second one can be golfed to 32 bytes as well:
<?=str_repeat("**********↵",10);\$\endgroup\$insertusernamehere– insertusernamehere2016年08月04日 13:41:12 +00:00Commented Aug 4, 2016 at 13:41 -
1\$\begingroup\$ As you already have a nice collection of alternatives, here is another for fun:
echo chunk_split(str_repeat("*",100),10);The longest so far, just in my vision this is the PHP way to do it. \$\endgroup\$manatwork– manatwork2016年09月01日 07:37:52 +00:00Commented Sep 1, 2016 at 7:37 -
\$\begingroup\$ Can be a byte shorter with WIN-1252 encoding:
for(;++$i<111;)echo$i%11?~Õ:~õ;orfor(;++$i<11;)echo~ÕÕÕÕÕÕÕÕÕÕõ;\$\endgroup\$aross– aross2016年09月29日 15:50:12 +00:00Commented Sep 29, 2016 at 15:50 -
\$\begingroup\$ Another modulo variant for 33 bytes:
for(;$i++<110;)echo"*↵"[$i%11<1];. And to add a 37 bytes solution to that collection:for(;$i++<110;)echo chr($i%11?42:10);. \$\endgroup\$Titus– Titus2017年06月09日 08:50:19 +00:00Commented Jun 9, 2017 at 8:50
MATL, 8 bytes
'*'10tX"
'*' % Push '*' (string containing an asterisk)
10t % Push 10 twice
X" % Repeat the string ×ばつ10 times. Implicitly display
JavaScript (ES6), 37 bytes
console.log(`**********
`.repeat(10))
A straightforward answer.
-
8\$\begingroup\$ Cant you save 6 by using
alert? \$\endgroup\$Kevin L– Kevin L2016年08月04日 12:45:37 +00:00Commented Aug 4, 2016 at 12:45 -
2\$\begingroup\$ Arguably you could save 13 bytes by removing the
console.log()and specifyingREPLin the title. \$\endgroup\$Patrick Roberts– Patrick Roberts2016年08月04日 23:56:05 +00:00Commented Aug 4, 2016 at 23:56
Brainfuck, 74 bytes
first brainfuck submission ever, first reasonable length program, too
+++>>+++>>+++++++[<+<+<<+>>>>-]<[>++++++<-]<<<[->++++++++++[>>>.<<<-]>.<<]
+++>>+++>>+++++++[<+<+<<+>>>>-]<[>++++++<-] < sets tape to 10 0 10 0 42
<<< moves to the first 10
[->++++++++++[>>>.<<<-]>.<<] <
loops while the first cell of the tape is not zero:
subtracts 1 from first cell
sets the second cell to 10,
loops while second cell is not zero: prints 42 cell, subtracts from second cell
moves to third cell, prints it
-
-
-
-
14\$\begingroup\$ points for trying though, right..? ;_; \$\endgroup\$Destructible Lemon– Destructible Lemon2016年08月04日 11:13:34 +00:00Commented Aug 4, 2016 at 11:13
-
\$\begingroup\$ also post the answer yourself \$\endgroup\$Destructible Lemon– Destructible Lemon2016年08月04日 11:14:47 +00:00Commented Aug 4, 2016 at 11:14
Haskell, 29 bytes
putStr$[0..9]>>"**********\n"
<list1> >> <list2> makes (length <list1>) copies of <list2>.
vim, 8 bytes
10a*<ESC>Y9p
<ESC> is 0x1b.
Annotated
10a*<ESC> # append * 10 times
Y # copy line into default register
9p # paste 9 times
-
1\$\begingroup\$ Congrats on posting in the Language of the Month! \$\endgroup\$Makonede– Makonede2021年04月14日 22:37:29 +00:00Commented Apr 14, 2021 at 22:37
J, (削除) 10 (削除ここまで) 9 bytes
1 byte thanks to @Adám.
10 10$'*'
Explanation
10 10 specifies the dimension to the operator $ which builds an array with the specified dimensions.
-
1\$\begingroup\$ Also 9 bytes:
'*'$~,~10\$\endgroup\$Conor O'Brien– Conor O'Brien2016年08月04日 18:26:36 +00:00Commented Aug 4, 2016 at 18:26
Cheddar, (削除) 21 (削除ここまで) 20 bytes
print('*'*10+'
')*10
Yet another straightforward answer.
-
4\$\begingroup\$ Use a literal newline to save 1 byte \$\endgroup\$Leaky Nun– Leaky Nun2016年08月04日 10:51:22 +00:00Commented Aug 4, 2016 at 10:51
-
2\$\begingroup\$ Make it a function using
->instead of print maybe? \$\endgroup\$Downgoat– Downgoat2016年08月04日 19:00:59 +00:00Commented Aug 4, 2016 at 19:00