#! /usr/bin/perl use warnings; use strict; sub rev { my ($x) = @_; my $r = my $z = 0; my $start = 1; while ($x) { ! ($r *= 10) and $z += $start or undef $start; $r += $x % 10; $x = ($x - $x % 10) / 10; } return '0' x ($z - 1) . $r } use Test::More tests => 4; is rev(3), 3; is rev(123456789), 987654321; is rev(4444), 4444; is rev(1000), '0001';
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: Daily Coding Puzzles - Oct 29th - Nov 2nd
Replies for: Wednesday Write a program to reverse the digits of a positive integer but without converting it to a string.
For further actions, you may consider blocking this person and/or reporting abuse