|
-
Feb 21st, 2006, 04:14 PM
#1
Thread Starter
Member
setup a sort of search function returning an array
Would be nice if somebody could help me setup a sort of search function returning an array.
This search function uses an array with primenumbers:
Prime() = {1,2,3,5,7,11,13,17,19}.
Goal is to find every possible sum of primenumbers to be another primenumber, BUT only in this way,
example:
1+2=3, 2+1+2=5, 2+3=5, 1+2+1+2+1=7, 2+3+2=7, 1+2+3+5=11.
You see that every new primenumber you sum, is the next or previous one in row.
Every primenumber can be devided in combinations of smaller primenumbers and in these combinations I am interrested. For every primenumber I want to know all possible combinations.
So I worked out a method of sequencing where every possible combination will be found. You will find it after my vba code I tried to program. My VBA knowledge is to limited to make it work. Maybe it will help understand my question, although it is full of errors..
VB Code:
returnArray(row,column)
PrimeSum=0
row=0
column=0
counter=0
DoWhile PrimeSum<Prime(n) 'for n>2, n is search-function input-value.
returnArray(row,column)=Prime(counter)
PrimeSum=PrimeSum+Prime(counter)
counter=counter+1
column=column+1
for example, when n=4 then Prime(n)=7.
At the end of this loop the PrimeSum=11 and returnArray contains the values 1,2,3.
But now the difficult part occurs. We have to go back and try if Prime(counter-2) is possible
VB Code:
If PrimeSum=Prime(n)
returnArray(row,column)=Prime(counter)
row=row+1
counter=counter-2
'Then copy in primeArray the values of the last row in the new one
'except the last value and go on with the DoWhile-loop.
ElseIf PrimeSum>Prime
column=column-1
counter=counter-2
'and go on with the DoWhile-loop
In the end the function has to perform following sequence:
1+2+3+5=11
1+2+3+2=8
1+2+1+2+3=9
1+2+1+2+1=7 is true
2+3+5=10
2+3+2=7 is true
2+1+2+3=8
2+1+2+1+2=8
3+5=8
3+2+3=8
3+2+1+2=8
5+7=12
5+3=8
7=7 is true
This sequence learns there are three sums of primenumbers to be true:
1+2+1+2+1=7
2+3+2=7
7=7
These results have to be put in a two-dimensional array like this:
1,2,1,2,1
2,3,2
7
This function I try to make, is part of a pre-study for a musical composition with primenumbers and it would help me much collecting the nessessary musical material I need for this composition.
Last edited by Tobian; Feb 23rd, 2006 at 09:43 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|