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:
7total width, including the left and right edge characters.2Number 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:
^!!!!!!!^
$
$
$
$
^!!!!!!!^
$
$
$
$
^!!!!!!!^
Cheating and standard loopholes are not allowed.
Your code must not print anything to STDERR.
Your code may accept any character encoding you choose as the input, but any character encoding you choose must, as a minimum, support all the 95 printable ASCII characters.
The shortest code, in bytes, that completes this challenge successfully, is the winning code.
Leaderboard
var QUESTION_ID=92138,OVERRIDE_USER=58717;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}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>
29 Answers 29
05AB1E, (削除) 16 (削除ここまで) 14 bytes
×ばつs×ばつ`»D®»
Explanation
×ばつ # create a string of the correct nr of horizontal chars
s.ø # add the corner char on both sides
© # save in register while keeping it on the stack
|` # push the remaining inputs to the top of the stack
×ばつ` # push the correct nr of vertical chars on the stack
» # join on newline (joining the top vertical and horizontal sections)
D # duplicate this
® # push the horizontal part again
» # join everything on newline
Saved 4 bytes thanks to Adnan.
-
1\$\begingroup\$ Out of curiosity, why are you using the
©register :p? \$\endgroup\$Adnan– Adnan2016年09月03日 17:42:47 +00:00Commented Sep 3, 2016 at 17:42 -
1\$\begingroup\$ @Adnan: Good catch! I was going to, but ended up not using it and forgot to remove it :) \$\endgroup\$Emigna– Emigna2016年09月03日 17:46:21 +00:00Commented Sep 3, 2016 at 17:46
-
1\$\begingroup\$ @muddyfish: Reading the explanation from the question that part wasn't obvious, so I missed it. Thanks for letting me know! \$\endgroup\$Emigna– Emigna2016年09月03日 20:14:10 +00:00Commented Sep 3, 2016 at 20:14
-
1\$\begingroup\$ There's also a special surround command which works here:
Í×s.øU×S»X»D»Xr». \$\endgroup\$Adnan– Adnan2016年09月03日 20:42:04 +00:00Commented Sep 3, 2016 at 20:42 -
2\$\begingroup\$ @Adnan: Right you are. Good thinking! I've never used that before :) \$\endgroup\$Emigna– Emigna2016年09月03日 20:47:36 +00:00Commented Sep 3, 2016 at 20:47
Python, (削除) 53 (削除ここまで) (削除) 51 (削除ここまで) 55 Bytes
lambda a,b,c,d,e:d.join("\n"*-~b).join([c+e*(a-2)+c]*3)
+4 Bytes thanks to @nimi
anonymous lambda function, to call it, write f= before it. Example:
>>> print f(4,1,"€","|","-")
€--€
|
€--€
|
€--€
alternative, 53 Bytes
lambda a,b,c,d,e:((c+e*a+c+"\n"+(d+"\n")*b)*3)[:-b*2]
old version with the special case of no input, (削除) 69 (削除ここまで) (削除) 65 (削除ここまで) 63 Bytes
yay to changing the requirements mid-challenge...
lambda a=1,b=1,(c,d,e)="+|-":d.join("\n"*-~b).join([c+e*a+c]*3)
-
2\$\begingroup\$ Small bug: the first argument (
2in your example) is the total length of the line, including the corners, so the right input for your shape isf(4,1 ...). \$\endgroup\$nimi– nimi2016年09月03日 18:57:13 +00:00Commented Sep 3, 2016 at 18:57 -
\$\begingroup\$ @nimi thanks for the tip. (+4 bytes :( ) OPs first example is a bit confusing. (Some of the other answers have this bug aswell) \$\endgroup\$KarlKastor– KarlKastor2016年09月03日 22:06:22 +00:00Commented Sep 3, 2016 at 22:06
C, (削除) 167 (削除ここまで) (削除) 161 (削除ここまで) 159 bytes
Yeah.
#define p putchar
i,j;g(a,c,e){p(c);for(i=2;i++<a;)p(e);p(c);p(10);}h(b,d){for(i=0;i++<b;){p(d);p(10);}}f(a,b,c,d,e){g(a,c,e);h(b,d);g(a,c,e);h(b,d);g(a,c,e);}
-
2\$\begingroup\$ puts("") -> p('\n') ? or even p(10) if that'll work \$\endgroup\$RiaD– RiaD2016年09月04日 22:03:42 +00:00Commented Sep 4, 2016 at 22:03
-
\$\begingroup\$ How did I miss that! Thanks, @RiaD. \$\endgroup\$betseg– betseg2016年09月04日 23:34:11 +00:00Commented Sep 4, 2016 at 23:34
-
\$\begingroup\$ Also if you start loop with 2, you will save to more bytes \$\endgroup\$RiaD– RiaD2016年09月05日 06:51:45 +00:00Commented Sep 5, 2016 at 6:51
Ruby, (削除) 54 (削除ここまで) (削除) 45 (削除ここまで) 42 bytes
->x,y,c,v,h{[c+h*~-~-x+c+$/]*3*((v+$/)*y)}
It's an anonymous function that takes the different part of the input as separate parameters and returns the result as a complete string.
For example,
f=->x,y,c,v,h{[c+h*~-~-x+c+$/]*3*((v+$/)*y)}
puts f[6, 2, 'Ø', 'V', '>']
prints
Ø>>>>Ø
V
V
Ø>>>>Ø
V
V
Ø>>>>Ø
Javascript (ES6), 64 bytes
(h,v,e,V,H)=>(v=(h=e+H.repeat(h-2)+e)+`
${V}`.repeat(v)+`
`)+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,'+','@','#'))
-
\$\begingroup\$ Does this handle the special case of no input? \$\endgroup\$Conor O'Brien– Conor O'Brien2016年09月03日 17:00:22 +00:00Commented Sep 3, 2016 at 17:00
-
\$\begingroup\$
{ "message": "Script error.", "filename": "", "lineno": 0, "colno": 0 }when run inline. \$\endgroup\$noɥʇʎԀʎzɐɹƆ– noɥʇʎԀʎzɐɹƆ2016年09月03日 22:41:24 +00:00Commented Sep 3, 2016 at 22:41 -
\$\begingroup\$ @AgentCrazyPython - Run on IE? It has no support for
.repeat()\$\endgroup\$Arnauld– Arnauld2016年09月03日 22:54:33 +00:00Commented Sep 3, 2016 at 22:54 -
\$\begingroup\$ @Arnauld naw, safari \$\endgroup\$noɥʇʎԀʎzɐɹƆ– noɥʇʎԀʎzɐɹƆ2016年09月03日 23:34:07 +00:00Commented Sep 3, 2016 at 23:34
-
\$\begingroup\$ oh, it's ES6... \$\endgroup\$noɥʇʎԀʎzɐɹƆ– noɥʇʎԀʎzɐɹƆ2016年09月03日 23:34:17 +00:00Commented Sep 3, 2016 at 23:34
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="")
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.
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
awithout specific initialisation (it's already declared in the function declaration) - thanks @LuisMendo
-
1\$\begingroup\$ @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 soais already declared in the function declaration as the return value. Thanks :) \$\endgroup\$Tom Carpenter– Tom Carpenter2016年09月04日 03:11:07 +00:00Commented Sep 4, 2016 at 3:11 -
\$\begingroup\$ 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. \$\endgroup\$Tom Carpenter– Tom Carpenter2016年09月04日 03:17:15 +00:00Commented Sep 4, 2016 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'
-
2\$\begingroup\$ This is already very good. But you can play a bit with the input format and also solve the flaw that the challenge does not say the repeats are
< 10by putting/(.)(.)/;,ドル=$' x<>;say+(1ドル.2ドルx(<>-2).1ドル.$/)x3in a file (since it uses$') and calling withperl -M5.010 -n prog.pl <<< '^!S\n4\n9'(use real newlines) which counts as 48 bytes (2 extra handicap since it cannot be combined with-e) \$\endgroup\$Ton Hospel– Ton Hospel2016年09月04日 09:45:18 +00:00Commented Sep 4, 2016 at 9:45 -
\$\begingroup\$ @TonHospel Thanks. Right, I had not even noticed that this wouldn't work with numbers
>10.. Great work with the input format, thanks. \$\endgroup\$Dada– Dada2016年09月04日 11:23:19 +00:00Commented Sep 4, 2016 at 11:23 -
\$\begingroup\$ This is getting close to abusing the freedom to select the input format, but:
perl -nE '/.$/;,ドル=$/.<>x<>;say+($`.$&x(<>-2).$`)x3' <<< '^$\n!\n4\n9'is 41 bytes (no more$') and also gets rid of the spurious trailing newline \$\endgroup\$Ton Hospel– Ton Hospel2016年09月04日 17:04:38 +00:00Commented Sep 4, 2016 at 17:04 -
\$\begingroup\$ @TonHospel Indeed, I came up with that solution after your first suggestion, but I wasn't too comfortable with it because of the input format... Since we both thought about it, I changed my answer, but still, I feel like it's a bit cheaty... \$\endgroup\$Dada– Dada2016年09月04日 20:23:09 +00:00Commented Sep 4, 2016 at 20:23
Dyalog APL, (削除) 31 (削除ここまで) 29 bytes
Prompts for horizontal-character, width, junction-character, height, vertical-character – in that order.
h↓⊃⍪/3/⊂↑(⍞⍴⍨h←⎕),⊂⍞{∊⍺⍵⍺}⎕⍴⍞
⎕⍴⍞ input-horizontal-character and repeat input-width times (⍵ below)
⍞{...} input-junction-character which will be ⍺ in the function...
∊⍺⍵⍺ flatten [[junction],[horizontals],[junction]]
⊂ encapsulate so it can be part of a list
(...), prepend...
h←⎕ input-height
⍞⍴⍨ input-vertical-character and repeat it that many times
↑ make the list of strings into a character table
⊂ encapsulate (so it can be repeated as a whole)
3/ repeat it three times
╻ ╻ ╻
┗━ ┗━ ┗━
⍪/ concatenate the three pieces vertically
╻
┣━
┣━
┗━
(this encapsulates them too, so we need to...)
⊃ remove the encapsulation
h↓ drop the first h (rows)
┏━
┣━
┗━
C, 130 bytes
#define p putchar
#define E for(o=0;o++<O;p(10))p(S);
#define W for(p(P),D=0;D++<C-2;)p(_);p(P);p(10);
f(C,O,P,S,_,D,o){W E W E W}
Usage:
main(){f(7,2,'+','|','-');}
Output
+-----+
|
|
+-----+
|
|
+-----+
-
\$\begingroup\$ Removing the semicolons in
defines and adding it asf(C,O,P,S,_,D,o){W;E;W;E;W;}saves a byte. \$\endgroup\$betseg– betseg2016年09月28日 16:44:11 +00:00Commented Sep 28, 2016 at 16:44
C#, 108 bytes
(m,n,e,v,h)=>{string x=e+new string(h,m-2)+e+"\n",y=new string(v,n).Replace(v+"",v+"\n");return x+y+x+y+x;};
Anonymous function which generates each horizontal and vertical line and builds the final output.
Ungolfed function:
(m,n,e,v,h)=>
{
string x = e + new string(h, m - 2) + e + "\n",
y = new string(v, n).Replace(v + "", v + "\n");
return x + y + x + y + x;
};
Full program with test cases:
using System;
namespace LetterEWithoutE
{
class Program
{
static void Main(string[] args)
{
Func<int,int,char,char,char,string>f= (m,n,e,v,h)=>{string x=e+new string(h,m-2)+e+"\n",y=new string(v,n).Replace(v+"",v+"\n");return x+y+x+y+x;};
Console.WriteLine(f(7,2,'+','|','-'));
Console.WriteLine(f(7,2,'@','|','-'));
Console.WriteLine(f(7,2,'@','|','#'));
Console.WriteLine(f(8,3,'+','|','#'));
Console.WriteLine(f(8,3,'+','@','#'));
Console.WriteLine(f(9,4,'^','$','!'));
}
}
}
MATL, 15 bytes
Thanks to @muddyfish for a correction
2-Y"yv!iiY"!yyy
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
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:
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:
+-----+
|
|
+-----+
|
|
+-----+
?¿¿¿¿¿¿¿?
¡
¡
¡
¡
?¿¿¿¿¿¿¿?
¡
¡
¡
¡
?¿¿¿¿¿¿¿?
Bash + coreutils, 105 bytes
printf -- "3ドル`printf -- "4ドル%.0s" $(seq 1ドル)`3ドル`printf "\n5ドル%.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 + * |...
3ドルprintf -- "4ドル%.0s" $(seq 1ドル)3ドルprintf "\n5ドル%.0s" $(seq 2ドル)Create the first horizontal segment and vertical segment all together. This would result in:
+*****+ | |printf -- "3ドルprintf -- "4ドル%.0s" $(seq 1ドル)3ドルprintf "\n5ドル%.0s" $(seq 2ドル)%.0s\n" {1..3}Repeat the previously created part
3times over. This now results in:+*****+ | | +*****+ | | +*****+ | |printf -- "3ドルprintf -- "4ドル%.0s" $(seq 1ドル)3ドルprintf "\n5ドル%.0s" $(seq 2ドル)%.0s\n" {1..3}|sed -n 1,$((2ドル*2+3))pFinally pipe the previous output to
sedto get rid of the last 2 line segments by only outputting the first<Vertical Segment Length>*2+3lines of theE. We finally get theEwe 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,'+','|','#'))
+######+
|
|
+######+
|
|
+######+
-
\$\begingroup\$ you have 2 too many dashes in the output \$\endgroup\$Blue– Blue2016年09月03日 20:05:58 +00:00Commented Sep 3, 2016 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.
With comments:
[
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^$!
^!!!!!!!^
$
$
$
$
^!!!!!!!^
$
$
$
$
^!!!!!!!^
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.
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>.
Vyxal, 10 bytes
⇩*+Ǐ∇εJǏ∞⁋
* # Repeat the horizontal character...
⇩ # Horizontal distance - 2 times
+Ǐ # Prepend and append the corner character
∇ε # Push the vertical character repeated by the amount
J # Append that to the line
Ǐ # Append the first line
∞ # Mirror
⁋ # Join by newlines
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
@##@
CJam, 23 bytes
riri)N*r2*\r*\@r**a3*\*
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
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
-
\$\begingroup\$ If you use
,"\n"instead of."\n", you can drop the parens for the ternary. \$\endgroup\$Titus– Titus2016年10月17日 14:20:20 +00:00Commented Oct 17, 2016 at 14:20 -
\$\begingroup\$
for($h++;$i<=2*$h;)and$i++%$hsaves another byte. \$\endgroup\$Titus– Titus2016年10月17日 14:24:02 +00:00Commented Oct 17, 2016 at 14:24 -
\$\begingroup\$
$v-1gives only 3 horizontal characters for[5,2,+,|,-]. Number of horizontal characters, not including the left and right edge characters \$\endgroup\$Titus– Titus2016年10月17日 14:37:27 +00:00Commented Oct 17, 2016 at 14:37 -
\$\begingroup\$ @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 \$\endgroup\$Jörg Hülsermann– Jörg Hülsermann2016年10月17日 14:46:20 +00:00Commented Oct 17, 2016 at 14:46
Eas an input, and make anEwithEs? \$\endgroup\$