# Make me a square!

Given one non-whitespace printable character, make a 3x3 square representation of that input. For example, if the input is #, then the output is:

###
# #
###


# Rules

• The output format is strict, although a trailing newline is allowed. It means that the space in the middle is required, and also that the two newline characters separating the three lines are required.

# Testcases

Input: #

Output:

###
# #
###


Input: A

Output:

AAA
A A
AAA


Input: 0

Output:

000
0 0
000


# Scoring

This is . Shortest answer in bytes wins.

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

/* Configuration */

var QUESTION_ID = 120052; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author.

/* App */

return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

jQuery.ajax({
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(a) {
var id = +a.share_link.match(/\d+/);
});
if (!data.has_more) more_answers = false;
comment_page = 1;
}
});
}

jQuery.ajax({
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(c) {
if (c.owner.user_id === OVERRIDE_USER)
});
else process();
}
});
}

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
return a.owner.display_name;
}

function process() {
var valid = [];

var body = a.body;
if(OVERRIDE_REG.test(c.body))
body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
});

var match = body.match(SCORE_REG);
if (match)
valid.push({
user: getAuthorName(a),
size: +match[2],
language: match[1],
});

});

valid.sort(function (a, b) {
var aB = a.size,
bB = b.size;
return aB - bB
});

var languages = {};
var place = 1;
var lastSize = null;
var lastPlace = 1;
valid.forEach(function (a) {
if (a.size != lastSize)
lastPlace = place;
lastSize = a.size;
++place;

.replace("{{NAME}}", a.user)
.replace("{{LANGUAGE}}", a.language)
.replace("{{SIZE}}", a.size)

var lang = a.language;
if (/<a/.test(lang)) lang = jQuery(lang).text();

languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link};
});

var langs = [];
for (var lang in languages)
if (languages.hasOwnProperty(lang))
langs.push(languages[lang]);

langs.sort(function (a, b) {
if (a.lang > b.lang) return 1;
if (a.lang < b.lang) return -1;
return 0;
});

for (var i = 0; i < langs.length; ++i)
{
var language = jQuery("#language-template").html();
var lang = langs[i];
language = language.replace("{{LANGUAGE}}", lang.lang)
.replace("{{NAME}}", lang.user)
.replace("{{SIZE}}", lang.size)
language = jQuery(language);
jQuery("#languages").append(language);
}

}
body { text-align: left !important}

width: 290px;
float: left;
}

#language-list {
width: 290px;
float: left;
}

font-weight: bold;
}

table td {
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>

</tbody>
</table>
</div>
<div id="language-list">
<h2>Winners by Language</h2>
<table class="language-list">
<tr><td>Language</td><td>User</td><td>Score</td></tr>
<tbody id="languages">

</tbody>
</table>
</div>
<table style="display: none">
</tbody>
</table>
<table style="display: none">
<tbody id="language-template">
</tbody>
</table>

• The fact that the size is fixed allows for some optimization. Answers form the linked challenge will probably not be competitive here. So I don't think it's a duplicate May 11 '17 at 14:33
• I was the one who downvoted, for it for being a simple, boring challenge. I'm normally a fan of easy challenges, as they're a good place for new golfers to start but this just feels too easy. May 11 '17 at 14:56
• @Ayoungcoder It is a perfectly valid reason to downvote a challenge. May 11 '17 at 14:59
• @Shaggy: In terms of difficulty, there's difficulty to write the program, and difficulty to golf the program. This program is easy to write, but I'm not so sure it's easy to golf it.
– user62131
May 11 '17 at 15:33
• In my opinion, this is a good challenge for people who are just getting started with code golfing. It's good to have a mix of difficulties. Overloading on any one type will be to the detriment of some part of the community. So, I'm glad this challenge was written. May 13 '17 at 6:22

# CJam, 11 10 bytes

r9*4St3/N*


Try it online!

Explanation:

r9*4St3/N* e# Expects single char (token) as input
r          e# Get input token (C)
9*        e# Repeat C 9 times
4St     e# Set the 5th char of C to be a space
3/   e# Split into parts of length 3
N* e# Join by newlines


# Windows batch, 37 bytes

@echo %1%1%1
@echo %1 %1
@echo %1%1%1


Simply outputs the first command-line argument in a square form.

# Emacs, 15 keystrokes

The current buffer must only contain the input character, and the cursor must be at the start of the line.

C-k C-y C-y C-y C-a C-k C-y RET C-y C-b BACKSPACE SPC C-e RET C-y


# 05AB1E, 7 6 bytes using the canvas and compressed integers.

3IŽ9¦Λ


Try it online!

• -1 byte by simply changing the Ƶ‘0« to Ž9¦ (see the How to compress large integers? section of this tip). Jan 3 '20 at 8:47
• @KevinCruijssen Thanks, I was trying to use compressed integers but it wasn't getting the 0 at the start.
– mekb
Jan 3 '20 at 20:34
• You're right, 0s at the start (both with compressed integers and compressed integer lists) doesn't work. But since it has to be a square anyway, and your previous answer was appending the 0 at the end, it can be a single compressed integer 2460 to save a byte. :) Jan 4 '20 at 11:52

# Python 3, 31 bytes

lambda s:3*s+f'\n{s} {s}\n'+3*s


Try it online!

$0=$0$0$0RS$0FS$0RS$0$0$0  Try it online! # MAWP, 29 bytes |!;!;!;25W;!;84W;!;25W;!;!;;.  Try it! -6 bytes from Dion's straightformard solution. # MAWP, 35 bytes %|7[1A~!~]////25W//84W//25W////~[;]  Manually shifting the stack was more practical than trying to loop through it and make a box. Try it! • Is this even golfed?? – null Aug 15 '20 at 8:13 • ...Ok, I take it back. – null Aug 15 '20 at 8:56 • Doesn't something so straightforward like this work..? – Dion Aug 18 '20 at 18:51 • What was I thinking when I made this?! Sep 30 '20 at 9:20 # Swift3, 50 bytes [1,2,3].map{$0==2 ? print(c+" "+c) : print(c+c+c)}


This uses the ternary operator to print different strings, depending on the row.

Try it online

# Aceto, 19 bytes

nppk
pKLp
pppn
,kpp


Read a single character (,), then activate sticky mode (k). Print it three times, a newline and then the character again (pppnp).

Deactivate sticky mode (K), then load the empty string from quick storage (L), print it (p), activate sticky mode again (k), and print the rest (pnppp).

# MATL, 8 bytes

4Y"0yv3e


Unlike my other MATL answer, this builds the output manually, without using any predefined literal.

Try it at MATL Online!

### Explanation

Consider input '^' as an example.

      % Implicitly input one char.
4Y"   % Repeat 4 times. Gives a string.     STACK: '^^^^'
0     % Push 0. Char 0 is shown as space.   STACK: '^^^^', 0
y     % Duplicate from below.               STACK: '^^^^', 0, '^^^^'
v     % Concatenate everything vertically.  STACK: ['^';'^';'^';'^';0'^';'^';'^';'^';'^']
3e    % Reshape into a 3-row char matrix.   STACK: ['^^^';'^ ^';'^^^']
% Implicitly display.


i:o:o:oao:$o" "|;o~  Try it online! # Retina, 18 bytes :$
$_$_
*2=.



Half of this code looks like trailing empty lines, I like that :)

Try it online!

### Explanation

There are three stages in this program, each of them prints a line of the output, in sequence.

:_$_  Add two more copies of the input at the end and print the resulting string. *2=.  There's a single space in the second line. This stage replaces the second character of the string with a space, prints the result, and then reverts the string to what it was before (thanks to the *)   The two final empty lines are a replacement stage with no effect. This is only needed because a final stage with no printing modifier implicitly prints the resulting string. • Save 1 byte by removing the third stage and putting the second stage into a group. The implicit print then moves from the stage to the group, allowing the stage's own dry run to be an additional output. (The ( needs to be at the start of the third line for this to work.) – Neil Jun 4 '17 at 16:24 ## C#, 7471 66 bytes m=>{System.Console.WriteLine("{0}{0}{0}\n{0} {0}\n{0}{0}{0}",m);};  golfed 5 bytes thanks to an anon • You can save some bytes if you use r==1?" ":m directly in WriteLine, instead of assigning it to s. May 12 '17 at 10:00 • You need to fully qualify the Console May 12 '17 at 10:56 ## C#, 30 bytes s=>s+s+s+$"\n{s} {s}\n"+s+s+s;


Compiles to a Func<string, string>.

Using Replace for 32 bytes.

c=>@"###
# #
###".Replace('#',c);


Compiles to a Func<char, string>.

• @ConorO'Brien Thanks, for some reason I have a problem typing string the right way round... May 12 '17 at 11:26

# ///, 27 bytes

/\\\#//\#\#\#
\#\ \#
\#\#\#


Try it online!

Since there is no other way to take input in ///, it is hard-coded.

/\\\#/INPUT HERE/\#\#\#
\#\ \#
\#\#\#


Version that takes input in Itflabtijtslwi (28 bytes):

GG\\\#GG\#\#\#
\#\ \#
\#\#\#


Try it online!

## QBIC, 23 20 bytes

Brute-forcing this is shorter than fancy string-flips...

?;+A+A?A+@ +A?A+A+A


A=;+A+A+@┘+A?A+@ +_fA


Explanation:

A=;     ; gets a cmd line parameter and assigns it to A$This overrides that value by +A+A appending itself two times +@┘ Then a literal newline +A And another copy of the input char ? PRINT A The combined A$ ("###\n#")
+@     a space
+_fA    and then the flipped version of A$ # Javascript (ES6), 32 bytes i=>### # # ###.replace(/#/g,i)  # R, 43 40 bytes cat(gsub("y",scan(,""),"yyy\ny y\nyyy")) Saved 3 bytes thanks to Giuseppe. Explanation: create a box using the character "y" and then substitute the input character. • You can drop 3 bytes by reading x from stdin instead of making it a function: cat(gsub("y",scan(,""),"yyy\ny y\nyyy")) May 19 '17 at 17:45 • using 1 in place of "y" saves 2 more bytes. Jan 30 '20 at 19:16 # Cubix, 26 bytes ./v.o;@?/i:::Ns:Ss:Nu/:::s  This is the first piece of Cubix code I've ever written...I was originally going to try to answer the Try to make a cube challenge, but I figured I'd answer the original (easier) question first. Cubix is pretty cool! ## R, 44 bytes cat(y<-rep(scan(,''),4),' ',y,sep='',fill=3)  Test and output: > cat(y<-rep(scan(,''),4),' ',y,sep='',fill=3) 1: # 2: Read 1 item ### # # ### >  • You can drop a few bytes by returning an anonymous function, but you can do even better by reading from stdin: cat(y=rep(scan(,''),4),' ',y,sep='',fill=3) is 43 bytes. May 19 '17 at 17:43 # Japt, 11 9 bytes ³+R+U+S ê  Try it online ## Explanation  :Implicit input of string U ³ :Repeat input 3 times +R :Append newline +U :Append input +S :Append space ê :Duplicate string, excluding last character, reverse it and append it to original  ## Alternative, 9 bytes I can't decide which version I prefer. [U³RUS]¬ê  Try it online ## Alternative, 10 bytes I really liked this version, but sadly it came in at a byte too big. NpU²RUS ¬ê  Try it online • Nice! p3  can be shortened to ³ May 19 '17 at 14:37 • Aha, hadn't spotted that. Thanks again, @obarakon. May 19 '17 at 14:39 # brainfuck, 48 bytes Great simple challenge. ,...>++++++++++.<.>+[->+>+++<<]>>-.<<<.>>-.<<...  Try it online! # Explanation ,... : take input, print it 3 times >++++++++++. : print ASCII with index 10 (new line) <.> : print input. +[->+>+++<<]>>-. : add 1 to 10, triple it, subtract one and print it (space) <<<.>>-.<<... : print input, newline, and input 3 times  # Perl 5, 23 + 1 (-p) = 24 bytes The brute force way seems to be the shortest. $_.="$_$_
$_$_
$_$_$_"  Try it online! # Syms, 21 bytes {}<[[[++~[{& &}~[>~>>  Try it online! • oops, didnt allow trailing [] but never specified it, lucky ig guess :) Sep 16 '17 at 6:37 • Um why is -i on Sep 25 '17 at 19:51 # K (oK), 8 bytes Solution: 3 3#5$4#


Try it online!

Example:

> 3 3#5$4#"@" ("@@@" "@ @" "@@@")  Explanation: Evaluated right-to-left. Build 'AAAA', then 'AAAA ' and then shape into the 3x3 grid required. 3 3#5$4# / the solution
4# / take 4 of whatever is to the right
5$/ right pad with whitespace to length 5 3 3# / shape into 3x3 grid  Bonus: The solution is a polyglot for q/kdb+: q)3 3#5$4#"*"
"***"
"* *"
"***"

• cool way of doing it Sep 26 '17 at 14:26

# Pepe, 54 bytes

REEeREEEeeReeerREeeeeEeEeReeereeeEeeeeeReeeREEeeReReee


Try it

Explanation:

REEe        # Input as str
REEEee      # Duplicate it
Reee        # Output whole stack
rREeeeeEeEe # Insert linefeed (10) to the stack
Reee        # Output whole stack
reeeEeeeee  # Print space (' ')
Reee        # Output whole stack
REEee       # Go to next position
ReReee      # Pop it (space) and output the whole stack


# Dart, 30 bytes

f(s)=>'$s$s$s\n$s $s\n$s$s$s';


Try it online!

# Acc!!, 58 bytes

N
Count i while 11-i {
Write _+i%4/3*(10-_)+i%6/5*(32-_)
}


Try it online!

### How?

Let's lay out the desired output in a line, substituting _ for the newlines, and look at patterns and indices.

###_# #_###
01234567890


We need newlines at indices 3 and 7, a space at index 5, and the input character at all other indices. To put it a different way, for index i, we want newline when i%4 == 3, space when i%6 == 5*, and the input character otherwise.

So, after reading the input character into the accumulator with N, we run a Count loop from 0 up to but not including 11. Iff i%4 is 3, i%4/3 is 1, and we output _+(10-_) i.e. 10 i.e. newline. Iff i%6 is 5, i%6/5 is 1, and we output _+(32-_) i.e. 32 i.e. space. Otherwise, we output _ i.e. the accumulator value i.e. the input character. Fortunately, the two modulo cases are never true at the same time; this would happen at index 11, but we stop at index 10.

* The modulo operation would seem unnecessary here, but (as far as I can tell) it is the shortest way to test i == 5 in Acc!!, which doesn't have a comparison operator.

# Keg, 11 bytes

???
? ?
???


It really just replaces the ?s with the input!

Alterate 11 byter

¿3*:&
? ?
&

• Neither program works on TIO
– Jo King
Dec 26 '19 at 9:12
• Because Keg needs a pull on TIO Dec 26 '19 at 9:13
• @JoKing Dennis is not very active this week. He didn't get the latest interpreter on TIO yet.
– user85052
Dec 26 '19 at 9:13
• @JoKing TIO is 19 commits behind the Keg repo Dec 26 '19 at 9:15

# naz, 46 bytes

1x1f0m9a1a1o0x1r2x1v3o1f1v1o0m4a8m1o1v1o1f1v3o


Strictly speaking, the above program outputs the exact byte stream required to make the square, though the top of the square will be misaligned given that the interpreter linked above always prepends output: to program output.

Explanation (with 0x commands removed)

1x1f0m9a1a1o     # Function 1
# Reset the register, add 10 and output (produces a newline)
1r2x1v           # Read the first byte of input and store it in variable 1
3o               # Output the byte 3 times
1f               # Call function 1
1v1o0m4a8m1o1v1o # Output variable 1, output 32 (space), then output variable 1
1f               # Call function 1
1v3o             # Output variable 1 3 times
`