Need help implementing an algorithm in python

Discussion in 'Python' started by ech0, Dec 6, 2005.

  1. ech0

    ech0 Guest

    I would appreciate any help I can get in finding a solution to the
    following problem:


    Below is a diagram:


    Lets say we have 4 terms (purple represents the terms). Some terms in
    these 4 terms combine to to make keywords (if we get the words in these
    sub-terms they should equal to the keywords (e.g. terms ['kaiser
    chiefs', 'i predict a riot', 'album'] combined make keywords ['kaiser',
    'chiefs', 'i', 'predict', 'a', 'riot', 'album']). There will be terms
    leftover sometimes, not all terms are used.


    How it searches for the answer is by combining terms from top to
    bottom, then checking to see if the keywords match the combined terms.

    We start by with 1 combination (combine two terms). In the diagram, it
    shows, t1 (term 1) combining with t2 then t3 then t4 (this is the red
    line). If it can't find a match, it continues. It shows t2 combining
    with t3 then t4 (dark green). If it can't find a match, it continues.
    It shows t3 combining with t4 (light green). If by then it can't find a
    match, we do the following:

    Now the above example was just 1 combination. It gets more complicated
    because we are going to have to keep increasing the number of
    combinations by 1 to find a match. We are going to keep doing this
    until combinations >= len(keywords). So now its two combinations. t1
    will combine with t2 and t3. Check if its a match. If not continue. t1
    will combine with t3 and t4. check if its a match. t2 will combine with
    t3 and t4. t3 and t4 can't combine by themselves because they are only
    two terms so we skip them (we already did 2 term combinations). After
    this if theres no match we do 3 combinations... all the way until
    combinations >= len(keywords).


    Here is what I have gotten so far:

    I know exactly what to do its just I have no way of translating the
    thought into programming code. If anybody can help at all I would
    greatly appreciate it.

    ech0, Dec 6, 2005
    1. Advertisements

  2. ech0

    gene tani Guest

    Be honest, is this a take-home final ?
    gene tani, Dec 6, 2005
    1. Advertisements

  3. ech0

    ech0 Guest

    I'm still in highschool. This is no homework. This is a personal
    project for me. I would normally do it myself but this one is just too
    complex, thats why I'm asking for help.
    ech0, Dec 6, 2005
  4. ech0

    ech0 Guest

    Just to point out... I came up with the algorithm. Which is why I can
    explain it so well. But implementing it into code is one well of a task.
    ech0, Dec 6, 2005
  5. ech0

    ech0 Guest

    wow. nevermind. i figured it out.
    ech0, Dec 6, 2005
  6. I hope that you will share it with those of us who haven't figured it
    out yet.

    Colin W.
    Colin J. Williams, Dec 6, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.