tag:blogger.com,1999:blog-6314876008291942531.post3792740830848285277..comments2024-01-14T00:36:43.430-08:00Comments on Antonio Gulli's coding playground: Compute if a number is a multiple of 5Unknownnoreply@blogger.comBlogger2125tag:blogger.com,1999:blog-6314876008291942531.post-90134792948245544552012-04-23T13:00:37.669-07:002012-04-23T13:00:37.669-07:00The above logic fails. 20 is not from 10 XOR 15.
...The above logic fails. 20 is not from 10 XOR 15.<br /><br />It is matter of checking last digit. Get the remainder mod 5. If it is 0 or 5, number is multiple of 5.Anonymoushttps://www.blogger.com/profile/09855100606552890649noreply@blogger.comtag:blogger.com,1999:blog-6314876008291942531.post-70055566645072530922012-02-11T19:01:45.230-08:002012-02-11T19:01:45.230-08:00Here the first five multiple of 5:
00101
01010
01...Here the first five multiple of 5:<br /><br />00101<br />01010<br />01111<br />10100<br />11001<br />...<br /><br />So, It seems that the pattern is: C = A XOR B i.e. the number in position C is the result of the XOR between the previous two numbers (of course the first two numbers of the sequence - 5 and 10 - are given).<br /><br />So, an algo could be to generate the sequence of all the possible binary numbers using the previous pattern until we reach the input number (so it is a multiplo of 5). As soon as we generate a bigger number we stops saying that the number is not a multiple of 5.Claudio Corsihttps://www.blogger.com/profile/13435215356783747956noreply@blogger.com