Skip to main content
added 92 characters in body
Source Link
lyxal
  • 34.3k
  • 2
  • 64
  • 141

Vyxal S, 124120 bitsv1, 15.5 bytes

s:¯0J⁽ṅḋ•ꜝƛ₍htU\¯Ǐ⁽ṅḋ•ꜝƛ₍htU\-j

Try it Online!Try it Online!

Explained

s:¯0J⁽ṅḋ•ꜝƛ₍htU\¯Ǐ⁽ṅḋ•ꜝƛ₍htU\-j
s:                 # Push two copies of the input list but sorted
  ¯0J¯Ǐ               # Forward differences of items with 0the first item appended
  - this is for making sure the length of the deltas matches the length of the input
    ⁽ṅḋ            # Grouped by whether they are <= 1
            # Reshape the sorted input to that shape
           # and remove the 0
                   # the top of the stack will be a list of lists of numbers that are ranges
          ƛ         # to each range
           ₍htU     #   either get the first and last item or just the first
               \-j  #   join on "-"
# S flag joins the result on spaces

Vyxal S, 124 bitsv1, 15.5 bytes

s:¯0J⁽ṅḋ•ꜝƛ₍htU\-j

Try it Online!

Explained

s:¯0J⁽ṅḋ•ꜝƛ₍htU\-j
s:                 # Push two copies of the input list but sorted
  ¯0J              # Forward differences of items with 0 appended
      ⁽ṅḋ           # Grouped by whether they are <= 1
        •          # Reshape the sorted input to that shape
         ꜝ         # and remove the 0
                   # the top of the stack will be a list of lists of numbers that are ranges
          ƛ        # to each range
           ₍htU    #   either get the first and last item or just the first
               \-j #   join on "-"
# S flag joins the result on spaces

Vyxal S, 120 bitsv1, 15 bytes

s:¯Ǐ⁽ṅḋ•ꜝƛ₍htU\-j

Try it Online!

Explained

s:¯Ǐ⁽ṅḋ•ꜝƛ₍htU\-j
s:                 # Push two copies of the input list but sorted
  ¯Ǐ               # Forward differences of items with the first item appended - this is for making sure the length of the deltas matches the length of the input
    ⁽ṅḋ            # Grouped by whether they are <= 1
       •           # Reshape the sorted input to that shape
        ꜝ          # and remove the 0
                   # the top of the stack will be a list of lists of numbers that are ranges
         ƛ         # to each range
          ₍htU     #   either get the first and last item or just the first
              \-j  #   join on "-"
# S flag joins the result on spaces
Source Link
lyxal
  • 34.3k
  • 2
  • 64
  • 141

Vyxal S, 124 bitsv1, 15.5 bytes

s:¯0J⁽ṅḋ•ꜝƛ₍htU\-j

Try it Online!

Explained

s:¯0J⁽ṅḋ•ꜝƛ₍htU\-j
s:                 # Push two copies of the input list but sorted
  ¯0J              # Forward differences of items with 0 appended
     ⁽ṅḋ           # Grouped by whether they are <= 1
        •          # Reshape the sorted input to that shape
         ꜝ         # and remove the 0
                   # the top of the stack will be a list of lists of numbers that are ranges
          ƛ        # to each range
           ₍htU    #   either get the first and last item or just the first
               \-j #   join on "-"
# S flag joins the result on spaces