Results 1 to 2 of 2

Thread: setup a sort of search function returning an array

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    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:
    1. returnArray(row,column)
    2. PrimeSum=0
    3. row=0
    4. column=0
    5. counter=0
    6. DoWhile PrimeSum<Prime(n) 'for n>2, n is search-function input-value.
    7.            returnArray(row,column)=Prime(counter)
    8.            PrimeSum=PrimeSum+Prime(counter)
    9.            counter=counter+1
    10.            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:
    1. If PrimeSum=Prime(n)
    2.            returnArray(row,column)=Prime(counter)
    3.            row=row+1  
    4.            counter=counter-2
    5.      'Then copy in primeArray the values of the last row in the new one
    6.      'except the last value and go on with the DoWhile-loop.
    7.    ElseIf PrimeSum>Prime
    8.            column=column-1
    9.            counter=counter-2
    10.      '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
  •  



Click Here to Expand Forum to Full Width