in reply to Matching permutations with regex
#!/usr/bin/perl -l # https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographi +c_order use strict; use warnings; $_ = 'aabbcc'; 1 while print, s/.*\K # find the last (.) # char such that (.*) # there is a later (latest) (.)(??{$1 ge $3 and '(*F)'}) # char greater than it (.*) # and get rest # swap those two chars ( $1 & $3 ) # then reverse everything after the first swapped char / $3 . reverse $2.$1.$4 /xe
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Matching permutations with regex
by QM (Parson) on Nov 22, 2018 at 09:20 UTC | |
by tybalt89 (Monsignor) on Nov 22, 2018 at 15:52 UTC |