Re: combination with constraints problem



"Harry Kus" <temp@xxxxxxxxxxx> wrote in message <g274m3$hai
$1@xxxxxxxxxxxxxxxxxx>...
.......
The function works fine except that it violates the q (upper
limit) constraints.
.......
----------
Yes, you have uncovered another bug, Harry. Sorry about that. The for-
loop line should actually read:

for k = max(N-sum(qt),0):min(N,q(end))

I actually tested this one and it seemed all right in the cases I ran. In your
example, it got your result minus the two fallacious rows with 4's in them. I
also tested it with q's that differed from one another and it seemed to handle
these properly. The function really ought to have a test at least initially to
check whether N <= sum(q) and issue a nasty note if not.

You should beware of long q vectors. These are capable of generating
enormous numbers of combinations.

Roger Stafford


.



Relevant Pages

  • Re: reverse a string
    ... the digital root of the specified characters. ... That is, if the constraints are violated, ... Therefore, if they are not observed, it indicates a bug in the ... should certainly try to fire this assertion, ...
    (comp.lang.c)
  • Re: Bug in win xp: Auto-detaching modeless dialog.
    ... Destroying the dialog is important whether there is a bug or not. ... >I don't think that windows API cares about design flaws. ... >> The whole loop with a sleep in it is a colossal blunder. ... My program does some time consuming calculations and from ...
    (microsoft.public.vc.mfc)
  • Re: New comer questions
    ... ebcause Harry saves himself and co. You're ... You'll get a neevr ending printout of Time Travel is Not That Tricky. ... It's a neevr ending infinite loop. ... Snape finds the map in Lupins office and heads towards the tree ...
    (alt.fan.harry-potter)
  • Re: A Beginner:Why is my program always returning true?
    ... and see what happens to find the third bug. ... This loop needs to scan increasingly higher indexes in the two strings yet ... Here's a simple rewrite to clean up the loops (without fixing your final ... goal here is always clear bug-free code first, and efficiency second. ...
    (comp.lang.java.programmer)
  • Re: [PATCH] Avoid buffer overflows in get_user_pages()
    ... In particular, "len" is a signed int, and it is only checked at the ... So, if it is passed in as zero, the loop ... I think that, if get_user_pageshas been asked to grab zero pages, ... Which is a bug, and you want to catch it. ...
    (Linux-Kernel)