The Letter E with E

Your task is to display the below letter "E" shaped ASCII art, given five inputs.

Examples:

Input: 7,2,+,|,- (Note: You don't have to follow this exact input format, and if you don't use it, then you must explain how your own input format works)

Explanation:

• 7 total width, including the left and right edge characters.

• 2 Number of vertical characters.

• + The character that should display at the edges.

• | The character that should display vertically between the edges.

• - The character that should display horizontally.

Output of the above example:

+-----+
|
|
+-----+
|
|
+-----+

Other examples:

Input: 7,2,@,|,-

Output:

@-----@
|
|
@-----@
|
|
@-----@

Input: 7,2,+,|,#

Output:

+#####+
|
|
+#####+
|
|
+#####+

Input: 8,3,+,|,#

Output:

+######+
|
|
|
+######+
|
|
|
+######+

Input: 8,3,+,@,#

Output:

+######+
@
@
@
+######+
@
@
@
+######+

Input: 9,4,^,$,! Output: ^!!!!!!!^$

$^!!!!!!!^$

)+v+h

Example

let f =
(h,v,e,V,H)=>(v=(h=e+H.repeat(h-2)+e)+
${V}.repeat(v)+ )+v+h console.log(f(8,3,'+','@','#')) • Does this handle the special case of no input? – Conor O'Brien Sep 3 '16 at 17:00 • { "message": "Script error.", "filename": "", "lineno": 0, "colno": 0 } when run inline. – noɥʇʎԀʎzɐɹƆ Sep 3 '16 at 22:41 • @AgentCrazyPython - Run on IE? It has no support for .repeat() – Arnauld Sep 3 '16 at 22:54 • @Arnauld naw, safari – noɥʇʎԀʎzɐɹƆ Sep 3 '16 at 23:34 • oh, it's ES6... – noɥʇʎԀʎzɐɹƆ Sep 3 '16 at 23:34 V, 18 bytes älJxxÀPjddÀpkäGYGp Try it online! R, 80 bytes Pretty repetitive : function(h,v,a,b,c)cat(t<-c(a,rep(c,h),a,"\n"),d<-rep(c(b,"\n"),v),t,d,t,sep="") Ungolfed : function(h,v,a,b,c) cat(t<-c(a,rep(c,h),a,"\n"), d<-rep(c(b,"\n"),v), t,d,t, sep="") Pyke, 16 15 bytes *2mtz:zn+Q*' +D Try it here! Pyth, 19 bytes jP*3,++Jw*-E2wJj*Ew A program that takes newline-separated input on STDIN of the corner character, number of horizontal characters, horizontal character, number of vertical characters and the vertical character, and prints the result. Try it online How it works jP*3,++Jw*-E2wJj*Ew Program. Jw Get the corner character. Store in J E Get the number of horizontal characters - 2 -2 * w Get the horizontal character and repeat it that many times + Add J at the beginning of that + J and at the end E Get the number of vertical characters * w Get the vertical character and repeat it that many times j Join the above on newlines , Construct a 2-element list from the horizontal and vertical strings *3 Repeat it 3 times P Everything except the last element j Join the above on newlines Implicitly print MATLAB, 95 92 91 85 81 bytes MATLAB 'E' function. (edit: doesn't work on Octave) function a=e(n,m,c,h,v);a(1:n)=h;a=[c a c];a(2:m+1,1)=v;a=[a;a;a];a=a(1:3+2*m,:); And ungolfed: function a=e(n,m,c,h,v); %Declare the function a(1:n)=h; %Initialise return with top line excluding the corners a=[c a c]; %Then add corner pieces a(2:m+1,1)=v; %Next add the first vertical part a=[a;a;a]; %Repeat three times vertically to get an E with a tail a=a(1:3+2*m,:); %And then lop off the tail The function should be called like: e(5,2,'*','-','|') Which will return: +-----+ | | +-----+ | | +-----+ This can probably be simplified a bit, I'll keep working on it. I don't like having the entire function declaration to get the input, so will see if I can improve that. • Saved 3 bytes by simplifying generation of first line to first make the line without corners and then add the corners as this reduces the number of times indexing is required. • Another byte saved by starting with the first corner. • 6 more bytes by replacing repmat(a,3,1) call with [a;a;a]. • Saved 4 bytes by using a without specific initialisation (it's already declared in the function declaration) - thanks @LuisMendo • @LuisMendo interesting. I originally had a=[c a c] in there but removed it to shrink things down as normally you can't index access a non-existent variable and create it in the process. I forgot that this was a function so a is already declared in the function declaration as the return value. Thanks :) – Tom Carpenter Sep 4 '16 at 3:11 • In fact you can do it even if not in a function - indexing a non-existent variable does create it. Learn new things every day. – Tom Carpenter Sep 4 '16 at 3:17 Perl, 40 + 1 (-n) = 41 bytes Thanks to @Ton Hospel for saving 14 bytes and allowing the program to work with entry greater than 10. /.$/;$,=$/.<>x<>;say+($.$&x(<>-2).$)x3 Need -n as well as -E (or -M5.010) to run. For instance : perl -nE '/.$/;$,=$/.<>x<>;say+($.$&x(<>-2).$)x3' <<< '^$
!
4
9'
• @TheBitByte Ok great, it's done, thanks. – Dada Sep 3 '16 at 23:40
}
}
}

MATL, 15 bytes

Thanks to @muddyfish for a correction

2-Y"yv!iiY"!yyy

Try it online!

Explanation

The stack contents after each step are indicated for clarity, using the first example in the challenge.

2-    % Implicitly input number of repetitions of the char of the horizontal line.
% Subtract 2
%   STACK: 5
Y"    % Implicitly input char of the horizontal line. Apply run-length decoding
%   STACK: '-----' (string)
y     % Implicitly input (from below) the char of the corners. Duplicate onto the top
%   STACK: '+', '-----', '+'
v!    % Concatenate all the stack horizontally. We now have the horizontal line
% including the corners
%   STACK: '+-----+'
iiY"  % Take two inputs: char of the vertical line and number of repetitions
%   STACK: '+-----+', '||'
!     % Transpose. This tranforms the string into a vertical char array, which
% gives the vertical line
%   STACK: '+-----+', ['|';'|'] (vertical char array)
y     % Duplicate from below: this pushes a new copy of the horizontal line
% onto the top of the stack
%   STACK: '+-----+', ['|';'|'], '+-----+'
y     % Duplicate from below: this pushes a new copy of the vertical line
% onto the top of the stack
%   STACK: '+-----+', ['|';'|'], '+-----+', ['|';'|'],
y     % Duplicate from below: this pushes a new copy of the horizontal line
% onto the top of the stack
%   STACK: '+-----+', ['|';'|'], '+-----+', ['|';'|'], '+-----+'
% Implicitly display

Bash + coreutils, 105 bytes

printf -- "$3printf -- "$4%.0s" $(seq$1)$3printf "\n$5%.0s" $(seq$2)%.0s\n" {1..3}|sed -n 1,$(($2*2+3))p

Assuming the file within which this is stored is named A.sh, the usage would be:

bash A.sh <Horizontal Segment Length w/out Edge Chars> <Vertical Segment Length> '<Left/Right Edge Char>' '<Char Between Edges>' '<Vertical Char>'

The -- are needed, just in case one of the character inputs happens to be a -, and printf apparently doesn't handle dashes in the beginning of a string very nice without the double-dashes.

Explanation

Assuming that the input is 5 2 + * |...

1. $3printf -- "$4%.0s" $(seq$1)$3printf "\n$5%.0s" $(seq$2)

Create the first horizontal segment and vertical segment all together. This would result in:

+*****+
|
|

2. printf -- "$3printf -- "$4%.0s" $(seq$1)$3printf "\n$5%.0s" $(seq$2)%.0s\n" {1..3}

Repeat the previously created part 3 times over. This now results in:

+*****+
|
|
+*****+
|
|
+*****+
|
|

3. printf -- "$3printf -- "$4%.0s" $(seq$1)$3printf "\n$5%.0s" $(seq$2)%.0s\n" {1..3}|sed -n 1,$(($2*2+3))p

Finally pipe the previous output to sed to get rid of the last 2 line segments by only outputting the first <Vertical Segment Length>*2+3 lines of the E. We finally get the E we want:

+*****+
|
|
+*****+
|
|
+*****+

PowerShell v2+, 60 59 bytes

param($a,$b,$c,$d,$e)(,($x="$c$($e*($a-2))$c")+,$d*$b)*2;$x

Takes input as individual command-line arguments. Constructs the horizontal string, stores that into $x for use later, then forms that into an array with the comma-operator ,. Performs array concatenation (i.e., adding elements to the end) of$d formulated into an array of $b elements. That, in turn, is formulated into an array of two elements with another comma operator, and is left on the pipeline. Then, the horizontal$x is left on the pipeline. Abuses the default formatting of Write-Output to put a newline between elements.

Example

PS C:\Tools\Scripts\golfing> .\the-letter-e-without-e.ps1 5 3 "z" "v" "d"
zdddz
v
v
v
zdddz
v
v
v
zdddz

Python 3, 60 bytes

A Function

def p(a,b,c,d,e):q=c+e*(a-2)+c;return(q+'\n'+(d+'\n')*b)*2+q

Test Case

>>> print(p(8,2,'+','|','#'))
+######+
|
|
+######+
|
|
+######+
• you have 2 too many dashes in the output – Blue Sep 3 '16 at 20:05

Brainf*ck, 147 bytes

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

Takes input from stdin as first 5 characters entered. The first two are have 48 subtracted from their ASCII code so 0-9 behave as expected. For numbers > 9, add 48 to the number and use the corresponding character. The other three characters are as specified in the challenge.

I'm sure it's not the optimal solution but life is too short to golf brainf*ck.

[
Input: number number corner vertical horizontal
Numbers are single digits; add 48 and use the ASCII character corresponding
to the number you want for numbers > 9.
First number is the number of characters across. Second is the number down.

Layout: {first number-2} {second number} {temp} {a} {b} {c}
]

,>,>++++++++[<------<------>>-]<<-->>>,>,>,
now we should have the first five cells with the specified layout
the 6th will hold 3 as a counter and the 7th 2 and the 8th 10 '\n'

>+++>++>++++++++++<<
[  while the 6th cell is not 0
-
<<<.    print corner
<<<[->>+>>>.<<<<<]  print horizontal characters
>>[-<<+>>]         copy temp back to 1st cell
>.>>>>>.           print corner and newline
<
[ If the second counter is not zero
-
<<<<<<[->+>>.>>>>.<<<<<<<]  print vertical and newline n times
>[<+>-]           copy temp back to 2nd cell
]
>>>>
]

Example run:

sean@SEANSBOX:~/Dropbox/Code/BF$./bf E.b 94^$!
^!!!!!!!^


^!!!!!!!^


^!!!!!!!^

PHP, 97 bytes

list(,$w,$h,$c,$v,$r)=$argv;echo$b=str_pad($a=str_pad($c,++$w,$r)."$c\n",--$h*2+$w,"$v\n"),$b,$a; no loop, only builtins. Run with php -r '<code>' <parameters>. Java 7, 205 129 bytes String c(int w,int h,String a,char b,char c){String r=a,n="\n",l="";for(;w-->2;r+=c);r+=a+n;for(;h-->0;l+=b+n);return r+l+r+l+r;} -76 bytes thanks to an anonymous stranger. PS: Don't go edit other people's posts next time. If you have something to golf please leave it as a comment, or if it's using a completely different approach you could make your own answer. Still thanks for golfing away all these bytes, though - whoever you are.. Ungolfed & test cases: Try it here. class M { static String c(int w, int h, String a, char b, char c){ String r = a, n = "\n", l = ""; for(; w-- > 2; r += c); r += a+n; for( ;h-- > 0; l += b+n); return r+l+r+l+r; } public static void main(String[] a) { System.out.print(c(7, 2, "+", '|', '-')); System.out.print(c(9, 4, "?", '¡', '¿')); } } Output: +-----+ | | +-----+ | | +-----+ ?¿¿¿¿¿¿¿? ¡ ¡ ¡ ¡ ?¿¿¿¿¿¿¿? ¡ ¡ ¡ ¡ ?¿¿¿¿¿¿¿? Racket 124 bytes (λ(w h a b c)(for((i 3))(display a)(for((i w))(display c))(display a)(when(< i 2)(displayln "")(for((j h))(displayln b))))) More readable form: (define(f w h a b c) (for((i 3)) (display a) (for((i w)) (display c)) (display a) (when(< i 2) (displayln "") (for((j h)) (displayln b))))) Testing: (f 7 2 "+" "|" "-" ) +-------+ | | +-------+ | | +-------+ C++, 121 Bytes #import<string> #import<iostream> #define f(w,h,C,W,H){std::string s(w,W),t;s=C+s+C+"\n";for(int i=h;i--;)t=t+H+"\n";std::cout<<s+t+s+t+s;} Ungolfed: #import<string> #import<iostream> #define f(w,h,C,W,H){ std::string s(w,W),t; //define two strings, one empty, one with horizontal characters s = C+s+C+"\n"; //assemble a horizontal bar for(int i=h;i--;) t=t+H+"\n"; //assemble a vertical bar std::cout<<s+t+s+t+s; //print } In C++ its not allowed to declare functions without type as in C. But macros that behave just like a function are totally possible. Note also that the ungolfed version will not compile until you add a "\" to each but the last line of the macro. You might save two additional bytes by removing the {}, but then you can't use the macro twice in a row. Usage: int main() { f(4,2,'+','-','|') f(2,1,'@','#','i') return 0; } Output: +----+ | | +----+ | | +----+ @##@ i @##@ i @##@ Try it online CJam, 23 bytes riri)N*r2*\r*\@r**a3*\* Try it online! The input is is in the given order, but should be space separated instead of using a comma. Some of the difficulty is getting the input the right order for CJam's join operation *; for comparison rearranging the input in could save 4 bytes. If the inputs are dubbed A B C D E then the program works something like this: ri e# get A as integer ri)N* e# create B+1 newlines r2* e# create 2 Cs \r* e# join newlines with D (hereafter ND) \@ e# bring A & Cs to the front r* e# create A Es * e# join, puts Es between Cs (hereafter CEC) a3* e# makes 3 copies of CEC strings \* e# join, puts NDs between CECs Lua(5.2), 144 bytes k,a,p,q=loadstring,arg,io.write,print l,d=k"for i=3,a[1]do p(a[5])end",k"for i=1,a[2]do q(a[4])end"b=a[3]p(b)l()q(b)d()p(b)l()q(b)d()p(b)l()p(b) Try it online! (Coding Ground) It should output something like that right now: +@@@@@+ l l +@@@@@+ l l +@@@@@+ Own input: 7 2 + l @ You can change the input in project->compile options and there change the values, each value as in the example but not separated by commas but by spaces. QBIC, 44 bytes ::;;;X=A[q,a-2|X=X+C]X=X+A ?X[1,2|[1,b|?B]?X Explanation ::;;; Get the input parameters, 2 numbers and 3 strings X=A[q,a-2|X=X+C]X=X+A Build the horizontal string: The corner string, x-2 times the filler string and another corner ?X Print the horizontal string [1,2| Do the next thing twice [1,b|?B]?X Print the right number of vertical strings, then the horizontal string. PHP, 94 Bytes <?list($v,$h,$p,$d,$r)=$_GET[a];for($h++;$i<=2*$h;)echo$i++%$h?$d:str_pad($p,$v-1,$r).$p,"\n"; Input format an array in the same order as the suggested string • If you use ,"\n" instead of ."\n", you can drop the parens for the ternary. – Titus Oct 17 '16 at 14:20 • for($h++;$i<=2*$h;) and $i++%$h saves another byte. – Titus Oct 17 '16 at 14:24
• \$v-1 gives only 3 horizontal characters for [5,2,+,|,-]. Number of horizontal characters, not including the left and right edge characters – Titus Oct 17 '16 at 14:37
• @Titus that is right, I have rollback your edit. 5 Horizontal means 3 Characters with 2 edges = 5. Make look at the question. And for the others ideas Thank You – Jörg Hülsermann Oct 17 '16 at 14:46