28
\$\begingroup\$

Today, November 11th, is known as Remembrance Day, Armistice Day, or Veterans Day (depending upon the country), and is a day of reflection and gratitude for members of the military and their service, specifically started to reflect the end of European hostilities in the first World War. Let us reflect on that with a simple ASCII-art output of 11/11.

Given an input n, output an ASCII-art rendition of 11/11 that is n units tall. Specifically, each 1 is composed of vertical pipes ||, the slash is composed of slashes //, and each character is two spaces apart. Note that this means varying output widths -- for example, for n=3 below, see how the "bottom" of the slash is two spaces from the 1 to its left, but is four spaces from the 1 on its right, so that the top of the slash lines up appropriately and is two spaces from the 1 on its right.

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


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


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


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


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

and so on.

Input

A single positive integer in any convenient format, n > 0.

Output

An ASCII-art representation of 11/11, following the above rules and examples. Leading/trailing newlines or other whitespace are optional, provided that the characters line up appropriately.

Rules

  • Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
\$\endgroup\$

20 Answers 20

4
\$\begingroup\$

Jelly, 24 bytes

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

TryItOnline!

How?

⁾| Ḥẋ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
\$\endgroup\$
21
\$\begingroup\$

JavaScript (ES6), 57 bytes

n=>" ".repeat(n).replace(/./g,"||  ||  $'//$`  ||  ||\n")
\$\endgroup\$
  • 2
    \$\begingroup\$ What the... forget my answer, this is genius. I should stop going the conventional route every single time :P \$\endgroup\$ – ETHproductions Nov 11 '16 at 17:18
  • \$\begingroup\$ That's slick. Nice answer. \$\endgroup\$ – AdmBorkBork Nov 11 '16 at 17:19
  • \$\begingroup\$ Can someone explain the $' and the $` in the regex? I've never seen that before and would love to understand it better. \$\endgroup\$ – Robert Hickman Nov 13 '16 at 23:54
  • 1
    \$\begingroup\$ @RobertHickman They refer to the part of the string after and before the match ($& would be the match itself). \$\endgroup\$ – Neil Nov 14 '16 at 0:10
  • \$\begingroup\$ @Neil, thanks! You learn something new everyday :) \$\endgroup\$ – Robert Hickman Nov 14 '16 at 1:31
7
\$\begingroup\$

05AB1E, 24 bytes

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

Try it online!

Explanation

                          # 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

Previous 26 byte version

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

Try it online!

\$\endgroup\$
  • 2
    \$\begingroup\$ That was fast!! \$\endgroup\$ – AdmBorkBork Nov 11 '16 at 16:44
  • \$\begingroup\$ " "×"//"«.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. \$\endgroup\$ – Magic Octopus Urn Nov 14 '16 at 17:34
6
\$\begingroup\$

Perl, 45 bytes

-9 bytes thanks to @Gabriel Benamy

47 bytes of code + 1 byte for -n flag.

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

Run with -nE flags :

perl -nE 'say$@="||  "x2,$"x$_,"//",$"x++$.,$@while$_--' <<< 5
\$\endgroup\$
  • \$\begingroup\$ Save 4 bytes by changing "|| ||" to "|| "x2 and then turning (2+$_) into just $_ \$\endgroup\$ – Gabriel Benamy Nov 11 '16 at 18:01
  • \$\begingroup\$ I think you can also drop the +( .. ) around the $@ assignment. It works on my computer, at least. \$\endgroup\$ – Gabriel Benamy Nov 11 '16 at 18:04
  • \$\begingroup\$ @GabrielBenamy I can indeed drop the +( .. ), thanks. However I can't change "|| ||" to "|| "x2 because I need two spaces between the ||. \$\endgroup\$ – Dada Nov 11 '16 at 18:06
  • \$\begingroup\$ "|| " 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+$_) \$\endgroup\$ – Gabriel Benamy Nov 11 '16 at 18:08
  • \$\begingroup\$ @GabrielBenamy Oh thanks, that would be SE formatting showing only one space in || when there were two them. \$\endgroup\$ – Dada Nov 11 '16 at 18:10
5
\$\begingroup\$

JavaScript (ES6), 88 77 bytes

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)
\$\endgroup\$
4
\$\begingroup\$

Retina, 29 bytes

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

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

\$\endgroup\$
3
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – nmjcman101 Nov 18 '16 at 20:04
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ Nice! Is it possible to remove the space in 1 TO? \$\endgroup\$ – DLosc Nov 11 '16 at 23:10
3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ You should try golfing your solution (eliminating uneeded whitespace, shortening identifiers) \$\endgroup\$ – cat Nov 13 '16 at 2:43
  • \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ – AdmBorkBork Nov 13 '16 at 19:12
3
\$\begingroup\$

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!

\$\endgroup\$
  • \$\begingroup\$ 1 byte shorter: x='|| '*2;print x+(n-i)*' '+'//'+' '*i+x[::-1] \$\endgroup\$ – mbomb007 Nov 11 '16 at 18:41
  • \$\begingroup\$ @mbomb007 You need two spaces between the 11s, not 1. That would make it equal. \$\endgroup\$ – Kade Nov 11 '16 at 18:42
  • \$\begingroup\$ That's just SE messing it up. It's still a byte shorter. repl.it/EViJ \$\endgroup\$ – mbomb007 Nov 11 '16 at 18:43
  • \$\begingroup\$ @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. \$\endgroup\$ – Kade Nov 11 '16 at 19:12
  • \$\begingroup\$ Then your current program is wrong, because that's what yours does. \$\endgroup\$ – mbomb007 Nov 11 '16 at 19:22
2
\$\begingroup\$

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="")
\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

Ruby, 60 bytes

->n{n.times{|i|puts (a='||  || ')+' '*(n-i)+'//  '+' '*i+a}}
\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

Powershell, 66 bytes

$a=read-host;1..$a|%{$s="||  ";$s*2+" "*($a-$_)+"// "+" "*$_+$s*2}
\$\endgroup\$
  • \$\begingroup\$ Welcome to the site! \$\endgroup\$ – DJMcMayhem Nov 14 '16 at 1:53
  • \$\begingroup\$ @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? \$\endgroup\$ – nedla2004 Nov 14 '16 at 2:03
  • \$\begingroup\$ @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. \$\endgroup\$ – DJMcMayhem Nov 14 '16 at 2:15
  • \$\begingroup\$ 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} \$\endgroup\$ – AdmBorkBork Nov 14 '16 at 13:50
  • \$\begingroup\$ Thanks for the welcomes, the edit, and the command line suggestions all! \$\endgroup\$ – ben Nov 17 '16 at 4:31
1
\$\begingroup\$

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:

||  ||            //  ||  ||
||  ||           //   ||  ||
||  ||          //    ||  ||
||  ||         //     ||  ||
||  ||        //      ||  ||
||  ||       //       ||  ||
||  ||      //        ||  ||
||  ||     //         ||  ||
||  ||    //          ||  ||
||  ||   //           ||  ||
||  ||  //            ||  ||
\$\endgroup\$
1
\$\begingroup\$

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}

\$\endgroup\$
0
\$\begingroup\$

Python 3, 78 bytes

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

Still trying to shorten...

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – ETHproductions Nov 22 '16 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.