25
\$\begingroup\$

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.

\$\endgroup\$
27
  • \$\begingroup\$ Very closely related. Also related. \$\endgroup\$ Commented Jul 8, 2016 at 7:02
  • \$\begingroup\$ @MartinEnder Yes, Very closely related, but not duplicate. \$\endgroup\$
    – user54200
    Commented Jul 8, 2016 at 7:03
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Commented Jul 8, 2016 at 7:07
  • 5
    \$\begingroup\$ If it was 99 Bottles Of Beer, it would be 99BOB. \$\endgroup\$
    – user54200
    Commented Jul 8, 2016 at 7:27
  • 1
    \$\begingroup\$ @MatthewRoh its still buggy, let me see if i can get a bf answer after all \$\endgroup\$ Commented Jul 29, 2016 at 23:35

35 Answers 35

24
\$\begingroup\$

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

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)

\$\endgroup\$
7
  • \$\begingroup\$ I just noticed that the input Programming Puzzles & Code Golf produces the incorrect string PP&CG in the output. The & should be removed \$\endgroup\$
    – Luis Mendo
    Commented Jul 10, 2016 at 13:02
  • \$\begingroup\$ @LuisMendo Aww, darn it! Thanks for pointing that out, I'll fix it sometime today. \$\endgroup\$
    – DJMcMayhem
    Commented Jul 10, 2016 at 14:43
  • \$\begingroup\$ @DrGreenEggsandIronMan So, you fixed it, right? [when? will? you? finally? fix? it?] \$\endgroup\$ Commented Jul 25, 2016 at 10:31
  • \$\begingroup\$ I'm not getting any output on TIO? \$\endgroup\$
    – Downgoat
    Commented Jul 26, 2016 at 18:02
  • \$\begingroup\$ @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. \$\endgroup\$
    – DJMcMayhem
    Commented Jul 26, 2016 at 18:03
7
\$\begingroup\$

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
\$\endgroup\$
4
  • \$\begingroup\$ Uhh.. I have not done assembly code for while. \$\endgroup\$
    – user54200
    Commented Jul 9, 2016 at 2:11
  • 3
    \$\begingroup\$ Me too. Started again about a week ago for golfing only \$\endgroup\$
    – meden
    Commented Jul 9, 2016 at 2:21
  • \$\begingroup\$ 3c 41 cmp al,a' shouldn't it be 3c 41 cmp al,'a' ? \$\endgroup\$
    – rav_kr
    Commented Jul 9, 2016 at 5:57
  • \$\begingroup\$ @rav_kr, sure, thanks fo noticing. Missed a quote while replacing hex codes with characters for readability. \$\endgroup\$
    – meden
    Commented Jul 12, 2016 at 1:51
4
\$\begingroup\$

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.
\$\endgroup\$
3
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jul 8, 2016 at 12:53
  • \$\begingroup\$ @MartinEnder What were your 54 bytes? \$\endgroup\$
    – Leaky Nun
    Commented Jul 8, 2016 at 13:17
  • \$\begingroup\$ retina.tryitonline.net/… \$\endgroup\$ Commented Jul 8, 2016 at 13:18
4
\$\begingroup\$

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

\$\endgroup\$
16
  • \$\begingroup\$ You can replace | | with | \$\endgroup\$
    – aloisdg
    Commented Jul 8, 2016 at 13:30
  • \$\begingroup\$ You can use string interpolation return$"+{x}+\n|{s}|\n+{x}+\n{new string(' ',m+1)}v";} \$\endgroup\$
    – aloisdg
    Commented Jul 8, 2016 at 13:33
  • 1
    \$\begingroup\$ thats a sweet method! \$\endgroup\$ Commented Jul 8, 2016 at 13:35
  • \$\begingroup\$ You can replace string.Join("", with string.Concat( \$\endgroup\$
    – aloisdg
    Commented Jul 8, 2016 at 13:35
  • 1
    \$\begingroup\$ You can remove the space after the return \$\endgroup\$
    – aloisdg
    Commented Jul 8, 2016 at 13:45
4
\$\begingroup\$

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
\$\endgroup\$
13
  • 3
    \$\begingroup\$ Its good though, considering that VBA is sometimes rubbish. \$\endgroup\$
    – user54200
    Commented Jul 8, 2016 at 13:21
  • \$\begingroup\$ 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. \$\endgroup\$
    – tjb1
    Commented Jul 8, 2016 at 13:57
  • \$\begingroup\$ Yeah ikr So true \$\endgroup\$
    – user54200
    Commented Jul 8, 2016 at 14:03
  • \$\begingroup\$ Can you remove the whitespace around operators? \$\endgroup\$ Commented Jul 8, 2016 at 18:37
  • 3
    \$\begingroup\$ Laughed at "Got rid of u" \$\endgroup\$
    – Rocko
    Commented Jul 9, 2016 at 18:34
4
\$\begingroup\$

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
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Uhh, do you mean output via STDOUT? But I don't mind because ITS OPPOSITE DAY!!! \$\endgroup\$
    – user54200
    Commented Jul 8, 2016 at 7:35
  • 1
    \$\begingroup\$ @MatthewRoh I meant outputing to the STDIN of your terminal ! (fixed... shame....) \$\endgroup\$
    – Katenkyo
    Commented Jul 8, 2016 at 7:37
  • \$\begingroup\$ n=(...):gsub("[^A-Z%d]","")s="+"..("-"):rep(#n).."+\n"return s.."|"..n.."|\n"..s..(" "):rep(#n).."V" is 100 bytes \$\endgroup\$
    – Leaky Nun
    Commented Jul 8, 2016 at 11:43
  • \$\begingroup\$ @LeakyNun using the pattern %u we gain some more bytes. Anyway, thanks :) (will update the ungolfed later) \$\endgroup\$
    – Katenkyo
    Commented Jul 10, 2016 at 14:22
3
+50
\$\begingroup\$

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.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ ಠ_ಠ No more golfing or language switches! Leave it where it is now! :P \$\endgroup\$
    – DJMcMayhem
    Commented Jul 8, 2016 at 8:12
  • \$\begingroup\$ @DrGreenEggsandIronMan Hahaha, it is still 3 painful bytes away from your answer :P. \$\endgroup\$
    – Adnan
    Commented Jul 8, 2016 at 8:14
  • 1
    \$\begingroup\$ Haha, I was celebrating when I saw it 7 bytes longer, and then slowly watched the gap disappear, one by one... \$\endgroup\$
    – DJMcMayhem
    Commented Jul 8, 2016 at 8:15
3
\$\begingroup\$

JavaScript (ES6), 99 bytes

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

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.
\$\endgroup\$
2
\$\begingroup\$

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)

\$\endgroup\$
2
  • 5
    \$\begingroup\$ It's missing the bottom 'v'. \$\endgroup\$ Commented Jul 8, 2016 at 10:21
  • \$\begingroup\$ @CarlesCompany It's fixed, at the cost of 19 more bytes. \$\endgroup\$
    – R. Kap
    Commented Jul 8, 2016 at 17:23
2
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ Does not work correctly. -1 Notify if you fix. \$\endgroup\$ Commented Jul 25, 2016 at 15:51
  • \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Fixed. Thank you \$\endgroup\$ Commented Jul 25, 2016 at 23:54
  • \$\begingroup\$ Actually, the link was golfing some code, and that's why I put it there. \$\endgroup\$ Commented Jul 26, 2016 at 12:08
2
\$\begingroup\$

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"
\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

Pyth, 38 37 bytes


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

Try it online.

Note the newline in the start.

\$\endgroup\$
1
\$\begingroup\$

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'
\$\endgroup\$
5
  • \$\begingroup\$ Can you use ascii in Python? If yes you can use 47<x<58|64<x<91 :) \$\endgroup\$
    – aloisdg
    Commented Jul 8, 2016 at 14:48
  • \$\begingroup\$ @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. \$\endgroup\$
    – user45941
    Commented Jul 8, 2016 at 15:15
  • \$\begingroup\$ [x for x in n if x.isupper()^x.isdigit()] is one byte shorter than filter(lambda x:x.isupper()^x.isdigit(),n) \$\endgroup\$
    – Leaky Nun
    Commented Jul 8, 2016 at 17:10
  • \$\begingroup\$ @LeakyNun: filter will return a string, but the list comprehension will return a list, which won't be usable in the return value expression. \$\endgroup\$ Commented Jul 12, 2016 at 2:36
  • \$\begingroup\$ Why XOR? Can't you use OR instead? XOR is more complex, and thus slower AFAIK. x.isupper()^x.isdigit() -> x.isupper()|x.isdigit() \$\endgroup\$ Commented Jul 25, 2016 at 15:33
1
\$\begingroup\$

Jolf, 35 bytes

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

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

\$\endgroup\$
1
\$\begingroup\$

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;
}
\$\endgroup\$
3
  • \$\begingroup\$ Why do you copy the argv element? \$\endgroup\$
    – mame98
    Commented Jul 10, 2016 at 13:19
  • \$\begingroup\$ Because the function modifies its input. I'm not sure modifying the parameters in place is defined behavior. \$\endgroup\$
    – owacoder
    Commented Jul 10, 2016 at 20:08
  • \$\begingroup\$ never thought about this... according to this SO answer it should be fine: stackoverflow.com/a/963504/3700391 \$\endgroup\$
    – mame98
    Commented Jul 10, 2016 at 20:49
1
\$\begingroup\$

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
\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – nimi
    Commented Jul 11, 2016 at 18:34
  • 1
    \$\begingroup\$ ... 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". \$\endgroup\$
    – nimi
    Commented Jul 11, 2016 at 18:40
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

CJam, 41

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

Try it online

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

APL, 52 49 bytes

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

(down to 49 thanks to the comment).

\$\endgroup\$
1
  • \$\begingroup\$ {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.) \$\endgroup\$
    – Adalynn
    Commented Jul 31, 2017 at 21:52
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

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'
\$\endgroup\$
1
\$\begingroup\$

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");
\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

Ruby, 81 bytes (78 + -p flag)

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

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
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.