# [plt-scheme] Combining digits to form numbers

((lambda (l) (string->number (apply string-append (map number->string l))))
'(1 2 3))
=
123
;P
Robby
On Mon, Feb 16, 2009 at 7:55 PM, Matthias Felleisen
<matthias at ccs.neu.edu> wrote:
>*
*>>* (foldl (lambda (x y) ( + x (* y 10) )) 0 '(1 2 3))
*>* 123
*>*
*>* -- Matthias
*>*
*>*
*>* On Feb 16, 2009, at 8:21 PM, Tim Wawrzynczak wrote:
*>*
*>* I think you're looking for something like this?
*>*
*>* (foldr (lambda (x y) ( + x (* y 10) )) 0 (reverse '(1 2 3)))
*>* = 123
*>*
*>* - inforichland
*>*
*>* On Mon, Feb 16, 2009 at 7:08 PM, Thomas Chust <chust at web.de> wrote:
*>>*
*>>* 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.
*>>* _________________________________________________
*>>* For list-related administrative tasks:
*>>* http://list.cs.brown.edu/mailman/listinfo/plt-scheme
*>*
*>* _________________________________________________
*>* For list-related administrative tasks:
*>* http://list.cs.brown.edu/mailman/listinfo/plt-scheme
*>*
*>* _________________________________________________
*>* For list-related administrative tasks:
*>* http://list.cs.brown.edu/mailman/listinfo/plt-scheme
*>*
*>*
*