Current location: Hot Scripts Forums » Programming Languages » PHP » Continual even division?


Continual even division?

Reply
  #1 (permalink)  
Old 06-09-05, 09:54 AM
-[OnTarget]- -[OnTarget]- is offline
Newbie Coder
 
Join Date: Mar 2005
Location: Orlando, Florida
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
Continual even division?

Problem:
take a number $num

$num = 32;

now continually divide $num / 2 until it reaches 1... ONLY return even values (no 5's for instance).. and DONT return duplicate entries

Anyone have a clue on how to do this?

^.^ I've tried several variations on the for loop and I still cant get it
__________________
BlueScripts - Free PHP Scripts
Reply With Quote
  #2 (permalink)  
Old 06-09-05, 11:28 AM
alabaster_lynch alabaster_lynch is offline
Wannabe Coder
 
Join Date: Mar 2005
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by -[OnTarget]-
Problem:
take a number $num

$num = 32;

now continually divide $num / 2 until it reaches 1... ONLY return even values (no 5's for instance).. and DONT return duplicate entries

Anyone have a clue on how to do this?

^.^ I've tried several variations on the for loop and I still cant get it
hmm...what would you do with something like that....oh well...try something like this
PHP Code:

while( $num != 1) {

  
$remainder $num 2;
  if (
$remainder == 1)
    
$num /= 2;
  else {
    
$num /= 2;
    echo 
$num;
  }

Hope this is what you wanted....Jose
Reply With Quote
  #3 (permalink)  
Old 06-09-05, 11:51 AM
-[OnTarget]- -[OnTarget]- is offline
Newbie Coder
 
Join Date: Mar 2005
Location: Orlando, Florida
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks that helps a bunch

Its for inserting some fake data into a table until it can be updated... it just needs to be in even increments
__________________
BlueScripts - Free PHP Scripts
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 06:49 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.