Skip to main content
Commonmark migration
Source Link

#05AB1E, 25 22 20 bytes

05AB1E, 25 22 20 bytes

#05AB1E, 25 22 20 bytes

05AB1E, 25 22 20 bytes

added 1149 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

-2 bytes and(and increased the performance by not generating the entire list) thanks to @Grimy.

Au            # Push the lowercase alphabet, and uppercase it
  2ã          # Create all possible pairs by taking the cartesian product with itself:
              #  ["AA","AB","AC",...,"ZY","ZZ"]
    ã         # Get the cartesian product of this list with itself:
              #  [["AA","AA"],["AA","AB"],...,["ZZ","ZZ"]]
s             # Swap to push the (implicit) input
 ₄‰           # Take the divmod-1000 of it
              #  i.e. 7483045 becomes [7483,45]
    `         # Push these values looseseparated to the stack
     U        # Pop and store the remainder part in variable `X`
      è       # Index the integer part into the list of letter-pairs we created earlier
              #  i.e. 7483 will result in ["AL","BV"]
X             # Push the remainder part from variable `X` again
 ₄+           # Add 1000 to the integerit
   ¦          # And remove the leading 1 (so now the number is padded with leading 0s)
              #  i.e. 45 becomes 1045 and then "045"
    '-.ø     '# Surround each numberthis with "-" (i.e. "045" becomes "-045-")
        ý     # Join the two pairs of letters by this
              #  i.e. ["AL","BV"] and "-045-" becomes "AL-045-BV"
              # (after which the top of the stack is output implicitly as result)

The last part (s₄‰`UèX₄+¦'-.øý) could be I₄÷èI₄+3.£.ý'-ý for an equal-bytes alternative:
Try it online or verify all test cases.

I₄÷           # Push the input, integer-divided by 1000
   è          # Use it to index into the letter-pairs we created earlier
              #  i.e. 7483045 becomes 7483 and then ["AL","BV"]
I₄+           # Push the input again, and add 1000
   3.£        # Only leave the last three digits
              #  i.e. 7483045 becomes 7484045 and then "045"
      .ý      # Intersperse the pair with this
              #  i.e. ["AL","BV"] and "045" becomes ["AL","045","BV"]
        '-ý  '# And join this list by "-"
              #  i.e. ["AL","045","BV"] becomes "AL-045-BV"
              # (after which the top of the stack is output implicitly as result)

-2 bytes and increased the performance by not generating the entire list thanks to @Grimy.

Au         # Push the lowercase alphabet, and uppercase it
  2ã       # Create all possible pairs by taking the cartesian product with itself:
           #  ["AA","AB","AC",...,"ZY","ZZ"]
    ã      # Get the cartesian product of this list with itself:
           #  [["AA","AA"],["AA","AB"],...,["ZZ","ZZ"]]
s          # Swap to push the (implicit) input
 ₄‰        # Take the divmod-1000 of it
           #  i.e. 7483045 becomes [7483,45]
    `      # Push these values loose to the stack
     U     # Pop and store the remainder part in variable `X`
      è    # Index the integer part into the list of letter-pairs we created earlier
           #  i.e. 7483 will result in ["AL","BV"]
X          # Push the remainder part from variable `X` again
 ₄+        # Add 1000 to the integer
   ¦       # And remove the leading 1 (so now the number is padded with leading 0s)
           #  i.e. 45 becomes 1045 and then "045"
    '-.ø  '# Surround each number with "-" (i.e. "045" becomes "-045-")
        ý  # Join the two pairs of letters by this
           #  i.e. ["AL","BV"] and "-045-" becomes "AL-045-BV"
           # (after which the top of the stack is output implicitly as result)

-2 bytes (and increased the performance by not generating the entire list) thanks to @Grimy.

Au            # Push the lowercase alphabet, and uppercase it
  2ã          # Create all possible pairs by taking the cartesian product with itself:
              #  ["AA","AB","AC",...,"ZY","ZZ"]
    ã         # Get the cartesian product of this list with itself:
              #  [["AA","AA"],["AA","AB"],...,["ZZ","ZZ"]]
s             # Swap to push the (implicit) input
 ₄‰           # Take the divmod-1000 of it
              #  i.e. 7483045 becomes [7483,45]
    `         # Push these values separated to the stack
     U        # Pop and store the remainder part in variable `X`
      è       # Index the integer part into the list of letter-pairs we created earlier
              #  i.e. 7483 will result in ["AL","BV"]
X             # Push the remainder part from variable `X` again
 ₄+           # Add 1000 to it
   ¦          # And remove the leading 1 (so now the number is padded with leading 0s)
              #  i.e. 45 becomes 1045 and then "045"
    '-.ø     '# Surround this with "-" (i.e. "045" becomes "-045-")
        ý     # Join the two pairs of letters by this
              #  i.e. ["AL","BV"] and "-045-" becomes "AL-045-BV"
              # (after which the top of the stack is output implicitly as result)

The last part (s₄‰`UèX₄+¦'-.øý) could be I₄÷èI₄+3.£.ý'-ý for an equal-bytes alternative:
Try it online or verify all test cases.

I₄÷           # Push the input, integer-divided by 1000
   è          # Use it to index into the letter-pairs we created earlier
              #  i.e. 7483045 becomes 7483 and then ["AL","BV"]
I₄+           # Push the input again, and add 1000
   3.£        # Only leave the last three digits
              #  i.e. 7483045 becomes 7484045 and then "045"
      .ý      # Intersperse the pair with this
              #  i.e. ["AL","BV"] and "045" becomes ["AL","045","BV"]
        '-ý  '# And join this list by "-"
              #  i.e. ["AL","045","BV"] becomes "AL-045-BV"
              # (after which the top of the stack is output implicitly as result)
added 122 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#05AB1E, 25 2222 20 bytes

Au2ãã₄ݨâε`₄+¦'Au2ããs₄‰`UèX₄+¦'-.øý}Iè

-2 bytes and increased the performance by not generating the entire list thanks to @Grimy.

Try it onlineTry it online or verify almost all test cases (the largest test case times out)verify all test cases.

Au             # Push the lowercase alphabet, and uppercase it
  2ã           # Create all possible pairs by taking the cartesian product with itself:
               #  ["AA","AB","AC",...,"ZY","ZZ"]
    ã          # Get the cartesian product of this list with itself:
               #  [["AA","AA"],["AA","AB"],...,["ZZ","ZZ"]]
s     ₄Ý     # Swap to #push Pushthe a(implicit) listinput
 in₄‰ the range [0,1000]
     # Take ¨the divmod-1000 of it
    # Remove the last value to make the# range [0i.e. 7483045 becomes [7483,999]45]
    `    â  # Push these values #loose Taketo the cartesianstack
 product of both lists:
 U     # Pop and store the remainder part in variable #`X`
  [[["AA","AA"],0],[["AA","AA"],1],...,[["ZZ","ZZ"],999]]
ε    è    # Index the integer part into #the Maplist eachof itemletter-pairs to:we created earlier
 `          #  i.e. #7483 will Pushresult themin separated["AL","BV"]
X to         # Push the stack
remainder part ₄+from variable `X` again
 ₄+        #  Add 1000 to the integer
    ¦          #  And remove the leading 1 (so now the numbersnumber areis padded with leading 0s)
     '-      #  i.øe. 45 becomes 1045 and '#then "045"
    '-.ø  '# Surround each number with "-" (i.e. "000""045" becomes "-000045-")
         ý     #  Join the two pairs of letters by this
               #   i.e. ["AA"["AL","AA"]"BV"] and "-000045-" becomes "AA"AL-000045-AA"
          }Iè  # After the map: use the input to index into the listBV"
               # (after which the top of the stack is output implicitly as result)

#05AB1E, 25 22 bytes

Au2ãã₄ݨâε`₄+¦'-.øý}Iè

Try it online or verify almost all test cases (the largest test case times out).

Au             # Push the lowercase alphabet, and uppercase it
  2ã           # Create all possible pairs by taking the cartesian product with itself:
               #  ["AA","AB","AC",...,"ZY","ZZ"]
    ã          # Get the cartesian product of this list with itself:
               #  [["AA","AA"],["AA","AB"],...,["ZZ","ZZ"]]
     ₄Ý        # Push a list in the range [0,1000]
       ¨       # Remove the last value to make the range [0,999]
        â      # Take the cartesian product of both lists:
               #  [[["AA","AA"],0],[["AA","AA"],1],...,[["ZZ","ZZ"],999]]
ε              # Map each item to:
 `             #  Push them separated to the stack
  ₄+           #  Add 1000 to the integer
    ¦          #  And remove the leading 1 (so now the numbers are padded with leading 0s)
     '-.ø     '#  Surround each number with "-" (i.e. "000" becomes "-000-")
         ý     #  Join the two pairs of letters by this
               #   i.e. ["AA","AA"] and "-000-" becomes "AA-000-AA"
          }Iè  # After the map: use the input to index into the list
               # (after which the top of the stack is output implicitly as result)

#05AB1E, 25 22 20 bytes

Au2ããs₄‰`UèX₄+¦'-.øý

-2 bytes and increased the performance by not generating the entire list thanks to @Grimy.

Try it online or verify all test cases.

Au         # Push the lowercase alphabet, and uppercase it
  2ã       # Create all possible pairs by taking the cartesian product with itself:
           #  ["AA","AB","AC",...,"ZY","ZZ"]
    ã      # Get the cartesian product of this list with itself:
           #  [["AA","AA"],["AA","AB"],...,["ZZ","ZZ"]]
s          # Swap to push the (implicit) input
 ₄‰        # Take the divmod-1000 of it
           #  i.e. 7483045 becomes [7483,45]
    `      # Push these values loose to the stack
     U     # Pop and store the remainder part in variable `X`
      è    # Index the integer part into the list of letter-pairs we created earlier
           #  i.e. 7483 will result in ["AL","BV"]
X          # Push the remainder part from variable `X` again
 ₄+        # Add 1000 to the integer
   ¦       # And remove the leading 1 (so now the number is padded with leading 0s)
           #  i.e. 45 becomes 1045 and then "045"
    '-.ø  '# Surround each number with "-" (i.e. "045" becomes "-045-")
        ý  # Join the two pairs of letters by this
           #  i.e. ["AL","BV"] and "-045-" becomes "AL-045-BV"
           # (after which the top of the stack is output implicitly as result)
added 35 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading
added 1468 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading