Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BEGIN {
- MAX=2000
- for (a = 0; a <= MAX; a++) {
- for (b = a; b <= MAX; b++) {
- print "\n"a"-"b
- regex = range2regex(a,b)
- split(regex,r,"|")
- for (i = 1; i in r; i++) print r[i]
- }
- }
- }
- function range2regex(a,z, k,m,b,r) {
- k = 10
- while (a <= z) {
- while (a > 0 && (m = a%k) == 0) k *= 10
- b = a - m + k - 1
- if (b > z) {
- k /= 10
- break
- }
- r = (r ? r "|" : "") range2charclass(a,b)
- a = b + 1
- k *= 10
- }
- while (a <= z) {
- while ((b = z - (z+1)%k) < a) k /= 10
- r = (r ? r "|" : "") range2charclass(a,b)
- a = b + 1
- k /= 10
- }
- return r
- }
- function range2charclass(a,b, k,p,q,r) {
- do {
- p = substr(a,++k,1)
- q = substr(b,k,1)
- r = r (p==q ? p : (p+1==q ? "["p""q"]" : "["p"-"q"]"))
- } while (p != "")
- return r
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement