Skip to main content
added 56 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Retina 0.8.2, 5555 53 bytes

\d
$*____ab
_
bc
(.)\1

(b|cac)a
a$1
}`(cbcbca?cbcbc)b
b$1
a

Try it online!Try it online! Link includes test cases. Explanation: Another port of @AndersKaseorg's Perl answer. Edit: Saved 2 bytes using @alephalpha's observation.

\d
$*____ab
_
bc

First expand each digit into n+3 underscores followed by ab, then replace each underscore with bc.

(.)\1

(b|cac)a
a$1
(cbcbca?cbcbc)b
b$1

Perform the simplifications.

}`

Repeat until no more simplifications can be made.

a

Count the remaining number of as.

Retina 0.8.2, 55 bytes

\d
$*____ab
_
bc
(.)\1

(b|cac)a
a$1
}`(cbcbca?)b
b$1
a

Try it online! Link includes test cases. Explanation: Another port of @AndersKaseorg's Perl answer.

\d
$*____ab
_
bc

First expand each digit into n+3 underscores followed by ab, then replace each underscore with bc.

(.)\1

(b|cac)a
a$1
(cbcbca?)b
b$1

Perform the simplifications.

}`

Repeat until no more simplifications can be made.

a

Count the remaining number of as.

Retina 0.8.2, 55 53 bytes

\d
$*____ab
_
bc
(.)\1

(b|cac)a
a$1
}`(cbcbc)b
b$1
a

Try it online! Link includes test cases. Explanation: Another port of @AndersKaseorg's Perl answer. Edit: Saved 2 bytes using @alephalpha's observation.

\d
$*____ab
_
bc

First expand each digit into n+3 underscores followed by ab, then replace each underscore with bc.

(.)\1

(b|cac)a
a$1
(cbcbc)b
b$1

Perform the simplifications.

}`

Repeat until no more simplifications can be made.

a

Count the remaining number of as.

Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Retina 0.8.2, 55 bytes

\d
$*____ab
_
bc
(.)\1

(b|cac)a
a$1
}`(cbcbca?)b
b$1
a

Try it online! Link includes test cases. Explanation: Another port of @AndersKaseorg's Perl answer.

\d
$*____ab
_
bc

First expand each digit into n+3 underscores followed by ab, then replace each underscore with bc.

(.)\1

(b|cac)a
a$1
(cbcbca?)b
b$1

Perform the simplifications.

}`

Repeat until no more simplifications can be made.

a

Count the remaining number of as.