#!/usr/bin/env perl use strict; use warnings; use List::Util qw(sum); # For each $n, convert $n to hex digits, add the digits together. If the # result has more than one hex digit, repeat this process adding the # digits together. When there is only one hex digit remaining, if the # digit is a '5', an 'a', or an 'f', the original number was divisible # by 5. for my $n (1..100) { my $h = sprintf '%x', $n; while(length($h) > 1) { $h = sprintf '%x', sum(map {hex $_} split //, $h); } print "$n is a multiple of 5\n" if $h =~ m/^[5af]$/; } #### 5 is a multiple of 5 10 is a multiple of 5 15 is a multiple of 5 20 is a multiple of 5 25 is a multiple of 5 30 is a multiple of 5 35 is a multiple of 5 40 is a multiple of 5 45 is a multiple of 5 50 is a multiple of 5 55 is a multiple of 5 60 is a multiple of 5 65 is a multiple of 5 70 is a multiple of 5 75 is a multiple of 5 80 is a multiple of 5 85 is a multiple of 5 90 is a multiple of 5 95 is a multiple of 5 100 is a multiple of 5