Armistice Day Challenge

28

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.

AdmBorkBork

Posted 2016-11-11T16:34:23.033

Reputation: 41 581

Answers

4

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

Jonathan Allan

Posted 2016-11-11T16:34:23.033

Reputation: 67 804

21

JavaScript (ES6), 57 bytes

n=>" ".repeat(n).replace(/./g,"||  ||  $'//$`  ||  ||\n")

Neil

Posted 2016-11-11T16:34:23.033

Reputation: 95 035

2What the... forget my answer, this is genius. I should stop going the conventional route every single time :P – ETHproductions – 2016-11-11T17:18:12.380

That's slick. Nice answer. – AdmBorkBork – 2016-11-11T17:19:45.613

Can someone explain the $' and the `$`` in the regex? I've never seen that before and would love to understand it better. – Robert Hickman – 2016-11-13T23:54:14.943

1@RobertHickman They refer to the part of the string after and before the match ($& would be the match itself). – Neil – 2016-11-14T00:10:11.543

@Neil, thanks! You learn something new everyday :) – Robert Hickman – 2016-11-14T01:31:29.453

7

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!

Emigna

Posted 2016-11-11T16:34:23.033

Reputation: 50 798

2That was fast!! – AdmBorkBork – 2016-11-11T16:44:25.793

" "×"//"«.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. – Magic Octopus Urn – 2016-11-14T17:34:19.080

6

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

Dada

Posted 2016-11-11T16:34:23.033

Reputation: 8 279

Save 4 bytes by changing "|| ||" to "|| "x2 and then turning (2+$_) into just $_ – Gabriel Benamy – 2016-11-11T18:01:17.097

I think you can also drop the +( .. ) around the $@ assignment. It works on my computer, at least. – Gabriel Benamy – 2016-11-11T18:04:21.437

@GabrielBenamy I can indeed drop the +( .. ), thanks. However I can't change "|| ||" to "|| "x2 because I need two spaces between the ||. – Dada – 2016-11-11T18:06:38.343

"|| " 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+$_) – Gabriel Benamy – 2016-11-11T18:08:02.980

@GabrielBenamy Oh thanks, that would be SE formatting showing only one space in || when there were two them. – Dada – 2016-11-11T18:10:05.713

5

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)

ETHproductions

Posted 2016-11-11T16:34:23.033

Reputation: 47 880

4

Retina, 29 bytes

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

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

Neil

Posted 2016-11-11T16:34:23.033

Reputation: 95 035

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

James

Posted 2016-11-11T16:34:23.033

Reputation: 54 537

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 – 2016-11-18T20:04:48.087

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

Posted 2016-11-11T16:34:23.033

Reputation: 7 463

1 byte shorter: x='|| '*2;print x+(n-i)*' '+'//'+' '*i+x[::-1] – mbomb007 – 2016-11-11T18:41:32.873

@mbomb007 You need two spaces between the 11s, not 1. That would make it equal. – Kade – 2016-11-11T18:42:27.197

That's just SE messing it up. It's still a byte shorter. https://repl.it/EViJ

– mbomb007 – 2016-11-11T18:43:11.190

@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 – 2016-11-11T19:12:11.903

Then your current program is wrong, because that's what yours does. – mbomb007 – 2016-11-11T19:22:06.130

@mbomb007 Good point, fixed that (so I saved the byte anyways). – Kade – 2016-11-11T19:36:19.927

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

Posted 2016-11-11T16:34:23.033

Reputation: 95 035

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

Posted 2016-11-11T16:34:23.033

Reputation: 119

Nice! Is it possible to remove the space in 1 TO? – DLosc – 2016-11-11T23:10:15.547

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

Posted 2016-11-11T16:34:23.033

Reputation: 481

You should try golfing your solution (eliminating uneeded whitespace, shortening identifiers) – cat – 2016-11-13T02:43:59.023

Welcome to PPCG! – AdmBorkBork – 2016-11-13T19:12:34.310

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

Posted 2016-11-11T16:34:23.033

Reputation: 3 363

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

Posted 2016-11-11T16:34:23.033

Reputation: 184 808

2

Ruby, 60 bytes

->n{n.times{|i|puts (a='||  || ')+' '*(n-i)+'//  '+' '*i+a}}

Lee W

Posted 2016-11-11T16:34:23.033

Reputation: 521

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

Posted 2016-11-11T16:34:23.033

Reputation: 5 503

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

Posted 2016-11-11T16:34:23.033

Reputation: 1 151

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

Posted 2016-11-11T16:34:23.033

Reputation: 161

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

Posted 2016-11-11T16:34:23.033

Reputation: 133

1

Powershell, 66 bytes

$a=read-host;1..$a|%{$s="||  ";$s*2+" "*($a-$_)+"// "+" "*$_+$s*2}

ben

Posted 2016-11-11T16:34:23.033

Reputation: 21

Welcome to the site! – James – 2016-11-14T01:53:41.007

@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 – 2016-11-14T02:03:28.377

@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.

– James – 2016-11-14T02:15:52.037

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 – 2016-11-14T13:50:37.640

Thanks for the welcomes, the edit, and the command line suggestions all! – ben – 2016-11-17T04:31:02.397

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

Posted 2016-11-11T16:34:23.033

Reputation: 41

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 – 2016-11-22T15:42:33.247