Der heutige 11. November ist als Gedenktag , Waffenstillstandstag oder Veteranentag (je nach Land) bekannt und ein Tag der Besinnung und Dankbarkeit für die Mitglieder des Militärs und ihren Dienst, der speziell das Ende der europäischen Feindseligkeiten widerspiegelt im ersten Weltkrieg. Lassen Sie uns dies mit einer einfachen ASCII-Ausgabe von reflektieren 11/11
.
Bei einer Eingabe n
wird eine ASCII-artige Wiedergabe ausgegeben 11/11
, die n
Einheiten groß ist. Insbesondere besteht jedes 1
aus vertikalen Rohren ||
, der Schrägstrich besteht aus Schrägstrichen //
und jedes Zeichen ist zwei Leerzeichen voneinander entfernt. Beachten Sie, dass dies unterschiedliche Ausgabebreiten bedeutet. n=3
Sehen Sie beispielsweise unten, wie der "Grund" des Schrägstrichs zwei Leerzeichen von 1
links, aber vier Leerzeichen von 1
rechts entfernt ist, sodass der obere Rand des Schrägstrichs angezeigt wird Richtet sich passend aus und ist zwei Felder von 1
rechts entfernt.
n = 1
|| || // || ||
n = 2
|| || // || ||
|| || // || ||
n = 3
|| || // || ||
|| || // || ||
|| || // || ||
n = 4
|| || // || ||
|| || // || ||
|| || // || ||
|| || // || ||
n = 5
|| || // || ||
|| || // || ||
|| || // || ||
|| || // || ||
|| || // || ||
und so weiter.
Eingang
Eine einzelne positive ganze Zahl in jedem geeigneten Format , n > 0
.
Ausgabe
Eine ASCII-artige Darstellung 11/11
gemäß den obigen Regeln und Beispielen. Führende / nachfolgende Zeilenumbrüche oder andere Leerzeichen sind optional, sofern die Zeichen richtig ausgerichtet sind.
Regeln
- Es ist entweder ein vollständiges Programm oder eine Funktion zulässig. Bei einer Funktion können Sie die Ausgabe zurückgeben, anstatt sie zu drucken.
- Standard-Schlupflöcher sind verboten.
- Dies ist Codegolf, daher gelten alle üblichen Golfregeln, und der kürzeste Code (in Byte) gewinnt.
$'
and the$`
in the regex? I've never seen that before and would love to understand it better.$&
would be the match itself).05AB1E, 24 bytes
Try it online!
Explanation
Previous 26 byte version
Try it online!
quelle
" "×"//"«.s¦R"|| || "s«vyû}»
, turns out palendromize isn't a good fit, for reasons more obvious now... and you beat my bytecount faster anyhow heh.Perl, 45 bytes
-9 bytes thanks to @Gabriel Benamy
47 bytes of code + 1 byte for
-n
flag.Run with
-nE
flags :quelle
"|| ||"
to"|| "x2
and then turning(2+$_)
into just$_
+( .. )
around the$@
assignment. It works on my computer, at least.+( .. )
, thanks. However I can't change"|| ||"
to"|| "x2
because I need two spaces between the||
."|| "
has two spaces after the pipes (it's just not rendering correctly here for some reason), and you're duplicating that string into"|| || "
which takes care of the extra 2 spaces from$"x(2+$_)
||
when there were two them.JavaScript (ES6),
8877 bytesThe recursive approach
may not becould not possibly be the shortest..map
version (88 bytes):Array comprehension (86 bytes):
for
loop version (89 bytes):.replace
version (85 bytes):quelle
Retina, 29 bytes
Port of my JavaScript solution. Note the space after
$*
and two spaces after||
.quelle
V, 30 bytes
Try it online!
As usual, here is a hexdump:
quelle
5i|| <esc>3b2r/
. You'll be at a slightly different place though, and I can't read V so I'm not sure if that matters.Batch, 130 bytes
Not a port of my JavaScript solution. Since
|
s are hard to manipulate in Batch, I usex
s as placeholders and replace them on output, this conveniently also reduces my code size. Starts by settings
to the desired output forn=1
(n
is passed on the command line), then inserts spaces as necessary to obtain the first line for the actual value ofn
, then loops through printing the string and shifting the slash left by one character each time.quelle
BaCon, 71 bytes
A complete BASIC program in one line.
quelle
1 TO
?Common Lisp, 216 bytes
I'm going to state right off the bat that this is an awful solution to the challenge. Nevertheless, it works, and I'm tired.
Usage:
For some reason, instead of doing anything sane, I decided to approach this with a loop inside a
format
call. This loop iterates through the contents returned by the other actual loop construct at the very end, with the last six elements removed (thus the repeatedbutlast
s). The contents of the value returned by this loop construct consist of a padding count for the front of the slashes, the padding characters (spaces), the padding count for the back of the slashes, and finally the same padding characters.I'm rather new to Lisp, and I understand that there is definitely a lot of room for improvement here.
quelle
Python 2,
767571 BytesStill working on a shorter version, not too bad though.
thanks mbomb007 for catching an error!
quelle
x='|| '*2;print x+(n-i)*' '+'//'+' '*i+x[::-1]
//
on the last row and two spaces after//
on the first row. It should be two spaces in both cases.R, 86 bytes
Just a simple
for
loop approach:quelle
Retina, 40 bytes
Try it online!
Explanation
This turns the input
N
intoWhere
S
corresponds toN
spaces.There are two things happening here.
;{:
indicates that this stage and the last one should be run in a loop until they fail to change the string.:
indicates that the result of this stage should be printed after each iteration and;
indicates that the final result of the loop (and therefore of the entire program) should not be printed. The stage itself just replaces thex
s with|| ||
on the first iteration (and does nothing afterwards), so that we now have the first line of the required output (and print it).Finally, this shifts the
//
one character to the left, provided there are still at least three spaces left of the//
. Afterwards we return to the previous stage (which now only prints the current line, since there are no morex
s) and then repeat.quelle
Ruby, 60 bytes
quelle
C,
116 9489 bytesTry it out on Ideone
quelle
Ruby,
767473 bytesAs a function it takes
7372 bytes, counting the definition:quelle
Powershell, 66 bytes
quelle
read-host
--param($a)1..$a|%{$s="|| ";$s*2+" "*($a-$_)+"// "+" "*$_+$s*2}
C#, 150 Bytes
Golfed:
Ungolfed:
Testing:
Output:
quelle
Groovy, 63 chars/bytes
Here's my attempt with Groovy, using an anonymous closure and simple loops to print the ASCII art to standard output:
{n->n.times{println'|| '*2+' '*(n-it-1)+'//'+' '*it+' ||'*2}}
You can try it online here. Just click "Edit in console" and then "Execute script".
Trying to do the same and returning a string instead of printing, I couldn't get below 71 bytes:
{n->a='';n.times{a+='|| '*2+' '*(n-it-1)+'//'+' '*it+' ||'*2+'\n'};a}
quelle
Python 3, 78 bytes
Still trying to shorten...
quelle
for
onto the same line asdef
? (Like this:def m(n):for e in range(n):print(a," "*(n-e),"//"," "*(e+1),a)
) Also, you can save two bytes by replacing(e+1)
with-~e
.