Make me a square!

22

8

Task

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.

Leaderboard

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 */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  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;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });  
}

getAnswers();

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 = [];
  
  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      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],
        link: a.share_link,
      });
    
  });
  
  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;
    
    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    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)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}
body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

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

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}
<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">
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">

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

    </tbody>
  </table>
</div>
<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>

Luc H

Posted 2017-05-11T14:21:55.880

Reputation: 461

2The 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 – Luis Mendo – 2017-05-11T14:33:30.357

12I 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. – Shaggy – 2017-05-11T14:56:37.133

1@Shaggy it's a bad practise to downvote challenges just because you dont like them, please delete your downvote. For you finding it easy, it is about having as little as possible bytes and i don't think that is really easy. – Luc H – 2017-05-11T14:57:52.217

32@Ayoungcoder It is a perfectly valid reason to downvote a challenge. – Post Rock Garf Hunter – 2017-05-11T14:59:21.433

2@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. – None – 2017-05-11T15:33:14.560

5In 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. – isaacg – 2017-05-13T06:22:56.353

Answers

31

Charcoal, 5 3 bytes

B³S

Try it online! Edit: Saved 40% thanks to @carusocomputing. Explanation:

B   Draw a box
³   3×3 (second dimension is implicit if omitted)
S   Using the input character

Neil

Posted 2017-05-11T14:21:55.880

Reputation: 95 035

3I feel like this is cheating...>_> – HyperNeutrino – 2017-05-11T14:50:21.200

14Then, of course, B³S to cheat the living crap outta this. – Magic Octopus Urn – 2017-05-11T14:51:25.510

1Why would this be cheating? @carusocomputing and neil his anwser seems right to me – Luc H – 2017-05-11T14:53:53.087

1@Ayoungcoder "cheating" as in "seems cheap" not as in "literal cheating"; the code has a built-in for "print a box of dimensions n using character s", the shortest code for this challenge being: 1. Read input. 2. Define dimension. 3. Print box. The answer to this challenge logically won't be below 2 bytes if input is implicit. – Magic Octopus Urn – 2017-05-11T14:54:19.337

@carusocomputing sorry, didnt know :), should it count this as caros' answer or Neil's answer :) – Luc H – 2017-05-11T14:55:51.520

2

@carusocomputing Ah, the irony - the implicit square behaviour annoyed me in my answer to Visualize the Euclidean algorithm again.

– Neil – 2017-05-11T14:56:13.690

@Ayoungcoder it's his answer :P. Crediting the -2 bytes I saved is the standard, nobody takes someone else's answer over by improving it. – Magic Octopus Urn – 2017-05-11T14:56:15.790

1@Ayoungcoder Although this is probably the shortest possible answer, I wouldn't accept it too soon to avoid putting prospective answerers off – Beta Decay – 2017-05-11T15:44:03.077

@BetaDecay im keeping it like this to thanks neil and caros, i will give it to someone else when they have a shorter one. – Luc H – 2017-05-11T15:46:53.393

inputting longer strings like abcdefgh also gives a fun output – Luc H – 2017-05-11T15:56:28.470

Damnit! I swore I'd remember to try Charcoal at the next opportunity after seeing this - guess I forgot to remember!

– Shaggy – 2017-05-11T17:10:23.433

@BetaDecay unless there exists a language that implicitly combines two of the 3 steps I previously mentioned, it's not possible to get a shorter answer; I don't know of any languages with "print 3x3 box of" or "3x3 shape using character x" and "in the shape of a box". Though, I agree, it is still possible to tie. – Magic Octopus Urn – 2017-05-11T17:16:36.873

I wonder if Charcoal would benefit from a stack based approach. If it's too different, maybe I could add dialects (Charstick (?) for stack-based memory, and Charbequeue for queue-based memory maybe) – ASCII-only – 2017-05-12T01:13:37.060

48

Carrot, 11 bytes

###
# #
###

Try it online!

The program is in caret-mode, where #s are replaced with the input.

user41805

Posted 2017-05-11T14:21:55.880

Reputation: 16 320

27The feeling when a program which looks completely invalid at first is actually perfectly valid. – Erik the Outgolfer – 2017-05-11T16:01:21.353

4@EriktheOutgolfer ever heard of Perl? – NoOneIsHere – 2017-08-11T04:45:13.377

@EriktheOutgolfer ever heard of Brainfuck? – None – 2020-01-04T13:10:29.267

19

Python 2, 32 bytes

lambda s:s+s.join(s+'\n \n'+s)+s

Try it online!
For s='a' : the middle s+'\n \n'+s generates a\n \na and s.join turns it in aa\na a\naa (bold as are the ones that .join adds), because .join accepts a string as an iterable, then it is surrounded with the two missing characters

Rod

Posted 2017-05-11T14:21:55.880

Reputation: 17 588

How does this add the characters to the middle line? Could you explain the answer please? – Notts90 supports Monica – 2017-05-12T13:26:02.780

1@Notts90 added an explanation c: – Rod – 2017-05-12T13:50:12.217

thanks I didn't know .join could iterate a string. – Notts90 supports Monica – 2017-05-12T13:55:32.620

This works in Python 3 too. Very cool BTW. (Also, using the same method 3*c+c.join('\n \n')+3*c ties at 32.) – Jonathan Allan – 2017-05-13T13:49:59.520

15

MATL, 5 bytes

3Y6*c

Try it online!

Explanation

3Y6   % Push predefined literal: [true true true; true false true; true true true]
*     % Implicitly input a character. Multiply element-wise by its code point
c     % Convert to char. Implicitly display. Char 0 is displayed as space

Luis Mendo

Posted 2017-05-11T14:21:55.880

Reputation: 87 464

1that was quick! didnt expect a 5 byte to come that fast. – Luc H – 2017-05-11T14:26:39.007

2Code-golfing languages, you know... ¯\(ツ) – Luis Mendo – 2017-05-11T14:27:32.280

11Of course, because why wouldn't you have a predefined literal for [true true true; true false true; true true true] – PunPun1000 – 2017-05-11T14:48:38.243

12

@PunPun1000 That's actually used a lot (together with convolution) as it's the standard 8-connectivity mask (Moore neighboorhood)

– Luis Mendo – 2017-05-11T14:51:17.520

3@LuisMendo That's awesome, learn something new on here every day, not always about code golfing – PunPun1000 – 2017-05-11T14:54:30.360

13

05AB1E, 8 bytes

4×ð«û3ô»

Try it online!

INPUT    # ['R']                 | Implicit Input: 'R'
---------#-----------------------+-------------------------------
4×       # ['RRRR']              | Repeat string 4 times.     
  ð      # ['RRRR',' ']          | Push space onto top of stack.
   «     # ['RRRR ']             | Concatenate last 2 items.
    û    # ['RRRR RRRR']         | Palindromize.
     3ô  # [['RRR','R R','RRR']] | Split into 3 pieces.
       » # ['RRR\nR R\nRRR']     | Join with newlines
---------#-----------------------+-------------------------------
OUTPUT   # RRR                   | Implicitly print the top
         # R R                   | of the stack on exit.
         # RRR                   |

Original idea using 30 as a binary number (unfinished, someone else try this in another lang):

05AB1E, 12 bytes

30bûTIð«‡3ô»

Try it online!

Magic Octopus Urn

Posted 2017-05-11T14:21:55.880

Reputation: 19 422

You have been outgolfed. – Oliver Ni – 2017-05-31T00:24:50.703

11

Python 3.6, 33 bytes

lambda c:f'{3*c}\n{c} {c}\n{3*c}'

Try it online!

Jonathan Allan

Posted 2017-05-11T14:21:55.880

Reputation: 67 804

No problem. It looks like it's actually 3.6.1 being run; if you try import sys and then sys.version in the repl, it returns 3.6.1 rather than 3.5.2. No idea why it says 3.5.2 at the top then, seems like they have made a mistake there! – numbermaniac – 2017-05-13T13:22:11.903

2Oh, haha, a case of "don't always believe what you read" - thanks! – Jonathan Allan – 2017-05-13T13:23:16.060

9

RPL (Reverse Polish Lisp), 60 characters

→STR 1 4 START DUP NEXT " " + SWAP + 4 ROLLD + + SWAP 2 PICK

(Note that "→" is a single character on the HP48 and compatible calculators)

Would visually represent what you want by having three items on the stack:

3.: "###"
2.: "# #"
1.: "###"

If you insist to return it as one string, one has to add the newline characters as well and combine the strings, left as exercise to the next tester.

Input (can be anything, does not need to be a string) Entered code Result

Explanation:

  • →STR: Make the last object in the stack into a string. (So the input can be anything, e.g. a number.)
  • 1 4: Push the number 1 and 4 to the stack.
  • START [...] NEXT: Like a for loop but without access to the counter variable. Takes two numbers from the stack (here, we just have pushed 1 and 4) and executes the code [...] the corresponding times (here, four times).
  • DUP: Duplicate the last entry in the stack.
  • " ": Push the string (i.e. the string with one whitespace) to the stack.
  • +: Take two objects from the stack and return them added together, for strings: Concatenated.
  • 4: Push the number 4 to the stack.
  • ROLLD: Takes the last element (here: 4 that we just have pushed) from the stack and rolls the next element as far down the stack as the number we just took from the stack specifies.
  • SWAP: Swaps the two last stack elements.
  • 2: Push 2 to the stack.
  • PICK: Takes an element (here: The 2 we just pushed to the stack), interprets it as a number n, and copies the nth element from the stack.

Golar Ramblar

Posted 2017-05-11T14:21:55.880

Reputation: 191

7

JavaScript, 28 bytes

c=>c+c+c+`
${c} ${c}
`+c+c+c

Try it

f=
c=>c+c+c+`
${c} ${c}
`+c+c+c
o.innerText=f(i.value="#")
i.oninput=_=>o.innerText=f(i.value)
<input id=i maxlength=1><pre id=o>

Shaggy

Posted 2017-05-11T14:21:55.880

Reputation: 24 623

I think you might be able to save a byte or two by storing the result of c+'\n'+c in a temporary. – Neil – 2017-05-11T14:48:13.420

Never mind, I miscounted, it's still 28 bytes. – Neil – 2017-05-11T14:48:37.653

@Neil: Yeah, there are a couple of options for assigning stuff to a variable, but they all come in at 28 bytes or more. – Shaggy – 2017-05-11T14:54:19.487

6

Jelly, 8 bytes

1 byte thanks to Erik the Outgolfer.

x4,`Ks3Y

Try it online!

Leaky Nun

Posted 2017-05-11T14:21:55.880

Reputation: 45 011

I was wondering how to do this... I had x4µ©;⁶;®œs3Y for 12 bytes because I couldn't figure out how to avoid having the repetition multiply my entire intermediate step but nice! – HyperNeutrino – 2017-05-11T14:50:08.487

1You know, there's a builtin K for doing j⁶. Oh, and there's a quick, ```, to convert a dyad to a monad by using the same argument on both sides. – Erik the Outgolfer – 2017-05-11T15:06:29.450

5

sed, 28 18 bytes

s:.:&&&\n& &\n&&&:

Try it online!

eush77

Posted 2017-05-11T14:21:55.880

Reputation: 1 280

this new one doesnt work, the old one did edit: it does but you forgot the : in the anwser – Luc H – 2017-05-11T14:40:11.577

@Ayoungcoder Sorry, mis-pasted the final :. Fixed. – eush77 – 2017-05-11T14:41:17.577

the try it online should be [Try it online!]: https://tio.run/nexus/sed#@19spWelpqYWk6emACLU1Kz@/0/i@pdfUJKZn1f8X7cIAA "sed – TIO Nexus"

– Luc H – 2017-05-11T14:42:15.500

@Ayoungcoder Of course, thanks. – eush77 – 2017-05-11T14:45:59.540

5

Brain-Flak, 76 70 + 1 = 71 bytes

Requires the -c flag

(((((((({})))<((([])[]{}<>)<>)>)<(<>({})({}){}()()<>)>)<([]()()())>)))

Try it online!

Post Rock Garf Hunter

Posted 2017-05-11T14:21:55.880

Reputation: 55 382

You can save 6 bytes if you replace (()()()()()){} with ([])[]{}. – 0 ' – 2017-05-11T15:48:21.077

Some competition :) – James – 2017-05-11T20:03:19.813

5

Java 7, 56 55 bytes

-1 Thanks to Leaky Nun for pointing out the space I missed

String a(char s){return"...\n. .\n...".replace('.',s);}

Simply replaces the periods with the given character, for input #:

...       ###
. .  =>   # #
...       ###

Try it online!

PunPun1000

Posted 2017-05-11T14:21:55.880

Reputation: 973

5

PHP, 32 Bytes

<?=strtr("000
0 0
000",0,$argn);

Try it online!

Jörg Hülsermann

Posted 2017-05-11T14:21:55.880

Reputation: 13 026

Quite interestingly <?=$a=$argn,"$a$a\n$a $a\n$a$a$a"; (real line break instead of \n of course) has exactly the same byte count. – Christoph – 2017-05-12T06:26:54.973

@Christoph make it as your approach. i have not try this alternative way – Jörg Hülsermann – 2017-05-12T09:36:03.890

5

Pyth, 7 bytes

jc3.[9d

Try this online.

Explanation:

jc3.[9d Expects quoted input.
  3     3
     9  9
      d ' '
        Q (eval'd input) as implicit argument
   .[   Pad B on both sides with C until its length is a multiple of A
 c      Split B to chunks of length A, last chunk may be shorter
j       Join A on newlines

Erik the Outgolfer

Posted 2017-05-11T14:21:55.880

Reputation: 38 134

4

Brain-Flak, 61, 59 bytes

(((((((({})))<([][][]())>)<(([][][]()){})>)<([]()()())>)))

Try it online!

This is 58 bytes of code +1 byte for the -c flag which enables ASCII input and output.

Explanation:

(((
   (
    (
     (

      #Duplicate the input 3 times
      ((({})))

#Push 10 (newline)
<([][][]())>

     #Push the input again
     )

#Push 32 (space)
<(([][][]()){})>

    #Push the input again
    )

#Push 10 (newline)
<([]()()())>)

#Push input 3 times
)))

James

Posted 2017-05-11T14:21:55.880

Reputation: 54 537

4

C (gcc), 49 47 bytes

Saved 2 bytes thanks to 2501!

j;f(i){for(j=12;j;)putchar(--j%4?j-6?i:32:10);}

Try it online! has a trailing newline

Conor O'Brien

Posted 2017-05-11T14:21:55.880

Reputation: 36 228

You can save two bytes by doing: for(j=11;j;)... – 2501 – 2017-05-12T09:38:14.883

4

05AB1E, 7 6 bytes

-1 byte thanks to carusocomputing.

ж¹ðJû

Explanation:

         # Implicit input                  # ['R']
 Ð       # Repeat string three times       # ['R', 'R', 'R']
  ¶      # Push newline character          # ['R', 'R', 'R', '\n']
   ¹     # Push first input                # ['R', 'R', 'R', '\n', 'R']
    ð    # Push space                      # ['R', 'R', 'R', '\n', 'R', ' ']
     J   # Join stack                      # ['RRR\nR ']
      û  # Palindromize ("abc" -> "abcba") # ['RRR\nR R\nRRR']
         # Implicit output                 # []

Uses the CP-1252 encoding. Try it online!

Oliver Ni

Posted 2017-05-11T14:21:55.880

Reputation: 9 650

Oooo... Smart, I never think about how palindromize works on newlines. – Magic Octopus Urn – 2017-05-31T12:51:39.650

ж¹ðJû for 6 bytes. – Magic Octopus Urn – 2017-05-31T12:54:04.467

3

Python 3, 34 bytes

lambda s:s*3+"\n"+s+" "+s+"\n"+s*3

Try it online!

Leaky Nun

Posted 2017-05-11T14:21:55.880

Reputation: 45 011

-1 byte: lambda x:x*3+'\n%s '%x+x+'\n'+x*3 – Erik the Outgolfer – 2017-09-16T11:41:04.250

3

Octave, 36 bytes

x=repmat(input(0),3);x(5)=32;disp(x)

Try it online!

Explanation

This creates a 3x3 char matrix with the input char repeated, and sets its 5th entry in column-major order (i.e. its center) to 32 (ASCII for space).

Luis Mendo

Posted 2017-05-11T14:21:55.880

Reputation: 87 464

3

Pyke, 5 bytes

dQA.X

Try it online!

Blue

Posted 2017-05-11T14:21:55.880

Reputation: 26 661

3

Ruby, 27 25 bytes

Saved 2 bytes thanks to Level River St

->x{[s=x*3,x+" "+x,s]*$/}

Try it online!

Alex

Posted 2017-05-11T14:21:55.880

Reputation: 371

when you are doing anwsers like this, please also include the footer as code because it does not work without – Luc H – 2017-05-11T19:51:48.860

@Ayoungcoder this is an anonymous function. you can assign it to a variable (f=...) then call it with f.call(...) – Cyoce – 2017-05-11T20:33:25.903

1You can use a literal newline inside quotes instead of "\n" for a saving of 1 byte . Even better use $/ which is a special variable set to newline by default - saving 2 bytes. – Level River St – 2017-05-11T21:59:06.237

1 byte less than the tr solution. nice work – Cyoce – 2017-05-25T05:14:14.720

3

Brainfuck, 40 bytes

+++++[->++<<++++++>],...>.<.<++.>.>.<...

Try it online! Requires an implementation that can access left of the starting position.

Also see: Graviton's brainfuck answer which takes a different approach (but is longer).


Explanation:

Brainfuck can do a lot of cool tricks with its limited instruction set. Unfortunately, this answer doesn't use any of them, because it's cheaper (in terms of bytes) to just hardcode everything.

+++++[->++<<++++++>]                         Sets the cells to |5*6|>0<|5*2|
,                   Takes input character into the middle cell | 30|>#<| 10|
...                                Print the top of the square | 30|>#<| 10| ###
>.                                   Print a newline character | 30| # |>10|    \n
<.                               Print another input character | 30|>#<| 10| #
<++.                  Add 30+2 for a space character and print |>32| # | 10|  _
>.                   And just print the 5 remaining characters | 32|>#<| 10|   #
>.                                                             | 32| # |>10|    \n
<...                                                           | 32|>#<| 10| ###

# = input character, _ = space (ASCII 32), \n = newline (ASCII 10)


Results in this beautiful box (for input '+'):

+++
+ +
+++

Zack C.

Posted 2017-05-11T14:21:55.880

Reputation: 491

3

Pyth, 11 bytes

jc++K*z4dK3

Try it online!

Explanation:

jc++K*z4dK3    expects a single char as input

j              joins on new line
 c        3    chops array into 3 sized pieces
  +            joins +K*z4d and K
   +           joins K*z4 and d
    K          initialize variable K as *z4
     *z4       duplicate the input 4 times
        d      variable initialized to string " "
         K     calls variable K, in this case *z4

chromaticiT

Posted 2017-05-11T14:21:55.880

Reputation: 211

Welcome to PPCG! – Stephen – 2017-08-13T02:49:28.480

2

><>, 24 23 bytes

i:o:o:oao:o84*o:a0!.<o$

Try it online!

Emigna

Posted 2017-05-11T14:21:55.880

Reputation: 50 798

2

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

Erik the Outgolfer

Posted 2017-05-11T14:21:55.880

Reputation: 38 134

2

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

Martyav

Posted 2017-05-11T14:21:55.880

Reputation: 61

2

V, 8 bytes

x3p2Ùlr 

Try it online!

Leaky Nun

Posted 2017-05-11T14:21:55.880

Reputation: 45 011

V has a (undocumented?) <M-h>ollow command that lets you hollow out the inside of your box: Try it online!

– nmjcman101 – 2017-09-25T20:13:33.063

2

J-uby, 22 20 bytes

-2 bytes thanks to @Jordan

:tr&"...
. .
..."&?.

Explanation

String#tr is Ruby's character-wise replace method. The first & binds :tr to "...\n. .\n...", and the second partially applies '.' to it. Effectively, this is ->s{"...\n. .\n...".tr('.',s)}

Cyoce

Posted 2017-05-11T14:21:55.880

Reputation: 2 690

Would :tr work as well as :gsub here? – Jordan – 2017-05-25T04:46:06.017

@Jordan yes, thanks! – Cyoce – 2017-05-25T05:02:16.677

2

C#,50 bytes

a=>Console.Write(a+a+a+"\n"+a+" "+a+"\n"+a+a+a);

Test Case:

var f = new Action<string>(
a=>Console.Write(a+a+a+"\n"+a+" "+a+"\n"+a+a+a);
);
f("#");

CHENGLIANG YE

Posted 2017-05-11T14:21:55.880

Reputation: 37

You need to fully qualify the Console i.e. System.Console.. – TheLethalCoder – 2017-05-12T10:56:27.107

2

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.

stevefestl

Posted 2017-05-11T14:21:55.880

Reputation: 539

2

Vim, 9 keystrokes

Assuming the input char is present in a buffer, vim makes this straightforward

x3pY2plr<space>

There is probably some magic vim commands of use here (there always seem to be some) so improvement suggestions are welcome. Only one keystroke behind V!

algmyr

Posted 2017-05-11T14:21:55.880

Reputation: 858

I'm pretty sure this is as short as it can get. Nice answer! – James – 2017-05-15T18:36:01.803

2

Z80 or 8080 Assembly, 21 bytes machine code

Assume a memory mapped I/O device:

              Z80                  8080
3A xx xx    ld  a, (input)      lda  input       ; get input character
11 0A 20    ld  de, 200ah       lxi  d, 200ah   ; space & newline
21 yy yy    ld  hl, output      lxi  h, output  ; get output address
77          ld  (hl), a         mov  m, a       ; output character * 3
77          ld  (hl), a         mov  m, a
77          ld  (hl), a         mov  m, a
73          ld  (hl), e         mov  m, e       ; output newline
77          ld  (hl), a         mov  m, a       ; output character
72          ld  (hl), d         mov  m, d       ; output space
77          ld  (hl), a         mov  m, a       ; output character
73          ld  (hl), e         mov  m, e       ; output newline
77          ld  (hl), a         mov  m, a       ; output character * 3
77          ld  (hl), a         mov  m, a
77          ld  (hl), a         mov  m, a
76          halt                hlt             ; or C9 ret

No interpreter needed!

Hexdump:

0000: 3A 00 FF 11 0A 20 21 01 FF 77 77 77 73 77 72 77
0010: 73 77 77 77 76

where the input address is at FF00h and the output address is mapped at FF01h. The actual addresses will depend on the actual hardware. Of course this assumes the I/O is memory mapped. If it is I/O mapped, it would take several extra bytes because Z80 & 8080 I/O instructions are two bytes each. This also assumes the output device interprets 0Ah as a newline and doesn't require a CR (0Dh) which would add an extra 4 bytes to the program.

Dan Howell

Posted 2017-05-11T14:21:55.880

Reputation: 71

Welcome to Codegolf.stackexchange, while it seems that you have everything under control please do read the help center and the list of faqs. Good first post – Rohan Jhunjhunwala – 2017-05-20T01:41:05.507

Can you provide a hexdump of your code? – CalculatorFeline – 2017-05-22T16:30:37.740

The hex bytes are in the first column, but if you want a "pure" hexdump, I've added it. – Dan Howell – 2017-05-23T00:07:07.570

2

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

TuxCrafting

Posted 2017-05-11T14:21:55.880

Reputation: 4 547

2

Python 3, 31 bytes

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

Try it online!

Mukundan

Posted 2017-05-11T14:21:55.880

Reputation: 1 188

2

StupidStackLanguage 28 bytes

jfffavvflflqvvvviifblflflfff

Explanation:

j # Get the input (x)
fff # first 3
avv # new line
fl # print new line
fl # first x
qvvvviifb # space
lf # second x
lf # new line
lfff # last 3 x's

Lebster

Posted 2017-05-11T14:21:55.880

Reputation: 21

Welcome to the site :) – sporeball – 2020-01-30T05:20:51.047

1

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).

L3viathan

Posted 2017-05-11T14:21:55.880

Reputation: 3 151

1

C#, 74 71 66 bytes

m=>{System.Console.WriteLine("{0}{0}{0}\n{0} {0}\n{0}{0}{0}",m);};

golfed 5 bytes thanks to an anon

Ceshion

Posted 2017-05-11T14:21:55.880

Reputation: 201

You can save some bytes if you use r==1?" ":m directly in WriteLine, instead of assigning it to s. – raznagul – 2017-05-12T10:00:20.140

You need to fully qualify the Console – TheLethalCoder – 2017-05-12T10:56:03.703

1

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

Graviton

Posted 2017-05-11T14:21:55.880

Reputation: 2 295

1

><>, 19 bytes

i:o:o:oao:$o" "|;o~

Try it online!

Teal pelican

Posted 2017-05-11T14:21:55.880

Reputation: 1 338

1

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
###
# #
###
> 

djhurio

Posted 2017-05-11T14:21:55.880

Reputation: 1 113

2You 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. – Giuseppe – 2017-05-19T17:43:06.180

1

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>.

TheLethalCoder

Posted 2017-05-11T14:21:55.880

Reputation: 6 930

@ConorO'Brien Thanks, for some reason I have a problem typing string the right way round... – TheLethalCoder – 2017-05-12T11:26:03.207

1

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.

Leo

Posted 2017-05-11T14:21:55.880

Reputation: 8 482

1Save 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 – 2017-06-04T16:24:44.877

1

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.

user2390246

Posted 2017-05-11T14:21:55.880

Reputation: 1 391

You can drop 3 bytes by reading x from stdin instead of making it a function: cat(gsub("y",scan(,""),"yyy\ny y\nyyy")) – Giuseppe – 2017-05-19T17:45:05.373

using 1 in place of "y" saves 2 more bytes. – Giuseppe – 2020-01-30T19:16:55.163

1

///, 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!

Comrade SparklePony

Posted 2017-05-11T14:21:55.880

Reputation: 5 784

1

QBIC, 23 20 bytes

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

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

Original answer:

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$

steenbergh

Posted 2017-05-11T14:21:55.880

Reputation: 7 772

1

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

Shaggy

Posted 2017-05-11T14:21:55.880

Reputation: 24 623

Nice! p3 can be shortened to ³ – Oliver – 2017-05-19T14:37:42.217

Aha, hadn't spotted that. Thanks again, @obarakon. – Shaggy – 2017-05-19T14:39:41.967

1

Javascript (ES6), 32 bytes

i=>`###
# #
###`.replace(/#/g,i)

user69538

Posted 2017-05-11T14:21:55.880

Reputation:

1

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!

Try it online! and also Watch the interpeter!

Giuseppe

Posted 2017-05-11T14:21:55.880

Reputation: 21 077

1

Syms, 21 bytes

{}<[[[++~[{& &}~[>~>>

Try it online!

CalculatorFeline

Posted 2017-05-11T14:21:55.880

Reputation: 2 608

oops, didnt allow trailing [] but never specified it, lucky ig guess :) – Luc H – 2017-09-16T06:37:11.973

Um why is -i on – CalculatorFeline – 2017-09-25T19:51:34.130

1

Perl 5, 23 + 1 (-p) = 24 bytes

The brute force way seems to be the shortest.

$_.="$_$_
$_ $_
$_$_$_"

Try it online!

Xcali

Posted 2017-05-11T14:21:55.880

Reputation: 7 671

1

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

u_ndefined

Posted 2017-05-11T14:21:55.880

Reputation: 1 253

1

Dart, 30 bytes

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

Try it online!

Elcan

Posted 2017-05-11T14:21:55.880

Reputation: 913

1

W d n, 8 bytes

º±▀σ\g┘╒

Uncompressed:

4*:' S++3,

Explanation:

4*         Repeat input 4 times
  :' S++   Put space in middle, append input * 4
        3, Chop into 3 equal pieces
Flag: n Join with newlines

W d, 13 11 9 bytes

Here's a version without chopping or similar built-ins.

↨i`♣T'@└µ

Explanation

Uncompressed is:

' a++bab++E
          E % Foreach in the string:
' a++       % (implicit) input, the space, and input
     bab++  % Output the string created by the input,
            % the current item, and the input
            % With a newline
            % The None isn't outputted

user85052

Posted 2017-05-11T14:21:55.880

Reputation:

1

Keg, 11 bytes

???
? ? 
???

It really just replaces the ?s with the input!

Alterate 11 byter

¿3*:&
? ?
&

Lyxal

Posted 2017-05-11T14:21:55.880

Reputation: 5 253

Neither program works on TIO – Jo King – 2019-12-26T09:12:39.620

Because Keg needs a pull on TIO – Lyxal – 2019-12-26T09:13:09.463

1@JoKing Dennis is not very active this week. He didn't get the latest interpreter on TIO yet. – None – 2019-12-26T09:13:13.490

@JoKing TIO is 19 commits behind the Keg repo – Lyxal – 2019-12-26T09:15:08.820

1

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

3IŽ9¦Λ

Try it online!

facepalm42

Posted 2017-05-11T14:21:55.880

Reputation: 405

1

-1 byte by simply changing the Ƶ‘0« to Ž9¦ (see the How to compress large integers? section of this tip).

– Kevin Cruijssen – 2020-01-03T08:47:54.843

@KevinCruijssen Thanks, I was trying to use compressed integers but it wasn't getting the 0 at the start. – facepalm42 – 2020-01-03T20:34:06.650

1You'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. :) – Kevin Cruijssen – 2020-01-04T11:52:32.843

1

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

sporeball

Posted 2017-05-11T14:21:55.880

Reputation: 461

1

GolfScript, 15 bytes

...n\." "\.n\..

Explanation

At the beginning of the program, the input is put onto the stack. Each . copies the top of stack. Each n pushes a newline onto the stack. " " pushes a space. \ swaps the top two elements. At the end of the program, the stack is output to the standard output.

Try it Online

LCU00

Posted 2017-05-11T14:21:55.880

Reputation: 31

13 bytes – None – 2020-01-23T04:20:02.190

1

TI-BASIC, 14 + 6 = 20 bytes

This submission uses two programs, the main one and a helper program called prgmΘ.

prgmΘ:Disp Ans+" "+Ans:prgmΘ         ;main program

Disp Ans+Ans+Ans                     ;helper program "prgmΘ"

Input is a string stored in Ans.

Tau

Posted 2017-05-11T14:21:55.880

Reputation: 1 935

1

AWK, 28 26 25 bytes

$0=$0$0$0RS$0FS$0RS$0$0$0

Try it online!

rootbeersoup

Posted 2017-05-11T14:21:55.880

Reputation: 111

0

Braingolf, 34 20 bytes

...#
<.># <.>#
<..&@

Little disappointed that this isn't easily golfed. At least it's shorter than JavaScript

Explanation:

For input #

                   | [35]
...                | [35,35,35,35]
   #<newline>      | [35,35,35,35,10]
<.>                | [35,35,35,35,10,35]
   #<space>        | [35,35,35,35,10,35,32]
     <.>           | [35,35,35,35,10,35,32,35]
        #<newline> | [35,35,35,35,10,35,32,35,10]
<..                | [35,35,35,10,35,32,35,10,35,35,35]
   &@              | Print entire stack

35 = # ASCII value
10 = <newline> ASCII value
32 = <space> ASCII value

Output:
###
# #
###

Skidsdev

Posted 2017-05-11T14:21:55.880

Reputation: 9 656

0

Retina, 21 bytes

.
$&$&$&¶$& $&¶$&$&$&

Try it online!

Leaky Nun

Posted 2017-05-11T14:21:55.880

Reputation: 45 011

It's shorter to match $ and insert $_ or `$`` (saving two bytes) – Martin Ender – 2017-05-11T18:38:48.613

0

Befunge, 26 bytes

~:::25*\:84*\:25*\::>:#,_@

Try it online!

Explanation

~::          Take input and put bottom row in stack (: is duplicate)
:25*\:84*\   Create second row (25* is 10 or newline, 84* is 32 or space)
:25*\::      Create top row
>:#,_@       Print out stack until the stack is empty

the \ after the numbers is to switch the stack around since you need the input on 
top of the stack to duplicate it

bwillsh

Posted 2017-05-11T14:21:55.880

Reputation: 11

0

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.

Luis Mendo

Posted 2017-05-11T14:21:55.880

Reputation: 87 464

0

bash, 43 38 bytes

read -sN1 x
echo "$x$x$x
$x $x
$x$x$x"

agc

Posted 2017-05-11T14:21:55.880

Reputation: 141

0

Scala, 23 bytes

a=>a*3+s"\n$a $a\n"+a*3

Accepts and returns a String. The s before a string literal allows you to use $-prefixed variables in it, or even ${expressions}. * repeats a String, like in Python.

Try it online!

Brian McCutchon

Posted 2017-05-11T14:21:55.880

Reputation: 503

0

VBScript, 72 bytes

n=chr(10):msgbox replace("###"&n&"# #"&n&"###","#",wscript.arguments(0))

VBScript sucks ;-)

Johan du Toit

Posted 2017-05-11T14:21:55.880

Reputation: 1 524

0

Foo, 40 bytes

&<character as ascii value>&3(-1<$c>)$c13<$c$c32$c$c13>&3(-1<$c>)

As Foo cannot take input, you should replace <character as ascii value> with the ASCII value of the character.

Try it online!

Okx

Posted 2017-05-11T14:21:55.880

Reputation: 15 025

0

Common Lisp, SBCL, 50 bytes

(format t"~@?
~a ~:*~a
~@*~@?""~3@{~a~:*~}"(read))

Explanation

format              ;printing function
~@?                 ;execute format string given as argument
~a ~:*~a            ;print current argument (will be result of (read))
                    ;then print space, go back one argument (to again use 
                    ;result of (read) and print it  
~@*~@?              ;go back to first argument, then execute format string 
                    ;given as this argument
"~3@{~a~:*~}"       ;loop three times printing argument number 2 
                    ;~:* makes it keep going back to argument number 2
(read)              ;take input

Ideas for improvement are welcomed.

user65167

Posted 2017-05-11T14:21:55.880

Reputation:

0

Excel VBA, 27 Bytes

Anonymous VBE immediate window function that takes input from cell [A1] on the Application.ActiveSheet object and outputs a 'square' to the VBE immediate window.

a=[A1]:?a;a;a:?a" "a:?a;a;a

Taylor Scott

Posted 2017-05-11T14:21:55.880

Reputation: 6 709

0

Swift, 54 bytes

var s=readLine()!,a=s+s+s+"\n";print(a+s+" "+s+"\n"+a)

Leena

Posted 2017-05-11T14:21:55.880

Reputation: 131

0

Sinclair ZX80/ZX81 (without sanity check), ~55 Bytes (listing)

 1 INPUT A$
 2 PRINT A$;A$;A$
 3 PRINT A$;" ";A$
 4 PRINT A$;A$;A$

With sanity check (ZX80 with 8K ROM or ZX81)

 1 INPUT A$
 2 IF NOT LEN A$ OR LEN A$>1 THEN GOTO 1
 3 PRINT A$;A$;A$
 4 PRINT A$;" ";A$
 5 PRINT A$;A$;A$

Line two of the latter version makes sure that there is a single character entered. So in the first example, it is possible to enter nothing and simply press NEW LINE.

The BASIC listing result with entry of asterisk

Shaun Bebbers

Posted 2017-05-11T14:21:55.880

Reputation: 1 814

1This would use 52 bytes of program memory. – Neil – 2017-06-04T16:29:40.413

So my approximation is broadly correct? I keep forgetting to POKE the memory to see how much actual RAMs my ZX80/81 programs take up; it also depends on the ROM used in the ZX80. If it's the 'old ROM' then each numeric variable is a 16-bit signed integer only, taking two bytes, whereas with the 8K ROM upgrade that becomes a floating point number of 5 bytes in memories total. – Shaun Bebbers – 2017-06-05T08:36:38.070

1Ah, well fortunately your program contains no numbers (at least, not the short version, which is what I counted). Also, I hope you PEEK to find out the actual usage, which would be PRINT PEEK 16396 + 256 * PEEK 16397 - 16509. – Neil – 2017-06-05T08:44:08.737

Thanks for this. I was making a general point about all of my ZX80/ZX81 entries rather than something specific about this listing – Shaun Bebbers – 2017-06-05T08:49:07.793

I'm just amazed that you have a ZX80 with the 8K ROM upgrade. (I'm just marginally too young for that, having started with the ZX81.) – Neil – 2017-06-05T09:11:20.680

Well, of sorts; I have a Minstrel clone that you can buy which has a 4K/8K ROM. I have lots of ZX81s in various states and a Commodore PET (3032) as well as a VIC/VC 20, C64, C128, +4 etc... I used to write about this stuff for Micro Mart magazine and others but now I'm a software developer I thought it best to make software for these old machines. I currently have a Commodore PET game and some ZX80/ZX81 games ready to be released by Monument Microgames. I'll also be making some VIC-20 and C16 stuff soon. – Shaun Bebbers – 2017-06-05T09:26:56.790

Our first 'home computer' was the Texas TI99/4a which I think pre-dates the ZX80 even. – Shaun Bebbers – 2017-06-05T09:27:36.927

Let us continue this discussion in chat.

– Shaun Bebbers – 2017-06-05T10:53:17.943

0

PowerShell, 26 Bytes

param($c)$c*3;"$c $c";$c*3

takes a char/length 1 string - then prints it 3 times, it twice with a separating space, and it 3 times again.

colsw

Posted 2017-05-11T14:21:55.880

Reputation: 3 195

0

braingasm, 18 bytes

,...10..32..10....

Yeah... read a byte, print it three times, then print a newline (10), then the byte again, then a space (32), that byte again, another newline and that byte three more times...

daniero

Posted 2017-05-11T14:21:55.880

Reputation: 17 193

0

Haskell, 45 44 bytes

-1 byte thanks to Laikoni

Naive approach

f s=putStrLn$s:s:s:'\n':s:' ':s:'\n':s:s:[s]

For some reason

f s=putStr$s:s:s:'\n':s:' ':s:'\n':s:s:[s]

won't output the last line on repl.it, but if it's still valid it shaves off 2 bits for a total of 42

And

f s=print$s:s:s:'\n':s:' ':s:'\n':s:s:[s]

will print the answer as "sss\ns s\nsss" instead of properly linebreaking. If that's valid it shaves off 3 bits for a total of 41

There is a solution with replace that's 42 bits long ... but that's without counting the bytes needed to import the necessary module. For reference:

import Data.String.Utils
f s=putStrLn$replace "." s "...\n. .\n..."

Sgt. Doggo

Posted 2017-05-11T14:21:55.880

Reputation: 111

You can shorten s:[] to [s]. – Laikoni – 2017-05-20T12:37:43.757

0

Ruby, 23+1 = 24 bytes

Uses the -n flag for +1 byte.

puts$_*3,$_+' '+$_,$_*3

Try it online!

Value Ink

Posted 2017-05-11T14:21:55.880

Reputation: 10 608

0

OCaml, 53 bytes

let f c=String.map(function '#'->c|c->c)"###
# #
###"

It's pretty bad. OCaml does not even have a replace function

Bash, 26 bytes

echo "$1$1$1
$1 $1
$1$1$1"

5 bytes less boring

juloo65

Posted 2017-05-11T14:21:55.880

Reputation: 81

Suggestion: Post you OCaml answer and Bash answers separately. – CalculatorFeline – 2017-05-22T16:29:37.973

0

Python 2, 34 bytes

lambda n:3*n+'\n'+n+" "+n+'\n'+3*n

Try it online!

Rohit-Pandey

Posted 2017-05-11T14:21:55.880

Reputation: 169

0

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#"*"
"***"
"* *"
"***"

streetster

Posted 2017-05-11T14:21:55.880

Reputation: 3 635

cool way of doing it – Luc H – 2017-09-26T14:26:23.523

0

UGL, 23 Bytes

j"\n"++l*I3l++i" "il*i3

try it online (write the code to stdin. you can also use the link at the top of the answer to try online, that accepts ctrl+v)

Equivalent Python code:

cur_inp = ""
def inp():
    global cur_inp
    cur_inp = input()
    return cur_inp
"\n".join([inp*3]+[cur_inp+" "+cur_inp]+[cur_inp*3])

Using Python's string multiplication.

Windmill Cookies

Posted 2017-05-11T14:21:55.880

Reputation: 601

0

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.

DLosc

Posted 2017-05-11T14:21:55.880

Reputation: 21 213

0

Burlesque, 20 bytes

3.*3.*{1 1}' D!)\[un

Try it online!

3.*       # Make a list of 3 instances     {A A A}
3.*       # Again                          {{A A A} {A A A} {A A A}}
{1 1}' D! # Set value at 1,1 to a space    {{A A A} {A   A} {A A A}}
)\[       # Concatenate each internal list {"AAA" "A A" "AAA"}
un        # Join array with newlines

Burlesque, 23 bytes

495b2"1"x/r~'0' r~3coun

Try it online!

Just for a bit of variety

495b2   # Read the number 495 as binary (111101111)
"1"x/r~ # Replace 1s with input char
'0' r~  # Replace 0 with space
3co     # Chunks of 3
un      # Separate by newlines

DeathIncarnate

Posted 2017-05-11T14:21:55.880

Reputation: 916

0

GolfScript, 13 bytes

4*.' '\++3/n*

Try it online!

Explanation

              # input #
4*            # ["####"]
  .           # ["####","####"]
   ' '        # ["####","####"," "]
      \       # ["####"," ","####"]
       ++     # ["#### ####"]
         3/   # [["###" "# #" "###"]]
           n* # [["###\n# #\n###"]]

user85052

Posted 2017-05-11T14:21:55.880

Reputation:

0

Husk, 6 bytes

Husk is way easier to use than Pyth.

C3w½*8

Try it online!

Explanation

    *8 Repeat the input 8 times. "!" -> "!!!!!!!!"
   ½   Halve the input. "!!!!!!!!" -> ["!!!!","!!!!"]
  w    Join with spaces. ["!!!!","!!!!"] -> "!!!! !!!!"
C3     Split into chunks of 3. ["!!!","! !","!!!"]

Husk automatically outputs lists joined with newlines

user85052

Posted 2017-05-11T14:21:55.880

Reputation:

0

J, 12 9 bytes

3 3$4j1#]

Try it online!

-3 thanks to FrownyFrog

Jonah

Posted 2017-05-11T14:21:55.880

Reputation: 8 729

3 3$4j1#] for 9 – FrownyFrog – 2020-02-06T03:40:02.220

That is quite nice. I had long forgotten about that complex trick, if I ever knew it. – Jonah – 2020-02-06T04:32:45.703

-1

Javascript (in-console), 42 bytes

for(i=3;i;i--)console.log(i%2?'iii':'i i')

Alternatively, this abomination:

i=3;while(i--)console.log(i%2?'i i':'iii')

The previous JavaScript answer was really cool, but you still need extra JavaScript to print out the square into the console or into an HTML element. I'm going for the shortest code including printing. If you put this code in-between two script tags and save it as an HTML page (so you aren't putting the code directly into the console) it's still only 59 bytes, but you can just run it from the developer console for the 42 bytes.

Explanation

for loop

i has to remain true for the for loop to keep running. When it hits 0 it is false and so stops. Counting down instead of up lets us save 2 characters over i=1;i=3;i++.

The code also has no spaces or semicolons- bad, I know. But with just one line, it still works!

The ternary operator reads "If i divided by 2 equals 0 (so if i is 2), print iii; otherwise, print i i." This means only the second line will print i i.

while loop

The while loop was a test that didn't get any fewer bytes, but was interesting. i is just defined outside of the loop. I didn't know that you could iterate inside of the while statement; it still goes until i becomes 0 from what I can tell. I don't know if this works cross-browser, but it worked in Chrome. I can't help but think there's a way to shorten the while version more, but I haven't figured it out yet...

Josh Powlison

Posted 2017-05-11T14:21:55.880

Reputation: 101

1First of all, welcome to the site! This looks like a very thorough first answer. Second, excuse me for being JavaScript illiterate but how does this program take input? It appears to me, again I'm completely illiterate in Javascript, this always print a square of is or perhaps a square made of the numbers 2, 1, and 0. – Post Rock Garf Hunter – 2017-09-18T03:47:23.210

I think the program is supposed to take a character of input and then create a square consisting of that character. – Esolanging Fruit – 2017-09-18T04:53:11.363

Also, you can collapse the the --i and the i into the middle section of the for loop to save a byte (but you'll have to swap the branches on the ? statement). – Esolanging Fruit – 2017-09-18T04:54:20.363

@FunkyComputerMan Thank you! In JavaScript, surrounding values with single quotes makes them into strings. The string could have been anything besides 'i', I just chose 'i' for the heck of it (and I was brainstorming if I could somehow print the character as well as the variable name and use some sort of hack there). – Josh Powlison – 2017-09-18T21:05:45.643

@Challenger5

Comment 1: Looking at the description again, you may be right. "Given one non-whitespace printable character, make a 3x3 square representation of that input." But that could imply that input needs to be 1 variable, and I'm not sure that most of these answers follow that (that said, I'm not fluent in a lot of these languages, so I could just be unable to read them right). I'm not 100% sure, so I'll keep my answer here.

Comment 2: Could you show me what the code would be? The shorthand you're referring to sounds familiar, but I'm struggling to find it online. – Josh Powlison – 2017-09-18T21:12:01.987

@JoshPowlison The code is for(i=3;i--;)console.log(i%2?'i i':'iii') (note that the ?: in the console.log statement has changed) – Esolanging Fruit – 2017-09-19T01:46:46.980

@JoshPowlison To confirm, the other submissions do input a char and use that, so I'm going to assume that's the correct behavior. As such, this answer is invalid. I recommend that you delete the answer and work on it while it's deleted, and then undelete it once you've got it working (that way, it won't get deleted by a mod, in which case you'd have to flag them to undelete it). – Esolanging Fruit – 2017-09-19T01:54:19.670