diff options
| author | southpawgeek <jen@southpawgeek.com> | 2020-02-24 23:07:12 -0500 |
|---|---|---|
| committer | southpawgeek <jen@southpawgeek.com> | 2020-02-24 23:07:12 -0500 |
| commit | 0f6260120be35fc120f9d711790e7094e99fb72e (patch) | |
| tree | bfdc59f4a04eed2f02add5587a043eafde8f51fb | |
| parent | f35ebb13433887c02b92a5fd1b3169d46f8dc70c (diff) | |
| download | perlweeklychallenge-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.pl | 12 |
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; } |
