Skip to main content
added 51 characters in body
Source Link
Razetime
  • 27.4k
  • 3
  • 29
  • 72

Husk, 2121 20 bytes

;moJ'-?I§e←→ε†sġ§=…eOI§e←→ε†sġ·=←O

Try it online!Try it online!

A bit lacking in the strings department, but does well.

No matter what I tried, it somehow stubbornly stayed at 21.

-1 byte from Dominic Van Essen.

Explanation

;moJ'-?I§e←→ε†sġ§=…eO
                    O order the list
               ġ      group the list by the following:
                   e  elements paired
                §=    equal
                  …   the range between them?
             †s       convert all the numbers to strings
 mo                   map each group to the following:
      ?     ε         if it's a single element:
       I              leave as is
        §e←→          otherwise, move the first and last elements to a list
   J'-                join with '-'
;                     nest to display in one line

Husk, 21 bytes

;moJ'-?I§e←→ε†sġ§=…eO

Try it online!

A bit lacking in the strings department, but does well.

No matter what I tried, it somehow stubbornly stayed at 21.

Explanation

;moJ'-?I§e←→ε†sġ§=…eO
                    O order the list
               ġ      group the list by the following:
                   e  elements paired
                §=    equal
                  …   the range between them?
             †s       convert all the numbers to strings
 mo                   map each group to the following:
      ?     ε         if it's a single element:
       I              leave as is
        §e←→          otherwise, move the first and last elements to a list
   J'-                join with '-'
;                     nest to display in one line

Husk, 21 20 bytes

;moJ'-?I§e←→ε†sġ·=←O

Try it online!

A bit lacking in the strings department, but does well.

No matter what I tried, it somehow stubbornly stayed at 21.

-1 byte from Dominic Van Essen.

Explanation

;moJ'-?I§e←→ε†sġ§=…eO
                    O order the list
               ġ      group the list by the following:
                   e  elements paired
                §=    equal
                  …   the range between them?
             †s       convert all the numbers to strings
 mo                   map each group to the following:
      ?     ε         if it's a single element:
       I              leave as is
        §e←→          otherwise, move the first and last elements to a list
   J'-                join with '-'
;                     nest to display in one line
Source Link
Razetime
  • 27.4k
  • 3
  • 29
  • 72

Husk, 21 bytes

;moJ'-?I§e←→ε†sġ§=…eO

Try it online!

A bit lacking in the strings department, but does well.

No matter what I tried, it somehow stubbornly stayed at 21.

Explanation

;moJ'-?I§e←→ε†sġ§=…eO
                    O order the list
               ġ      group the list by the following:
                   e  elements paired
                §=    equal
                  …   the range between them?
             †s       convert all the numbers to strings
 mo                   map each group to the following:
      ?     ε         if it's a single element:
       I              leave as is
        §e←→          otherwise, move the first and last elements to a list
   J'-                join with '-'
;                     nest to display in one line