Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Notifications
Mark all as read
Challenges

Post History

66%
+2 −0
Challenges Run-length encode a byte sequence

posted 12mo ago by Moshi‭  ·  edited 12mo ago by Moshi‭

Answer
#2: Post edited by user avatar Moshi‭ · 2021-10-13T22:38:59Z (12 months ago)
  • # [JavaScript (Node.js)], 101 bytes
  • ```javascript
  • x=>x.match(/(..)\1{0,62}/g).map(c=>c>'c'|c.length>5?(192+c.length/2).toString(16)+c[0]+c[1]:c).join``
  • ```
  • [Try it online!][TIO-kug951yh]
  • Everything can be solved with regexes.
  • Takes input and outputs as hex strings.
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kug951yh]: https://tio.run/##zZRBTsMwEEXX9Sm8s620zthAJUAJh2DZRmo62GmqYFeJhSqVnj0EBwQ3qP9iNPP@5q3mWH/UA/btKaycfzOjLcZzUZ7lex3wwHMupdiqCyzX@po3YsInjkWJJUP2ibIzrgmH8uGFq0ed/d65FjL419C3ruFqLTLcQDUNVT2hkEffut1uRO@GQIMZwkALuiELBgAKNNzBPVvOJ0SkACLYm71FQIX6f3@jJKCQiEQyGj8i9qZJQCERiWQ0okj1TIj1PeV/f4d6O/8fQS9k8c19Z2TnGx7bjLKto6uSsmm1kYkZMkGu4xc "JavaScript (Node.js) – Try It Online"
  • # [JavaScript (Node.js)], ~~101~~ 82 bytes
  • *-19 bytes thanks to Shaggy!*
  • ```javascript
  • x=>x.replace(/(..)\1{0,62}/g,(c,g)=>c>'c'||c[5]?(192+c.length/2).toString(16)+g:c)
  • ```
  • [Try it online!][TIO-kug951yh]
  • Everything can be solved with regexes.
  • Takes input and outputs as hex strings.
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kug951yh]: https://tio.run/##zZRBbsIwEEXX@BTe2VaCM3ZbJFolHKJLYBGmtguKbJRYCAk4ewpOpfYG@K9m3t@81T@0p3bAfn@Mcx@@zGjr8Vw3Z9mbY9ei4RWXUmzUBcqFvlWu5Fg6UTfYMGTXK67ftiuulrpA2Rnv4nelhYzhM/Z777haiMK9oxgx@CHSaIY40JquyYwBgAINL/DKyumFhBRAAjuzswioUP/vn5QMFDKRyEbjV8Q@NRkoZCKRjUYS2X4QYkNP@d/u0GCn/RH0QmYPHjoju@B4agvKNp7OG8rup01MTJAJcht/AA "JavaScript (Node.js) – Try It Online"
#1: Initial revision by user avatar Moshi‭ · 2021-10-07T01:21:11Z (12 months ago)
# [JavaScript (Node.js)], 101 bytes

```javascript
x=>x.match(/(..)\1{0,62}/g).map(c=>c>'c'|c.length>5?(192+c.length/2).toString(16)+c[0]+c[1]:c).join``
```

[Try it online!][TIO-kug951yh]

Everything can be solved with regexes.

Takes input and outputs as hex strings.

[JavaScript (Node.js)]: https://nodejs.org
[TIO-kug951yh]: https://tio.run/##zZRBTsMwEEXX9Sm8s620zthAJUAJh2DZRmo62GmqYFeJhSqVnj0EBwQ3qP9iNPP@5q3mWH/UA/btKaycfzOjLcZzUZ7lex3wwHMupdiqCyzX@po3YsInjkWJJUP2ibIzrgmH8uGFq0ed/d65FjL419C3ruFqLTLcQDUNVT2hkEffut1uRO@GQIMZwkALuiELBgAKNNzBPVvOJ0SkACLYm71FQIX6f3@jJKCQiEQyGj8i9qZJQCERiWQ0okj1TIj1PeV/f4d6O/8fQS9k8c19Z2TnGx7bjLKto6uSsmm1kYkZMkGu4xc "JavaScript (Node.js) – Try It Online"