Path: csiph.com!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.programming Subject: Re: A little puzzle. Date: Tue, 22 Nov 2022 12:54:50 +0000 Organization: A noiseless patient Spider Lines: 45 Message-ID: <87fsebkv39.fsf@bsb.me.uk> References: <875yf8nijb.fsf@bsb.me.uk> <87tu2sm2bg.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader01.eternal-september.org; posting-host="9b85f22d308ce2c1806d1ce4165d5a1d"; logging-data="114436"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mA2VtpUjqANixBY5sVPKDYZMzmMwhR7Y=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cancel-Lock: sha1:S+d95kLQVLBqMU1mIyFggq4uNik= sha1:XEfLBpg8VpK0DNYVWUdE7sYXW+Y= X-BSB-Auth: 1.387074027fac4496e015.20221122125450GMT.87fsebkv39.fsf@bsb.me.uk Xref: csiph.com comp.programming:15933 David Brown writes: > On 21/11/2022 22:21, Ben Bacarisse wrote: >> David Brown writes: >> >>> On 21/11/2022 21:45, Ben Bacarisse wrote: >>>> I wonder if there are any real posters here? Let's see... >>>> I came across a trivial programming task that must have been solved a >>>> thousand times by other programmers, but it had never crossed my path >>>> until yesterday. I must be feeling my age because I made a real hash of >>>> tackling it at first. Anyway, I thought it might be of interest. >>>> Consider any ordered measure that "wraps round" -- bearings in degrees, >>>> minutes in the hour, indeed hours in either the 12 or 24 hour clock. >>>> The problem is to determine if a given value is in the sub-range >>>> specified by a start and an en value. >>>> I was specifically concerned with integer values where the sub-range >>>> includes the start value but excludes the end value. >>>> Though I am not sure this merits the term "puzzle", I suggest that >>>> solutions be posted with some spoiler protection. Do all the news >>>> readers used by programmers (or ex programmers) all respect the presence >>>> of a form-feed character... >>>> >>>> ... like this? Because that's my favourite way, rather than posting >>>> lots of dummy lines before the solution. >>>> >>> >>> Are there any restrictions, such as sticking to integers? The problem >>> becomes quite difficult if your measure is the reals in [0, 1) and >>> your "n" is, say, π/4... >> I don't follow. What is "my" n? I did not mention an n. >> I don't see why the problem can't be naturally extended to a circular >> real interval [0, 1), subject to the fact that we'll use floating point >> numbers for practical purposes. But I don't think this is what you were >> talking about. > > Having now read Tim's post, I see I might have /completely/ > misinterpreted what you wrote. Your "en value" was not a step size > "n", but a typo for "end value". But then your problem comes down to > nothing more than a "modulo" function and a comparison, which sounds > far too simple a "puzzle". What's your solution? -- Ben.