Re: What is math:intdiv doing?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Thanks Lonny and Shian,

I found a solution to "intdev" which I now call intact division.

_tom


intdiv

include intdiv.ex 
public function intdiv(object dividend, object divisor) 

returns an intact division of two objects.

Arguments:
  1. dividend : any Euphoria object.
  2. divisor : any Euphoria object.
Returns:

An object, which will be a sequence if either dividend or divisor is a sequence.

Comments:

Starting with a number of items, how many containers are needed when each container has a fixed maximum size? Since you can not have a fractional container you must perform what we will call an intact division. Every container will be full of items except that the last container could be partially full--every container remains intact.

  • The dividend is the number of items to be packed.
  • The divisor is the size of the container.
  • The return is the number of intact containers.
Example 1:
include std/math.e 
 
atom tokens = 101 
atom perEnvelope = 5 
 
? 101/5 
--> 20.2  -- but, can not have 0.2 envelopes 
 
integer envelopes = intdiv( tokens, perEnvelope ) 
? envelopes 
--> 21 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu