Skip to main content
added 60 characters in body
Source Link
rayryeng
  • 1.6k
  • 1
  • 14
  • 19

MATLAB, 9393 91 bytes

Not the prettiest, but it gets the job done.

t=inputt=[32 input('','s');m='#####' 32];m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n; ' ' t ' ';flipud[n;t;flipud(n)] m])

Code Explanation

Step #1

t=inputt=[32 input('','s'); 32];

Read in a string from STDIN and place a leading and trailing single space inside it. 32 is the ASCII code for a space and reading in the input as a string type coalesces the 32s into spaces.

Step #2

m='#####'.';

Declare a character array of 5 hash signs in a column vector.

Step #3

n=repmat('# ',numel(t)+2,1)';'

Create a 2 row character matrix that is filled by hash signs first followed by white space after. The number of characters is the length of the input string plus 2 so that we can accommodate for the space before and after the string.

Step #4

disp([m [n; ' ' t ' ';flipud[n;t;flipud(n)] m])

We're going to piece everything together. We place the first column of 5 hashes, followed by the centre portion and followed by another column of 5 hashes. The centre portion consists of the 2 row character matrix created in Step #3, the input string itself which has a trailing and leading space, followed by the 2 row character matrix but reversed.

Example Runs

>> t=inputt=[32 input('','s');m='#####' 32];m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n;' ' t ' ';flipud[n;t;flipud(n)] m]);
This is something special for you
#####################################
#                                   #
# This is something special for you #
#                                   #
#####################################
>> t=inputt=[32 input('','s');m='#####' 32];m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n;' ' t ' ';flipud[n;t;flipud(n)] m]);
Hello World
###############
#             #
# Hello World #
#             #
###############
>> t=inputt=[32 input('','s');m='#####' 32];m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n;' ' t ' ';flipud[n;t;flipud(n)] m]);
I <3 Code Golf StackExchange!
#################################
#                               #
# I <3 Code Golf StackExchange! #
#                               #
#################################

MATLAB, 93 bytes

Not the prettiest, but it gets the job done.

t=input('','s');m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n; ' ' t ' ';flipud(n)] m])

Code Explanation

Step #1

t=input('','s');

Read in a string from STDIN

Step #2

m='#####'.';

Declare a character array of 5 hash signs in a column vector.

Step #3

n=repmat('# ',numel(t)+2,1)';

Create a 2 row character matrix that is filled by hash signs first followed by white space after. The number of characters is the length of the input string plus 2 so that we can accommodate for the space before and after the string

Step #4

disp([m [n; ' ' t ' ';flipud(n)] m])

We're going to piece everything together. We place the first column of 5 hashes, followed by the centre portion and followed by another column of 5 hashes. The centre portion consists of the 2 row character matrix created in Step #3, the input string itself which has a trailing and leading space, followed by the 2 row character matrix but reversed.

Example Runs

>> t=input('','s');m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n;' ' t ' ';flipud(n)] m]);
This is something special for you
#####################################
#                                   #
# This is something special for you #
#                                   #
#####################################
>> t=input('','s');m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n;' ' t ' ';flipud(n)] m]);
Hello World
###############
#             #
# Hello World #
#             #
###############
>> t=input('','s');m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n;' ' t ' ';flipud(n)] m]);
I <3 Code Golf StackExchange!
#################################
#                               #
# I <3 Code Golf StackExchange! #
#                               #
#################################

MATLAB, 93 91 bytes

Not the prettiest, but it gets the job done.

t=[32 input('','s') 32];m='#####'.';n=repmat('# ',numel(t),1)';disp([m [n;t;flipud(n)] m])

Code Explanation

Step #1

t=[32 input('','s') 32];

Read in a string from STDIN and place a leading and trailing single space inside it. 32 is the ASCII code for a space and reading in the input as a string type coalesces the 32s into spaces.

Step #2

m='#####'.';

Declare a character array of 5 hash signs in a column vector.

Step #3

n=repmat('# ',numel(t),1)'

Create a 2 row character matrix that is filled by hash signs first followed by white space after. The number of characters is the length of the input string plus 2 so that we can accommodate for the space before and after the string.

Step #4

disp([m [n;t;flipud(n)] m])

We're going to piece everything together. We place the first column of 5 hashes, followed by the centre portion and followed by another column of 5 hashes. The centre portion consists of the 2 row character matrix created in Step #3, the input string itself which has a trailing and leading space, followed by the 2 row character matrix but reversed.

Example Runs

>> t=[32 input('','s') 32];m='#####'.';n=repmat('# ',numel(t),1)';disp([m [n;t;flipud(n)] m])
This is something special for you
#####################################
#                                   #
# This is something special for you #
#                                   #
#####################################
>> t=[32 input('','s') 32];m='#####'.';n=repmat('# ',numel(t),1)';disp([m [n;t;flipud(n)] m])
Hello World
###############
#             #
# Hello World #
#             #
###############
>> t=[32 input('','s') 32];m='#####'.';n=repmat('# ',numel(t),1)';disp([m [n;t;flipud(n)] m])
I <3 Code Golf StackExchange!
#################################
#                               #
# I <3 Code Golf StackExchange! #
#                               #
#################################
Source Link
rayryeng
  • 1.6k
  • 1
  • 14
  • 19

MATLAB, 93 bytes

Not the prettiest, but it gets the job done.

t=input('','s');m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n; ' ' t ' ';flipud(n)] m])

Code Explanation

Step #1

t=input('','s');

Read in a string from STDIN

Step #2

m='#####'.';

Declare a character array of 5 hash signs in a column vector.

Step #3

n=repmat('# ',numel(t)+2,1)';

Create a 2 row character matrix that is filled by hash signs first followed by white space after. The number of characters is the length of the input string plus 2 so that we can accommodate for the space before and after the string

Step #4

disp([m [n; ' ' t ' ';flipud(n)] m])

We're going to piece everything together. We place the first column of 5 hashes, followed by the centre portion and followed by another column of 5 hashes. The centre portion consists of the 2 row character matrix created in Step #3, the input string itself which has a trailing and leading space, followed by the 2 row character matrix but reversed.

Example Runs

>> t=input('','s');m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n;' ' t ' ';flipud(n)] m]);
This is something special for you
#####################################
#                                   #
# This is something special for you #
#                                   #
#####################################
>> t=input('','s');m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n;' ' t ' ';flipud(n)] m]);
Hello World
###############
#             #
# Hello World #
#             #
###############
>> t=input('','s');m='#####'.';n=repmat('# ',numel(t)+2,1)';disp([m [n;' ' t ' ';flipud(n)] m]);
I <3 Code Golf StackExchange!
#################################
#                               #
# I <3 Code Golf StackExchange! #
#                               #
#################################