Generate a Stack Exchange Favicon

25

5

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.

user54200

Posted 2016-07-08T06:54:51.380

Reputation:

Very closely related. Also related. – Martin Ender – 2016-07-08T07:02:19.003

@MartinEnder Yes, Very closely related, but not duplicate. – None – 2016-07-08T07:03:17.500

Also, This is Highly inspired by PPCG itself. – None – 2016-07-08T07:05:21.353

Can you clarify what the text inside should be? For example, what if the name of the site was 99 bottles of beer. Would that be 99BOB? Does the box get bigger to compensate for that? Is there a maximum box size, or site name size? What kind of characters might appear in the site title? – James – 2016-07-08T07:06:26.070

1@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. – Martin Ender – 2016-07-08T07:07:28.257

Unlimited Box and Site name size. Also, if it was 99 bottles of beer, It would be 99. – None – 2016-07-08T07:08:00.113

@MartinEnder The related ones you linked have a whitespace front and behind the string. mine don't. – None – 2016-07-08T07:09:56.107

@MatthewRoh The actually seems like the most minor difference which isn't going to require any substantial changes to any of the existing solutions. The best case for this challenge is the acronymisation and the v. – Martin Ender – 2016-07-08T07:18:38.100

Also related – Peter Taylor – 2016-07-08T07:21:53.970

Why does 99 bottles of beer become 99 and not 99BOB? Is everything after a number excluded? – Adnan – 2016-07-08T07:24:06.113

Because It is numbers and uppercase, not numbers and first character. – None – 2016-07-08T07:26:44.640

4If it was 99 Bottles Of Beer, it would be 99BOB. – None – 2016-07-08T07:27:16.737

Oh okay, I missed that part :p. – Adnan – 2016-07-08T07:29:17.543

@MatthewRoh That would be a useful test case to add. – James – 2016-07-08T07:32:26.937

What about uppercase letters inside the string? i.e. would 99 bOttles Of Beer turn into 99OOB? – charredgrass – 2016-07-08T08:46:33.297

Yes. Every uppercase letters. – None – 2016-07-08T08:52:13.383

THERE IS NO BF ANSWER SO I AM GIVING AWAY TO MY FAVORITE – None – 2016-07-29T07:27:51.537

NOOOOO @MattherRoh, I have been working on it :( I am so close. I even created an assember to convert "readable" code to BF :((( – Rohan Jhunjhunwala – 2016-07-29T16:05:55.310

@Rohan :O Im really impressed – None – 2016-07-29T23:33:08.530

@MatthewRoh if I manage to get close I'lll still post it – Rohan Jhunjhunwala – 2016-07-29T23:34:53.777

1@MatthewRoh its still buggy, let me see if i can get a bf answer after all – Rohan Jhunjhunwala – 2016-07-29T23:35:19.607

@MatthewRoh heres what I have so far. https://sange.fi/esoteric/brainfuck/impl/interp/i.html

– Rohan Jhunjhunwala – 2016-07-31T01:14:23.493

Just cant figure out how to stirip uppercase characters in brainf*** – Rohan Jhunjhunwala – 2016-07-31T01:14:40.810

@RohanJhunjhunwala Check all uppercase. That would be simple I think. – None – 2016-07-31T01:30:41.180

@MattheyRoh yeah I think I may have an interesting solution – Rohan Jhunjhunwala – 2016-07-31T01:37:09.753

@Matthew I can just check if it is less than 96 :D – Rohan Jhunjhunwala – 2016-07-31T01:37:28.710

related – Taylor Scott – 2018-01-08T17:38:53.270

Answers

23

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):

Animation

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.

Loovjo

Posted 2016-07-08T06:54:51.380

Reputation: 7 357

lowercase V, not uppercase V – None – 2016-07-08T12:05:35.497

One character more, but avoids the special escaped characters: r|y uP$pYPVr-r+$.YjppVr $hrV – Bryce Wagner – 2016-07-08T12:06:26.843

You can replace i+↓←|␛␖ky$p with A+↓|␛␖ky0P to save a byte. – Lynn – 2016-07-08T23:32:57.000

Alternatively, replace the first eight strokes in Bryce’s approach with I|<END>|␛ – Lynn – 2016-07-08T23:41:47.617

I wonder if this has the most upvotes because of the cool picture. – Joe – 2016-07-26T18:59:21.923

@SirBidenXVII Probably. – Loovjo – 2016-07-26T18:59:59.653

10

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)

James

Posted 2016-07-08T06:54:51.380

Reputation: 54 537

I just noticed that the input Programming Puzzles & Code Golf produces the incorrect string PP&CG in the output. The & should be removed – Luis Mendo – 2016-07-10T13:02:14.900

@LuisMendo Aww, darn it! Thanks for pointing that out, I'll fix it sometime today. – James – 2016-07-10T14:43:01.410

@DrGreenEggsandIronMan So, you fixed it, right? [when? will? you? finally? fix? it?] – Erik the Outgolfer – 2016-07-25T10:31:51.533

I'm not getting any output on TIO? – Downgoat – 2016-07-26T18:02:09.853

@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.

– James – 2016-07-26T18:03:34.373

@DrGreenEggsandIronMan oh okay :( can you provide a link to a working version/github commit – Downgoat – 2016-07-26T18:05:09.823

@Downgoat I'm not sure when the last working commit was. A minor change fixes things though (see the new answer) – James – 2016-07-26T18:07:35.583

7

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
c3           retn            ;Return to caller
_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

meden

Posted 2016-07-08T06:54:51.380

Reputation: 711

Uhh.. I have not done assembly code for while. – None – 2016-07-09T02:11:31.097

3Me too. Started again about a week ago for golfing only – meden – 2016-07-09T02:21:20.723

3c 41 cmp al,a' shouldn't it be 3c 41 cmp al,'a' ? – rav_kr – 2016-07-09T05:57:43.073

@rav_kr, sure, thanks fo noticing. Missed a quote while replacing hex codes with characters for readability. – meden – 2016-07-12T01:51:10.163

4

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

Katenkyo

Posted 2016-07-08T06:54:51.380

Reputation: 2 857

1Uhh, do you mean output via STDOUT?

But I don't mind because ITS OPPOSITE DAY!!! – None – 2016-07-08T07:35:29.963

1@MatthewRoh I meant outputing to the STDIN of your terminal ! (fixed... shame....) – Katenkyo – 2016-07-08T07:37:13.640

n=(...):gsub("[^A-Z%d]","")s="+"..("-"):rep(#n).."+\n"return s.."|"..n.."|\n"..s..(" "):rep(#n).."V" is 100 bytes – Leaky Nun – 2016-07-08T11:43:35.150

@LeakyNun using the pattern %u we gain some more bytes. Anyway, thanks :) (will update the ungolfed later) – Katenkyo – 2016-07-10T14:22:03.267

4

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.

Leaky Nun

Posted 2016-07-08T06:54:51.380

Reputation: 45 011

Nice, I tried this earlier, but ended up with 54 bytes. An alternative for the first stage is T\dLp`dL_` but it's the same length, unfortunately. – Martin Ender – 2016-07-08T12:53:38.360

@MartinEnder What were your 54 bytes? – Leaky Nun – 2016-07-08T13:17:42.463

4

Excel VBA, 375 359 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

tjb1

Posted 2016-07-08T06:54:51.380

Reputation: 561

3Its good though, considering that VBA is sometimes rubbish. – None – 2016-07-08T13:21:36.977

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 – 2016-07-08T13:57:29.990

Yeah ikr So true – None – 2016-07-08T14:03:57.570

Can you remove the whitespace around operators? – Morgan Thrapp – 2016-07-08T18:37:53.080

They are added automatically by the program, I don't know if that's an option or not. – tjb1 – 2016-07-08T18:43:35.283

3Laughed at "Got rid of u" – CocoaBean – 2016-07-09T18:34:13.803

I think you can remove some whitespace. It is automatically added after you paste the golfed code. – Erik the Outgolfer – 2016-07-25T15:14:21.140

I cannot run the code with whitespace removed because the VBA editor adds it automatically so I can't verify that it will run with it missing. – tjb1 – 2016-07-25T15:17:57.313

To justify removing whitespace, remove it in a text editor, then paste back into VBA. If VBA handles it correctly, you're good with the shortened version. – Joffan – 2016-07-26T00:15:11.010

I've put it in notepad, removed spaces, pasted back into the VBA editor and spaces are back. The editor adds them, if you delete them in the editor and click the mouse anywhere, it adds them. I cannot test the program without them. – tjb1 – 2016-07-26T11:13:17.483

Yep. But if the code you start with doesn't have spaces and they are automatically inserted by the VBA editor and then it works, you have tested your space-reduced code. – Joffan – 2016-07-26T17:46:25.360

And do look up the String function. – Joffan – 2016-07-26T18:37:16.437

For Each x in Split([A1]):a=a+IIf(x Like"[a-zA-Z]*",Left(x,1),""):Next:s="+"+String(Len(a),45)+"+":?s:?"|"a"|":?s:?Spc(Len(a))"v - 128 Bytes – Taylor Scott – 2019-03-03T20:32:56.903

4

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

downrep_nation

Posted 2016-07-08T06:54:51.380

Reputation: 1 152

You can replace | | with | – aloisdg moving to codidact.com – 2016-07-08T13:30:38.613

You can use string interpolation return$"+{x}+\n|{s}|\n+{x}+\n{new string(' ',m+1)}v";} – aloisdg moving to codidact.com – 2016-07-08T13:33:59.307

1thats a sweet method! – downrep_nation – 2016-07-08T13:35:21.460

You can replace string.Join("", with string.Concat( – aloisdg moving to codidact.com – 2016-07-08T13:35:22.790

You can replace your where lambda with (n=>n>47&n<58|n>64&n<91)) – aloisdg moving to codidact.com – 2016-07-08T13:39:21.293

i thought about doing ascii comparisons – downrep_nation – 2016-07-08T13:41:21.130

1You can remove the space after the return – aloisdg moving to codidact.com – 2016-07-08T13:45:16.947

Also I would use a lambda this anonymous function are allowed. s=>{..}; instead of string h(string s){..}; – aloisdg moving to codidact.com – 2016-07-08T13:46:56.843

You can remove the space in n>64 &n<91 – aloisdg moving to codidact.com – 2016-07-08T14:17:37.907

I added all this edits to the tips for code golfinf in C# thread :)

– aloisdg moving to codidact.com – 2016-07-08T14:59:57.077

good job!, lemme add some more edits – downrep_nation – 2016-07-08T15:02:12.780

@downrep_nation - Can't you shorten m + 1, or is the whitespace significant? – owacoder – 2016-07-08T23:38:00.353

@owacoder He doesnt need it. I wrote it without earlier :) – aloisdg moving to codidact.com – 2016-07-09T02:13:03.507

If you change the Where-lambda to Where(Char.IsLetterOrDigit) you should be able to save a few characters, – Smetad Anarkist – 2016-07-25T12:17:41.263

You can save 3 bytes by adding using S=System.String; and replacing string with S. – LegionMammal978 – 2016-07-31T02:42:52.957

148 bytes by using a regex and eliminating the variable m: string h(string s){s=Regex.Replace(s,"[^A-Z0-9]","");var x=new string('-',s.Length);return$"+{x}+\n|{s}|\n+{x}+\n{new string(' ', s.Length + 1)}v";} – wertzui – 2018-03-08T10:41:39.760

3

2sable, 36 34 33 32 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.

Adnan

Posted 2016-07-08T06:54:51.380

Reputation: 41 965

2ಠ_ಠ No more golfing or language switches! Leave it where it is now! :P – James – 2016-07-08T08:12:16.947

@DrGreenEggsandIronMan Hahaha, it is still 3 painful bytes away from your answer :P. – Adnan – 2016-07-08T08:14:36.410

1Haha, I was celebrating when I saw it 7 bytes longer, and then slowly watched the gap disappear, one by one... – James – 2016-07-08T08:15:38.650

3

JavaScript (ES6), 99 bytes

(s,t=s.replace(/[^0-9A-Z]/g,``),g=c=>t.replace(/./g,c))=>`${s=`+${g(`-`)}+
`}|${t}|
${s}${g(` `))v`

Neil

Posted 2016-07-08T06:54:51.380

Reputation: 95 035

3

Haskell, 107 Bytes

This answer is heavily based on the answer by Zylviij and the comments by nimi. I would have added more comments to that answer, but alas, I don't have enough rep.

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.

MarLinn

Posted 2016-07-08T06:54:51.380

Reputation: 231

2

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"

Kevin Cruijssen

Posted 2016-07-08T06:54:51.380

Reputation: 67 575

2

Python 3.5, 114 93 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)

R. Kap

Posted 2016-07-08T06:54:51.380

Reputation: 4 730

5It's missing the bottom 'v'. – Carles Company – 2016-07-08T10:21:43.293

@CarlesCompany It's fixed, at the cost of 19 more bytes. – R. Kap – 2016-07-08T17:23:51.490

2

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.

Destructible Lemon

Posted 2016-07-08T06:54:51.380

Reputation: 5 908

Does not work correctly. -1 Notify if you fix. – Erik the Outgolfer – 2016-07-25T15:51:13.613

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Fixed. Thank you – Destructible Lemon – 2016-07-25T23:54:10.227

Actually, the link was golfing some code, and that's why I put it there. – Erik the Outgolfer – 2016-07-26T12:08:13.947

1

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");

Logern

Posted 2016-07-08T06:54:51.380

Reputation: 845

1

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

FrownyFrog

Posted 2016-07-08T06:54:51.380

Reputation: 3 112

1

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!

Dom Hastings

Posted 2016-07-08T06:54:51.380

Reputation: 16 415

1

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!

Blue

Posted 2016-07-08T06:54:51.380

Reputation: 26 661

1

Pyth, 38 37 bytes


Jj*\-lK@jrG1UTz"++"jK"||"JtXJ"-+"" v

Try it online.

Note the newline in the start.

PurkkaKoodari

Posted 2016-07-08T06:54:51.380

Reputation: 16 699

1

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'

atlasologist

Posted 2016-07-08T06:54:51.380

Reputation: 2 945

Can you use ascii in Python? If yes you can use 47<x<58|64<x<91 :) – aloisdg moving to codidact.com – 2016-07-08T14:48:44.540

@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. – Mego – 2016-07-08T15:15:12.920

[x for x in n if x.isupper()^x.isdigit()] is one byte shorter than filter(lambda x:x.isupper()^x.isdigit(),n) – Leaky Nun – 2016-07-08T17:10:33.470

@LeakyNun: filter will return a string, but the list comprehension will return a list, which won't be usable in the return value expression. – Nikita Borisov – 2016-07-12T02:36:58.473

Why XOR? Can't you use OR instead? XOR is more complex, and thus slower AFAIK. x.isupper()^x.isdigit() -> x.isupper()|x.isdigit() – Erik the Outgolfer – 2016-07-25T15:33:39.077

1

Jolf, 35 bytes

Ά+,Alγ/x"[^A-Z0-9]"1'+'-'|γS*lγ" 'v

I need a shorter way to remove all but caps & numbers...

Conor O'Brien

Posted 2016-07-08T06:54:51.380

Reputation: 36 228

1

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;
}

owacoder

Posted 2016-07-08T06:54:51.380

Reputation: 1 556

Why do you copy the argv element? – mame98 – 2016-07-10T13:19:49.190

Because the function modifies its input. I'm not sure modifying the parameters in place is defined behavior. – owacoder – 2016-07-10T20:08:40.543

never thought about this... according to this SO answer it should be fine: http://stackoverflow.com/a/963504/3700391

– mame98 – 2016-07-10T20:49:23.677

1

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

Zylviij

Posted 2016-07-08T06:54:51.380

Reputation: 390

1You'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 – 2016-07-11T18:34:11.380

1... 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 – 2016-07-11T18:40:26.757

1

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').

someonewithpc

Posted 2016-07-08T06:54:51.380

Reputation: 191

1

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'

Luis Mendo

Posted 2016-07-08T06:54:51.380

Reputation: 87 464

1

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.

Barbarossa

Posted 2016-07-08T06:54:51.380

Reputation: 21

1

CJam, 41

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

Try it online

aditsu quit because SE is EVIL

Posted 2016-07-08T06:54:51.380

Reputation: 22 326

1

APL, 52 49 bytes

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

(down to 49 thanks to the comment).

lstefano

Posted 2016-07-08T06:54:51.380

Reputation: 850

{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.) – Zacharý – 2017-07-31T21:52:13.703

1

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!

Leaky Nun

Posted 2016-07-08T06:54:51.380

Reputation: 45 011

0

Japt 2.0 -R, 37 36 bytes

Saved 1 byte thanks to Shaggy

r/\W|\a/
'+²¬qUÊî-
[V'|+U+'|V'viUÊî]

Run it online

Oliver

Posted 2016-07-08T06:54:51.380

Reputation: 7 160

1r/\W|\a/ should save a byte. – Shaggy – 2018-06-05T16:17:58.430

0

SmileBASIC 3, 131 bytes

INPUT N$WHILE""<N$C$=SHIFT(N$)IF@0<C$&&"[">C$||"/"<C$&&":">C$THEN W$=W$+C$
WEND
L=LEN(W$)H$="+"+"-"*L+"+
?H$?"|"+W$+"|
?H$?" "*L+"v

snail_

Posted 2016-07-08T06:54:51.380

Reputation: 1 982

0

Kotlin, 129 126 bytes

{s:String->val x=s.filter{it in('A'..'Z')+('0'..'9')}
val h="-".repeat(x.length)
"+$h+\n|$x|\n+$h+\n${" ".repeat(x.length)}v"}

Try it online!

snail_

Posted 2016-07-08T06:54:51.380

Reputation: 1 982

0

C# (Visual C# Interactive Compiler), 128 bytes

x=>{x=Replace(x,"[^A-Z0-9]","");Write("{0}{1}\n{0}{2}","+"+"+\n".PadLeft(x.Length+2,'-'),$"|{x}|","v".PadLeft(x.Length+1,' '));}

Try it online!

Embodiment of Ignorance

Posted 2016-07-08T06:54:51.380

Reputation: 7 014

0

Ruby, 81 bytes (78 + -p flag)

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

Value Ink

Posted 2016-07-08T06:54:51.380

Reputation: 10 608

0

PHP, 112 bytes

<?$s=str_replace('-',' ',$m=ereg_replace('.','-',$n=ereg_replace('[^A-Z0-9]','',$x)));echo"+$m+
|$n|
+$m+
$s",v;
  • PHP<5.4 with register_globals=1, call php-cgi -f <filename> x="<name>";echo""
  • add <pre> after echo" for call in web browser <scriptpath>?x=<name>;
  • for PHP>=5.4: replace $x with $_GET[x] (+6)
    or with $argv[1] to call php <filename> "<name>";echo"" (+6)
  • you may want to add -d error_reporting=0 to cli options

There are times when I love that PHP accepts newlines in constant strings.

  • str_repeat looked like a buddy here, but costs 3 bytes
  • <?=(<assignments>)?"<output>".v:0 costs 1 byte
  • <?=(<assignments>)," <output>",v; does neither cost nor save, but adds a leading blank line to the output

Titus

Posted 2016-07-08T06:54:51.380

Reputation: 13 814

0

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

sadfaf

Posted 2016-07-08T06:54:51.380

Reputation: 101