Skip to main content
added 34 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

A square of length 2n+1 would be just right (i.e., no surrounding whitespace) for a straightforward implementation, but we'll use one of length 5n to save a couple of bytes. Thankfully, surrounding whitespace is allowed.

A square of length 2n+1 would be just right for a straightforward implementation, but we'll use one of length 5n to save a couple of bytes. Thankfully, surrounding whitespace is allowed.

A square of length 2n+1 would be just right (i.e., no surrounding whitespace) for a straightforward implementation, but we'll use one of length 5n to save a couple of bytes. Thankfully, surrounding whitespace is allowed.

added 13 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

For each digit in the input, after selecting the corresponding 8-bit integer, we repeat the ith character of the representation of 8 exactly ai times, where ai is the ith bit of the integer. This pushes an array of strings of either one or zero characters. By dividing this array into chunks of length 3, we obtain an array where each element corresponds to a line of the representation.

Now, we compute the vectorized maximum of the strings that represent the square and the strings that represent the digit. The strings / and \ are bigger than the string      , so they will replace the spaces in the square. The empty string, however, is smaller than the string      , so empty strings in the digit representation will preserve the spaces in the square.

For each digit in the input, after selecting the corresponding 8-bit integer, we repeat the ith character of the representation 8 ai times, where ai is the ith bit of the integer. This pushes an array of strings of either one or zero characters. By dividing this array into chunks of length 3, we obtain an array where each element corresponds to a line of the representation.

Now we compute the vectorized maximum of the strings that represent the square and the strings that represent the digit. The strings / and \ are bigger than the string   , so they will replace the spaces in the square. The empty string, however, is smaller than the string   , so empty strings in the digit representation will preserve the spaces in the square.

For each digit in the input, after selecting the corresponding 8-bit integer, we repeat the ith character of the representation of 8 exactly ai times, where ai is the ith bit of the integer. This pushes an array of strings of either one or zero characters. By dividing this array into chunks of length 3, we obtain an array where each element corresponds to a line of the representation.

Now, we compute the vectorized maximum of the strings that represent the square and the strings that represent the digit. The strings / and \ are bigger than the string    , so they will replace the spaces in the square. The empty string, however, is smaller than the string    , so empty strings in the digit representation will preserve the spaces in the square.

added 1728 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

We start by examining the lengthnumber of digits n in the input and pushing a square of spaces big enough to cover the output. In the implementation, this square will be encoded as a two-dimensional array of one-character strings.

A square of length 2n+1 would be just right for a straightforward implementation, but we'll use one of length 5n to save a couple of bytes. Thankfully, surrounding whitespace is allowed.

Code (yet to come)

r_,      e# Read a token from STDIN and push the length of a copy.
5*_      e# Multiply the length by 5 and push a copy.
Sa*      e# Repeat the array [" "] that many times.
a*       e# Repeat the array [[" " ... " "]] that many times.
\{       e# For each character C in the input:
  ~      e#   Push eval(C), i.e., the digit the character represents.

  "÷Ðëúܾ¿ðÿþ"

         e#   Push the encodings of all 10 seven slash representations.

  =      e#   Select the proper one.
  i2b    e#   Push the resulting characters code point in base 2, i.e., its bits.
  S      e#   Push " ".
  "\/"4* e#   Push "\/\/\/\/".
  +W<    e#   Concatenate and eliminate the last character.
  .*     e#   Vectorized repetition.

         e#   For the digit 5, e.g., we have [1 0 1 1 1 1 1 0] and  " \/\/\/\" on
         e#   the stack, so .* yields [" " "" "/" "\" "/" "\" "/" ""].

  3/     e#   Divide the representation into chunks of length 3, i.e., its lines.
  ..e>   e#   Compute the twofold vectorized maximum, as explained above.
  2fm>   e#   Rotate each line to characters to the right.
  2m>    e#   Rotate the lines two units down.
}/
Wf%      e# Reverse each line.
N*       e# Place linefeeds between them.

The last rotations would mess up the output if the square's side length was smaller than 2n+3. Since 5n ≥ 2n+3 for all positive integers n, the square is big enough to prevent this.

We start by examining the length of the input and pushing a square of spaces big enough to cover the output. In the implementation, this square will be encoded as a two-dimensional array of one-character strings.

Code (yet to come)

We start by examining the number of digits n in the input and pushing a square of spaces big enough to cover the output. In the implementation, this square will be encoded as a two-dimensional array of one-character strings.

A square of length 2n+1 would be just right for a straightforward implementation, but we'll use one of length 5n to save a couple of bytes. Thankfully, surrounding whitespace is allowed.

Code

r_,      e# Read a token from STDIN and push the length of a copy.
5*_      e# Multiply the length by 5 and push a copy.
Sa*      e# Repeat the array [" "] that many times.
a*       e# Repeat the array [[" " ... " "]] that many times.
\{       e# For each character C in the input:
  ~      e#   Push eval(C), i.e., the digit the character represents.

  "÷Ðëúܾ¿ðÿþ"

         e#   Push the encodings of all 10 seven slash representations.

  =      e#   Select the proper one.
  i2b    e#   Push the resulting characters code point in base 2, i.e., its bits.
  S      e#   Push " ".
  "\/"4* e#   Push "\/\/\/\/".
  +W<    e#   Concatenate and eliminate the last character.
  .*     e#   Vectorized repetition.

         e#   For the digit 5, e.g., we have [1 0 1 1 1 1 1 0] and  " \/\/\/\" on
         e#   the stack, so .* yields [" " "" "/" "\" "/" "\" "/" ""].

  3/     e#   Divide the representation into chunks of length 3, i.e., its lines.
  ..e>   e#   Compute the twofold vectorized maximum, as explained above.
  2fm>   e#   Rotate each line to characters to the right.
  2m>    e#   Rotate the lines two units down.
}/
Wf%      e# Reverse each line.
N*       e# Place linefeeds between them.

The last rotations would mess up the output if the square's side length was smaller than 2n+3. Since 5n ≥ 2n+3 for all positive integers n, the square is big enough to prevent this.

added 1824 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading
added 74 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading
deleted 173 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading
added 137 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading
deleted 58 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading
deleted 58 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading
deleted 58 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading