in reply to Re^2: Algorithm for "Incrementing" strings
in thread Algorithm for "Incrementing" strings
The general "increment a string" algorithm popped into my head much later so I checked back and was happy to see that it had already been posted. Here is my formulation of it that requires no set-up (easy for a human to compose when told what "digits" to use but not appropriate to use if the digits are not pre-set):
s{([^Z])?(Z*)$}{ local $_ = ( $1 // 'Z' ) . $2; tr/BCDFGHJ-NP-TV-Z/CDFGHJ-NP-TV-ZB/; $_ }e;
Decrement:
s{(([^B])|B)(B*)$}{ local $_ = ( $2 // '' ) . $3; tr/CDFGHJ-NP-TV-ZB/BCDFGHJ-NP-TV-Z/; $_ }e;
- tye
|
---|