Fammi un s'more ! Ti dico la larghezza, la quantità di cracker Graham, la quantità di cioccolato e la quantità di marshmallow. Un esempio:
Ingresso:
Larghezza: 10
Graham: 3
Cioccolato: 2
Marshmallow: 1.
Produzione:
GGGGGGGGGG
GGGGGGGGGG
GGGGGGGGGG
CCCCCCCCCC
CCCCCCCCCC
MMMMMMMMMM
GGGGGGGGGG
GGGGGGGGGG
GGGGGGGGGG
È così facile? Ehm ... si.
Si noti che l'input dovrebbe essere un elenco di argomenti per una funzione o un programma, non una stringa. Puoi scegliere prima Larghezza, poi Graham, ma qualsiasi ordine va bene.
Casi di test completi se sei interessato.
Stack snippet (per test, ecc.)
Questo per testare l'output.
var smore = function(width, graham, chocolate, marshmallow){
return ("G".repeat(width) + "\n").repeat(graham) +
("C".repeat(width) + "\n").repeat(chocolate) +
("M".repeat(width) + "\n").repeat(marshmallow) +
("G".repeat(width) + "\n").repeat(graham);
};
Snippetify(smore);
<script src="https://programmer5000.com/snippetify.min.js"></script>
Width: <input type = "number">
Graham: <input type = "number">
Chocolate: <input type = "number">
Marshmallow: <input type = "number">
<button>Try it out!</button>
<pre data-output></pre>
Appunti:
- È possibile includere una nuova riga finale alla fine dell'ultima riga. Puoi anche usare una
\anziché una nuova riga. - Questo è code-golf .
- Qualsiasi domanda? Commento sotto: