# Reflections in Water [closed]

Take a string as input. This string can be as long as you'd like, however, it may only include letters and spaces––no numbers, punctuation, etc. When a word is passed into your function, an image will be made out of it. This image is the input word written out using only these characters: , /, \, and |. You do not need to use all of these characters, but you may not use any others. Only words are inputed; no numbers or any other characters.

Here are a couple examples:

Input : "String"

Return :

–––    –––    –––   –––  |\    |   –––
|        |    |   |   |   | \   |  |
–––     |    |–––    |   |  \  |  | ––
|    |    |   \   |   |   \ |  |   |
–––     |    |    \ –––  |    \|   –––     //uppercase string written out
––––––––––––––––––––––––––––––––––––––––    //bar
//line break
–––     |    |    / –––  |    /|   –––
|    |    |   /   |   |   / |  |   |
–––     |    |–––    |   |  /  |  | ––
|        |    |   |   |   | /   |  |
–––    –––    –––   –––  |/    |   –––     //uppercase string written upside-down (reflected)


After the all caps string written out, there is a bar and then a line break. After that, there is the same string, just mirrored/upside-down. The bar under the word spelled out should be the length of the written out string. The upside down word––the reflection––goes one line beneath the line break.

Here is another example:

Input : "hi"

Return :

|  |  –––
|  |   |
|––|   |
|  |   |
|  |  –––
–––––––––

|  |  –––
|  |   |
|––|   |
|  |   |
|  |  -––


Add a ripple effect. Have something like a random indent between 0 and 3 spaces before each line in the reflection. Here's an example of what it could look like:

Input : "hi"

Return :

|  |  –––
|  |   |
|––|   |
|  |   |
|  |  –––
–––––––––

|  |  –––
|  |   |
|––|   |
|  |   |
|  |  -––


## Your code should be in the following form:

function createAwesomeness(string) -> string {
let s = //your code that creates the 'image'
return s
}

print createAwesomeness("string")
print createAwesomeness("bananas")


## A couple notes:

• Every language is valid
• Suggestion: Do not copy the font-set as a dictionary or array because that adds a lot to your code's size. Both as a challenge and to lower your code's size, try to use a function of sorts to create the letters
• Along with your code, have:
• The size in bytes of your function
• The number of characters of your function
• The two examples
• Shortest, working code wins
• There is currently no deadline

If any further explanation is needed, please tell me in the comments!

Any response is welcome and greatly appreciated!

## closed as unclear what you're asking by Peter Taylor, Dennis♦, Geobits, SuperJedi224, es1024Aug 7 '15 at 7:10

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Could you please show the complete fontset that we are supposed to use in this challange? – Loovjo Aug 5 '15 at 18:03
• Anyway, instead of showing how the answer should be in a function, I would suggest just saying "You should create a function named createAwesomeness that takes the string as the only argument" or something similar. – Loovjo Aug 5 '15 at 18:06
• Are letter representations for "S", "T", "R", "I", "N" and "G" other than the ones shown above also valid, or are the ones from above a fixed part of the font set to be used? – Chiru Aug 5 '15 at 19:16
• In order to avoid disputes over whether letter representations "reasonably resemble" the letter, you should mandate specific representations. (That's also probably the only way you'll get letter representations which use more than one character). With respect to the deadline: deadlines are a Bad Thing™. By all means wait a week before awarding the accepted answer, but a) there's no need to say that you will do that; b) if someone comes along later with a better answer, accept that one instead. – Peter Taylor Aug 6 '15 at 18:32
• I'm voting to close as unclear what you're asking, since, without predefined ASCII art representations of all characters, there's no objective way to determine if a given submission is valid or not. A code golf competition like this one needs a tight specification. Otherwise, the shortest answer is just the one that generates the ugliest font. – Dennis Aug 6 '15 at 18:48

# JavaScript (ECMAScript 6) (580 characters/bytes)

Probably not the best/shortest way to do this, but here's my two cents' worth:

a=x=>{l=["#####","#   #","#","  #","    #","# #","#  ##","####",""],g=[0,1,1],t=[8,8,8,8,8,0,1,...g,7,1,0,1,7,0,2,2,2,0,7,1,1,1,7,0,2,0,2,0,0,2,0,2,2,0,2,0,1,...g,...g,0,3,3,3,0,0,4,4,4,...g,5,5,1,2,2,2,2,0,0,...g,1,1,1,1,6,1,...g,1,0,0,1,0,2,2,...g,6,0,0,1,0,5,1,0,2,0,4,0,0,3,3,3,3,1,1,1,1,...g,1,1,3,1,1,1,0,...g,3,1,1,1,1,0,3,3,0,4,0,2,0],s=(n,r)=>l[t[5*n+r]].padRight(8),y=Array(10).fill("");for(r=-1,z=0;++r<5&z<x.length;r==4&&++z?r=-1:0){c=x[z].charCodeAt()&31;y[r]+=s(c,r),y[9-r]+=s(c,r)}return${y.slice(0,5).join }${"-".repeat(y[0].length-3)}

${y.slice(5).join }} console.log(a("string")) console.log(a("bananas"))  Note that although this is standard ES6, this strictly requires sloppy mode (heh, get it?) which hasn't landed in all of the JS engines/transpilers yet; it'll probably be ready this winter. If anyone knows a way to run this code in a sloppy environment as of today, feel free to edit. Well, since people still need to reproduce my output, I'll just give you the strict version that only differs in the way that it uses "let" to declare variables instead of making them globals by omitting it. Feel free to verify that I only added "let" in four places and changed nothing further. Here's the strict version that you can run today already using babel: let a=x=>{let l=["#####","# #","#"," #"," #","# #","# ##","####",""],g=[0,1,1],t=[8,8,8,8,8,0,1,...g,7,1,0,1,7,0,2,2,2,0,7,1,1,1,7,0,2,0,2,0,0,2,0,2,2,0,2,0,1,...g,...g,0,3,3,3,0,0,4,4,4,...g,5,5,1,2,2,2,2,0,0,...g,1,1,1,1,6,1,...g,1,0,0,1,0,2,2,...g,6,0,0,1,0,5,1,0,2,0,4,0,0,3,3,3,3,1,1,1,1,...g,1,1,3,1,1,1,0,...g,3,1,1,1,1,0,3,3,0,4,0,2,0],s=(n,r)=>l[t[5*n+r]].rpad(8),y=Array(10).fill("");for(let r=-1,z=0;++r<5&z<x.length;r==4&&++z?r=-1:0){let c=x[z].charCodeAt()&31;y[r]+=s(c,r),y[9-r]+=s(c,r)}return${y.slice(0,5).join
}
${"-".repeat(y[0].length-3)}${y.slice(5).join
}}
console.log(a("string"))
console.log(a("bananas"))


## Output

The first console.log yields STRING:

#####   #####   #####   #####   #   #   #####
#         #     #   #     #     #   #   #
#####     #     #####     #     #   #   #####
#     #     # #       #     #  ##   #   #
#####     #     #   #   #####   #   #   #####
---------------------------------------------

#####     #     #   #   #####   #   #   #####
#     #     # #       #     #  ##   #   #
#####     #     #####     #     #   #   #####
#         #     #   #     #     #   #   #
#####   #####   #####   #####   #   #   #####


and the second console.log yields BANANAS:

####    #####   #   #   #####   #   #   #####   #####
#   #   #   #   #   #   #   #   #   #   #   #   #
#####   #####   #   #   #####   #   #   #####   #####
#   #   #   #   #  ##   #   #   #  ##   #   #       #
####    #   #   #   #   #   #   #   #   #   #   #####
-----------------------------------------------------

####    #   #   #   #   #   #   #   #   #   #   #####
#   #   #   #   #  ##   #   #   #  ##   #   #       #
#####   #####   #   #   #####   #   #   #####   #####
#   #   #   #   #   #   #   #   #   #   #   #   #
####    #####   #   #   #####   #   #   #####   #####


## How it works:

My idea was to generate the the alphabet by compressing letters with respect to similar lines. Thus, every letter in the alphabet can be represented as a 5-dimensional vector of numbers that correspond to a string that again corresponds to a row in a letter.

This approach is made a lot easier when every letter has the same width, as this enables us to re-use some string patterns more effectively. With this idea in mind, I then designed a font that is optimized for similar-looking lines in letters, so that it compresses well:

#####
#   #
#####
#   #
#   #

####
#   #
#####
#   #
####

#####
#
#
#
#####

####
#   #
#   #
#   #
####

#####
#
#####
#
#####

#####
#
#####
#
#

#####
#
#####
#   #
#####

#   #
#   #
#####
#   #
#   #

#####
#
#
#
#####

#####
#
#
#
#####

#   #
#   #
# #
# #
#   #

#
#
#
#
#####

#####
#####
#   #
#   #
#   #

#   #
#   #
#   #
#  ##
#   #

#####
#   #
#   #
#   #
#####

#####
#   #
#####
#
#

#####
#   #
#   #
#  ##
#####

#####
#   #
#####
# #
#   #

#####
#
#####
#
#####

#####
#
#
#
#

#   #
#   #
#   #
#   #
#####

#   #
#   #
#   #
#   #
#

#   #
#   #
#   #
#####
#####

#   #
#   #
#
#   #
#   #

#   #
#   #
#####
#
#

#####
#
#####
#
#####

=========================================

0: #####
1: #   #
2: #
3:   #
4:     #
5: # #
6: #  ##
7: ####
8:

A = [0, 1, 0, 1, 1]
B = [7, 1, 0, 1, 7]
C = [0, 2, 2, 2, 0]
D = [7, 1, 1, 1, 7]
E = [0, 2, 0, 2 ,0]
F = [0, 2, 0, 2, 2]
G = [0, 2, 0, 1, 0]
H = [1, 1, 0, 1, 1]
I = [0, 3, 3, 3, 0]
J = [0, 4, 4, 4, 0]
K = [1, 1, 5, 5, 1]
L = [2, 2, 2, 2, 0]
M = [0, 0, 1, 1, 1]
N = [1, 1, 1, 6, 1]
O = [0, 1, 1, 1, 0]
P = [0, 1, 0, 2, 2]
Q = [0, 1, 1, 6, 0]
R = [0, 1, 0, 5, 1]
S = [0, 2, 0, 4, 0]
T = [0, 3, 3, 3, 3]
U = [1, 1, 1, 1, 0]
V = [1, 1, 1, 1, 3]
W = [1, 1, 1, 0, 0]
X = [1, 1, 3, 1, 1]
Y = [1, 1, 0, 3, 3]
Z = [0, 4, 0, 2, 0]


To further assist compression, I decided to only use number signs (#) to form letters, resulting in better compression. Another great thing about this approach is that it allows me to do a very simple reflection logic, since I'm not required to transform "\" to "/". The resulting font is exceptionally ugly, but as long as it compresses well, I really don't mind about its looks.

In the end, I managed to represent every single letter of the alphabet by using eight different patterns in total (plus one additional dummy pattern for spaces). It was in my best interest to use no more than 10 different patterns (or else I'd have to pay the price of requiring two characters to write down some numbers in the code). I then serialized all letter information in an array, added a little bit of letter selection/concatenation logic, and voilà.

• Would using # work better? – wizzwizz4 Feb 8 '16 at 18:41
• Yes, # looks much nicer than -. Edited, thanks! – Chiru Feb 8 '16 at 18:48