Re: [PHP] Finding if a number is in the range

2001-05-18 Thread MaD dUCK

also sprach Zak Greant (on Thu, 17 May 2001 11:50:35PM -0600):
> Do you really need a chainsaw to cut a piece of cake? ;)

hehe. depends.
and come on, i simultaneously have a point and am joking...

martin;  (greetings from the heart of the sun.)
  \ echo mailto: !#^."<*>"|tr "<*> mailto:"; net@madduck
-- 
fermentation fault.
coors dumped.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Finding if a number is in the range

2001-05-18 Thread MaD dUCK

also sprach Joseph Blythe (on Fri, 18 May 2001 02:29:40PM +0930):
> I give these ideas a go unfortunately the ranges are not contiguous, 
> they are all over the place.

so you make new ranges to fill spaces and associate a bool with
each... or you check them linearly...

martin;  (greetings from the heart of the sun.)
  \ echo mailto: !#^."<*>"|tr "<*> mailto:"; net@madduck
-- 
"for art to exist,
 for any sort of aesthetic activity or perception to exist,
 a certain physiological precondition is indispensable: intoxication." 
-- friedrich nietzsche

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Finding if a number is in the range

2001-05-18 Thread Christian Reiniger

On Friday 18 May 2001 06:16, MaD dUCK wrote:
> also sprach Zak Greant (on Thu, 17 May 2001 09:35:18PM -0600):
> > Or just use a simple chain of if statements :)
>
> yeah, but that's so O(n) !
> i can do in O(lg n)
> or, given n CREW processors, in O(1) time!
>
> yes, i have just finished my computational theory and computer
> algorithms honors exam.

Well, then you *do* know that O(log n) can be slower than O(n), right? :)
For a small number of ranges the chained ifs are most likely faster...

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

(A)bort (R)etry (P)retend this never happened ...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Finding if a number is in the range

2001-05-17 Thread Zak Greant

MaD dUCK wrote:
> also sprach Zak Greant (on Thu, 17 May 2001 09:35:18PM -0600):
> > Or just use a simple chain of if statements :)
> 
> yeah, but that's so O(n) !
> i can do in O(lg n)
> or, given n CREW processors, in O(1) time!
> 
> yes, i have just finished my computational theory and computer
> algorithms honors exam.

Do you really need a chainsaw to cut a piece of cake? ;)

--zak


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Finding if a number is in the range

2001-05-17 Thread Joseph Blythe


MaD dUCK wrote:

> also sprach Zak Greant (on Thu, 17 May 2001 09:35:18PM -0600):
> 
>> Or just use a simple chain of if statements :)
> 
> 
> yeah, but that's so O(n) !
> i can do in O(lg n)
> or, given n CREW processors, in O(1) time!
> 
> yes, i have just finished my computational theory and computer
> algorithms honors exam.

Smarty Pants :-)

I give these ideas a go unfortunately the ranges are not contiguous, 
they are all over the place.

Thanks.

Joseph





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Finding if a number is in the range

2001-05-17 Thread MaD dUCK

also sprach Zak Greant (on Thu, 17 May 2001 09:35:18PM -0600):
> Or just use a simple chain of if statements :)

yeah, but that's so O(n) !
i can do in O(lg n)
or, given n CREW processors, in O(1) time!

yes, i have just finished my computational theory and computer
algorithms honors exam.

martin;  (greetings from the heart of the sun.)
  \ echo mailto: !#^."<*>"|tr "<*> mailto:"; net@madduck
-- 
si vis pacem, para bellum

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Finding if a number is in the range

2001-05-17 Thread Zak Greant

Or just use a simple chain of if statements :)

if ($num >= 200 && $num <= 299) {
echo "$num is between 200 and 299";
} else if ($num >=1000 && $num <= 2263) {
echo "$num is between 1000 and 2263";
} else if ($num >=2264 && $num <= 2499) {
echo "$num is between 2264 and 2499";
} else {
echo "$num is not between 200 and 299, 
1000 and 2263 or 2264 and 2499";
}

If you have a large number of these to do,
you could store your upper and lower bounds
in an array and use a loop to process the
bounds.

ie.
// set up our bounds
$bounds = array (
-10, -1,
0, 199,
200, 299,
1000, 2263,
2264, 2499
);

// make sure that we have a matched sets of bounds
// the bounds array should have at least 2 elements
// and the remainer (modulus) of $count / 2 should be 0
$count = count ($bounds);

$count > 1 AND 0 === ($count % 2)
OR die ('The $bounds array must contain one or more matched
elements.');

for ($index = 0; $index < $count; $index += 2) {
if ($number >= $bounds[$index] && $number <= $bounds[$index + 1]) {
$between = sprintf ("%s is between %s and %s.",
$number, $bounds[$index], $bounds[$index + 1]);
break;
}
}

if (isset ($between)) {
echo $between;
} else {
// join the bounds into a string separated by ..
$bounds = join ('..', $bounds);

// convert every second set of .. to 
$bounds = ereg_replace ('([^.]+\.\.[^.]+)\.\.', '\1', $bounds);
 
echo "Number $number not found with any of the specified
ranges:$bounds";
}





--zak

- Original Message ----- 
From: "MaD dUCK" <[EMAIL PROTECTED]>
To: "Joseph Blythe" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, May 17, 2001 7:53 PM
Subject: Re: [PHP] Finding if a number is in the range


> also sprach Joseph Blythe (on Fri, 18 May 2001 11:12:23AM +0930):
> > How do I find if a number is in a range example:
> 
> assuming that the ranges are continuous, make an array of the first
> number for each range and then implement a custom binary search for
> O(lg n) performance.
> 
> martin;  (greetings from the heart of the sun.)
>   \ echo mailto: !#^."<*>"|tr "<*> mailto:"; net@madduck
> -- 
> "i wish there was a knob on the tv to turn up the intelligence.
>  there's a knob called 'brightness', but it doesn't seem to work."
>   -- gallagher
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Finding if a number is in the range

2001-05-17 Thread MaD dUCK

also sprach Joseph Blythe (on Fri, 18 May 2001 11:12:23AM +0930):
> How do I find if a number is in a range example:

assuming that the ranges are continuous, make an array of the first
number for each range and then implement a custom binary search for
O(lg n) performance.

martin;  (greetings from the heart of the sun.)
  \ echo mailto: !#^."<*>"|tr "<*> mailto:"; net@madduck
-- 
"i wish there was a knob on the tv to turn up the intelligence.
 there's a knob called 'brightness', but it doesn't seem to work."
  -- gallagher

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Finding if a number is in the range

2001-05-17 Thread Joseph Blythe

hello,

How do I find if a number is in a range example:

0200-0299
1000-2263
2264-2499

Lets say I choose 203 how would find which number range it was in?

I was sort of thinking of using arrays of all the number ranges and 
using the in_array function to find which range the numbers are in, but 
this would take some time as there are around 3000+ numbers.

I do however have all the numbers in a database already but they are not 
categorized in ranges.

A better way?

Thanks

Joseph




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]