[plt-scheme] Combining digits to form numbers
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
>
> ))
> [...]
Hello,
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.
cu,
Thomas
--
When C++ is your hammer, every problem looks like your thumb.