Défi du jour de l'armistice

28

Aujourd'hui, le 11 Novembre, est connu comme le jour du Souvenir , jour de l' Armistice , ou Journée des anciens combattants (selon les pays), et une journée de réflexion et de reconnaissance pour les membres des forces armées et leur service, plus précisément commencé à tenir compte de la fin des hostilités européennes pendant la première guerre mondiale. Réfléchissons à cela avec une simple sortie ASCII de 11/11.

Étant donné une entrée n, sortez un rendu ASCII-art de ce 11/11qui est des nunités de haut. Plus précisément, chacun 1est composé de tuyaux verticaux ||, la barre oblique est composée de barres obliques //et chaque caractère est séparé de deux espaces. Notez que cela signifie des largeurs de sortie variables - par exemple, pour n=3ci-dessous, voyez comment le "bas" de la barre oblique est de deux espaces de la 1gauche, mais de quatre espaces de la 1droite, de sorte que le haut de la barre oblique s'aligne correctement et se trouve à deux espaces de la 1droite.

n = 1
||  ||  //  ||  ||


n = 2
||  ||   //  ||  ||
||  ||  //   ||  ||


n = 3
||  ||    //  ||  ||
||  ||   //   ||  ||
||  ||  //    ||  ||


n = 4
||  ||     //  ||  ||
||  ||    //   ||  ||
||  ||   //    ||  ||
||  ||  //     ||  ||


n = 5
||  ||      //  ||  ||
||  ||     //   ||  ||
||  ||    //    ||  ||
||  ||   //     ||  ||
||  ||  //      ||  ||

etc.

Contribution

Un entier positif unique dans un format pratique , n > 0.

Sortie

Une représentation ASCII de 11/11 , suivant les règles et exemples ci-dessus. Les sauts de ligne de début / fin ou d'autres espaces sont facultatifs, à condition que les caractères s'alignent correctement.

Règles

  • Un programme complet ou une fonction sont acceptables. S'il s'agit d'une fonction, vous pouvez renvoyer la sortie plutôt que de l'imprimer.
  • Les failles standard sont interdites.
  • Il s'agit de donc toutes les règles de golf habituelles s'appliquent et le code le plus court (en octets) l'emporte.
AdmBorkBork
la source

Réponses:

4

Gelée , 24 octets

⁾| Ḥẋ2µ,Ṛðj
⁶ẋṖ;⁾//ṙḶÇ€Y

TryItOnline!

Comment?

⁾| Ḥẋ2µ,Ṛðj - Link 1, join two "11"s with: middle
⁾|          - string literal: "| "
   Ḥ        - double          "||  "
    ẋ2      - repeat twice    "||  ||  "
      µ     - monadic chain separation
       ,    - pair with
        Ṛ   - reversed       ["||  ||  ","  ||  ||"]
         ð  - dyadic chain separation
          j - join with input "||  ||  middle  ||  ||"

⁶ẋṖ;⁾//ṙḶÇ€Y - Main link: n       e.g. 5
⁶            - literal ' '        ' '
 ẋ           - repeat n times     "     "
  Ṗ          - remove last entry  "    "
   ;         - concatenate with
    ⁾//      - literal "//"       "    //"
        Ḷ    - lowered range(n)   [0,1,2,3,4]
       ṙ     - rotate left        ["    //","   // ","  //  "," //   ","//    "]
         Ç€  - call last link (1) as a monad for €ach
           Y - join with line feeds
Jonathan Allan
la source
21

JavaScript (ES6), 57 octets

n=>" ".repeat(n).replace(/./g,"||  ||  $'//$`  ||  ||\n")
Neil
la source
2
Qu'est-ce que ... oubliez ma réponse, c'est du génie. Je devrais arrêter d'
emprunter
C'est lisse. Bonne réponse.
AdmBorkBork
Quelqu'un peut-il expliquer le $'et le $`dans l'expression rationnelle? Je n'avais jamais vu ça auparavant et j'aimerais mieux le comprendre.
Robert Hickman
1
@RobertHickman Ils se réfèrent à la partie de la chaîne après et avant la correspondance (ce $&serait la correspondance elle-même).
Neil
@Neil, merci! Vous apprenez quelque chose de nouveau tous les jours :)
Robert Hickman
7

05AB1E , 24 octets

<ðׄ//J¹FD"  ||"2׊««,À

Essayez-le en ligne!

Explication

                          # implicit input n
<ð×                       # push n-1 spaces
   „//J                   # join with "//"
       ¹F                 # input times do:
         D                # duplicate top of stack
          "  ||"2×        # push "  ||  ||"
                  Â       # push "||  ||  "
                   Š      # move the top of the stack down 2 places on the stack
                    ««    # concatenate the top 3 elements of the stack
                      ,   # print with newline
                       À  # rotate top of stack left

Version précédente de 26 octets

F"||  "2שð¹N-<ׄ//ðN×®RJ,

Essayez-le en ligne!

Emigna
la source
2
C'était rapide!!
AdmBorkBork
" "×"//"«.s¦R"|| || "s«vyû}», il s'avère que palendromize n'est pas un bon ajustement, pour des raisons plus évidentes maintenant ... et vous battez mon bytecount plus vite de toute façon heh.
Urne de poulpe magique
6

Perl, 45 octets

-9 octets grâce à @Gabriel Benamy

47 octets de code + 1 octet pour l' -nindicateur.

say$@="||  "x2,$"x$_,"//",$"x++$.,$@while$_--

Courez avec des -nEdrapeaux:

perl -nE 'say$@="||  "x2,$"x$_,"//",$"x++$.,$@while$_--' <<< 5
Dada
la source
Économisez 4 octets en changeant "|| ||"en "|| "x2puis en devenant (2+$_)juste$_
Gabriel Benamy
Je pense que vous pouvez également laisser tomber +( .. )la $@tâche. Cela fonctionne au moins sur mon ordinateur.
Gabriel Benamy
@GabrielBenamy Je peux en effet laisser tomber le +( .. ), merci. Cependant, je ne peux pas passer "|| ||"à "|| "x2car j'ai besoin de deux espaces entre les ||.
Dada
"|| "a deux espaces après les tuyaux (c'est juste qu'il ne s'affiche pas correctement ici pour une raison quelconque), et vous dupliquez cette chaîne dans "|| || "laquelle prend soin des 2 espaces supplémentaires de$"x(2+$_)
Gabriel Benamy
@GabrielBenamy Oh merci, ce serait le formatage SE montrant un seul espace || quand il y en avait deux.
Dada
5

JavaScript (ES6), 88 77 octets

f=(n,i=n)=>i--?`||  ||  ${" ".repeat(i)}//${" ".repeat(n+~i)}  ||  ||
`+f(n,i):""

The recursive approach may not be could not possibly be the shortest.


.map version (88 bytes):

n=>[...Array(n)].map((_,i)=>`||  ||  ${" ".repeat(n+~i)}//${" ".repeat(i)}  ||  ||`).join`
`

Array comprehension (86 bytes):

n=>[for(_ of Array(i=n))`||  ||  ${" ".repeat(--i)}//${" ".repeat(n+~i)}  ||  ||`].join`
`

for loop version (89 bytes):

n=>{for(a="",i=n;i--;a+=s+" ".repeat(i+2)+`//${" ".repeat(n-i+1)+s}
`)s="||  ||";return a}

.replace version (85 bytes):

n=>`||  ||  q  ||  ||
`[r="repeat"](n).replace(/q/g,_=>" "[r](--i)+"//"+" "[r](n+~i),i=n)
ETHproductions
la source
4

Retina, 29 bytes

.+
$* 
.
xx$'//$`  xx¶
x
||  

Port of my JavaScript solution. Note the space after $* and two spaces after ||.

Neil
la source
3

V, 30 bytes

4i||  2Bi//  Àé XÀ«ñÄf/é Elx

Try it online!

As usual, here is a hexdump:

0000000: 3469 7c7c 2020 1b32 4269 2f2f 2020 1bc0  4i||  .2Bi//  ..
0000010: e920 58c0 abf1 c466 2fe9 2045 6c78       . X....f/. Elx
DJMcMayhem
la source
I think you could change the initial part to 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.
nmjcman101
3

Batch, 130 bytes

@set s=xx//  xx
@set l=@for /l %%i in (2,1,%1)do @call
%l% set s=%%s://= //%%
%l%:l
:l
@echo %s:x=^|^|  %
@set s=%s: //=// %

Not a port of my JavaScript solution. Since |s are hard to manipulate in Batch, I use xs as placeholders and replace them on output, this conveniently also reduces my code size. Starts by setting s to the desired output for n=1 (n is passed on the command line), then inserts spaces as necessary to obtain the first line for the actual value of n, then loops through printing the string and shifting the slash left by one character each time.

Neil
la source
3

BaCon, 71 bytes

A complete BASIC program in one line.

INPUT n:FOR x=1 TO n:?"||  ||",SPC$(n-x+2),"//",SPC$(x+1),"||  ||":NEXT
Peter
la source
Nice! Is it possible to remove the space in 1 TO?
DLosc
3

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.

(defun arm (n) (format t "~{||  || ~v,,,vA//~v,,,vA ||  ||~%~}" (butlast (butlast (butlast (butlast (butlast (butlast (loop for i from 1 to (+ n 1) append `(,(- (+ n 1) i) #\Space #\Space ,i #\Space #\Space))))))))))

Usage:

* (arm 4)
||  ||     //  ||  ||
||  ||    //   ||  ||
||  ||   //    ||  ||
||  ||  //     ||  ||

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 repeated butlasts). 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.

artificialnull
la source
You should try golfing your solution (eliminating uneeded whitespace, shortening identifiers)
cat
Welcome to PPCG!
AdmBorkBork
3

Python 2, 76 75 71 Bytes

Still working on a shorter version, not too bad though.

n=input()
k='||  ||'
for i in range(n):print k,(n-i)*' '+'//'+' '*-~i,k

thanks mbomb007 for catching an error!

Kade
la source
1 byte shorter: x='|| '*2;print x+(n-i)*' '+'//'+' '*i+x[::-1]
mbomb007
@mbomb007 You need two spaces between the 11s, not 1. That would make it equal.
Kade
That's just SE messing it up. It's still a byte shorter. repl.it/EViJ
mbomb007
@mbomb007 According to that repl.it page there are three spaces before // on the last row and two spaces after // on the first row. It should be two spaces in both cases.
Kade
Then your current program is wrong, because that's what yours does.
mbomb007
2

R, 86 bytes

Just a simple for loop approach:

x="||  ||";n=scan();for(i in 1:n)cat(x,rep(" ",2+n-i),"//",rep(" ",1+i),x,"\n",sep="")
Billywob
la source
2

Retina, 40 bytes

.+
x $&$* //  x
;{:`x
||  ||
   //
  // 

Try it online!

Explanation

.+
x $&$* //  x

This turns the input N into

x S//  x

Where S corresponds to N spaces.

;{:`x
||  ||

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 the xs 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 more xs) and then repeat.

Martin Ender
la source
2

Ruby, 60 bytes

->n{n.times{|i|puts (a='||  || ')+' '*(n-i)+'//  '+' '*i+a}}
Lee W
la source
2

C, 116 94 89 bytes

c,d;f(a){for(d=a;a--;puts("  ||  ||"))for(c=-1;c<d;)printf(a-c++?c?" ":"||  ||  ":"//");}

Try it out on Ideone

ceilingcat
la source
1

Ruby, 76 74 73 bytes

x="||  ||";n=gets.to_i;puts (1..n).map{|i|x+" "*(n-i+2)+"//"+" "*(i+1)+x}

As a function it takes 73 72 bytes, counting the definition:

def f n,x="||  ||";(1..n).map{|i|x+" "*(n-i+2)+"//"+" "*(i+1)+x}*?\n;end
bfontaine
la source
1

Powershell, 66 bytes

$a=read-host;1..$a|%{$s="||  ";$s*2+" "*($a-$_)+"// "+" "*$_+$s*2}
ben
la source
Welcome to the site!
DJMcMayhem
@DrMcMoylex Just wondering, I saw this answer and was going to do the same thing you did, but it said that I did not change enough in my edit. How were you able to do this?
nedla2004
@nedla2004 Once you have 1,000 reputation, (or 2,000 for fully graduated sites) you'll get full editing priveleges. Until then, all your edits have to be at least 6 characters and will be reviewed by other users with more rep. Since I have over 1,000 rep, I am allowed to submit small edits immediately.
DJMcMayhem
Welcome to PPCG! You can save a couple bytes by taking command-line input instead of read-host -- param($a)1..$a|%{$s="|| ";$s*2+" "*($a-$_)+"// "+" "*$_+$s*2}
AdmBorkBork
Thanks for the welcomes, the edit, and the command line suggestions all!
ben
1

C#, 150 Bytes

Golfed:

string A(int n){string a="",b= "||  ||";for(int i=0;i<n;i++)a+=b+"  //  ".PadLeft(5+n-i,'\0')+string.Concat(Enumerable.Repeat(" ",i))+b+"\n";return a;

Ungolfed:

public string A(int n)
{
  string a = "", b = "||  ||";
  for (int i = 0; i < n; i++)
    a += b + "  //  ".PadLeft(5 + n - i, '\0') + string.Concat(Enumerable.Repeat(" ", i)) + b + "\n";
  return a;
}

Testing:

Console.WriteLine(new ArmisticeDayChallenge().A(11));

Output:

||  ||            //  ||  ||
||  ||           //   ||  ||
||  ||          //    ||  ||
||  ||         //     ||  ||
||  ||        //      ||  ||
||  ||       //       ||  ||
||  ||      //        ||  ||
||  ||     //         ||  ||
||  ||    //          ||  ||
||  ||   //           ||  ||
||  ||  //            ||  ||
Pete Arden
la source
1

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}

Rado
la source
0

Python 3, 78 bytes

a="||  ||"
def m(n):
    for e in range(n):print(a," "*(n-e),"//"," "*(e+1),a)

Still trying to shorten...

Juntos
la source
Welcome to PPCG! Might you be able to move the for onto the same line as def? (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.
ETHproductions