Re: LZ: Routine Help Again


[Prev][Next][Index][Thread]

Re: LZ: Routine Help Again



> Ok, I know I posted this before, but the answers I got weren't 
> specific enough for my purposes.
> 
> In my MineHunt program, I generate a random number between 0 and
> 139.  I need to be able to tell if any number ends in a 0 or
> a 9 (9, 20, 59, etc).  This routine needs to be such that if I do
> get one of these numbers then I can simply regenerate a new one.
> Speed is not a consideration, but size definatly is.


  Finding the last digit of a (decimal) number is called "taking the number 
mod 10".  The basic idea is to divide by 10 & get the remainder.  If 
speed doesn't matter, do this:
  Divide by 10.
  Multiply the result by 10.
  Subtract from the original #.


                     /***********************************
                     *           Daniel Knapp           *
                     *       FeatherWate Software       *
                     *     email: dankna@bergen.org     *
                     *                                  *
                     *      Whose account this is,      *
                     *         I think I know.          *
                     * The sysop is in Berkely, though. *
                     * She will not see me typing here, *
                     *        To watch this Mac         *
                     *          Refuse to go.           *
                     ***********************************/


References: