I need a subroutine for my program written in scheme that takes an integer, say 34109, and puts it into a list with elements 3, 4, 1, 0, 9. The integer can be any length. Does anyone have a trick for this? I’ve thought about using modulo for every place, but I don’t think it should be that complicated.
Share
The simplest way I can think of, is by using arithmetic operations and a named
letfor implementing a tail-recursion:Alternatively, you can solve this problem using string operations:
This can be compressed into a single function, but I believe it’s easier to understand if we split the problem in subparts as above.
Anyway, the results are as expected: