Task 1: Remove leading zeros
"The Great Zero Trim: When Numbers Shed Their Leading Skin!"
Write a script or one-liner to remove leading zeros from positive numbers.
The Strategy: Use regex to match and remove leading zeros, handling the special case where all zeros collapse to a single '0'.
Perl Implementation
sub remove_leading_zeros {
my $num = shift;
$num =~ s/^0+//;
return length($num) ? $num : '0';
}
Python Implementation
def remove_leading_zeros(num: str) -> str:
return re.sub(r'^0+(?!$)', '', num)