[plt-scheme] Combining digits to form numbers

From: Thomas Chust (chust at web.de)
Date: Mon Feb 16 20:08:49 EST 2009

2009-02-16 aditya shukla <adityashukla1983 at gmail.com>:
> [...]
> (define guess (lambda(lsb csb msb)
>         This is the part which i was not able to do , how can i combine lsb
> , csb and msb so the number is of the form (msbcsblsb) .Is there any
> function in scheme which can do this
>                          ))
> [...]


there are indeed functions in Scheme that can be used do this -- they
are called + and * ;-)

All you need to do is multiply each digit of the number with the value
of its position and add up the results. If you want to create a more
general solution for an arbitrary number of digits, a function like
foldr comes in handy, too.


When C++ is your hammer, every problem looks like your thumb.

Posted on the users mailing list.