Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2005
    Posts
    697

    Equation Numbers

    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:

    Code:
    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:

    Code:
    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:

    Code:
    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:

    Code:
    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:

    Code:
    [1-2].
    [24][38[49].
    [14][5-7][46][46].
    87979.
    454645.
    6456464.
    54766246.
    Any help would be greatly appreciated, thanks!

  2. #2
    Join Date
    Mar 2009
    Posts
    2,222
    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:
    Code:
    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

  3. #3
    Join Date
    Apr 2005
    Posts
    697
    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...

  4. #4
    Join Date
    Mar 2009
    Posts
    2,222
    Quote Originally Posted by tim2718281 View Post
    Code:
                 if length(temp) > 2 then temp = "[" || left(temp,1) || "-" right(temp,1) || "]"
    should be
    Code:
                 if length(temp) > 2 then temp = "[" || left(temp,1) || "-" || right(temp,1) || "]"
    || stands for joining strings together.

  5. #5
    Join Date
    Apr 2005
    Posts
    697
    Here's what I got thus far, please guide me thru this:

    Code:
    <?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...

  6. #6
    Join Date
    Mar 2009
    Posts
    2,222
    Quote Originally Posted by ti_nhatrang View Post
    Here's what I got thus far, please guide me thru this:

    Code:
    <?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.

  7. #7
    Join Date
    Apr 2005
    Posts
    697
    I wouldn't know where to even begin... I don't even know php that well... was hoping for someone to rescue me...

Similar Threads

  1. The Planet | The Equation for Great Hosting: These Deals + Our Service
    By KHazard in forum Dedicated Hosting Offers
    Replies: 4
    Last Post: 04-18-2008, 10:31 AM
  2. numbers
    By Frimon86 in forum Running a Web Hosting Business
    Replies: 7
    Last Post: 07-22-2006, 03:00 PM
  3. 1-800 Numbers
    By L.C. in forum Web Hosting Lounge
    Replies: 5
    Last Post: 12-15-2004, 10:44 PM
  4. Finish this Equation.....
    By talon39 in forum Running a Web Hosting Business
    Replies: 4
    Last Post: 08-04-2003, 06:10 PM
  5. the support equation
    By greengunboat in forum Running a Web Hosting Business
    Replies: 9
    Last Post: 01-15-2002, 12:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •