Need help implementing an algorithm in python

E

ech0

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

==================================================================

Below is a diagram:
http://www.muchographiks.com/algo.jpg

THE PROBLEM

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.

POSSIBLE ANSWER?

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:
http://pastebin.com/450352

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.

Thanks.
 
G

gene tani

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

==================================================================

Below is a diagram:
http://www.muchographiks.com/algo.jpg

THE PROBLEM

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.

POSSIBLE ANSWER?

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:
http://pastebin.com/450352

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.

Thanks.

Be honest, is this a take-home final ?
 
E

ech0

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.
 
E

ech0

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top