Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Added explanation
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

Explanation

 a,b are cmdline args; s is space; x is empty string (implicit)
Ph:'-Xa<>3JW'+
 '-Xa String of hyphens of length a
 <>3 grouped into substrings of (maximum) length 3
 JW'+ Join on +, also wrapping the result in +
 h: Assign that string to h (mnemonic: "header")
P and print it (with newline)
PsX#h-2WR:'|Xb<>2J'+^xh
 '|Xb String of pipes of length b
 <>2 grouped into substrings of (maximum) length 2
 J'+ joined on +
 ^x and split on empty string (i.e. converted to list of chars)
 sX#h-2 String of len(h)-2 spaces
 WR: Wrap the spaces with the list of chars
 Note 1: WR operates itemwise on lists, so the result is a list,
 each item of which consists of the spaces wrapped in an item
 from the list of chars
 Note 2: the : compute-and-assign meta-operator is here abused
 to give WR: lower precedence than J and ^ and avoid parentheses
P Print that list, newline-separated (-n flag)
 h Autoprint the header a second time as the footer

Explanation

 a,b are cmdline args; s is space; x is empty string (implicit)
Ph:'-Xa<>3JW'+
 '-Xa String of hyphens of length a
 <>3 grouped into substrings of (maximum) length 3
 JW'+ Join on +, also wrapping the result in +
 h: Assign that string to h (mnemonic: "header")
P and print it (with newline)
PsX#h-2WR:'|Xb<>2J'+^xh
 '|Xb String of pipes of length b
 <>2 grouped into substrings of (maximum) length 2
 J'+ joined on +
 ^x and split on empty string (i.e. converted to list of chars)
 sX#h-2 String of len(h)-2 spaces
 WR: Wrap the spaces with the list of chars
 Note 1: WR operates itemwise on lists, so the result is a list,
 each item of which consists of the spaces wrapped in an item
 from the list of chars
 Note 2: the : compute-and-assign meta-operator is here abused
 to give WR: lower precedence than J and ^ and avoid parentheses
P Print that list, newline-separated (-n flag)
 h Autoprint the header a second time as the footer
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

Pip, 38 bytes

37 bytes of code, +1 for -n flag.

Ph:'-Xa<>3JW'+PsX#h-2WR:'|Xb<>2J'+^xh

Takes width and height as command-line arguments. Try it online!

AltStyle によって変換されたページ (->オリジナル) /