|
Another request for help
|
|
11-10-2009, 11:01 AM
Post: #1
|
|||
|
|||
|
Another request for help
Hello,
I need a bit of help with something again .So, I have X = [4, 2, 2, 6, 2, 2, 3, 3, 3, 8, 2, 2, 4, 4, 4, 4, 9, 3, 3, 3,...] Basically, it contains only the numbers which have divisors (excluding numbers that are only divisible with themselves) and their divisors written as many times as they are worth and the divisors are taken from the smallest to the biggest. Now, I have to write a function ( or a set of functions) that can generate the values in X as they are called. (without memorizing the vector X). So if I would call .. Generate(...); 4 times, I would get 4, then 2, then 2, and then 6. and so on as they are called. Again, X can't be memorized. I've been trying to get this done for a few hours now and I can't make head or tails of something that works. Any help would be appreciated. Thanks. |
|||
|
11-10-2009, 11:06 AM
Post: #2
|
|||
|
|||
RE: Another request for help
(11-10-2009 11:01 AM)Dwel Wrote: Hello, can you just pass the reference of x to another variable? |
|||
|
11-10-2009, 11:11 AM
(This post was last modified: 11-10-2009 11:16 AM by Dwel.)
Post: #3
|
|||
|
|||
|
RE: Another request for help
Well, X is just as a guideline of what values I will have to use later in the code. But I can't get them by manually inserting them. I have to call them (a.k.a. generating them as I need them).
For example : With Code: function NextDiv(nr,d:integer):integer;If I would keep calling Gen(...) I'd get the values of Y = [1, 2, 3, 4, 2, 5, 6, 2, 3, 7, 8, 2, 4, 9, 3, 10, 2, 5, 11, 12, ...]. Which is different from my X now, but illustrates what I'm looking at doing for it. I tried to alter this to make it adapt to X, but to no succes. |
|||
|
11-10-2009, 11:28 AM
Post: #4
|
|||
|
|||
|
RE: Another request for help
I would say pass by ref
|
|||
|
11-10-2009, 08:42 PM
Post: #5
|
|||
|
|||
|
RE: Another request for help
I have solution for this. It is a bit complicated and it can be optimized, but i will post it like this because it works.
The fact is that you need to check numbers that have divisors, or better said numbers that are not prime, so i made function for checking if numbers are prime. After that you need to divide that number on it's factors and to write them that number of times as they are worth. I made that like you said generate() function that generates that. So here is the solution : Code: program array_test;Test it, i tested it and it works perfectly ! There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
11-11-2009, 02:39 AM
Post: #6
|
|||
|
|||
|
RE: Another request for help
Sorry for the delay, but I wasn't home.
I have read the program this morning and tried it and as far as the values generated go, it works perfectly. But in the main program, I will have to complete yet another matrix by calling the values of X (4..2..2..6..etc), without memorizing it. As the matrix will get populated in a weird sequence, I will have to call the generation every step of the way ( in the matrix, it starts at [i,j] = [1,1], where the generate would give it 4, then the j would increase to 2, [1,2] so the generation call should return 2, and so on). |
|||
|
11-11-2009, 04:15 AM
Post: #7
|
|||
|
|||
|
RE: Another request for help
So you mean you have sequence 4,2,2,6,2,2,3,3,3. . .
And that should be in matrix, but i don't know which length of matrix do you want. I mean that "m" and "n" ! Tell me example, what should matrix look like. Does it have to look like you enter m and n and it will generate numbers like this : m=3 and n=3 4 2 2 6 2 2 3 3 3 I don't understand the task ! There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
11-11-2009, 04:34 AM
(This post was last modified: 11-11-2009 04:54 AM by Dwel.)
Post: #8
|
|||
|
|||
|
RE: Another request for help
So. the values, that sequence 4.2.2.6.2.2.3.3.3, etc, has to be generated as I call it. Basically. In the program that only does the generation code.
If i would write Generate(..);Generate(..);Generate(..);Generate(..); in the main program loop. The output would be 4 2 2 6. Now, the matrix has to be populated in a weird manner. For example: Code: m and n I think should be chosen by the user.![]() The algorithm for the matrix population I have done. All i need to add to it is the CALL which would bring me the next value in the sequence. (generated on spot since the sequence isn't memorized). To be even more clear. I need to access the values of the sequence, NOT by having an "n" that dictates how many values are generated, but to call the generation function n times. This way I can fill the matrix by calling the next value every time my Mat[i.j] moves to the new location. |
|||
|
11-11-2009, 05:39 AM
Post: #9
|
|||
|
|||
|
RE: Another request for help
That is spiral filling of matrix. I would need time for this, this is complex issue !
There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
11-11-2009, 05:49 AM
(This post was last modified: 11-11-2009 06:20 AM by Dwel.)
Post: #10
|
|||
|
|||
|
RE: Another request for help
I don't need the whole problem. Just the generation part. To me more concise, how do you alter your code, that could generate the values, in order for me to call them as I stated?
I already have the code which fills the matrix in a spiral, I just need the calling function so I can place every value in it's place as the matrix is filled. |
|||
|
« Next Oldest | Next Newest »
|



.


![[Image: test.jpg]](http://i250.photobucket.com/albums/gg242/Dwelpor/test.jpg)