Velocity Reviews > Algorithm to reduce string

# Algorithm to reduce string

Paulo Roberto Bianchi de Oliveira
Guest
Posts: n/a

 05-19-2010
Hi, if I have some string like: "2010051912101" can it be reduced to as min
numbers as possible?

Because it's the "date+hour+milsec+etc" generated on the DB, but on the doc
that will be impressed it must be reduced because the operator will inform
it via phone... So minimizes errors typing on tel keyboard

Do you know if there's any algorithm? And I need to be able to get the
inverse too, the reduced to the original string...

Is it possible? Thanks

Guest
Posts: n/a

 05-19-2010
Gazing into my crystal ball I observed "Paulo Roberto Bianchi de
Oliveira" <(E-Mail Removed)> writing in
news:(E-Mail Removed):

> Hi, if I have some string like: "2010051912101" can it be reduced to
> as min numbers as possible?
>
> Because it's the "date+hour+milsec+etc" generated on the DB, but on
> the doc that will be impressed it must be reduced because the operator
> will inform it via phone... So minimizes errors typing on tel keyboard
>
> Do you know if there's any algorithm? And I need to be able to get the
> inverse too, the reduced to the original string...
>
> Is it possible? Thanks
>
>

I'm not quite sure I understand what you want to do. AFAICS that IS the
minimum, unless you want parts of the date, then you could do something
like:

thedate = "2010051912101"

datetotest = mid(thedate,5,2) & "-" & mid(thedate,7,2) & "-" & left
(thedate,4) & " " & mid(thedate,9,2) & ":" & mid(thedate,11,2) & ":" &
mid(thedate,12)

theyear = datepart("y",datetotest)
themonth = datepart("m",datetotest)
theday = datepart("d",datetotest)
thehour = datepart("h",datetotest)
thesecond = datepart("s",datetotest)

Then you could put it all back together again, or do datediff, dateadd,
etc.

--
Arbpen Web Site Design Services
Please respond to the group so others can share

Evertjan.
Guest
Posts: n/a

 05-20-2010
Paulo Roberto Bianchi de Oliveira wrote on 19 mei 2010 in
microsoft.public.inetserver.asp.general:

> Hi, if I have some string like: "2010051912101" can it be reduced to
> as min numbers as possible?
>
> Because it's the "date+hour+milsec+etc" generated on the DB, but on
> the doc that will be impressed it must be reduced because the operator
> will inform it via phone... So minimizes errors typing on tel keyboard
>
> Do you know if there's any algorithm? And I need to be able to get the
> inverse too, the reduced to the original string...

All redusing reduces diversity,
but if you do not mind that,
you could reduce to a 1 character string:

function reduce(s){
return (s=='2010051912101')?'1':'0';
};

function expand(s){
return (s=='1')?'2010051912101':'';
};

--
Evertjan.
The Netherlands.

Evertjan.
Guest
Posts: n/a

 05-20-2010
Evertjan. wrote on 20 mei 2010 in
microsoft.public.inetserver.asp.general:

> Paulo Roberto Bianchi de Oliveira wrote on 19 mei 2010 in
> microsoft.public.inetserver.asp.general:
>
>> Hi, if I have some string like: "2010051912101" can it be reduced to
>> as min numbers as possible?
>>
>> Because it's the "date+hour+milsec+etc" generated on the DB, but on
>> the doc that will be impressed it must be reduced because the operator
>> will inform it via phone... So minimizes errors typing on tel keyboard
>>
>> Do you know if there's any algorithm? And I need to be able to get the
>> inverse too, the reduced to the original string...

>
> All redusing reduces diversity,
> but if you do not mind that,
> you could reduce to a 1 character string:
>
> function reduce(s){
> return (s=='2010051912101')?'1':'0';
>};
>
> function expand(s){
> return (s=='1')?'2010051912101':'';
>};

More:

This is no "Reductio ad absurdum" but the concequence of your failing to
define constraints of that string, like:

Is only one string possible, either it is or empty?
Must the string always have the same length?
Can there be only figures in the string?
Does the string contain a date/time sequence?

If the string can have any content, so has no constraints,
no reduction is possible.

If the string is concidered to be a base-10 number,
you could convert it to a base 26+26+10= 62 number,
and use A-Z a-z 0-9 to depict that.

--
Evertjan.
The Netherlands.