Genera uno Favicon di scambio di stack


25

Riconosci il logo PPCG? sembra così, quando ne fai un'arte ascii.

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

Ora, in questo codice Golf, creerai un codice, che crea loghi per altri siti, simile al logo PPCG.

Cosa dovresti fare

La stringa "Accorciata" sarà la stringa, con tutte le lettere maiuscole e i numeri nella stringa di input (che sarebbe PPCGquando la stringa di input è Programming Puzzles & Code Golf)

La scatola" (

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

) dovrebbe adattarsi perfettamente alla corda accorciata (non più grande o più piccola)

Inoltre, la vparte deve essere esattamente 1 in basso e 1 a sinistra in basso a destra +.

Quindi genera la casella che contiene la stringa accorciata.

Esempio

Stack Overflow:

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

Area 51:

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

Regole

Si può presumere che l'input contenga almeno una cifra o una lettera maiuscola.

Si applicano le regole standard del .



@MartinEnder Sì, strettamente correlato, ma non duplicato.

1
@MatthewRoh Lo scopo dei collegamenti è che le sfide si presentino nella barra laterale, non è un voto doppio. Detto questo, personalmente ritengo che rimuovere i personaggi indesiderati e anche stampare il ^non aggiunga molto rispetto alla seconda sfida che ho collegato, ma non lancerò un dupe hammer su questo, ma lascerò che il comunitz decida se lo considerano un dupe o non.
Martin Ender,

4
Se lo fosse 99 Bottles Of Beer, lo sarebbe 99BOB.

1
@MatthewRoh è ancora pieno di bug, fammi vedere se riesco a ottenere una risposta dopo tutto
Rohan Jhunjhunwala

Risposte:


23

Vim, 42 colpi

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

Sostituisci <DOWN>con , <LEFT>con , <ESC>con esce <C-V>con CTRL+ V.

Ecco un'animazione di questo script in esecuzione (versione precedente che utilizza un Vanziché un v):

Animation

Spiegazione della sceneggiatura:

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

V minuscola, non V maiuscola

Un altro personaggio, ma evita gli speciali caratteri di escape: r | y uP ​​$ pYPVr-r + $. YjppVr $ hrV
Bryce Wagner

È possibile sostituire i+↓←|␛␖ky$pcon A+↓|␛␖ky0Pper salvare un byte.
Lynn,

In alternativa, sostituisci i primi otto colpi nell'approccio di Bryce conI|<END>|␛
Lynn

Mi chiedo se questo ha il maggior numero di voti a causa della bella immagine.
Joe,

10

V 34 byte

Ó[^A-Z0-9]
ys$|ÄVr-r+$.YLppVr x$rv

Nota che funzionava con una versione precedente, ma non funziona con la versione corrente per provarla online. Sono passato Äal YPquale è funzionalmente equivalente.

Provalo online!

Spiegazione:

Ó[^A-Z0-9]

Rimuovi tutto tranne cifre e caratteri maiuscoli.

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

Ora, il buffer si presenta così:

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

E il nostro cursore si trova sulla prima colonna dell'ultima riga.

Vr                 "Change the whole last line to spaces
   x               "Delete a character
    $rv            "And change the last character to a 'v'

Versione non competitiva: (31 byte)


Ho appena notato che l'input Programming Puzzles & Code Golfproduce una stringa errata PP&CGnell'output. La &deve essere rimosso
Luis Mendo

@LuisMendo Aww, dannazione! Grazie per averlo sottolineato, lo risolverò oggi.
DJMcMayhem

@DrGreenEggsandIronMan Quindi, l'hai risolto, giusto? [quando? volontà? tu? finalmente? risolvere? vero?]
Erik the Outgolfer,

Non ricevo alcun output su TIO?
Downgoat,

@Downgoat V recentemente ha avuto un enorme aggiornamento, e sfortunatamente ha risolto alcune cose che sto esaminando, ma non sono sicuro di quanto tempo ci vorrà per risolvere.
DJMcMayhem

7

Codice macchina x86 a 16 bit, 72 byte

In esadecimale:

565789F731C9FCAC84C074143C5A77F73C4173083C3977EF3C3072EBAA41EBE75F5EE81500B07CAA51F3A4AB59E80A00B020F3AAB076AA91AAC351B02BAAB02DF3AAB82B10AB59C3

Parametri: SI= stringa di input, DI- buffer di output.

Emette una stringa terminata NULL con linee delimitate da newline. Utilizza la stringa di input come buffer temporaneo.

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

Uhh .. Non ho fatto il codice assembly per un po '.

3
Anch'io. Ricominciato circa una settimana fa solo per giocare a golf
data

3c 41 cmp al,a' non dovrebbe essere 3c 41 cmp al,'a' ?
rav_kr,

@rav_kr, certo, grazie per averlo notato. Mancato un preventivo durante la sostituzione di codici esadecimali con caratteri per la leggibilità.
data

4

Retina , 43 byte

[^A-Z\d]

.+
+$.&$*-+¶|$&|¶+$.&$*-+¶$.&$* V

Provalo online!

Questa è la sfida perfetta per dimostrare Retina, il linguaggio del golf di Martin Ender.

Questa soluzione è divisa in due fasi (quelle che chiamiamo fasi), entrambe le fasi sono una fase di sostituzione.

Il primo stadio:

[^ AZ \ d]

Questo corrisponde alle sottostringhe corrispondenti [^A-Z\d] , ovvero i caratteri che non sono maiuscoli e non cifre, quindi sostituirli con nulla, il che significa eliminarli.

Il secondo stadio:

.+
+$.&$*-+¶|$&|¶+$.&$*-+¶$.&$* V

Il .+ corrisponde l'intero risultato, quindi sostituisce con la seconda linea.

Nella seconda riga:

  • $& si riferisce all'intera partita
  • $.& si riferisce alla lunghezza dell'intera partita
  • $*significa prendere il numero intero precedente, ripetere il carattere successivo più volte. Qui $.&$*-significa ripetere per -quanto sia lunga la partita.
  • si riferisce a una nuova riga.

Bene, l'ho provato prima, ma ho finito con 54 byte. Un'alternativa per il primo stadio è T`dLp`dL_, purtroppo, della stessa lunghezza.
Martin Ender,

@MartinEnder Quali erano i tuoi 54 byte?
Leaky Nun,


4

C #, 183 177 165 byte

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

moltiplicare i caratteri è terribile in C #. suggerimenti apprezzati

grazie mille ad aloisdg per -18 byte


Puoi sostituirlo | |con|
aloisdg dice Reinstate Monica l'

Puoi usare l'interpolazione di stringhereturn$"+{x}+\n|{s}|\n+{x}+\n{new string(' ',m+1)}v";}
aloisdg dice Reinstate Monica l'

1
questo è un metodo dolce!
downrep_nation

Puoi sostituirlo string.Join("", constring.Concat(
aloisdg dice Reinstate Monica l'

1
Puoi rimuovere lo spazio dopo chereturn
aloisdg dice Reinstate Monica l'

4

Excel VBA, 375 359 358 byte:

Funziona, mi arrendo nel tentativo di renderlo più breve ...

Modifica: passato all'istruzione case da istruzioni if, -16 byte

Edit2: eliminato te e sostituito con 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

3
Va bene però, considerando che VBA a volte è spazzatura.

Faccio solo questi per la sfida, so che non posso competere con VBA. Di solito alla fine diventano super confusi dopo aver cambiato tutte le variabili dai nomi alle singole lettere.
tjb1,

Sì, ikr So true

Riesci a rimuovere lo spazio bianco attorno agli operatori?
Morgan Thrapp,

3
Rise di "
Mi sono

4

Lua, 145 99 byte

Non c'è molto da dire, manipolare le stringhe è sempre prolisso in lua :). Accetta un argomento della riga di comando e l'output tramite STDOUT

Grazie a @LeakyNun per avermi salvato 45 byte!

n=(...):gsub("[^%u%d]","")s="+"..("-"):rep(#n).."+\n"return s.."|"..n.."|\n"..s..(" "):rep(#n).."V"

100 byte proposti da @LeakyNun

n=(...):gsub("[^A-Z%d]","")s="+"..("-"):rep(#n).."+\n"return s.."|"..n.."|\n"..s..(" "):rep(#n).."V"

OLD 145 byte

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

1
Uh, intendi l'output tramite STDOUT? Ma non mi dispiace perché IL SUO GIORNO OPPOSTO !!!

1
@MatthewRoh intendevo l'output sullo STDIN del tuo terminale! (risolto ... peccato ...)
Katenkyo,

n=(...):gsub("[^A-Z%d]","")s="+"..("-"):rep(#n).."+\n"return s.."|"..n.."|\n"..s..(" "):rep(#n).."V"è di 100 byte
Leaky Nun l'

@LeakyNun usando il modello %uotteniamo qualche byte in più. Ad ogni modo, grazie :) (aggiornerò il non golfato più tardi)
Katenkyo,

3

2sable , 36 34 33 32 31 byte

Presentazione di 2sable :). Sebbene abbia molto in comune con 05AB1E, questo in realtà si unisce automaticamente allo stack anziché emettere la parte superiore dello stack. Codice:

žKA-ég'-×'+DŠJDU„
|®sX¶®gð×'v

Utilizza la codifica CP-1252 .


2
ಠ_ಠ Niente più golf o cambi di lingua! Lascialo dove si trova ora! : P
DJMcMayhem

@DrGreenEggsandIronMan Hahaha, mancano ancora 3 byte dolorosi alla tua risposta: P.
Adnan,

1
Haha, stavo celebrando quando l'ho visto 7 byte più a lungo, e poi lentamente ho guardato scomparire il divario, uno per uno ...
DJMcMayhem

3

JavaScript (ES6), 99 byte

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

3

Haskell, 107 byte

Questa risposta è fortemente basata sulla risposta di Zylviij e sui commenti di nimi . Avrei aggiunto altri commenti a quella risposta, ma purtroppo non ho abbastanza rappresentante.

o n=t++'|':f++"|\n"++t++(f>>" ")++"v"where f=[c|c<-n,any(==c)$['0'..'9']++['A'..'Z']];t='+':(f>>"-")++"+\n"

Trucchi aggiuntivi utilizzati:

  • Sostituito intersectdalla sua implementazione in modo da poter eliminare l'importazione. (Nota a margine: l'implementazione è quasi testualmente quella della biblioteca, non sono riuscito a trovare una versione più breve.)
  • Spostato le funzioni di supporto nella whereclausola in modo che le funzioni possano usare il nparametro internamente.
  • Dopodiché, è (#)stato abbastanza corto da essere allineato.
  • Metti tutto su una riga per limitare gli spazi bianchi extra.

2

Python 3.5, 114 93 112 byte:

import re;Y=re.findall('[A-Z0-9]',input());I='+'+'-'*len(Y)+'+\n|';print(I+''.join(Y)+I[::-1]+'\n'+' '*len(Y)+'v')

Un programma completo. Fondamentalmente utilizza un'espressione regolare per abbinare tutte le occorrenze di lettere maiuscole e numeri, quindi crea la casella della dimensione esatta in base alla lunghezza dell'elenco di corrispondenze e infine inserisce "al suo interno" l'elenco di corrispondenze delle corrispondenze.

Provalo online! (Ideone)


5
Manca la parte inferiore 'v'.
Carles Company,

@CarlesCompany È stato risolto, al costo di altri 19 byte.
R. Kap

2

Python 3, 121 124 byte

Risolto errore stupido

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

non importa librerie come altre risposte di Python.



@ EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Risolto. Grazie
Destructible Lemon,

In realtà, il link stava giocando a golf un po 'di codice, ed è per questo che l'ho messo lì.
Erik the Outgolfer,

2

Java 8, 149 byte

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

Provalo online.

Spiegazione:

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"

1

Pyke, 39 byte

cFDh~u{!Ih(sil\-*\+R\+sj\|i\|++jild*\v+

Provalo qui!

12 byte di creazione di mini-string, 20 byte di formattazione. Gioia!



1

Python 2, 113 byte

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'

Puoi usare ascii in Python? Se sì, puoi usare 47<x<58|64<x<91:)
aloisdg dice Reinstate Monica l'

@aloisdg A differenza di C / C ++, Python non usa un chartipo integrale : tutti i caratteri nelle stringhe Python sono essi stessi stringhe e non possono essere confrontati direttamente con gli interi. Dovrebbe essere 47<ord(x)<58or 64<ord(x)<91.
Mego

[x for x in n if x.isupper()^x.isdigit()]è un byte più corto difilter(lambda x:x.isupper()^x.isdigit(),n)
Leaky Nun

@LeakyNun: il filtro restituirà una stringa, ma la comprensione dell'elenco restituirà un elenco, che non sarà utilizzabile nell'espressione del valore restituito.
Nikita Borisov,

Perché XOR Non puoi usare OR invece? XOR è più complesso, e quindi AFAIK più lento. x.isupper()^x.isdigit()->x.isupper()|x.isdigit()
Erik the Outgolfer,

1

Jolf, 35 byte

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

Ho bisogno di un modo più breve per rimuovere tutti tranne maiuscole e numeri ...


1

C, 171 163

La funzione f()modifica il suo input e stampa il risultato.

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

Programma di test

Richiede un parametro, la stringa da utilizzare nella 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;
}

Perché copi l'elemento argv?
mame98,

Perché la funzione modifica il suo input. Non sono sicuro che modificare i parametri in atto sia un comportamento definito.
owacoder,

mai pensato a questo ... secondo questa risposta e quindi dovrebbe andare bene: stackoverflow.com/a/963504/3700391
mame98

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"

uso

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

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

1
Stai utilizzando replicate, lengthed fesclusivamente in questa combinazione, in modo da poterli unire in una funzione: r=replicate.length.fe chiamarlo come r n '-'. È possibile salvare ancora più byte utilizzando un operatore infix: (#)=replicate.length.fe n#'-'/ n#' '. Inoltre replicate.lengthè >>(con una stringa singleton invece di un carattere), quindi è: (#)=(>>).fe n#"-"/ n#" ", entrambi senza ( )attorno ad esso.
nimi,

1
... anche: non c'è bisogno di ( )intorno t ne f n. "|"++lo è '|':. Tutto sommato: o n=t n++'|':f n++"|\n"++t n++n#" "++"V".
nimi,

1

Bash, 99 74 byte

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

Utilizzo: esegui il comando sopra, digita il nome del sito, premi Invio e poi Ctrl+D (invia 'end of file').



1

R, 108 byte

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

Spiegazione

Andando dall'interno verso l'esterno (perché chi non ama assegnare variabili globali dall'interno di una regex), supponendo che ssia la nostra stringa di input:

y<-gsub("[^A-Z0-9]","",s) mantiene maiuscole e numeri, assegna il valore risultante a y.

gsub(".","-",y<-...) sostituisce tutti i caratteri con trattini in precedenza.

x<-gsub("(.*)","+\\1+\n",gsub(...)) mandrini a + delle estremità della riga di trattini e una nuova riga e la memorizziamo come 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.


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!


1

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.)
Zacharý

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!


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'

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

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

0

Ruby, 81 bytes (78 + -p flag)

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

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
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.