Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #15916 > unrolled thread
| Started by | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| First post | 2022-11-21 20:45 +0000 |
| Last post | 2022-12-01 06:51 -0800 |
| Articles | 20 on this page of 84 — 9 participants |
Back to article view | Back to comp.programming
A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-21 20:45 +0000
Re: A little puzzle. David Brown <david.brown@hesbynett.no> - 2022-11-21 22:06 +0100
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-21 21:21 +0000
Re: A little puzzle. David Brown <david.brown@hesbynett.no> - 2022-11-22 09:17 +0100
Re: A little puzzle. Richard Heathfield <rjh@cpax.org.uk> - 2022-11-22 11:07 +0000
Re: A little puzzle. David Brown <david.brown@hesbynett.no> - 2022-11-22 15:17 +0100
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-22 11:40 +0000
Re: A little puzzle. David Brown <david.brown@hesbynett.no> - 2022-11-22 15:26 +0100
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-22 15:28 +0000
Re: A little puzzle. David Brown <david.brown@hesbynett.no> - 2022-11-22 16:30 +0100
Re: A little puzzle. David Brown <david.brown@hesbynett.no> - 2022-11-22 09:23 +0100
Re: A little puzzle. Richard Heathfield <rjh@cpax.org.uk> - 2022-11-22 11:08 +0000
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-22 12:54 +0000
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-21 17:39 -0800
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-22 13:00 +0000
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-22 05:31 -0800
Re: A little puzzle. Richard Heathfield <rjh@cpax.org.uk> - 2022-11-22 11:04 +0000
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-22 12:53 +0000
Re: A little puzzle. Paul N <gw7rib@aol.com> - 2022-11-22 05:01 -0800
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-22 05:48 -0800
Re: A little puzzle. David Brown <david.brown@hesbynett.no> - 2022-11-22 15:31 +0100
FFs [was Re: A little puzzle] Richard Harnden <richard.nospam@gmail.com> - 2022-11-22 16:29 +0000
Re: A little puzzle. Richard Heathfield <rjh@cpax.org.uk> - 2022-12-14 13:57 +0000
Re: A little puzzle. Richard Heathfield <rjh@cpax.org.uk> - 2022-12-14 13:58 +0000
Re: A little puzzle. Richard Heathfield <rjh@cpax.org.uk> - 2022-12-14 16:22 +0000
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-22 05:24 -0800
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-22 15:23 +0000
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-23 08:04 -0800
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-24 00:06 +0000
Re: A little puzzle. Richard Heathfield <rjh@cpax.org.uk> - 2022-11-24 04:06 +0000
Re: A little puzzle. David Brown <david.brown@hesbynett.no> - 2022-11-24 09:29 +0100
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-24 13:23 +0000
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-24 13:14 +0000
Re: A little puzzle. Richard Heathfield <rjh@cpax.org.uk> - 2022-11-24 14:00 +0000
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-24 14:59 +0000
Re: A little puzzle. Richard Harnden <richard.nospam@gmail.com> - 2022-11-24 19:00 +0000
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-24 20:36 +0000
Re: A little puzzle. Andreas <nobody@me.com> - 2022-11-27 00:38 +0100
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-27 00:11 +0000
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-24 14:51 -0800
Re: A little puzzle. "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-11-25 09:30 +0100
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-25 01:16 -0800
Re: A little puzzle. "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-11-25 11:11 +0100
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-25 06:26 -0800
Re: A little puzzle. "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-11-25 15:59 +0100
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-26 16:25 +0000
Re: A little puzzle. "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-11-26 19:36 +0100
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-27 02:03 +0000
Re: A little puzzle. "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-11-27 11:02 +0100
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-12-01 04:30 -0800
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-12-02 00:22 +0000
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-12-02 22:30 -0800
Re: A little puzzle. Julio Di Egidio <julio@diegidio.name> - 2022-12-03 02:43 -0800
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-27 18:38 -0800
Re: A little puzzle. Julio Di Egidio <julio@diegidio.name> - 2022-11-27 02:27 -0800
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-27 19:23 -0800
Re: A little puzzle. Julio Di Egidio <julio@diegidio.name> - 2022-11-27 22:59 -0800
Re: A little puzzle. Julio Di Egidio <julio@diegidio.name> - 2022-11-27 23:03 -0800
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-28 07:22 -0800
Re: A little puzzle. Julio Di Egidio <julio@diegidio.name> - 2022-11-28 10:20 -0800
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-29 04:29 -0800
Re: A little puzzle. Julio Di Egidio <julio@diegidio.name> - 2022-11-29 04:50 -0800
Re: A little puzzle. Richard Heathfield <rjh@cpax.org.uk> - 2022-11-29 14:47 +0000
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-29 17:23 +0000
Re: A little puzzle. Julio Di Egidio <julio@diegidio.name> - 2022-11-29 09:50 -0800
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-30 01:39 -0800
Re: A little puzzle. Richard Heathfield <rjh@cpax.org.uk> - 2022-11-30 11:10 +0000
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-30 02:24 -0800
Re: A little puzzle. Julio Di Egidio <julio@diegidio.name> - 2022-11-30 06:28 -0800
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-12-01 06:55 -0800
Re: A little puzzle. Julio Di Egidio <julio@diegidio.name> - 2022-12-02 01:54 -0800
Re: A little puzzle. Richard Harnden <richard.nospam@gmail.com> - 2022-11-28 11:20 +0000
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-28 07:30 -0800
Re: A little puzzle. Richard Harnden <richard.nospam@gmail.com> - 2022-11-28 17:15 +0000
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-29 04:03 -0800
Re: A little puzzle. Richard Harnden <richard.nospam@gmail.com> - 2022-11-29 15:03 +0000
Re: A little puzzle. "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-11-29 16:13 +0100
Re: A little puzzle. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-29 17:37 +0000
Re: A little puzzle. "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-11-29 19:02 +0100
Re: A little puzzle. Julio Di Egidio <julio@diegidio.name> - 2022-11-29 10:10 -0800
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-30 03:32 -0800
Re: A little puzzle. Julio Di Egidio <julio@diegidio.name> - 2022-11-30 06:36 -0800
Re: A little puzzle. Richard Harnden <richard.nospam@gmail.com> - 2022-11-30 15:21 +0000
Re: A little puzzle. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-12-01 06:51 -0800
Page 1 of 5 [1] 2 3 4 5 Next page →
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2022-11-21 20:45 +0000 |
| Subject | A little puzzle. |
| Message-ID | <875yf8nijb.fsf@bsb.me.uk> |
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. -- Ben.
[toc] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2022-11-21 22:06 +0100 |
| Message-ID | <tlgp7v$3sinl$1@dont-email.me> |
| In reply to | #15916 |
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...
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2022-11-21 21:21 +0000 |
| Message-ID | <87tu2sm2bg.fsf@bsb.me.uk> |
| In reply to | #15917 |
David Brown <david.brown@hesbynett.no> 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. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2022-11-22 09:17 +0100 |
| Message-ID | <tli0jj$25jq$1@dont-email.me> |
| In reply to | #15919 |
On 21/11/2022 22:21, Ben Bacarisse wrote: > David Brown <david.brown@hesbynett.no> 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. >>> Thunderbird seems to respect it when showing the posts. I am not sure of the most convenient way to add one. I'll try copy-and-pasting your FF character... >>> Did that work? >> >> 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. You referred to a "start value" and an "en value". I like to use names, so I'll call the "start value" "a", and use "n" for the "en value". So as far as I understand it, you are asking for a function that takes an input "x" and determines if there is an integer "i" such that x ≡ a + i.n where the congruence is over a "wrapping" set. > > 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. > Well, the point is if "being specifically concerned with integers" means the puzzle is limited to integer ranges, or if that is just what you were thinking about first. I suppose you /do/ mean sticking to integers, because I'd be surprised if a solution were possible once you bring arbitrary real numbers into it. That kind of mathematics leads to things like the Banach-Tarski paradox, and watching far too many maths Youtube videos...
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2022-11-22 11:07 +0000 |
| Message-ID | <tliagn$3pa84$7@dont-email.me> |
| In reply to | #15926 |
On 22/11/2022 8:17 am, David Brown wrote: > On 21/11/2022 22:21, Ben Bacarisse wrote: >> David Brown <david.brown@hesbynett.no> writes: >> >>> On 21/11/2022 21:45, Ben Bacarisse wrote: >>>> 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. >>>> > > Thunderbird seems to respect it when showing the posts. I am not > sure of the most convenient way to add one. I'll try > copy-and-pasting your FF character... > > >>> > > Did that work? The answer "no" springs to mind. -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2022-11-22 15:17 +0100 |
| Message-ID | <tlilld$3sro$1@dont-email.me> |
| In reply to | #15929 |
On 22/11/2022 12:07, Richard Heathfield wrote: > On 22/11/2022 8:17 am, David Brown wrote: >> On 21/11/2022 22:21, Ben Bacarisse wrote: >>> David Brown <david.brown@hesbynett.no> writes: >>> >>>> On 21/11/2022 21:45, Ben Bacarisse wrote: >>>>> 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. >>>>> >> >> Thunderbird seems to respect it when showing the posts. I am not sure >> of the most convenient way to add one. I'll try copy-and-pasting your >> FF character... >> >> >>> >> >> Did that work? > > The answer "no" springs to mind. > It worked fine for me, in the sense that regardless of the size of the Thunderbird window used to view the message, everything after each FF was just beyond view until I scrolled down. When replying to the message, Thunderbird compacts it all. What happens in your newsreader? You also have Thunderbird, albeit a slightly newer version than mine. But for Ben's newsreader to be happy, it seems the FF needs to be at the start of a line.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2022-11-22 11:40 +0000 |
| Message-ID | <87tu2rkyjp.fsf@bsb.me.uk> |
| In reply to | #15926 |
David Brown <david.brown@hesbynett.no> writes: > On 21/11/2022 22:21, Ben Bacarisse wrote: >> David Brown <david.brown@hesbynett.no> 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. >>>> > > Thunderbird seems to respect it when showing the posts. I am not sure of the most convenient way to add one. I'll try copy-and-pasting your > FF character... > >>>> > > Did that work? Yes, but for my newsreader a form feed only hides what's below it when at the start of a line. >>> 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. > > You referred to a "start value" and an "en value". Sorry, typo. End value. > I like to use names, so I'll call the "start value" "a", and use "n" > for the "en value". So as far as I understand it, you are asking for > a function that takes an input "x" and determines if there is an > integer "i" such that > > x ≡ a + i.n > > where the congruence is over a "wrapping" set. Hmm... I must have made a real hash of the description (and I was being deliberately a bit vague for reasons that should come out later) because there is always such an i. Here's an example. An event starts at 5 minutes to the hour (start = 55) and ends at quarter past (end = 15). The x's 55, 58, 3, 12 and so on are in the range, 53, 17 and 33 are not. The fact that all data are integers is not really material. We could consider compass points in [0, 2*pi) and have arbitrary start and end bearings. >> 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. > > Well, the point is if "being specifically concerned with integers" > means the puzzle is limited to integer ranges, or if that is just what > you were thinking about first. I suppose you /do/ mean sticking to > integers, because I'd be surprised if a solution were possible once > you bring arbitrary real numbers into it. That kind of mathematics > leads to things like the Banach-Tarski paradox, and watching far too > many maths Youtube videos... I think I've not explained the problem well because there's not that rarefied about it! -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2022-11-22 15:26 +0100 |
| Message-ID | <tlim77$3u8n$1@dont-email.me> |
| In reply to | #15931 |
On 22/11/2022 12:40, Ben Bacarisse wrote: > David Brown <david.brown@hesbynett.no> writes: > >> On 21/11/2022 22:21, Ben Bacarisse wrote: >>> David Brown <david.brown@hesbynett.no> writes: >>> (We don't need secrets here, I think, so I'll snip the FF's.) >>>> 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. >> >> You referred to a "start value" and an "en value". > > Sorry, typo. End value. > >> I like to use names, so I'll call the "start value" "a", and use "n" >> for the "en value". So as far as I understand it, you are asking for >> a function that takes an input "x" and determines if there is an >> integer "i" such that >> >> x ≡ a + i.n >> >> where the congruence is over a "wrapping" set. > > Hmm... I must have made a real hash of the description (and I was being > deliberately a bit vague for reasons that should come out later) because > there is always such an i. Maybe I had formed an impression of the problem too early, and interpreted everything you wrote to fit that idea. Certainly for my interpretation, there is not always such an "i". (For example, use modulo 24, with a = 0, n = 4, and x = 1. No "i" can be found. It's all about cyclic groups and subgroups. Since I have no doubt at all that you know this, I assume I am misinterpreting you again :-) ) > > Here's an example. An event starts at 5 minutes to the hour (start = > 55) and ends at quarter past (end = 15). The x's 55, 58, 3, 12 and so > on are in the range, 53, 17 and 33 are not. > OK. We are talking ranges, rather than points. > The fact that all data are integers is not really material. We could > consider compass points in [0, 2*pi) and have arbitrary start and end > bearings. > >>> 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. >> >> Well, the point is if "being specifically concerned with integers" >> means the puzzle is limited to integer ranges, or if that is just what >> you were thinking about first. I suppose you /do/ mean sticking to >> integers, because I'd be surprised if a solution were possible once >> you bring arbitrary real numbers into it. That kind of mathematics >> leads to things like the Banach-Tarski paradox, and watching far too >> many maths Youtube videos... > > I think I've not explained the problem well because there's not that > rarefied about it! > Surely it is not that unusual to enjoy things like this? <https://www.youtube.com/watch?v=s86-Z-CbaHA>
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2022-11-22 15:28 +0000 |
| Message-ID | <87r0xvj9ea.fsf@bsb.me.uk> |
| In reply to | #15940 |
David Brown <david.brown@hesbynett.no> writes: > OK. We are talking ranges, rather than points. Yes. So much confusion from a missing 'd'! Sorry. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2022-11-22 16:30 +0100 |
| Message-ID | <tlipvj$48av$2@dont-email.me> |
| In reply to | #15943 |
On 22/11/2022 16:28, Ben Bacarisse wrote: > David Brown <david.brown@hesbynett.no> writes: > >> OK. We are talking ranges, rather than points. > > Yes. So much confusion from a missing 'd'! Sorry. > Yes, but it made the thread more fun!
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2022-11-22 09:23 +0100 |
| Message-ID | <tli0tl$26a9$1@dont-email.me> |
| In reply to | #15919 |
On 21/11/2022 22:21, Ben Bacarisse wrote: > David Brown <david.brown@hesbynett.no> 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".
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2022-11-22 11:08 +0000 |
| Message-ID | <tliaih$3pa84$8@dont-email.me> |
| In reply to | #15927 |
On 22/11/2022 8:23 am, David Brown wrote: > But then your problem comes down to nothing more than a "modulo" > function and a comparison, which sounds far too simple a "puzzle". That's where I ended up too. -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2022-11-22 12:54 +0000 |
| Message-ID | <87fsebkv39.fsf@bsb.me.uk> |
| In reply to | #15927 |
David Brown <david.brown@hesbynett.no> writes: > On 21/11/2022 22:21, Ben Bacarisse wrote: >> David Brown <david.brown@hesbynett.no> 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.
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2022-11-21 17:39 -0800 |
| Message-ID | <86ilj7ahsv.fsf@linuxsc.com> |
| In reply to | #15916 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> 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.
The question I think you're asking is to write a function like this
/* is_circularly_between( a, b, c ) -
* 1 if b is circularly between a and c,
* 0 otherwise
* interval [ a, c ) is closed at the 'a' end, open at the 'c' end
*
* The parameters a, b, and c are all of a single type T,
* where T allows relational (ordering) comparisons.
*
* Assumes a, b, and c all have legitimate values.
*/
int
is_circularly_between( T a, T b, T c ){
/* to be determined */
}
with T being some integer type. Assuming this is right I have
written such a function (but am not posting it just yet).
> Though I am not sure this merits the term "puzzle", I suggest that
> solutions be posted with some spoiler protection.
That's good, thank you for the reminder.
> Do all the news
> readers used by programmers (or ex programmers) all respect the presence
> of a form-feed character...
> Next page...
Mine does, for some values of "respect". It does have the property
that it hides what follows.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2022-11-22 13:00 +0000 |
| Message-ID | <87a64jkut1.fsf@bsb.me.uk> |
| In reply to | #15920 |
Tim Rentsch <tr.17687@z991.linuxsc.com> writes: > The question I think you're asking is to write a function like this Yes, but I deliberately did not present the question with this degree of clarity! I wanted to present the problem as I came across it because what little fun it offers comes from clarifying the issue. >> Though I am not sure this merits the term "puzzle", I suggest that >> solutions be posted with some spoiler protection. > > That's good, thank you for the reminder. Your explanation of the issue is, to my mind, a teeny tiny spoiler put "above the fold". >> Do all the news >> readers used by programmers (or ex programmers) all respect the presence >> of a form-feed character... >> Next page... > > Mine does, for some values of "respect". It does have the property > that it hides what follows. Yes. In the old days (which is only the late 80s in this case) I think all newsreaders would require some action to see that part of a message after a form feed, so that was how spoilers were put "below the fold". -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2022-11-22 05:31 -0800 |
| Message-ID | <861qpv9kts.fsf@linuxsc.com> |
| In reply to | #15934 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes: > Tim Rentsch <tr.17687@z991.linuxsc.com> writes: > >> The question I think you're asking is to write a function like this > > Yes, but I deliberately did not present the question with this degree of > clarity! I wanted to present the problem as I came across it because > what little fun it offers comes from clarifying the issue. Ah ha. I didn't understand that before. >>> Though I am not sure this merits the term "puzzle", I suggest that >>> solutions be posted with some spoiler protection. >> >> That's good, thank you for the reminder. > > Your explanation of the issue is, to my mind, a teeny tiny spoiler put > "above the fold". Yes, I realized that only later and after the fact. My apologies.
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2022-11-22 11:04 +0000 |
| Message-ID | <tliab3$3pa84$6@dont-email.me> |
| In reply to | #15916 |
On 21/11/2022 8:45 pm, Ben Bacarisse wrote:
> I wonder if there are any real posters here?
Nobody here but us chickens.
> 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...
Dunno. Let's find out:
Ctrl-L coming up:
> ... like this? Because that's my favourite way, rather than posting
> lots of dummy lines before the solution.
Your problem is closely related to the very first question I was
ever posed (in early 1982), by a friend who needed to be able to
establish cleanly in a single expression whether a keypress was a
digit (ASCII 48-57). The relevant dialect of BASIC didn't have
anything like an isdigit function.
The friend was on the point of giving up on me when I handed him
ABS(K-52.5)<4.5
Nowadays we might render this in C as:
int inrange(int lo, int hi, int k)
{
return (k-(lo+hi)/2)<((hi-lo)/2);
}
although of course in C the problem would be far better solved as:
int inrange(int lo, int hi, int k)
{
return (lo <= k) && (k < hi);
}
or even as a macro.
I must confess I'm not entirely certain I have correctly
interpreted your puzzle, which I have taken to mean "is this a
given value in the given range", but this seems just a bit too
easy for you to make a hash of, but I'm sure I've made hashes of
worse. I've missed something, haven't I?
--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2022-11-22 12:53 +0000 |
| Message-ID | <87leo3kv55.fsf@bsb.me.uk> |
| In reply to | #15928 |
Richard Heathfield <rjh@cpax.org.uk> writes:
> On 21/11/2022 8:45 pm, Ben Bacarisse wrote:
>> I wonder if there are any real posters here?
>
> Nobody here but us chickens.
>
>> 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...
>
> Dunno. Let's find out:
>
> Ctrl-L coming up:
>
>
>
Didn't see a form feed there. Here's one (I hope):
> although of course in C the problem would be far better solved as:
>
> int inrange(int lo, int hi, int k)
> {
> return (lo <= k) && (k < hi);
> }
>
> or even as a macro.
>
> I must confess I'm not entirely certain I have correctly interpreted
> your puzzle, which I have taken to mean "is this a given value in the
> given range", but this seems just a bit too easy for you to make a
> hash of, but I'm sure I've made hashes of worse. I've missed
> something, haven't I?
The circular wrapping. On a clock, 55 is in the range of minutes that
starts at 45 and ends at 5.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Paul N <gw7rib@aol.com> |
|---|---|
| Date | 2022-11-22 05:01 -0800 |
| Message-ID | <4f03335d-63ca-447b-b538-dd8a59c11fa9n@googlegroups.com> |
| In reply to | #15932 |
On Tuesday, November 22, 2022 at 12:53:47 PM UTC, Ben Bacarisse wrote:
> Richard Heathfield <r...@cpax.org.uk> writes:
>
> > On 21/11/2022 8:45 pm, Ben Bacarisse wrote:
> >> I wonder if there are any real posters here?
> >
> > Nobody here but us chickens.
> >
> >> 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...
> >
> > Dunno. Let's find out:
> >
> > Ctrl-L coming up:
> >
> >
> >
> Didn't see a form feed there. Here's one (I hope):
> > although of course in C the problem would be far better solved as:
> >
> > int inrange(int lo, int hi, int k)
> > {
> > return (lo <= k) && (k < hi);
> > }
> >
> > or even as a macro.
> >
> > I must confess I'm not entirely certain I have correctly interpreted
> > your puzzle, which I have taken to mean "is this a given value in the
> > given range", but this seems just a bit too easy for you to make a
> > hash of, but I'm sure I've made hashes of worse. I've missed
> > something, haven't I?
> The circular wrapping. On a clock, 55 is in the range of minutes that
> starts at 45 and ends at 5.
What's wrong with - subtract start from both end and value, add the modulus if either is negative, and compare?
For example, in your example we subtract 45 from 5 (end) and 55 (value) to get -40 (end) and 10 (value). Adjusting gives 20 (end) and 10 (value). 10 is below 20 so we're in the range.
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2022-11-22 05:48 -0800 |
| Message-ID | <86wn7n85i6.fsf@linuxsc.com> |
| In reply to | #15935 |
Paul N <gw7rib@aol.com> writes:
> On Tuesday, November 22, 2022 at 12:53:47 PM UTC, Ben Bacarisse wrote:
>
>> Richard Heathfield <r...@cpax.org.uk> writes:
[...]
>>> although of course in C the problem would be far better solved as:
>>>
>>> int inrange(int lo, int hi, int k)
>>> {
>>> return (lo <= k) && (k < hi);
>>> }
>>>
>>> or even as a macro.
>>>
>>> I must confess I'm not entirely certain I have correctly interpreted
>>> your puzzle, which I have taken to mean "is this a given value in the
>>> given range", but this seems just a bit too easy for you to make a
>>> hash of, but I'm sure I've made hashes of worse. I've missed
>>> something, haven't I?
>>
>> The circular wrapping. On a clock, 55 is in the range of minutes that
>> starts at 45 and ends at 5.
>
> What's wrong with - subtract start from both end and value, add the
> modulus if either is negative, and compare?
Suppose start is 9223372036854775800 and end is -9223372036854775800
(or the corresponding values for type 'int', those values are for a
64-bit signed integer type). The subtraction gives undefined behavior.
[toc] | [prev] | [next] | [standalone]
Page 1 of 5 [1] 2 3 4 5 Next page →
Back to top | Article view | comp.programming
csiph-web