introduction
Nous connaissons tous le cool S (également connu sous les noms de Superman S, Stüssy S, Super S, Skater S, Pointy S, Graffiti S, etc.): des milliards d'écoliers du monde entier ont dessiné ce S et se sont immédiatement sentis fiers d'eux-mêmes. Au cas où vous avez oublié ou eu un enfance complètement pas cool , voici une image de ce cool S:
Soit un facteur d'échelle n
en entrée (où ), émettez le Cool S en ASCII art.
Comment le dessiner
De la page Wikipedia sur le Cool S:
Sortie
Le Cool S quand n
= 1 est:
^
/ \
/ \
/ \
| | |
| | |
\ \ /
\ \/
/\ \
/ \ \
| | |
| | |
\ /
\ /
\ /
v
Et pour différentes valeurs de n
, vous augmentez simplement les n
temps de sortie . Par exemple, n
= 2:
^
/ \
/ \
/ \
/ \
/ \
| | |
| | |
| | |
| | |
\ \ /
\ \ /
\ \/
/\ \
/ \ \
/ \ \
| | |
| | |
| | |
| | |
\ /
\ /
\ /
\ /
\ /
v
Notez que les sections verticales sont deux fois plus longues et l’espacement entre les lignes verticales est deux fois plus large.
Et quand n
= 3:
^
/ \
/ \
/ \
/ \
/ \
/ \
/ \
| | |
| | |
| | |
| | |
| | |
| | |
\ \ /
\ \ /
\ \ /
\ \/
/\ \
/ \ \
/ \ \
/ \ \
| | |
| | |
| | |
| | |
| | |
| | |
\ /
\ /
\ /
\ /
\ /
\ /
\ /
v
Remarque: Bien que non requis, votre code peut également prendre en chargen
= 0:
^
/ \
\\/
/\\
\ /
v
Gagnant
Le programme le plus court en octets gagne.
Λ
Réponses:
Charbon de bois ,
58 53 47 4341 octetsEssayez-le en ligne!
Je voulais juste essayer une autre approche, cela dessine l’extérieur par des réflexions (merci à Neil d’avoir développé l’idée) et dessine ensuite la partie intérieure. Comme Charcoal a la
:Left
direction par défaut pour tracer des lignes, je l’utilise autant que possible pour sauvegarder des octets en traçant le S horizontalement, comme ceci:Et puis je dois juste faire pivoter la toile de 90 degrés dans le sens anti-horaire.
la source
Rotate
? Cela me donne une idée ...Python 3 ,
255249248209 octets-6 bytes thanks to Kevin Cruijssen
-1 byte thanks to Kevin Cruijssen
-39 bytes thanks to Rod and Jo King
Try it online!
It now handles n=0.
la source
o+~d
can bem-d
andrange(o)
can berange(m+1)
, and then you can removeo=m+1\n
to save 6 bytes. Nice answer though, +1 from me.p(s)\np(s[::-1])
top(s+q+s[::-1])
: 248 bytesprint
, and more 4 by removing[]
fromjoin([...])
, totalizing 238 bytesq.join
in a variable to save a byteq.join
s, and a couple of other thingsCharcoal,
474241 bytesTry it online! Link is to verbose version of code. Explanation: Draws the following lines in order:
Where
5
is the current character of the stringv^
. At the end of the first loop the cursor is then positioned at point9
. The entire canvas is then rotated so that the other half of the Cool S can be drawn. (The canvas actually gets rotated twice, but this is just an implementation detail.)Charcoal doesn't support
RotateCopy(:Up, 4)
but if it did then this would work for 33 bytes:la source
Canvas,
363229 bytesTry it here!
A whole lot of stack manipulation. (outdated) explanation:
la source
Python 2,
227208207202196181 bytesTry it online!
Thks to Jo King for 1 byte; and then another 5 bytes total (via
n => 2*n
).Works for
n=0
as well.la source
C (gcc),
379353344334 bytesI used a couple of
#define
s for subexpression elimination and several globals to communicate between the internal functions. The main loop goes {0,1,2,3,3,2,1,0} to construct the S.Thanks to Jonathan Frech for the suggestions.
Try it online!
la source
w -r-1
could possibly be golfed tow~r
.C (gcc),
260254 bytes-6 bytes thanks to ceilingcat.
Try it online!
Rundown
We can divide the shape into parts:
Each part could be described by a number of lines, three chars, and three relationships to certain values that decides the field-width at each line.
A first iteration came to be:
The calls to the
g()
macro looks very much like a table could be constructed and looped over. Field-widths are sometimes related to the index counter, and sometimes not. We can generalise the field-width to beF * i + A
, where F is some factor to multiplyi
with, and A is some value to add to the width. So the last width of the fourth call above would be-2 * i + t
, for example.Thus we get:
In the end it was not much shorter than a tightened version of the
g()
calling one, but shorter is shorter.la source
Java, 435 bytes
The function itself takes 435 bytes. There is certainly room for improvement, "high level" by analyzing the rules about where to place which character (in the end the S is point-symmetric), and "low-level", by classical golfing (maybe pulling out another variable or combining two of the
for
-loops). But it's a first shot with this rather ungolfy language:la source
t=...
a bit less where it would save bytes. If you have any questions about any of the changes I made, let me know. :)PHP,
378374378377376335331328 bytes-3 bytes, thanks to manatwork
-4 bytes, used str_pad instead of str_repeat
-41 bytes, thanks to manatworks' suggestions
-1 byte, merged two increments into a +=2
-1 byte, removed superfluous \
-4 bytes by echoing once.Forgot I needed to pass the string into the function so this is more bytesWorks for n = 0 as well.
Try it online!
la source
'v'
in the finalecho
.$i>0
and$m>0
can be written simply as$i
and$m
..
concatenation after it to,
. Try it online!Python 3,
321307 bytesThanks to @EsolangingFruit for saving 14 bytes
Try it online!
Python 2, 303 bytes
Try it online!
la source
'\\','/'
on the second line with*'\/'
to save three bytes.print
input()
automaticallyeval()
s the string, so you can skip theint()
call as well.for l in L:print(*l,sep="")
(I don't think there is an equivalent in Python 2).