Ho dimenticato il giorno degli asciugamani
Script PHP per entrambi gli esempi (errore, formattazione della stringa)
Script php corretto, l'input è autoesplicativo
Script PHP con più commenti / commenti $argvdi input per vedere risultati diversi
Come forse saprai, il 25 maggio è ben noto come Towel Day , a causa dei molti usi che un asciugamano può avere.
Un semplice estratto del libro "The Hitchhiker's Guide to the Galaxy" (personalmente ho preso questo libro come "guida di tutti i giorni" ) afferma:
"Un asciugamano è la cosa più enormemente utile che un autostoppista interstellare può avere. In parte ha un grande valore pratico."
Se hai bisogno di maggiori informazioni sugli asciugamani, controlla questa risposta SE.scifi
La sfida
Spero che lo farai con un asciugamano usato come una coperta per le gambe.
Scrivi un programma o una funzione completi in qualsiasi linguaggio di programmazione valido che accetta due input
size Integer : #The size
message string : #A sentence
Come disegnare un asciugamano con questi valori?
Primo utilizzosize :
Disegna un asciugamano a seconda delle dimensioni, ascii-art per il nostro asciugamano
width = 12*size
#the line that has the "bar" its always present with different sizes
Width is defined as:
from the first | to the second | has to be equal to size*12 including both ||
<- width->
[===| |====]
| 12 chars || 1 height starts here, just after the "bar"
| SIZE = 1 || 2
| || 3 height = 5*size
| || 4
| || 5 height ends here just before the first line |=======|
|==========|| # the lines with the #
|==========|| # are always fixed
""""""""""""| # it means, every towel
| | # always has this 5 rows
"""""""""""" # no matter the size
Secondo, dagli il message
Devi dargli un messaggio, cos'è un asciugamano senza un bel messaggio cucito in filo d'oro?
Esempio 1
input: size=1, message="a simple message can stay with size"
width = 12*size
#the line that has the "bar" it's always present with different sizes
#no words allowed at the bar level
[===| |====]
| a simple || 1 height starts here, just after the "bar"
| message || 2
| can stay || 3 height = 5*size
| with size|| 4
| || 5 height ends here just before the first line |=======|
|==========|| # the lines with the #
|==========|| # are always fixed
""""""""""""| # it means, every towel
| | # always has this 5 rows
"""""""""""" # no matter the size
Esempio 2
input size=2
message="Don't Panic and bring a towel to SE Programming Puzzles and CodeGolf"
The size is 2
That means 24 width and 10 heigth
<- 24 chars width ->
[===| |====]
| Don't Panic and bring|| 1
| a towel to SE || 2
| Programming Puzzles || 3
| and CodeGolf || 4
| || 5
| || 6
| || 7
| || 8
| || 9
| || 10
|======================|| # The lines with the "#"
|======================|| # always present and
""""""""""""""""""""""""| # adapted to
| | # the towel width
"""""""""""""""""""""""" #
Criteri di risposta accettati
- Questo è codegolf quindi si applicano le normali regole.
Regole
Si garantisce che tutte le stringhe di input si adattano alle dimensioni, quindi nessun input simile
size=1; message="This string is just tooooooooooooooooooooo long to fit the width and height of your towel".Il formato della stringa dipende da te, ad esempio se vuoi centrare le sottostringhe.
Le interruzioni di parola non sono consentite.
Le modifiche
Mi dispiace davvero per qualsiasi confusione, perché gli asciugamani ansii che disegno non corrispondono ai parametri, ho aggiunto uno script PHP per entrambi gli esempi per verificare gli output previsti.
Grazie anche a tutte le persone che hanno votato e considerato la mia prima sfida: D.
current line + next wordsupererà il limite consentito per il tuo asciugamano @Jakob come decide lo script php che ho pubblicato.