aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsouthpawgeek <jen@southpawgeek.com>2020-02-24 23:07:12 -0500
committersouthpawgeek <jen@southpawgeek.com>2020-02-24 23:07:12 -0500
commit0f6260120be35fc120f9d711790e7094e99fb72e (patch)
treebfdc59f4a04eed2f02add5587a043eafde8f51fb
parentf35ebb13433887c02b92a5fd1b3169d46f8dc70c (diff)
downloadperlweeklychallenge-club-0f6260120be35fc120f9d711790e7094e99fb72e.tar.gz
perlweeklychallenge-club-0f6260120be35fc120f9d711790e7094e99fb72e.tar.bz2
perlweeklychallenge-club-0f6260120be35fc120f9d711790e7094e99fb72e.zip
fixed challenge to account for 1s *and* 0s
-rw-r--r--challenge-049/southpawgeek/ch-1.pl12
1 files changed, 9 insertions, 3 deletions
diff --git a/challenge-049/southpawgeek/ch-1.pl b/challenge-049/southpawgeek/ch-1.pl
index 8f7c7dce76..4edfd257c9 100644
--- a/challenge-049/southpawgeek/ch-1.pl
+++ b/challenge-049/southpawgeek/ch-1.pl
@@ -5,9 +5,15 @@ use feature qw/say/;
my ($int) = @ARGV;
die "$int isn't an int! \n" if $int =~ /\D/;
-say "checking $int";
-for (my $i = 1;;$i++){
+for (my $i = 2;;$i++){
my $bin = sprintf("%b", $i);
- say "$bin is the smallest 0/1 multiple of $int" and last unless $bin % $int;
+ next if $bin == $int;
+
+ # we know it starts with 1, but make sure there's at least one 0
+ next unless $bin =~ /0+/;
+
+ say "$bin is the smallest multiple of $int with 1s *and* 0s."
+ and last
+ unless $bin % $int;
}