| Bytes | Lang | Time | Link |
|---|---|---|---|
| 039 | AWK | 241106T211013Z | xrs |
| 028 | Raku Perl 6 rakudo | 241213T165528Z | xrs |
| 007 | MathGolf | 241108T080212Z | Kevin Cr |
| 032 | Haskell | 241107T015432Z | Dannyu N |
| 005 | Japt mR | 170602T231445Z | Shaggy |
| 005 | Vyxal j | 210529T071115Z | emanresu |
| 031 | Zsh | 210529T065022Z | pxeger |
| 004 | Canvas | 180908T160040Z | dzaima |
| 007 | Charcoal | 170603T004814Z | Neil |
| 019 | Perl 5 | 171022T031741Z | Xcali |
| 011 | J | 171021T205309Z | FrownyFr |
| 049 | R | 171021T200343Z | Rudier |
| 050 | Tcl | 171021T192915Z | sergiol |
| 036 | JavaScript ES6 | 170603T101056Z | Shaggy |
| 011 | APL Dyalog | 170608T123445Z | Adá |
| 145 | brainfuck | 170604T162156Z | vityavv |
| 010 | CJam | 170604T180238Z | Esolangi |
| 046 | C | 170603T000516Z | dbandstr |
| 025 | PowerShell | 170602T231233Z | colsw |
| 078 | C# | 170603T195925Z | Arthur R |
| 055 | Bash | 170602T232227Z | Conor O& |
| 008 | Pyke | 170603T152818Z | Blue |
| 009 | Ohm | 170603T153303Z | Datboi |
| 014 | QBIC | 170603T082717Z | steenber |
| 007 | V | 170603T074545Z | user4180 |
| 026 | Python 3 | 170603T060501Z | ovs |
| 005 | Pyth | 170602T230202Z | Maria |
| 074 | Go | 170603T013054Z | totallyh |
| 032 | Retina | 170603T003639Z | Neil |
| 197 | #+ | 170602T234555Z | Conor O& |
| 007 | Japt | 170602T232415Z | ETHprodu |
| 070 | R | 170602T232532Z | Giuseppe |
| 007 | Jelly | 170602T230424Z | Jonathan |
| 007 | MATL | 170602T225413Z | Luis Men |
| 006 | 05AB1E | 170602T225253Z | Emigna |
| 032 | Python 2.7 | 170602T223848Z | Koishore |
| 012 | J | 170602T223503Z | Conor O& |
| 005 | SOGL | 170602T222300Z | dzaima |
| 026 | Mathematica | 170602T221951Z | ZaMoC |
AWK, 43 39 bytes
{for(;i<$2*$1;)printf"[]"(i++%$1?RS:X)}
{for(;i++<$1;)s=s"[]";for(;j++<$2;)print s}
Raku (Perl 6) (rakudo), 28 bytes
$a,$b {put "[]"xx$a for ^$b}
$a,$b { # columns, rows
put "[]" # print a box
xx$a # repeat $a times
for ^$b} # repeat $b lines
MathGolf, 7 bytes
û[]*a*n
Inputs in the order \$w,h\$.
Explanation:
û[] # Push string "[]"
* # Repeat it the first (implicit) input-integer amount of times as string
a # Wrap this string into a list
* # Repeat it the second (implicit) input-integer amount of times as list
n # Join this list by newlines
# (after which the entire stack is output implicitly as result)
PS: Æû[]*p (loop with print - 6 bytes) wouldn't work, because MathGolf starts from the first implicit input again when it runs out of inputs, instead of reusing the final input if there are no more, like most golfing languages do (e.g. inputs 4,2 would result in output "[][]\n[][][][]\n[][]\n[][][][]" instead of the intended "[][]\n[][]\n[][]\n[][]").
Vyxal j, 6 5 bytes
ƛk[⁰*
Takes height then width.
-1 thanks to lyxal.
ƛ # map 0...(height) to...
k[ # `[]`
* # repeated...
⁰ # (width)
* # times
# (j flag) join by newlines
Charcoal, 8 7 bytes
EN×[]Iη
Try it online! Link is to verbose version of code. Takes input in the order height, width. Charcoal's drawing primitives aren't suited to this, so this just takes the easy way out and repeats the [] string appropriately. Explanation:
N First input as a number
E Map over implcit range
η Second input
I Cast to number
[] Literal string
× Repeat
Implicitly print on separate lines
R, 49 bytes
s=scan;cat(rep(c(rep("[]",s()),"\n"),s()),sep="")
Ungolfed :
s=scan # Creates an alias for the scan function
cat( # Prints to STDOUT
rep( # The repetion of the following string :
c(rep("[]",s()),"\n"), # "[]" repeated the number of times inputed by the user, followed by a linebreak
s()), # This number of time (again, user inputed)
sep="") # with no separator
JavaScript (ES6), 43 36 bytes
From the comments, a trailing newline is now permitted.
w=>h=>("[]".repeat(w)+`
`).repeat(h)
Try it
f=
w=>h=>("[]".repeat(w)+`
`).repeat(h)
oninput=_=>o.innerText=f(+i.value)(+j.value);o.innerText=f(i.value=2)(j.value=2)
*{font-family:sans-serif;}
input{margin:0 5px 0 0;width:50px;}
<label for=i>w: </label><input id=i type=number><label for=j>h: </label><input id=j type=number><pre id=o>
APL (Dyalog), 11 bytes
'[]'⍴⍨⊢,2×⊣
'[]' the string
⍴⍨ cyclically repeated to fill the shape
⊢ right argument (rows)
, and
2× twice
⊣ the left argument (columns)
brainfuck, 145 bytes
+++++++++[>++++++++++<-]>+[>+>+<<-]>>++>,>+++++++++[<----->-]<--->>>,>+++++++++[<----->-]<--->++++++++++<[<<<[>+>+<<-]>[<<<.>.>>-]>[<<+>>-]>>.<-]
My first ever code golf! Yay!
The input is in ascii + 48, so in order to do 50, 50 you must input b, b (the ascii letters for 98)
Explanation
+++++++++[>++++++++++<-]>+ Get the opening square bracket into first position
[>+>+<<-] Get it into the second and third position
>>++ Get the third position to be the closing bracket
>
,>+++++++++[<----->-]<--- Get first number into fourth cell
>>>
,>+++++++++[<----->-]<--- Get second number into seventh cell
>++++++++++ get newline into 8th position
<
[ Start our height loop
<<<[>+>+<<-] Get the width into the fifth and sixth positions
>[ Start our width loop at the fifth position
<<<.>. Print the second and third positions
>>-] Decrement the fifth position
>
[<<+>>-] copy the sixth position into the fourth position
>>. print newline
<-]
CJam, 10 bytes
l~"[]"*N+*
C, 47 46 bytes
f(w,h){for(h*=w;h--;)printf(h%w?"[]":"[]\n");}
or
f(w,h){for(h*=w;h--;)printf("[]%c",h%w?0:10);}
My first code golf attempt, did I miss anything obvious?
PowerShell, 25 Bytes
param($w,$h),("[]"*$w)*$h
-3 thanks to Mathias!
C#, 78 bytes
(w,h)=>"".PadLeft(h).Replace(" ","".PadLeft(w).Replace(" ","[]")+'\n').Trim();
This is shorter than with for-loops and I'm not aware of any function in C# which can repeat with less code.
Bash, 55 bytes
seq $(($1*$2))|sed s/.*/[]/|tr -d "
"|fold -w $(($1*2))
Try it online! Uses the TIO flavor of bash, since I run windows.
Ohm, 9 bytes
M"[]"َJ,
Explanation
M"[]"َJ,
M //Executes code input1 times
"[]" //Pushes []
َ //Duplicates [] input2 times
J //Joins the stack
, //Prints with a trailing newline
QBIC, 14 bytes
[:|?[:|?@[]`';
Explanation:
[:| FOR a = 1 to (read input from cmd line)
? PRINT a newlne
[:| FOR c = 1 to (read input from cmd line)
?@[]` PRINT A$ (containing the box)
'; and inject a semicolon in the compiled QBasic code to suppress newlines
This takes its arguments in the order of #rows, #cols. Output starts with a newline.
V, 7 bytes
Ài[]<esc>ÀÄ
where <esc> is 0x1b.
Explanation
Ài[]<esc> " arg1 times insert []
ÀÄ " arg2 times duplicate this line
Pyth - 7 5 bytes
-2 bytes by a clever trick thanks to insert_name_here
VE*`Y
Explanation:
VE*`Y
V # Loop
E # <input> number of times
`Y # String representation of empty list (used to be "[]", but insert_name_here pointed out this shorter alternative)
* # repeat string implicit input number of times
# implicit print
Go, 74 bytes
import."strings"
func(x,y int)string{return Repeat(Repeat("[]",x)+"\n",y)}
Retina, 32 bytes
.+
$*
1(?=1*(¶1+))|.
$1
G`1
1
[]
Try it online! Takes height and width input on separate lines.
;#+, 197 bytes
>;;;;;;~++++++++:>~;;;;:>~*(-:~<~+-::>-:::<~<-+++++++++~:::<~+-:::>-::*)-::<-::::>-::(;)::>-::*(-:~<~+-::>-:::<~<-+++++++++~:::<~+-:::>-::*)-:<~<;;;;;-+>-:<-:-(-:::~<-:::(~<#<-;;-#~;)-:<#-::<;>-:-)
Try it online! Requires a zero byte after each input number.
I kinda don't know how this works. What I can tell you is that this part of the code:
*(-:~<~+-::>-:::<~<-+++++++++~:::<~+-:::>-::*)-::<-::::>-::(;)::>-::*(-:~<~+-::>-:::<~<-+++++++++~:::<~+-:::>-::*)
is parsing the input numbers.
Japt, 7 bytes
6 bytes of code, +1 for the -R flag.
VÆç"[]
Doesn't work in the latest version due to a bug with ç, but it does work in commit f619c52. Test it online!
Explanation
VÆ ç"[]
VoX{Uç"[]"} // Ungolfed
// Implicit: U, V = input integers
VoX{ } // Create the range [0...V) and replace each item X with
Uç"[]" // U copies of the string "[]".
-R // Join the result with newlines.
// Implicit: output result of last expression
R, 70 bytes
p=paste
function(w,h)p(rep(p(rep('[]',w),collapse=''),h),collapse='
')
Returns an anonymous function that constructs and returns the string.
45 bytes, non-conforming
function(w,h)write(matrix('[]',w,h),'',w,,'')
An anonymous function that prints out the string in the desired format.
Jelly, 7 bytes
ẋ⁾[]ẋ$Y
A dyadic link returning a list of characters (or a full program printing the result).
How?
ẋ⁾[]ẋ$Y - Main link: number w, number h e.g. 2, 3
ẋ - repeat w h times [2,2,2]
$ - last two links as a monad:
⁾[] - literal ['[',']'], "[]"
ẋ - repeat list (vectorises) ["[][]","[][]","[][]"]
Y - join with newlines "[][]\n[][]\n[][]"
- if a full program, implicit print
MATL, 7 bytes
v&DiiX"
Explanation
v % Concatenate the (non-existing) stack contents: gives []
&D % String representation: gives '[]'
ii % Take two inputs
X" % Repeat those numbers of times vertically and horizontally. Implicit display
05AB1E, 6 bytes
F„[]×,
Explanation
Input takes as height, width
F # height times do
„[] # push "[]"
× # repeat width times
, # print with newline
J, 12 bytes
'[]'$~],+:@[
Explanation
'[]'$~],+:@[ input: y, x
+:@[ double y
], pair with x
this gives (x, 2y)
$~ shape the left argument into the right argument's shape
'[]' 2-length character string
This gives us an x by 2y string of repeating [] characters.
SOGL, 5 bytes
Ƨ[]*∙
Simple:
Ƨ[] push "[]"
* multiply horizontally (repeating width times)
∙ get an array with input (height) items of that
implicitly output the array joined with newlines
Mathematica, 26 bytes
Grid@Table["[]",{#2},{#}]&