let rec loop rev i =
if i = 0 then rev
else loop (rev * 10 + (i % 10)) (i / 10)
// usage, returns 987654321
let reversed = loop 0 123456789
i % 10
rev * 10
i / 10
I happened to remember these little number tricks from a previous challenge. This is basically using integers as digit stacks.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.