# Generate information cards with titles

You must take input in the form of

title|line1|line2|(...)|line[n]


And output an information card. It's hard to explain how to make the card, so here's a quick example:

Input

1234567890|12345|1234567890123|pie|potato|unicorn


Output

/===============\
|  1234567890   |
|===============|
| 12345         |
| 1234567890123 |
| pie           |
| potato        |
| unicorn       |
\---------------/


Detailed specifications:

• The title must be centered (if there are an odd number of characters you can decide whether to put an extra space after or before it).
• The remaining lines must be left-aligned.
• All of them must have at least one space of padding before and after.
• Each line must be the same length.
• The lines must be the smallest length possible in order to fit all of the text.
• The first and last character of each row (except for the first and last rows) must be a |.
• There must be a /, a row of =s, and a \ in the line right before the title. (the first line)
• There must be a |, a row of =s. and a | in the line right after the title. (the third line)
• There must be a \, a row of -s, and a / in the last line.
• For the example input provided, your program's output must exactly match the example output provided.
• The input will always contain at least one |; your programs behaivior when a string like badstring is input does not matter.

This is so the shortest code in character count wins.

• In python input() interprets the input as python code. Is it ok to use input and take the input in quotes, if so do we need to add 2 for the quotes?
– user8777
Sep 25 '13 at 0:00
• @LegoStormtroopr I suppose that's okay, but add +2 for quotes then
– Doorknob
Sep 25 '13 at 1:27

## Ruby, 153147 140 characters

h,*d=s=gets.chop.split(?|)
puts"/%s\\
|%s|
|%s|"%[e=?=*k=2+l=s.map(&:size).max,h.center(k),e]
d.map{|x|puts"| %%-%ds |"%l%x}
$><<?\\+?-*k+?/  Double format string in the second-to-last line :D • l=s.map(&:size).max saves 4 Sep 24 '13 at 5:28 • Also no need for parentheses around k=l+2 (2 chars), center(k) (2 chars), k=2+l=s.... (2 chars). Sep 24 '13 at 7:39 • @CarySwoveland Thanks, edited – Doorknob Sep 24 '13 at 12:15 • @Howard I fixed the first one, but I'm not sure where you're seeing the second or third ones...? – Doorknob Sep 24 '13 at 12:15 • "| %s |"%h.center(l) -> "|%s|"%h.center(k) which removes 2 spaces. And l=s.map(&:size).max;e=?=*k=l+2" -> e=?=*k=2+l=s.map(&:size).max Sep 24 '13 at 17:13 # Python 2.7 - 168 = 166 + 2 for quotes. This assumes we can accept the input with surrounding quotes, hence the possible +2. Either way +2 is better than the +4 required if you use raw_input() vs. just input(). b="|" s=input().split(b) w=max(map(len,s)) x=w+2 S="| %s |" print"\n".join(["/"+"="*x+"\\",S%s[0].center(w),b+"="*x+b]+[S%i.ljust(w)for i in s[1:]]+["\\"+"-"*x+"/"])  Thanks to Volatility for the max(map(len,s)) tip. A very cool tip. edit: Corrected top row problem. And the above outputs this: > python i.py "1234567890|12345|1234567890123|pie|potato|unicorn" /===============\ | 1234567890 | |===============| | 12345 | | 1234567890123 | | pie | | potato | | unicorn | \---------------/  • This doesn't work in either Python 2 or 3. You should either change input to raw_input or use print as a function. Also, change len(max(s,key=len)) into max(map(len,s)) and get rid of the space before for i in s[1:] to save 5 chars Sep 24 '13 at 6:31 • I've checked in the past using input() and assuming the text is entered as a string is usually permissable. I'll squeeze your other suggestions in later. Thanks :) – user8777 Sep 24 '13 at 6:57 • @LegoStormtroopr If you assume the input in a slightly different format you should: 1) Ask if it is admissable to the OP, 2) State it somewhere. Also, when doing this, I think it would be correct to also provide a sample that uses the format explained in the question. Sep 24 '13 at 13:11 • @Bakuriu Done!! – user8777 Sep 25 '13 at 1:41 • I count 165 characters (+2=167 total). – Doorknob Sep 25 '13 at 13:00 ### GolfScript, 97 characters '|'/{' ':!{1/*}:E~}%.{,}%$-1=:L'='*:§'/\\'E\(.,L\-)2/{!E}*L<'||':^E§^E@{!L*+L<^E}/L'-'*'\\/'E]n*

> 1234567890|12345|1234567890123|pie|potato|unicorn

/===============\
|   1234567890  |
|===============|
| 12345         |
| 1234567890123 |
| pie           |
| potato        |
| unicorn       |
\---------------/

• § that's an interesting variable name. :P
– Doorknob
Feb 23 '14 at 22:59

# Charcoal, 66 bytes

≔∕Ｓ|ι≔⁺⌈ＥιＬκ²ς/×=ς↓\↓⁺Ｌι¹←/←ς↑\↑⁺Ｌι¹↘Ｍ∕⁻ςＬ§ι⁰¦²→Ｐ§ι⁰Ｍ±²¦¹Ｐ×=ςＭ↘✂ι¹


I wasn't getting a proper result with reflection, so I made the box manually.

Try it online!

# Charcoal (Verbose), 385 bytes

Assign(Divide(InputString,"|"),i)
Print("/")
Print(Times("=",v))
Print(:Down,"\\")
Print(:Down,Length(i)+1)
Print(:Left,"/")
Print(:Left, v)
Print(:Up, "\\")
Print(:Up,Length(i)+1)
Move(:DownRight)
Move(Minus(v,Length(AtIndex(i,0)))/2,:Right)
MultiPrint(AtIndex(i,0))
Move(Negate(2),1)
MultiPrint(Times("=",v))
Move(:DownRight)
Print(Slice(i,1))


Try it online!

• Nice answer! Unrelated: How many of you got my 1+ Christmas gift on 12/25/2020?
– null
Jan 29 '21 at 10:36
• I don't remember getting one, I think Jan 29 '21 at 10:38
• That's pretty sad, I worked hard on that one :( it's an 1+ chirstmas tree program I posted on twtxt :)
– null
Feb 7 '21 at 4:10
• @null haven't checked twtxt in a while. I'll see it! Feb 7 '21 at 4:19
• Tell Lyxal I'm back ;)
– null
Jul 26 '21 at 16:24

import Data.List.Split
z=replicate
l=length
p w s=' ':s++z(w-l s)' '
c w s=p w$z(div(w-l s-1)2)' '++s t(i:s)=let r=z m;m=(+)1$maximum$map l(i:s)in"/="++r '='++"\\\n"++"|"++c m i++"|\n|="++r '='++"|\n"++concat['|':p m x++"|\n"|x<-s]++"\\-"++r '-'++"/" main=do l<-getLine;putStrLn$t$splitOn"|"l  … I’m a little new to this one :D # Vyxal, 60 bytes \|/DvLG⇧D\=*\/p\\+,„h⋏\|pǏ,:\|$-Ǐ,‹£Ḣƛ¥↲ðp\|pǏ,;¥›\=*\\p\/+,


Try it Online!

Longer than I'd like...

# C# 4.5 - 375 347 chars

;) [If someone is interested to see how C# differs from others]

var c = input.Split('|').ToList();
int l = c.Select(s => s.Length).Max() + 2;


• You can save a LOT of characters by using one-char variable names and removing all that whitespace...
– Doorknob
Sep 24 '13 at 23:31
• I might be wrong but I always assume that a complete program is required unless the OP states that a code snippet is acceptable. This is a long way from a complete program. Sep 25 '13 at 0:00
• Brought it down to 305 simply by renaming variables and removing whitespace: var c=input.Split('|').ToList();int l=c.Select(s=>s.Length).Max()+2;Console.WriteLine("/{0}\\\r\n| {1} |\r\n|{0}|\r\n{2}\r\n\\{3}/\r\n","=".PadRight(l,'='),c[0].PadLeft(c[0].Length+((l-c[0].Length)/2)-1).PadRight(l-2),string.Join("\r\n",c.Select(s=>"| "+s.PadRight(-2)+" |").Skip(1)),"-".PadRight(l,'-'));
– Doorknob
Sep 25 '13 at 1:58
• Thanks Doorknob. Can't we recognize minimum functions calls instead of total chars? That helps us [includes solutions providers also]. Because after sometime [after a year], it would be hard to understand code written by me and that also helps others to understand code easily. Sep 25 '13 at 17:28
• The whole point of code golf is to solve a task in the least amount of characters... en.wikipedia.org/wiki/Code_golf
– Doorknob
Sep 25 '13 at 21:08

# Javascript, 373 364

l="length";m=" ";a="\\";b="/";c="|";p=m+c;v="join";u="concat";o=[];q=Array;i=prompt().split(c);j=i.slice().sort(function(d,e){return e[l]-d[l]})[0][l]+3;i=i.map(function(d,e){s=q(o[l]=0|(e?j-d[l]-1:(j-d[l])/2))[v](m);return(e?p:c+s+(d[l]&1?m:""))+d+(e?s:s+m)+p});x=q(o[l]=j)[v]("=");r=[b+x+a,i.shift(),c+x+c][u](i)[u](a+q(o[l]=j)[v]("-")+b);console.log(r[v]("\n"))


Output

/===============\
|  1234567890   |
|===============|
| 12345         |
| 1234567890123 |
| pie           |
| potato        |
| unicorn       |
\---------------/


Edit Notes:
Thanks @Doorknob!: -9 Characters =)

• There should be a lot of space for golfing left Sep 25 '13 at 12:13
• Some things I see: o={length:0} --> o=[] (-8 chars), p="| " --> p=c+m (-1 char)
– Doorknob
Sep 25 '13 at 12:19
• @Doorknob Oh... thanks =), i just wonder right now why i added length at all, that makes no sense. Sep 25 '13 at 12:23

# Java - 549492468453 432

class a{static<T>void p(T p){System.out.println(p);}public static void main(String[]a){String b="/=";int l=0,t,i;a=a[0].split("\\|");for(String s:a)l=(t=s.length())>l?t:l;for(t=0;t<l;t++)b+="=";b+="=\\";p(b);i=a[0].length();p(String.format("| %"+(l+i)/2+"s%"+(l-i)/2+"s |",a[0]," "));b="|=";for(t=0;t<l;t++)b+="=";b+="=|";p(b);for(t=1;t<a.length;t++)p(String.format("| %-"+l+"s |",a[t]));b="\\-";for(t=0;t<l;t++)b+="-";b+="-/";p(b);}}


With line breaks and tabs

class a{

static<T>void p(T p){System.out.println(p);}

public static void main(String[]a){
a=a[0].split("\\|");
String b="/=";
int l=0,t,i;

for(String s:a)l=(t=s.length())>l?t:l;

for(t=0;t<l;t++)b+="=";
b+="=\\";
p(b);

p(String.format("| %"+(l+i)/2+"s%"+(l-i)/2+"s |",a[0]," "));

b="|=";
for(t=0;t<l;t++)b+="=";
b+="=|";
p(b);

for(t=1;t<a.length;t++)p(String.format("| %-"+l+"s |",a[t]));

b="\\-";
for(t=0;t<l;t++)b+="-";
b+="-/";
p(b);
}
}