# Generate a Stack Exchange Favicon

Do you recognize the PPCG logo? it looks like this, when you do an ascii art of it.

+---+
|PCG|
+---+
v


Now, In this Code Golf, You will make a code, that makes logos for other sites, similar to the PPCG logo.

# What You should do

The "Shortened" string will be the string, with all upper case letters and numbers in the input string.(Which would be PPCG when the input string is Programming Puzzles & Code Golf)

The "Box" (

+---+
|   |
+---+
v


) should fit the Shortened string perfectly.(No bigger or smaller)

Also the v part should be exactly 1 down and 1 left to the down right +.

Then output the box which has the shortened string in it.

# Example

Stack Overflow:

+--+
|SO|
+--+
v


Area 51:

+---+
|A51|
+---+
v


# Rules

You may assume that the input contains at least one digit or upper case letter.

Standard rules apply.

• Jul 8 '16 at 7:02
• @MartinEnder Yes, Very closely related, but not duplicate.
– user54200
Jul 8 '16 at 7:03
• @MatthewRoh The purpose of the links is so that the challenges show up in the sidebar, it's not a dupe vote. That said, I personally think removing the unwanted characters and also printing the ^ doesn't add much compared to the second challenge I linked, but I won't cast a dupe hammer on that but let the communitz decide whether they consider it a dupe or not. Jul 8 '16 at 7:07
• If it was 99 Bottles Of Beer, it would be 99BOB.
– user54200
Jul 8 '16 at 7:27
• @MatthewRoh its still buggy, let me see if i can get a bf answer after all Jul 29 '16 at 23:35

# Vim, 42 strokes

:s/[^A-Z0-9]//g
YPVr-i+<DOWN><LEFT>|<ESC><C-V>ky$pYjppVr$xrv


Replace <DOWN> with , <LEFT> with , <ESC> with esc and <C-V> with CTRL+V.

Here's an animation of this script running (old version which uses a V instead of a v):

Explanation of the script:

:s/[^A-Z0-9]//g                               # Remove all the characters that are not uppercase or numbers using a Regex.
YPVr-                                         # Duplicate the current, and replace all the characters of the upper one with dashes.
i+<DOWN><LEFT>|<ESC>                     # Insert a + on the upper line, and a | on the second line.
<C-V>ky$p # Copy the + and | to the end of both lines. Yjpp # Copy the upper line to the bottom two times. Vr$    # Replace the bottom most line with spaces and put the cursor on the last character.
xrv # Remove the last character and replace the second last character with a v.

• lowercase V, not uppercase V
– user54200
Jul 8 '16 at 12:05
• One character more, but avoids the special escaped characters: r|y uP$pYPVr-r+$.YjppVr $hrV Jul 8 '16 at 12:06 • You can replace i+↓←|␛␖ky$p with A+↓|␛␖ky0P to save a byte.
– Lynn
Jul 8 '16 at 23:32
• Alternatively, replace the first eight strokes in Bryce’s approach with I|<END>|␛
– Lynn
Jul 8 '16 at 23:41
• I wonder if this has the most upvotes because of the cool picture.
– Joe
Jul 26 '16 at 18:59

# V 34 bytes

Ó[^A-Z0-9]
ys$|ÄVr-r+$.YLppVr x$rv  Note that this worked in an older version, but doesn't work in the current version on try it online. I changed Ä to YP which is functionally equivalent. Try it online! Explanation: Ó[^A-Z0-9]  Remove everything except for digits and uppercase characters. ys$|              "Surround this line with '|' characters.
Ä             "Duplicate this line
Vr-          "Replace this whole duplicated line with '-' characters
r+        "replace the first character with '+'
$"Move to the end of the line, and . "Repeat our last command. This is the same as 'r+' Y "Yank the current line pp "and paste it twice L "At the end of our text  Now, the buffer looks like this: +---+ |A51| +---+ +---+  And our cursor is at the first column of the last line. Vr "Change the whole last line to spaces x "Delete a character$rv            "And change the last character to a 'v'


Non-competing version: (31 bytes)

• I just noticed that the input Programming Puzzles & Code Golf produces the incorrect string PP&CG in the output. The & should be removed Jul 10 '16 at 13:02
• @LuisMendo Aww, darn it! Thanks for pointing that out, I'll fix it sometime today. Jul 10 '16 at 14:43
• @DrGreenEggsandIronMan So, you fixed it, right? [when? will? you? finally? fix? it?] Jul 25 '16 at 10:31
• I'm not getting any output on TIO? Jul 26 '16 at 18:02
• @Downgoat V just recently had a huge update, and unfortunately it borked some things I'm looking into it, but I'm not sure how long it'll take to fix. Jul 26 '16 at 18:03

# 16-bit x86 machine code, 72 bytes

In hex:

565789F731C9FCAC84C074143C5A77F73C4173083C3977EF3C3072EBAA41EBE75F5EE81500B07CAA51F3A4AB59E80A00B020F3AAB076AA91AAC351B02BAAB02DF3AAB82B10AB59C3


Parameters: SI = input string, DI - output buffer.

Outputs a NULL-terminated string with lines delimited by newline. Uses input string as a temporary buffer.

56           push   si
57           push   di
89 f7        mov    di,si    ;Using source string as a buffer
31 c9        xor    cx,cx    ;Counter
fc           cld
_loop:
ac           lodsb
84 c0        test   al,al    ;Test for NULL
74 14        jz     _draw    ;Break
3c 5a        cmp    al,'z'   ;\
77 f7        ja     _loop    ; |
3c 41        cmp    al,'a'    ; \
73 08        jae    _stor    ;  >[A-Z0-9]?
3c 39        cmp    al,'9'   ; /
77 ef        ja     _loop    ; |
3c 30        cmp    al,'0'   ;/
72 eb        jb     _loop
_stor:
aa           stosb           ;Store char in the source buffer
41           inc    cx
eb e7        jmp    _loop
_draw:
5f           pop    di
5e           pop    si
e8 15 00     call   _line    ;Output the first line
b0 7c        mov    al,'|'   ;This proc upon return leaves '\n' in AH
aa           stosb           ;First char of the second line
51           push   cx
f3 a4        rep    movsb    ;Copy CX logo characters from the source buffer
ab           stosw           ;Outputs "|\n", which is still in AX
59           pop    cx
e8 0a 00     call   _line    ;Output the third line
b0 20        mov    al,0x20  ;Space
f3 aa        rep    stosb    ;Output it CX times
b0 76        mov    al,'v'
aa           stosb           ;Output the final 'v'
91           xchg   cx,ax    ;CX == 0
aa           stosb           ;NULL-terminate the string
_line:
51           push   cx
b0 2b        mov    al,'+'
aa           stosb
b0 2d        mov    al,'-'
f3 aa        rep    stosb     ;'-'*CX
b8 2b 10     mov    ax,0x102b ;"+\n"
ab           stosw
59           pop    cx
c3           retn

• Uhh.. I have not done assembly code for while.
– user54200
Jul 9 '16 at 2:11
• Me too. Started again about a week ago for golfing only Jul 9 '16 at 2:21
• 3c 41 cmp al,a'  shouldn't it be 3c 41 cmp al,'a'  ? Jul 9 '16 at 5:57
• @rav_kr, sure, thanks fo noticing. Missed a quote while replacing hex codes with characters for readability. Jul 12 '16 at 1:51

# Retina, 43 bytes

[^A-Z\d]

.+
+$.&$*-+¶|$&|¶+$.&$*-+¶$.&$* V  Try it online! This is the perfect challenge to demonstrate Retina, Martin Ender's golfing language. This solution is divided into two steps (what we call stages), both stages being a replacement stage. The first stage: [^A-Z\d]  This matches the substrings which match [^A-Z\d], which is the characters that are not uppercase and not digits, and then substitute them by nothing, meaning deleting them. The second stage: .+ +$.&$*-+¶|$&|¶+$.&$*-+¶$.&$* V


The .+ matches the whole result, and then substitutes it with the second line.

In the second line:

• $& refers to the whole match • $.& refers to the length of the whole match
• $* means take the previous integer, repeat the next character that many times. Here $.&$*- means to repeat - however long the match is. • ¶ refers to a new-line. • Nice, I tried this earlier, but ended up with 54 bytes. An alternative for the first stage is TdLpdL_ but it's the same length, unfortunately. Jul 8 '16 at 12:53 • @MartinEnder What were your 54 bytes? Jul 8 '16 at 13:17 • retina.tryitonline.net/… Jul 8 '16 at 13:18 ## C#, 183 177 165 bytes string h(string s){s=string.Concat(s.Where(n=>n>47&n<58|n>64 &n<91));int m=s.Length;var x=new string('-',m);return$"+{x}+\n|{s}|\n+{x}+\n{new string(' ', m + 1)}v";}


multiplying chars is terrible in C#. suggestions appreciated

thanks alot to aloisdg for -18 bytes

• You can replace | | with | Jul 8 '16 at 13:30
• You can use string interpolation return$"+{x}+\n|{s}|\n+{x}+\n{new string(' ',m+1)}v";} Jul 8 '16 at 13:33 • thats a sweet method! Jul 8 '16 at 13:35 • You can replace string.Join("",  with string.Concat( Jul 8 '16 at 13:35 • You can remove the space after the return Jul 8 '16 at 13:45 # Excel VBA, 375359 358 bytes: It works, I give up on trying to make it shorter... Edit: Switched to case statement from if statements, -16 bytes Edit2: Got rid of u and replaced with Len(b), -1 byte Function b(x) For i = 1 To Len(x) a = Mid(x, i, 1) e = Asc(a) If e > 64 And e < 91 Or e > 47 And e < 58 Then b = b & a Next i For Z = 1 To 4 y = "" Select Case Z Case 2 y = "|" & b & "|" Case 4 For i = 1 To Len(b) y = y & " " Next i y = y & "v" Case Else y = "+" For i = 1 To Len(b) y = y & "-" Next i y = y & "+" End Select Debug.Print y Next Z End Function  • Its good though, considering that VBA is sometimes rubbish. – user54200 Jul 8 '16 at 13:21 • I just do these for the challenge, I know I can't compete with VBA. Usually end up super confused at the end after changing all the variables from names to single letters. – tjb1 Jul 8 '16 at 13:57 • Yeah ikr So true – user54200 Jul 8 '16 at 14:03 • Can you remove the whitespace around operators? Jul 8 '16 at 18:37 • Laughed at "Got rid of u" Jul 9 '16 at 18:34 ## Lua, 145 99 Bytes Not much to say, manipulating strings is always wordy in lua :). Takes a command-line argument and output via STDOUT Thanks to @LeakyNun for saving me 45 Bytes ! n=(...):gsub("[^%u%d]","")s="+"..("-"):rep(#n).."+\n"return s.."|"..n.."|\n"..s..(" "):rep(#n).."V"  100 Bytes proposed by @LeakyNun n=(...):gsub("[^A-Z%d]","")s="+"..("-"):rep(#n).."+\n"return s.."|"..n.."|\n"..s..(" "):rep(#n).."V"  OLD 145 Bytes g="|"..(...):gsub("%a+",function(w)return w:sub(1,1)end):gsub("%s",'').."|"S="+"..g.rep("-",#g-2).."+"p=print p(S)p(g)p(S)p(g.rep(" ",#g-2).."v")  ### Ungolfed g="|" -- g is the second, and starts with a | ..(...):gsub("%a+", -- append the string resulting of the iteration on each word function(w) -- in the input, applying an anonymous function return w:sub(1,1) -- that return the first character of the word end):gsub("%s",'') -- then remove all spaces .."|" -- and append a | S="+"..g.rep("-",#g-2).."+" -- construct the top and bot of the box p=print -- alias for print p(S)p(g)p(S) -- output the box p(g.rep(" ",#g-2).."v") -- output #g-2 spaces (size of the shortened name), then v  • Uhh, do you mean output via STDOUT? But I don't mind because ITS OPPOSITE DAY!!! – user54200 Jul 8 '16 at 7:35 • @MatthewRoh I meant outputing to the STDIN of your terminal ! (fixed... shame....) Jul 8 '16 at 7:37 • n=(...):gsub("[^A-Z%d]","")s="+"..("-"):rep(#n).."+\n"return s.."|"..n.."|\n"..s..(" "):rep(#n).."V" is 100 bytes Jul 8 '16 at 11:43 • @LeakyNun using the pattern %u we gain some more bytes. Anyway, thanks :) (will update the ungolfed later) Jul 10 '16 at 14:22 # 2sable, 36343332 31 bytes Presenting 2sable :). Although it has a lot in common with 05AB1E, this one actually auto joins the stack rather than outputting the top of the stack. Code: žKA-Ã©g'-×'+DŠJDU„ |Â®sX¶®gð×'v  Uses the CP-1252 encoding. • ಠ_ಠ No more golfing or language switches! Leave it where it is now! :P Jul 8 '16 at 8:12 • @DrGreenEggsandIronMan Hahaha, it is still 3 painful bytes away from your answer :P. Jul 8 '16 at 8:14 • Haha, I was celebrating when I saw it 7 bytes longer, and then slowly watched the gap disappear, one by one... Jul 8 '16 at 8:15 ## JavaScript (ES6), 99 bytes (s,t=s.replace(/[^0-9A-Z]/g,),g=c=>t.replace(/./g,c))=>${s=+${g(-)}+ }|${t}|
${s}${g( ))v


o n=t++'|':f++"|\n"++t++(f>>" ")++"v"where f=[c|c<-n,any(==c)$['0'..'9']++['A'..'Z']];t='+':(f>>"-")++"+\n"  Additional tricks used: • Replaced intersect by its implementation so the import can be dropped. (Side note: the implementation is nearly verbatim the library one, I couldn't find a shorter version.) • Moved the helper functions into the where clause so functions can use the n parameter internally. • After that, (#) was short enough to be inlined. • Put everything on one line to limit extra whitespace. # Python 3.5, 11493 112 bytes: import re;Y=re.findall('[A-Z0-9]',input());I='+'+'-'*len(Y)+'+\n|';print(I+''.join(Y)+I[::-1]+'\n'+' '*len(Y)+'v')  A full program. Basically uses a regular expression to match all occurrences of uppercase letters and numbers, then creates the box of the exact size based on the length of the list of matches, and finally puts the joined list of matches "inside" it. Try It Online! (Ideone) • It's missing the bottom 'v'. Jul 8 '16 at 10:21 • @CarlesCompany It's fixed, at the cost of 19 more bytes. Jul 8 '16 at 17:23 # Python 3, 121 124 bytes Fixed stupid mistake s='' for i in input():_=ord(i);s+=("",i)[91>_>64or 47<_<58] x=len(s) c='+'+"-"*x+'+' print(c+"\n|"+s+"|\n"+c+"\n"+" "*x+"v")  does not import libraries like other python answer. • Does not work correctly. -1 Notify if you fix. Jul 25 '16 at 15:51 • @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Fixed. Thank you Jul 25 '16 at 23:54 • Actually, the link was golfing some code, and that's why I put it there. Jul 26 '16 at 12:08 # Java 8, 149 bytes s->{s=s.replaceAll("[^A-Z0-9]","");String t="+",r;int l=s.length(),i=l;for(;i-->0;t+="-");for(r=(t+="+\n")+"|"+s+"|\n"+t;++i<l;r+=" ");return r+"v";}  Try it online. Explanation: s->{ // Method with String as both parameter and return-type s=s.replaceAll("[^A-Z0-9]",""); // Leave only the uppercase letters and digits String t="+", // Temp-String, starting at "+" r; // Result-String int l=s.length(), // Amount of uppercase letters and digits l i=l;for(;i-->0;t+="-");// Loop and append l amount of "-" to the temp-String for(r=(t+="+\n") // Append "+" and a new-line to the temp-String +"|"+s+"|\n"+t; // Set the result to t, "|", modified input, "|", new-line, t // all appended to each other ++i<l;r+=" "); // Loop and append l amount of spaces to the result return r+"v";} // Return the result-String with appended "v"  ## Pyke, 39 bytes cFDh~u{!Ih(sil\-*\+R\+sj\|i\|++jild*\v+  Try it here! 12 bytes of mini-string creation, 20 bytes of formatting. Joy! # Pyth, 38 37 bytes  Jj*\-lK@jrG1UTz"++"jK"||"JtXJ"-+"" v Try it online. Note the newline in the start. ## Python 2, 113 bytes def f(n):c=filter(lambda x:x.isupper()^x.isdigit(),n);L=len(c);h='+'+L*'-'+'+\n';return h+'|'+c+'|\n'+h+' '*L+'v'  • Can you use ascii in Python? If yes you can use 47<x<58|64<x<91 :) Jul 8 '16 at 14:48 • @aloisdg Unlike C/C++, Python doesn't use an integral char type - all characters in Python strings are themselves strings, and cannot be directly compared with integers. It would need to be 47<ord(x)<58or 64<ord(x)<91. – user45941 Jul 8 '16 at 15:15 • [x for x in n if x.isupper()^x.isdigit()] is one byte shorter than filter(lambda x:x.isupper()^x.isdigit(),n) Jul 8 '16 at 17:10 • @LeakyNun: filter will return a string, but the list comprehension will return a list, which won't be usable in the return value expression. Jul 12 '16 at 2:36 • Why XOR? Can't you use OR instead? XOR is more complex, and thus slower AFAIK. x.isupper()^x.isdigit() -> x.isupper()|x.isdigit() Jul 25 '16 at 15:33 # Jolf, 35 bytes Ά+,Alγ/x"[^A-Z0-9]"1'+'-'|γS*lγ" 'v  I need a shorter way to remove all but caps & numbers... # C, 171 163 Function f() modifies its input and prints out the result. l;f(char*n){char*p=n,*s=n,c[99];for(;*n;++n)isupper(*n)+isdigit(*n)?*p++=*n:0;*p=0;memset(c,45,l=strlen(s));c[l]=0;printf("+%s+\n|%s|\n+%s+\n%*.cv\n",c,s,c,l,32);}  ## Test Program Requires one parameter, the string to use in the favicon: #include <stdlib.h> #include <stdio.h> #include <string.h> int main(int argc, const char **argv) { char *input=malloc(strlen(argv[1])+1); strcpy(input,argv[1]); f(input); free(input); return 0; }  • Why do you copy the argv element? Jul 10 '16 at 13:19 • Because the function modifies its input. I'm not sure modifying the parameters in place is defined behavior. Jul 10 '16 at 20:08 • never thought about this... according to this SO answer it should be fine: stackoverflow.com/a/963504/3700391 Jul 10 '16 at 20:49 # Haskell, 161 import Data.List r=replicate l=length f n=intersect n$['0'..'9']++['A'..'Z']
t n='+':(r(l$f n)'-')++"+\n" o n=(t n)++"|"++(f n)++"|\n"++(t n)++(r(l$f n)' ')++"V"


### Usage

o"Stack Overflow"
+--+
|SO|
+--+
V

o"Area 51"
+---+
|A51|
+---+
V

• You're using replicate, length and f exclusively in this combination, so you can merge them into one function: r=replicate.length.f and call it like r n '-'. You can save even more bytes by using an infix operator: (#)=replicate.length.f and n#'-' / n#' '. Additionally replicate.length is >> (with a singleton string instead of a char), so it's: (#)=(>>).f and n#"-" / n#" ", both without ( ) around it.
– nimi
Jul 11 '16 at 18:34
• ... also: no need for the ( ) around t n and f n. "|"++ is '|':. All in all: o n=t n++'|':f n++"|\n"++t n++n#" "++"V".
– nimi
Jul 11 '16 at 18:40

# Bash, 99 74 bytes

s=$(sed s/[^A-Z0-9]//g);a=${s//?/-};echo -e "+$a+\n|$s|\n+$a+\n${s//?/ }v"


Usage: Run the above command, type the site name, press enter and then Ctrl + D (send 'end of file').

# CJam, 41

"||"q_'[,65>A,s+--*__"+-"er_@\_,((S*]N*'v


Try it online

# R, 108 bytes

cat(x<-gsub("(.*)","+\\1+\n",gsub(".","-",y<-gsub("[^A-Z0-9]","",s))),"|",y,"|\n",x,gsub("."," ",y),"v",sep="")


## Explanation

Going from the inside out (because who doesn't love assigning global variables from inside a regex), assuming s is our input string:

y<-gsub("[^A-Z0-9]","",s) keeps capitals and numbers, assigns the resulting value to y.

gsub(".","-",y<-...) replaces all characters with hyphens in the above.

x<-gsub("(.*)","+\\1+\n",gsub(...)) chucks a + on either end of the row of hyphens, and a newline, and we store that as x.

The rest is pretty straightforward, output in the appropriate order, and use the fact that the number of spaces before the v will be the same as the length of y.

# Brachylog, 61 bytes

Linked to the repository at Jul 7 to ensure backward compatibility.

lybL:{,."-"}ac:"+"c:"+"rcAw@NNw"|"Bw?wBwNwAwNwL:{," "w}a,"v"w


### Non-competing, 53 bytes

lL:"-"rjb:"+"c:"+"rcAw@NNw"|"Bw?wBwNwAwNw" ":Ljbw"v"w


Try it online!

## APL, 52 49 bytes

{x⍪2⌽'v'↑⍨≢⍉x←⍉z⍪⍨(z←'+|+')⍪'-','-',⍨⍪⍵/⍨⍵∊⎕D,⎕A}


(down to 49 thanks to the comment).

• {x⍪2⌽'v'↑⍨≢⍉x←⍉z⍪⍨(z←'+|+')⍪'-','-',⍨⍪⍵/⍨⍵∊⎕D,⎕A} (You never parenthesize one of the arguents in a reversed argument function when golfing. It always can be in normal order to save a byte.) Jul 31 '17 at 21:52

## Perl, 57 bytes

56 bytes code + 1 for -p.

y/a-z //d;$d="-"x y///c;$_="+$d+ |$_|
+$d+ ".$"x y///c.v


I originally tried to make this only using regexes, but it was much larger than I'd hoped, so I've used some string repetition instead.

Try it online!

# MATL, 34 bytes

t1Y24Y2hm)T45&Ya'+|+'!wy&h10M~'v'h


Try it online!

t        % Implicit input. Duplicate
1Y2      % Uppercase letters
4Y2      % Digit characters
h        % Concatenate horizontally: string with uppercase letters and digits
m        % True for input chars that are uppercase letters or digits
)        % Keep only those
T45&Ya   % Pad up and down with character 45, which is '-'. Gives three-row char array
'+|+'!   % Push this string and transpose into a column vector
wy       % Swap, duplicate the second array from the top. This places one copy of the
% column vector below and one above the three-row char array
&h       % Contatenate all stack arrays horizontally. This gives the box with the text
10M      % Retrieve the string with selected letters
~        % Logical negate. Gives zeros, which will be displayes as spaces
'v'      % Push this character
h        % Concatenate horizontally with the zeros.
% Implicitly display the box with the text followed by the string containing
% the zero character repeated and the 'v'


## JavaScript (ES6), 119 bytes

h=a=>"+"+"-".repeat(a.length)+"+\n";j=a=>(a=a.replace(/[^A-Z0-9]/g,""),h(a)+"|"+a+"|\n"+h(a)+" ".repeat(a.length)+"v");


# J, 52 bytes

'v'(<3 _2)}4{.1":]<@#~2|'/9@Z'&I.[9!:7@'+++++++++|-'


Try it online!

   [9!:7@'+++++++++|-'            Set the box drawing characters.
'/9@Z'&I.                 Interval index, 1 for numbers, 3 for
uppercase letters.
]  #~2|                 Mod 2, and filter
the characters that correspond to 1s.
<@                     Put them in a box.
1":                    Convert to a character matrix, so we can do stuff to it.
4{.                    Add a 4th line filled with spaces
'v'(<3 _2)}                Insert a “v” at 3,−2


# Ruby, 81 bytes (78 + -p flag)

gsub(/[^A-Z\d]/,'')
gsub(/.+/){"+#{k=?-*s=$&.size}+ |#{$&}|
+#{k}+
#{' '*s}v"}


## Common Lisp (Lispworks), 159 bytes bytes

(defun f(s)(labels((p(c l)(dotimes(i l)(format t"~A"c))))(let((l(length s)))#1=(p"+"1)#2=(p"-"l)#3=(format t"+~%")(format t"|~A|~%"s)#1##2##3#(p" "l)(p"v"1))))


ungolfed:

(defun f (s)
(labels ((p (c l)
(dotimes (i l)
(format t "~A" c))))
(let ((l (length s)))
#1=(p "+" 1)
#2=(p "-" l)
#3=(format t "+~%")
(format t "|~A|~%" s)
#1#
#2#
#3#
(p " " l)
(p "v" 1))))


Usage:

CL-USER 2 > (f "so")
+--+
|so|
+--+
v
NIL

CL-USER 3 > (f "pcg")
+---+
|pcg|
+---+
v
NIL