Skip to main content
Commonmark migration
Source Link

#05AB1E, 35 34 bytes

05AB1E, 35 34 bytes

#05AB1E, 35 34 bytes

05AB1E, 35 34 bytes

deleted 9 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#05AB1E, 3535 34 bytes

.γa}2ôε`„PN…- =2ä‡s∍}J©¶.ø¶ì'_®∍DŠ»J©¶ĆìĆ'_®∍DŠ»

Try it onlineTry it online or verify all test casesverify all test cases.

.γ                # Consecutive group the (implicit) input by:
  a               #  Check if the character is a letter
   }2ô            # After the group by: split it into parts of size 2
ε                 # Map each pair of integer + letter to:
 `                #  Pop and push them separated to the stack
  „PN             #  Push string "PN"
     …- =         #  Push string "- ="
         2ä       #  Split it into 2 parts: ["- ","="]
           ‡      #  Transliterate the "P" to "- " and "N" to "="
            s     #  Swap to take the integer value
             ∍    #  Extend (or shorten) the string to that length
              }J  # After the map: join all parts together to a single string
                © # And store it in variable `®` (without popping)
¶               # Surround it# withPush a leading andnewline trailingcharacter newline"\n"
 Ć  ¶ì              # PrependDouble anit additional"\n\n"
 newline forì the required asymmetrical output
           # Prepend it in front of the #string
 (otherwise a mirrorĆ could have been used to save some bytes)      # Enclose the string, appending it's own first character
'_               '# Push string "_"
  ®∍              # Extend it to a size equal to the length of string `®`
    D             # Duplicate it
     Š            # Triple swap the three values on the stack from a,b,c to c,a,b
      »           # Join the values on the stack with newline delimiter
                  # (after which the result is output implicitly)

#05AB1E, 35 bytes

.γa}2ôε`„PN…- =2ä‡s∍}J©¶.ø¶ì'_®∍DŠ»

Try it online or verify all test cases.

.γ                # Consecutive group the (implicit) input by:
  a               #  Check if the character is a letter
   }2ô            # After the group by: split it into parts of size 2
ε                 # Map each pair of integer + letter to:
 `                #  Pop and push them separated to the stack
  „PN             #  Push string "PN"
     …- =         #  Push string "- ="
         2ä       #  Split it into 2 parts: ["- ","="]
           ‡      #  Transliterate the "P" to "- " and "N" to "="
            s     #  Swap to take the integer value
             ∍    #  Extend (or shorten) the string to that length
              }J  # After the map: join all parts together to a single string
                © # And store it in variable `®` (without popping)
¶               # Surround it with a leading and trailing newline
   ¶ì             # Prepend an additional newline for the required asymmetrical output
                  # (otherwise a mirror could have been used to save some bytes)
'_               '# Push string "_"
  ®∍              # Extend it to a size equal to the length of string `®`
    D             # Duplicate it
     Š            # Triple swap the three values on the stack from a,b,c to c,a,b
      »           # Join the values on the stack with newline delimiter
                  # (after which the result is output implicitly)

#05AB1E, 35 34 bytes

.γa}2ôε`„PN…- =2ä‡s∍}J©¶ĆìĆ'_®∍DŠ»

Try it online or verify all test cases.

.γ                # Consecutive group the (implicit) input by:
  a               #  Check if the character is a letter
   }2ô            # After the group by: split it into parts of size 2
ε                 # Map each pair of integer + letter to:
 `                #  Pop and push them separated to the stack
  „PN             #  Push string "PN"
     …- =         #  Push string "- ="
         2ä       #  Split it into 2 parts: ["- ","="]
           ‡      #  Transliterate the "P" to "- " and "N" to "="
            s     #  Swap to take the integer value
             ∍    #  Extend (or shorten) the string to that length
              }J  # After the map: join all parts together to a single string
                © # And store it in variable `®` (without popping)
¶                 # Push a newline character "\n"
 Ć                # Double it "\n\n"
  ì               # Prepend it in front of the string
   Ć              # Enclose the string, appending it's own first character
'_               '# Push string "_"
  ®∍              # Extend it to a size equal to the length of string `®`
    D             # Duplicate it
     Š            # Triple swap the three values on the stack from a,b,c to c,a,b
      »           # Join the values on the stack with newline delimiter
                  # (after which the result is output implicitly)
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#05AB1E, 35 bytes

.γa}2ôε`„PN…- =2ä‡s∍}J©¶.ø¶ì'_®∍DŠ»

Try it online or verify all test cases.

Explanation:

.γ                # Consecutive group the (implicit) input by:
  a               #  Check if the character is a letter
   }2ô            # After the group by: split it into parts of size 2
ε                 # Map each pair of integer + letter to:
 `                #  Pop and push them separated to the stack
  „PN             #  Push string "PN"
     …- =         #  Push string "- ="
         2ä       #  Split it into 2 parts: ["- ","="]
           ‡      #  Transliterate the "P" to "- " and "N" to "="
            s     #  Swap to take the integer value
             ∍    #  Extend (or shorten) the string to that length
              }J  # After the map: join all parts together to a single string
                © # And store it in variable `®` (without popping)
¶.ø               # Surround it with a leading and trailing newline
   ¶ì             # Prepend an additional newline for the required asymmetrical output
                  # (otherwise a mirror could have been used to save some bytes)
'_               '# Push string "_"
  ®∍              # Extend it to a size equal to the length of string `®`
    D             # Duplicate it
     Š            # Triple swap the three values on the stack from a,b,c to c,a,b
      »           # Join the values on the stack with newline delimiter
                  # (after which the result is output implicitly)