Re: Re: PHP Math Question

From: Date: Fri, 12 Dec 2003 05:41:35 +0000
Subject: Re: Re: PHP Math Question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-172548@lists.php.net to get a copy of this message
"Mike D" <mike@awn.com> wrote in message news:BBFE14A9.107A2%mike@awn.com...
I'm am completely stumped on a seemingly simple math formula I need to find a way to map a set of numbers up to 4 (e.g. 1,2,3,4 or 1,2) to any number in a range of up to 10,000 (ideally, unlimited). Such that, (e.g. 1,2,3,4) 1 is to 1 2 is to 2 3 is to 3 4 is to 4 5 is to 1 6 is to 2 7 is to 3 8 is to 4 9 is to 1 10 is to 2 11 is to 3 12 is to 4 13 is to 1 14 is to 2 15 is to 3 16 is to 4
etc. Here is an (untested) function that may work: function map_four( $num ) {
    $map_val = $num % 4;
    if ($map_val) {
        return $map_val;
    } else {
        return 4;
    }
} Basically, it looks like a modulus with 4, except that you want multiples of four to return four instead of zero. Unless, of course, I completely misunderstood the question. Which is not uncommon as of late. -- Rob

« previous php.general (#172548) next »