Path: csiph.com!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.programming Subject: Re: A little puzzle. Date: Fri, 25 Nov 2022 01:16:19 -0800 Organization: A noiseless patient Spider Lines: 24 Message-ID: <86fse78kd8.fsf@linuxsc.com> References: <875yf8nijb.fsf@bsb.me.uk> <865yf79l66.fsf@linuxsc.com> <87wn7nj9mb.fsf@bsb.me.uk> <86sfi98xnx.fsf@linuxsc.com> <87leo1i5bo.fsf@bsb.me.uk> <86k03k7yqe.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader01.eternal-september.org; posting-host="550d041c20870749b799fca3b763087e"; logging-data="990341"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gvlaFXzR4dErzN44l8abwXvZs530zruM=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:VCU2mhlVAB7RlrWudlgN1PJlblg= sha1:C7FRsNQ4PU4bg2Pz3w/GBK+GfvM= Xref: csiph.com comp.programming:15966 "Dmitry A. Kazakov" writes: > On 2022-11-24 23:51, Tim Rentsch wrote: > >> For the general case we would like to handle any circular measure >> (for convenience having coordinates in some integer range). >[...] >> Exercise: write a function to answer this kind of question for >> circular measures in general. You may assume integer coordinates >> and intervals that include the starting point but do not include >> the end point. Give a suitable declaration for the function, >> and separately give a function definition to implement the given >> interface. > > Usual technique is expanding the range this or that way. E.g. > > - Computing differences in the specified direction and complementing > by the modulo when the difference turns negative. > - Using large non-modular numbers that never overflow, e.g. with > indices of a ring buffer. A 64-bit sequence number I is the new > "index." To access elements I mod N is used. Even Edsgar Dijkstra wrote code to show solutions to programming exercises. Where is your code?