2

I need to write a program which takes 4 inputs as follows

  • N = The number of integers to be generated (10 < N < 10000)
  • Start = The minimum value of the integers (100 < Start)
  • End = The maximum value of the integers
  • Step = The minimum difference between any two integers (100 < Step)

and generates N integers within the range [Start,End]

I shall call the generated integers as GI

They are subjected to the following constraints-

  • Every GI must be unique
  • The difference between any 2 GIs must be at least equal to the "Step" value
  • No GI must be a linear combination of any of the other GIs

by linear combination, I mean

GI[i] != a1*GI[1] + a2*GI[2] + a2*GI[3] + ... an*GI[n]
where n!=i for any n,i within [1,N] and {a1,a2,a3...an} are some integers
and != means 'Not equal to'

What is a good (if not the best) method to code this?

I have thought of one algorithm to find primes within that range using Atkin's sieve. Now if the number of primes is larger than N, then proceed with checking linearity condition, else generate random numbers satisfying step condition till N values are reached and then proceed with checking.... This doesn't sound that much elegant to me. So I am interested in better methods

closed as too broad by Bart van Ingen Schenau, Blrfl, Scant Roger, user22815, Robert Harvey Jan 4 '16 at 16:34

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Have sketched out some algorithms yourself yet? Your question seems a lot like a homework assignment. Show us what you've done. – COME FROM Dec 31 '15 at 11:02
  • Can you explain the problem you are trying to solve with this algorithm? It is difficult to assess if it is a good or bad algorithm without knowing the problem it is trying to solve. Or is this as @COMEFROM asked, just a home work assignment for Algorithms 101. In which case I'll say what you mother would no doubt say, you won't learn by copying some one else's answer :-) – Cormac Mulhall Dec 31 '15 at 11:14
  • @CormacMulhall I couldn't find any online reference to this kind of problem. Actually, this problem sprung up during my undergrad research. I have thought of one algorithm to find primes within that range using atkin's sieve. Now if the number of primes is larger than N, then proceed with checking linearity condition, else generate random numbers satisfying step condition till N values are reached and then proceed with checking.... This doesn't sound that much elegant to me. So I am interested in better methods – Injitea Dec 31 '15 at 12:22
  • @gnat I am sorry but this is a desperate attempt to get a solution. For the method which I am currently using, see my reply to ComacMulhall – Injitea Dec 31 '15 at 12:28
  • 1
    The "no linear combinations" requirement is the only non-trivial one that makes this question potentially interesting and understandably non-googleable. Until I got to that part I was in complete agreement with the other comments that this looks like a request to do your homework for you. I'd highly recommend rewriting the question to focus on that requirement, and introduce n/start/end/step at the end so they look like the minor details they are (or I could rewrite it for you, if you agree this change would not misrepresent your question). – Ixrec Dec 31 '15 at 16:02

Browse other questions tagged or ask your own question.