Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Cookies in boxes - algorithmic challenge Date: Fri, 17 Apr 2026 07:40:13 -0700 Organization: A noiseless patient Spider Lines: 69 Message-ID: <865x5p7ir6.fsf@linuxsc.com> References: <20260401163447.000052de@yahoo.com> <86tstlwjak.fsf@linuxsc.com> <20260408222330.00005cf8@yahoo.com> <865x5zbg10.fsf@linuxsc.com> <20260411225637.0000632e@yahoo.com> <865x5x9kbw.fsf@linuxsc.com> <20260413171129.0000003d@yahoo.com> <86a4v26pup.fsf@linuxsc.com> <20260417144410.00006d46@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Fri, 17 Apr 2026 14:40:15 +0000 (UTC) Injection-Info: dont-email.me; posting-host="738ee48dc04a4aad956daf44a6eea24b"; logging-data="2658472"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FJld5CtdQoLIHszWXA4OsfCYuNAd5PIk=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:9kETpXUNY/hKGnW39FQnlh0Q0dU= sha1:q8DoQ7xhWy2K9SI4IRXu4VWLHEM= Xref: csiph.com comp.lang.c:397630 Michael S writes: > On Thu, 16 Apr 2026 23:52:14 -0700 > Tim Rentsch wrote: [...] > I'd guess that every regular c.l.c reader knows that you like guessing > games. Even if I don't think that it is appropriate here, up to the > certain limit, I am willing to participate. I posted what I did because I wanted the focus to be on reading the code and not on running the code. I was hoping that understanding would be feasible without needing any guessing. > It's pretty easy to guess that the code above preceded by: > > [...] Looks reasonable. > However I both can not and don't want to guess the content of your > cores routine best_next_ctype(). And without it I don't have much to > say about you solution. Here is one implementation of best_next_ctype(): Ctype best_next_ctype( Index depth, Bset free, Bsets *bsets, Ctype ctypes[] ){ // permute? return ctypes[depth]; } At the "permute?" comment an implementation could perform any permutation of the elements of the ctypes[] array, within the range of ctypes[depth] and ctypes[COOKIE_LIMIT-1], and the result should still be a working solution. Or just leave it as a comment. The correctness of the code doesn't depend on what permutation is done or how the choice is made. >> The main thing is I hope the above routine does a better job of >> conveying my thoughts and understandings. > > It looks like unlike your friend you missed the key - equity of number > of boxes and number of sorts of cookies is not accidental! The way the code is written it allows the value of COOKIE_LIMIT to be chosen independently of the value of N_BOXES (or at least I hope it does). I didn't explore any such cases but it might be interesting to do that. > It's the > most important thing in the whole exercise. It's what make solution > feasible for much bigger values of N_BOXES, probably up to several K > in less than 1 sec. Of course for the code posted the value of N_BOXES must be no more than the number of bits in the bitset type Bset (which is meant to be short for "Box set", or a set of box values). > But, then again, without source code of best_next_ctype() I can not be > sure about it. My questions are these. One, could you understand what the code is doing and how it works? And two, if given an appropriate choice of what permutation is done in best_next_ctype(), does this code do the same thing as your code? I was trying to match the behavior of your code but I wasn't able to figure out how it decided where to go next.