add without carry

John Machin sjmachin at lexicon.net
Fri Sep 15 10:50:24 EDT 2006


Jason wrote:
> Jon Ribbens wrote:
> > In article <450a7dec$0$14661$626a54ce at news.free.fr>, Bruno Desthuilliers wrote:
> > >
> > > No need to think too long to come up with the most possibly Q&D solution:
> > >
> > > res = int(str(5 + 7)[-1])
> >
> > Am I missing something subtle in the question or is there some reason
> > that nobody has posted the correct solution:
> >
> >   (a + b) % 10
> >
> > ?
>
> You're not missing anything.  That's the obvious solution.  We're just
> celebrating our non-Dutchness at the moment.
>
> >>> def bound(value, maxBound):
> ...     while value > maxBound:

Does non-Dutchness require or permit bugs like > instead of >= or are
you merely having a braino?

> ...         value -= maxBound
> ...     return value
> ...
> >>> bound(5 + 6, 10)
> 1
> >>> bound(8 + 7, 10)
> 5
> 
> See?  I'm definitely not Dutch.
> 
>     --Jason




More information about the Python-list mailing list