1. RE: math Question.... how to do a check sum?

Pete Lomax wrote:
> 
> 
> On Thu, 11 Dec 2003 12:40:57 +0000, shepardmar at yahoo.com wrote:
> 
> >the idea is to reduce the sum from the variables so they
> >are under 22
> >
> >ex.
> >
> >if total is 599  then
> >5+9+9 =23 is over 22 so reduce futher  2+3 = 5
> >
> This will do the trick:

<snip>

> ?checksum(170)	-- prints 8
> ?checksum(599)	-- prints 5

Alternatively, remainder( sum, 22 ) would work.

170 => 16
599 => 5

Matt Lewis

new topic     » topic index » view message » categorize

2. RE: math Question.... how to do a check sum?

Hey Pete!
That works perfect!!!!
Thanks.


Pete Lomax wrote:
> 
> 
> On Thu, 11 Dec 2003 12:40:57 +0000, shepardmar at yahoo.com wrote:
> 
> >the idea is to reduce the sum from the variables so they
> >are under 22
> >
> >ex.
> >
> >if total is 599  then
> >5+9+9 =23 is over 22 so reduce futher  2+3 = 5
> >
> This will do the trick:
> 
> function checksum(integer c)
> sequence s
> 	while c>22 do
> 		s=sprintf("%d",{c})
> 		c=0
> 		for i=1 to length(s) do
> 			c+=s[i]-'0'
> 		end for
> 	end while
> 	return c
> end function
> ?checksum(170)	-- prints 8
> ?checksum(599)	-- prints 5
> 
> Regards,
> Pete
> http://palacebuilders.pwp.blueyonder.co.uk/euphoria.html
>

new topic     » goto parent     » topic index » view message » categorize

3. RE: math Question.... how to do a check sum?

Thanks Matt!
I tried your idea too!
Many thanks!!!



Matt Lewis wrote:
> 
> 
> Pete Lomax wrote:
> > 
> > 
> > On Thu, 11 Dec 2003 12:40:57 +0000, shepardmar at yahoo.com wrote:
> > 
> > >the idea is to reduce the sum from the variables so they
> > >are under 22
> > >
> > >ex.
> > >
> > >if total is 599  then
> > >5+9+9 =23 is over 22 so reduce futher  2+3 = 5
> > >
> > This will do the trick:
> 
> <snip>
> 
> > ?checksum(170)	-- prints 8
> > ?checksum(599)	-- prints 5
> 
> Alternatively, remainder( sum, 22 ) would work.
> 
> 170 => 16
> 599 => 5
> 
> Matt Lewis
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu