note
LanX
<I>> Other monks have suggested a binary search solution, but did not provide an example. </I><P>
FWIW I did, but didn't publish, since it didn't fit into [davido]'s benchmark (which has also it flaws by only testing 42)<P>
<c>
DB<47> sub tst { if ($_>=9) { if ($_>=41 and $_<=56) {1} elsif ($_<=10) {1} } elsif ($_<=6) { if ($_>=5){1} elsif \
($_<=2 and $_>=1) {1} }}
DB<48> %in = map { $_ => 1 } 1,2,5,6,9,10,41..56
DB<49> tst != $in{$_} and print "error $_" for 1..190
DB<50>
</c><P>
I was also pondering about how to optimize a solution (time and memory) for all cases.<P>
Like potentially
<UL>
<LI> many points
<LI> many ranges
<LI> floats instead of integers
<LI> multiple dimensions (like rectangular areas in a plane)
</UL>
An "optimal" solution would involve combining different techniques ...<P>
And some techniques which were prominent in similar older threads haven't been mentioned yet.<P>
Anyway all of this is far beyond what the OP wanted.<P>
<B>But yes:</B> again "I'm suggesting but not providing an example" ;-)<P>
<div class="pmsig"><div class="pmsig-708738">
<!--nowiki--><p>Cheers Rolf<br>
<sub>(addicted to the Perl Programming Language :)
<br> <i> [id://1153804|Wikisyntax for the Monastery]</i>
</sub>
<!--nowiki-->
</div></div><!-- Wiki2Monks {"version":1.16} -->
11127640
11127703