A
A
Alexander2015-12-11 16:13:18
PHP
Alexander, 2015-12-11 16:13:18

It is necessary to convert the number capacity from one format to another, who can suggest the algorithm?

Good day, dear colleagues.
There is a task to decompose numbering capacity type "9266070005-9266099923"
into components (mask):
9266070005, 9266070006, 9266070007, 9266070008, 9266070009, 926607001, 926607002
926607003, 926607004, 926607005, 926607006, 926607007, 926607008, 926607009, 92660701, 92660702, 92660703, 92660704, 92660705, 92660706, 92660707, 92660708, 92660709, 9266071, 9266072, 9266073, 9266074, 9266075, 9266076, 9266077, 9266078
9266079, 926608, 9266091, 9266092, 9266093, 9266094, 9266095, 9266096, 9266097, 9266098, 92660991, 92660992 92660993 92660994 92660995 92660996 92660997 92660998 926609990 926609991 9266099920 9266099921
The initial ranges are about 4700, but historically it has developed that the capacities are used precisely by masks and not by ranges.
It is not an option to do a direct enumeration, it is also an enumeration from the last different character (in the case of 9266050000-9266099999, you can still bypass it and do it by enumeration, getting 5 masks, but this is also not the best option).
There are no initial conditions:
1. Numbers of the initial range are always in one DEF code
2. Numbers of the initial range are always 10 digits
3. The first number of the range is always less than or equal to the last one.
4. At the output, you need to get the minimum number of masks covering the original range (including the first and last number).
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mrrl, 2015-12-11
@zzzmmtt

Good job. In C# it would look like this:

long x0=9266070005,x1=9266099923;
            long n=1;
            x1++;
            while(x0<x1) {
                if(x1-x0<n) n/=10;
                else if((x0/n)%10==0 && x1-x0>=10*n) n*=10;
                else{
                    Console.Write("{0}, ",x0/n);
                    x0+=n;
                }
            }

Whether it is possible to rewrite it well in PHP, I don't know.

T
throughtheether, 2015-12-11
@throughtheether

I would use prefix trees if I were you. Summarization (you also need a minimum number of prefixes, or, as you call them, "masks"), most likely, you will have to write it yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question