[PHP] Re: PHP Math Question
Mike D [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 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 And so on... Is anyone good at math, that can throw me a bone? Thanks y'all, Mike D Mike Dunlop AWN, Inc. // www.awn.com [ e ] [EMAIL PROTECTED] [ p ] 323.606.4237 Here is some simple code to solve that problem(if i have understood right): ?php for($i = 1, $j = 1; $i = 1; $i++, $j++){ if($j == 5){ $j = 1; print \nbr; } print $i is to $jbr\n; } ? Eric -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: PHP Math Question
I do not know if I understand well, but what about $group=$number % 4; if ($group==0) $group=4; Brona -Original Message- From: Eric Bolikowski [mailto:[EMAIL PROTECTED] Sent: Thursday, December 11, 2003 10:53 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: PHP Math Question Mike D [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 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 And so on... Is anyone good at math, that can throw me a bone? Thanks y'all, Mike D Mike Dunlop AWN, Inc. // www.awn.com [ e ] [EMAIL PROTECTED] [ p ] 323.606.4237 Here is some simple code to solve that problem(if i have understood right): ?php for($i = 1, $j = 1; $i = 1; $i++, $j++){ if($j == 5){ $j = 1; print \nbr; } print $i is to $jbr\n; } ? Eric -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP Math Question
I like Eric's idea of showing the values and added a form to it so you can select the number of items to show before running the script. ?php if(!$_POST[Submit]) { echo form method=post action=.$_SERVER[PHP_SELF]. Maximum Number to Show: input type=text name=i size=5 value=1 input type=submit name=Submit value=Show /form; } else { for($i = 1, $j = 1; $i = $_POST[i]; $i++, $j++){ if($j == 5){ $j = 1; print \nbr; } print $i. is to .$j.br\n; } // end for ? Jim - Original Message - From: Bronislav Kluka [EMAIL PROTECTED] To: Eric Bolikowski [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, December 11, 2003 5:22 PM Subject: RE: [PHP] Re: PHP Math Question | I do not know if I understand well, but what about | | $group=$number % 4; | if ($group==0) $group=4; | | Brona | | -Original Message- | From: Eric Bolikowski [mailto:[EMAIL PROTECTED] | Sent: Thursday, December 11, 2003 10:53 PM | To: [EMAIL PROTECTED] | Subject: [PHP] Re: PHP Math Question | | | | Mike D [EMAIL PROTECTED] wrote in message | news:[EMAIL PROTECTED] | 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 | | And so on... | | Is anyone good at math, that can throw me a bone? | | Thanks y'all, | Mike D | | | | Mike Dunlop | AWN, Inc. | // www.awn.com | [ e ] [EMAIL PROTECTED] | [ p ] 323.606.4237 | | Here is some simple code to solve that problem(if i have | understood right): | | ?php | | for($i = 1, $j = 1; $i = 1; $i++, $j++){ | | if($j == 5){ |$j = 1; |print \nbr; | } | | print $i is to $jbr\n; | | } | | ? | | Eric | | -- | PHP General Mailing List (http://www.php.net/) | To unsubscribe, visit: http://www.php.net/unsub.php | | | -- | PHP General Mailing List (http://www.php.net/) | To unsubscribe, visit: http://www.php.net/unsub.php | | -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP Math Question
Mike D [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP Math Question
Website Managers.Net [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I like Eric's idea of showing the values and added a form to it so you can select the number of items to show before running the script. ?php if(!$_POST[Submit]) { echo form method=post action=.$_SERVER[PHP_SELF]. Maximum Number to Show: input type=text name=i size=5 value=1 input type=submit name=Submit value=Show /form; } else { for($i = 1, $j = 1; $i = $_POST[i]; $i++, $j++){ if($j == 5){ $j = 1; print \nbr; } print $i. is to .$j.br\n; } // end for ? Jim - Original Message - From: Bronislav Kluèka [EMAIL PROTECTED] To: Eric Bolikowski [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, December 11, 2003 5:22 PM Subject: RE: [PHP] Re: PHP Math Question | I do not know if I understand well, but what about | | $group=$number % 4; | if ($group==0) $group=4; | | Brona | | -Original Message- | From: Eric Bolikowski [mailto:[EMAIL PROTECTED] | Sent: Thursday, December 11, 2003 10:53 PM | To: [EMAIL PROTECTED] | Subject: [PHP] Re: PHP Math Question | | | | Mike D [EMAIL PROTECTED] wrote in message | news:[EMAIL PROTECTED] | 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 | | And so on... | | Is anyone good at math, that can throw me a bone? | | Thanks y'all, | Mike D | | | | Mike Dunlop | AWN, Inc. | // www.awn.com | [ e ] [EMAIL PROTECTED] | [ p ] 323.606.4237 | | Here is some simple code to solve that problem(if i have | understood right): | | ?php | | for($i = 1, $j = 1; $i = 1; $i++, $j++){ | | if($j == 5){ |$j = 1; |print \nbr; | } | | print $i is to $jbr\n; | | } | | ? | | Eric | | -- | PHP General Mailing List (http://www.php.net/) | To unsubscribe, visit: http://www.php.net/unsub.php | | | -- | PHP General Mailing List (http://www.php.net/) | To unsubscribe, visit: http://www.php.net/unsub.php | | Mike sent me an email, and it seemed that he was satisfied with the script that I made: ?php for($i = 1, $j = 1; $i = 1; $i++, $j++){ if($j == 5){ $j = 1; print \nbr; } print $i is to $jbr\n; } ? Good idea to rather make an interface for this, Jim! Eric -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php