aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.