in reply to Re^2: How to replace greedy alternation?
in thread How to replace greedy alternation?
Indeed, getting rid of the clutter first, and then remove all but the first instance of each letter:
I imagine a more cunning monk can improve the reduction step -- though the amount of work it does obviously depends on how many repeated letters need to be removed.sub reduc { my ($s) = @_ ; $s =~ tr/abcd//cd ; 1 while $s =~ s/(.).*?\K\1+//g ; return $s ; } ; print reduc('1b22a7b3d3ccaacccbcccacccddcceqcc11oabepd'), "\n" ; # badc print reduc('1b22w7b3d3ccsqcccbccc2cccddcceqcc11o9bepd'), "\n" ; # bdc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to replace greedy alternation?
by Anonymous Monk on Jan 29, 2009 at 06:37 UTC | |
by gone2015 (Deacon) on Jan 29, 2009 at 13:26 UTC |