
|
View Full Version : Equation Numbers
ti_nhatrang 09-29-2009, 07:16 PM Hello all,
Working on another project and I would definitely need some help, I will povide examples below... If anyone cold help, I would really appreciate it.
I have set of numbers from my results in mysql:
1
2
234
489
1546
4764
4666
87979
454645
6456464
54766246
The above are results I need to put in a dynamic equation, and the length of numbers are grouped into the same equation, for example taking the results from above:
1
2
234
489
1546
4564
4666
87979
454645
6456464
54766246
The above are grouped results need to put into an equation and we need to remove any duplication of number in the group. For example let's take group 3:
Before:
1|5|4|6
4|7|6|4
4|6|6|6
After:
[14][5-7][46][46].
As you can see that I've stipped the duplicates in the first column, and onl keeping the difference. And notice the 2nd column, there's a legit sequence of 5 thru 7, so we need to do, [5-7].
At the end of the day, I would like the final results to look like below:
1
2
234
489
1546
4764
4666
87979
454645
6456464
54766246
The above are results I need to put in a dynamic equation, and the length of numbers are grouped into the same equation, for example taking the results from above:
[1-2].
[24][38[49].
[14][5-7][46][46].
87979.
454645.
6456464.
54766246.
Any help would be greatly appreciated, thanks!
tim2718281 09-29-2009, 08:15 PM I have read this post three times; as I understand it, it is nothing to do with equations.
What you start with is some groups of digits; within a group, each line has the same number of digits.
1
2
234
489
1546
4764
4666
87979
454645
6456464
54766246
And what you want to end up with is one output line for each group.
[1-2].
[24][38[49].
[14][5-7][46][46].
87979.
454645.
6456464.
54766246.
Each line has one item for each column in its corresponding group.
Each output line has one entry for each column in the corresponding input group.
Each entry is of the form [x...z] where "x...z" are all the digits in order that appear in the input column.
However, there the input column has three or more numerically adjacent digits, they are represented by a range such as "5-8" meaninf "5678".
And if there is only a single digit in the input column, the brackets "[" and "]" are omitted.
That's all easy enough. You just need to write the program.
So in pseudocode, and omitting detail of recognising ends of groups:
for each group
for each line in group
set digitarray to 0
for each column in line
set digitarray.columndigit to 1
end of column loop
end of line loop
set outstring to null
set digitarray.10 to 0 to simplify logic
for each digit from 0 to 9
if digitarray.digit = 0 then iterate
else set temp to digit
for digit from digit+1 to 9
if digitarray.digit = 0 then leave innerloop
else temp = temp || digit2
end of inner digit loop
if length(temp) > 2 then temp = "[" || left(temp,1) || "-" right(temp,1) || "]"
outstring = outstring || temp
end
end outer digit loop
output outstring || "."
end of group loop
ti_nhatrang 09-29-2009, 08:56 PM Tim,
Thank you for your help. I will look into this right now to see if I can pull it out of the database and get this done. If I were to have it all in a table, I would I go about pull it all out and have this set of codes you've just written for me.
Thanks again in advance...
tim2718281 09-29-2009, 09:55 PM if length(temp) > 2 then temp = "[" || left(temp,1) || "-" right(temp,1) || "]"
should be
if length(temp) > 2 then temp = "[" || left(temp,1) || "-" || right(temp,1) || "]"
|| stands for joining strings together.
ti_nhatrang 09-30-2009, 01:46 AM Here's what I got thus far, please guide me thru this:
<?php
$con = mysql_connect("localhost","numbers","numbers");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("numbers", $con);
$gxlc_db = mysql_query("SELECT ccodes FROM original limit 2000") or die(mysql_error());
while($gxlc = mysql_fetch_array($gxlc_db)) {
$ccode = $gxlc['ccodes'];
for each $ccode[]
for each line in group
set digitarray to 0
for each column in line
set digitarray.columndigit to 1
end of column loop
end of line loop
set outstring to null
set digitarray.10 to 0 to simplify logic
for each digit from 0 to 9
if digitarray.digit = 0 then iterate
else set temp to digit
for digit from digit+1 to 9
if digitarray.digit = 0 then leave innerloop
else temp = temp || digit2
end of inner digit loop
if length(temp) > 2 then temp = "[" || left(temp,1) || "-" right(temp,1) || "]"
outstring = outstring || temp
end
end outer digit loop
output outstring || "."
end of group loop
Obviously the above doesn't work, am not sure how to get this work at all, please help...
tim2718281 09-30-2009, 02:27 AM Here's what I got thus far, please guide me thru this:
<?php
$con = mysql_connect("localhost","numbers","numbers");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("numbers", $con);
$gxlc_db = mysql_query("SELECT ccodes FROM original limit 2000") or die(mysql_error());
while($gxlc = mysql_fetch_array($gxlc_db)) {
$ccode = $gxlc['ccodes'];
for each $ccode[]
for each line in group
set digitarray to 0
for each column in line
set digitarray.columndigit to 1
end of column loop
end of line loop
set outstring to null
set digitarray.10 to 0 to simplify logic
for each digit from 0 to 9
if digitarray.digit = 0 then iterate
else set temp to digit
for digit from digit+1 to 9
if digitarray.digit = 0 then leave innerloop
else temp = temp || digit2
end of inner digit loop
if length(temp) > 2 then temp = "[" || left(temp,1) || "-" right(temp,1) || "]"
outstring = outstring || temp
end
end outer digit loop
output outstring || "."
end of group loop
Obviously the above doesn't work, am not sure how to get this work at all, please help...
You need to convert the pseudocode I wrote to PHP.
ti_nhatrang 09-30-2009, 03:10 AM I wouldn't know where to even begin... I don't even know php that well... was hoping for someone to rescue me...
|