diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-02-29 21:56:12 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-29 21:56:12 +0000 |
| commit | 9503f8ea87f701b132b015677933a7303ae4787b (patch) | |
| tree | d4f1be20213f15e678b99e3a985e359166b8403f | |
| parent | 7e2026e75c002480a83e3b1e5001a8eb0adec421 (diff) | |
| parent | a42746b136af9ddf5f0460f32a7fb49ba76783d4 (diff) | |
| download | perlweeklychallenge-club-9503f8ea87f701b132b015677933a7303ae4787b.tar.gz perlweeklychallenge-club-9503f8ea87f701b132b015677933a7303ae4787b.tar.bz2 perlweeklychallenge-club-9503f8ea87f701b132b015677933a7303ae4787b.zip | |
Merge pull request #1327 from southpawgeek/master
solution for challenge #1
| -rw-r--r-- | challenge-049/southpawgeek/ch-1.pl | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-049/southpawgeek/ch-1.pl b/challenge-049/southpawgeek/ch-1.pl new file mode 100644 index 0000000000..4edfd257c9 --- /dev/null +++ b/challenge-049/southpawgeek/ch-1.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature qw/say/; + +my ($int) = @ARGV; +die "$int isn't an int! \n" if $int =~ /\D/; + +for (my $i = 2;;$i++){ + my $bin = sprintf("%b", $i); + 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; +} |
