Thread: Equidistant Letter Sequencing

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    28

    Equidistant Letter Sequencing

    I am interested in performing Equidistant Letter Sequencing (as in the Bible Code) on various pieces of ASCII text. What would be the easiest way to do this? Searching for a string within a string is simple enough using the find(), but how would I go about seperating one string by integrals of each skip (i.e. every 5 letters of text, every 10 letters, every 20 letters).

    Also, how efficient will this be? What is the fastest most efficient method of doing this in a large body of text (several thousand characters).

    Thanks.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You could do something like this:
    Code:
    double step = (double)extraspaces/spaces;
    Then increment a double by step once per space printed, and while it's >= 1, print a space and -= 1.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    I think I need to describe what ELS is a little better. First I would have a large string of text. Then I would have a user specify a skip variable. Then I would skip every number of letters indicated by the skip variable.

    An example:

    UNDERWARANTY

    position = position + skip

    position = position + 2

    position = 0 + 2 = 2; U N

    position = 2 + 2 = 4; D E

    position = 4 + 2 = 6; R W

    position = 6 + 2 = 8; A R

    position = 8 + 2 = 10; A N

    position = 10 + 2 = 12; T Y

    As you can see there are two two new strings generated by a skip of 2. UDRAAT and NEWRNY when displayed in the grid the word new is formed. I want to be able to search for instances of user specified words like this.

    Thanks.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    The only way I can think to do this so far is like this:

    recieve the text and set it as a string - MasterString

    recieve the desired search word and set it as a string - SearchWord

    recieve a specified skip value and set it as an integer - skip

    then seperate the MasterString into smaller strings of the length of the specified skip - an aray of strings called RowStrings

    then seperate the strings effectivily into columns by setting a new array of strings to match the corresponding letters (i.e. the first letters of each row to the spaces in the array)

    then use find() and rfind() to look for each instance of the SearchWord in the columns forwards and backwards

    Is this an efficient way of doing this? What class functions/algorithms would I need to use in order to do this?

    Any help would be greatly appreciated.

    Thanks.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Can you show an example with a skip of 3.

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Here is one with a skip of four:

    NOMANKNOWSMYNAME

    NOMA
    NKNO
    WSMY
    NAME


    This shows ASK imbedded with a negetive skip of four (that is searching from the end forward for the search word).

    Thanks.

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Quote Originally Posted by Dave_Sinkula
    Thanks for the help.

    Yes I have already read all of that. I know how it works mathematically. I need to know how I might do the searching and seperating efficiently in C++.

    Thanks.

  9. #9
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Here is a specific question that I need an answer for in order to implement this first algorithm:

    Is there a preset way to set part of a string array to another string array?

    Thanks.

  10. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Could I use the string copy function in order to split up the master string into smaller intervals of the skip?

    Thanks.

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> Is there a preset way to set part of a string array to another string array?
    There is, but I can't think of a way to take advantage of it to get every nth element out of the string and into another.

    I would think you could do this with a simple loop and a vector of strings whose size is equal to the skip value.

    Pseudo-algorithm:

    Get value for MASTERSTRING, SEARCHSTRING, and SKIP.

    Create a vector of SKIP empty strings called SUBSTRINGLIST.
    For each character in MASTERSTRING (call it MASTERSTRING[i])
    -- Let j = i % SKIP
    -- If SEARCHSTRING[SUBSTRINGLIST[j].size()] == MASTERSTRING[i] Then
    -- -- SUBSTRINGLIST[j].push_back(MASTERSTRING[i])
    -- -- If SUBSTRINGLIST[j].size() == SEARCHSTRING.size() Then SUCCESS!
    -- Else
    -- -- SUBSTRINGLIST[j].clear()
    -- End If
    End For

    That algorithm is actually not quite right... If a substring is "xyzlllamasabc" and the search string is "llamas" it will fail because the third 'l' will cause the substring to clear and it will miss the word. I'll leave it to you to figure out how to fix that if you decide to use this basic algorithm.
    Last edited by Daved; 04-19-2006 at 01:19 PM.

  12. #12
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Thanks alot for that. I am going to write some code now based on the ideas I collected here and I'll post what I have been able to do.

    Thanks.

  13. #13
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    Here is what I have so far. I am not extremely familiar with vectors and I think I may have interpreted your algorithm incorrectly. I am getting an error after I input the variables. The program abrubtly ends. Take a look:

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    #include <vector>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        string TEXT = "";
        string SEARCHWORD = "";
        int SKIP = 0;
        
        cout<<"Input text to search: "<<endl;
        cin>>TEXT;
        cout<<endl;
        
        cout<<"Input word to search for: "<<endl;
        cin>>SEARCHWORD;
        cout<<endl;
        
        cout<<"Input skip value: "<<endl;
        cin>>SKIP;
        cout<<endl;
        
        vector<string> SUBSTRINGLIST(SKIP);
        
        for(int i = 0; i <= TEXT.size(); i++)
        {
            for(int SUBSTRING = 0; SUBSTRING <= SUBSTRINGLIST.size(); SUBSTRING++)
            {
                if(SEARCHWORD[SUBSTRING] == TEXT[i])
                {
                    SUBSTRINGLIST[SUBSTRING].push_back(TEXT[i]);
                    if(SUBSTRINGLIST[SUBSTRING].size() == SEARCHWORD.size())
                    {
                         cout<<"Search word found."<<endl;
                    }
                    else 
                    {
                         SUBSTRINGLIST[SUBSTRING].clear();
                    }
                }
    
            }
        }
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }


    Any help is appreciated.

    Thanks.

  14. #14
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    I replaced SUBSTRINGLIST[SUBSTRING].clear() with just SUBSTRINGLIST.clear()

    It fixed the abrupt exit, but I don't think the code is working. Have I coded this algorithm correctly?

    Thanks.

  15. #15
    Registered User
    Join Date
    Apr 2006
    Posts
    28
    I inputed my first example. It didn't find it. Am I doing something wrong here?

    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I ...
    By geekrockergal in forum C Programming
    Replies: 21
    Last Post: 02-07-2009, 10:40 AM
  2. counting letter occurences in a string
    By pjr5043 in forum C++ Programming
    Replies: 35
    Last Post: 05-05-2008, 09:18 PM
  3. Advice requested, Code makes sense to me, not compiler
    By andrew.bolster in forum C Programming
    Replies: 53
    Last Post: 01-06-2008, 01:44 PM
  4. help using strings and mapping
    By trprince in forum C Programming
    Replies: 29
    Last Post: 12-01-2007, 04:01 PM
  5. Big Letter became small letter
    By cogeek in forum C Programming
    Replies: 27
    Last Post: 12-13-2004, 02:04 PM