In: Computer Science
Develop, write and certify a properly recursive procedure
reverseDigits to input a positive integer n
and to output the integer formed by reversing the digits of n. Thus
(reverseDigits 1234) returns the
integer 4321. Please answer using Dr Racket(R5RS language)
//define the logic first
(define
invert-number-aux (λ (n res)
(if (empty? n) res
(invert-number-aux
(take n (-(length n) 1)) ;new n
(append res (list (last n))) ;new res
)
)))
(define
invert-number (λ (n)
(string->number (list->string (invert-number-aux (string->list(number->string n)) '())))
))