aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-02-27 11:49:42 +0000
committerGitHub <noreply@github.com>2020-02-27 11:49:42 +0000
commit443f67f4c339ed52532b0461c6970dd3ccabf938 (patch)
tree663e4aa8089a3881c6ae6ed36ab7702f946e9281
parentf3f87009ce41a4f8b3dd13a492aa53d5a69c0bf3 (diff)
parent0e833cab3416554823901d8a9e1f565a5f5d0bbf (diff)
downloadperlweeklychallenge-club-443f67f4c339ed52532b0461c6970dd3ccabf938.tar.gz
perlweeklychallenge-club-443f67f4c339ed52532b0461c6970dd3ccabf938.tar.bz2
perlweeklychallenge-club-443f67f4c339ed52532b0461c6970dd3ccabf938.zip
Merge pull request #1318 from jacoby/master
ch-1
-rw-r--r--challenge-049/dave-jacoby/perl/ch-1.pl39
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-049/dave-jacoby/perl/ch-1.pl b/challenge-049/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..1d0ca0cc81
--- /dev/null
+++ b/challenge-049/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use utf8;
+use feature qw{ postderef say signatures state switch };
+no warnings
+ qw{ experimental::postderef experimental::smartmatch experimental::signatures };
+
+use Carp;
+
+my $number = int $ARGV[0];
+croak 'Not a positive number' unless $number > 0;
+
+my $smallest = smallest_multiple( $number);
+
+say qq{The smallest multiple of $number containing just 0 and 1 is $smallest};
+exit;
+
+
+sub smallest_multiple( $n ) {
+ my $dec = 1;
+ while ( 1 ) {
+ my $bin = sprintf '%b', $dec;
+ return $bin if $bin % $n == 0 ;
+ $dec++;
+ }
+}
+
+__DATA__
+Smallest Multiple
+
+Write a script to accept a positive number as
+command line argument and print the smallest
+multiple of the given number consists of digits 0 and 1.
+
+For example:
+For given number 55, the smallest multiple is 110
+consisting of digits 0 and 1.