Your challenge: write a function that multiplies two numbers using the Russian peasant algorithm. There is no language restriction, though anything on the esoteric language list will probably be ignored. Spoiler alert: the solution(s) will undoubtedly appear in the comments.
I think I found it... 9 pages of code entries posted so far? Al Gore won't be very happy over all the CO2 generated ;)
I think I all people on this planet would stop talking for 1 day we solved the CO2 problem already..thats including Al.. ;-)
I Like these brain trainers.. But Cormullion posted already the trick...<<iekss>>..now I need to wait for another one to come by.. I was too quick in clicking..;-)
Here is the same solution, but with more normal indenting. Still ends up being 6 line, like Lutz' solution, but uses tail recursion and maybe does fewer assignments?
Desired False values:
0 (integer or float)
"" (empty string)
Current False values:
false (symbol)
nil (symbol)
() (empty list)
I do know that there are reasons for not allowing "" or 0 as false values. Can someone fill me in? As a former C programmer, I find them very comfortable idioms.
I do know that there are reasons for not allowing "" or 0 as false values. Can someone fill me in? As a former C programmer, I find them very comfortable idioms.
Thanks Lutz. Maybe I'll start using (if-not-null ...) in my code now. Not as satisfying as a straight (if) statement, not as impressive in a code contest like the russian peasant one, but it will work. Are there reasons somewhere for not having (not (null? ..)) as the default for (if, or, and, case) and relatives? Just LISP tradition? I did read a JavaScript book by a LISP guy where he was really negative about that very feature of JavaScript, but I couldn't quite make out why he thought it was a bad feature.
Ted
Lutz wrote:
I do know that there are reasons for not allowing "" or 0 as false values. Can someone fill me in? As a former C programmer, I find them very comfortable idioms.