1. math Question.... how to do a check sum?
- Posted by <shepardmar at yahoo.com> Dec 11, 2003
- 501 views
Hi Everybody: I was trying to add some variables and check to see if they equal a value, and place that value into another variable. ex 5 variables 5,7,10,78,70 = 170 then cut this number to a smaller one like so 170 = 1 +7 +0 = 8 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 Unless I have overlooked something.. I dont a see a way to split the variable so I can do this...without hard coding it. I am familiar with basic and with basic you can cut the variable say 23 into 2 and 3 then add them. does euphoria support this type of function? Any assitance would be greatly appreciated thanks shep
2. Re: math Question.... how to do a check sum?
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Dec 11, 2003
- 480 views
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