aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2020-03-01 13:39:37 +0100
committerLubos Kolouch <lubos@kolouch.net>2020-03-01 13:39:37 +0100
commit3165b84ede465772a96ed02f9d8e607140dc5760 (patch)
treeb1f3265f001d9e2c162cf6759b68ce5ae54f75af
parent4a0e7a230f9da4ca47237cf6323ff3fb07757889 (diff)
downloadperlweeklychallenge-club-3165b84ede465772a96ed02f9d8e607140dc5760.tar.gz
perlweeklychallenge-club-3165b84ede465772a96ed02f9d8e607140dc5760.tar.bz2
perlweeklychallenge-club-3165b84ede465772a96ed02f9d8e607140dc5760.zip
CH049 LK
-rw-r--r--challenge-049/lubos-kolouch/perl/ch-1.pl56
-rw-r--r--challenge-049/lubos-kolouch/perl/ch-2.pl44
2 files changed, 100 insertions, 0 deletions
diff --git a/challenge-049/lubos-kolouch/perl/ch-1.pl b/challenge-049/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..c500098aac
--- /dev/null
+++ b/challenge-049/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,56 @@
+#!/usr/bin/perl
+#===============================================================================
+#
+# FILE: ch-1.pl
+#
+# USAGE: ./ch-1.pl
+#
+# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-049/
+#
+# TASK #1
+# 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.
+#
+# OPTIONS: ---
+# REQUIREMENTS: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: Lubos Kolouch
+# ORGANIZATION:
+# VERSION: 1.0
+# CREATED: 02/29/2020 08:38:26 PM
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+use feature qw/say/;
+
+
+sub find_multiple_0_1 {
+ my $input = shift;
+
+ my $count = 0;
+
+ while ($input !~ /^[01]+$/) {
+ $input += $input;
+ # for some numbers there is probably no result, so let's just return -1
+ return -1 if $count == 1000;
+ $count++;
+ }
+
+ return $input;
+}
+
+my $what = $ARGV[0];
+
+say find_multiple_0_1($what);
+
+use Test::More;
+
+is(find_multiple_0_1(55),110);
+done_testing;
diff --git a/challenge-049/lubos-kolouch/perl/ch-2.pl b/challenge-049/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..3f154f73b4
--- /dev/null
+++ b/challenge-049/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+#===============================================================================
+#
+# FILE: ch-2.pl
+#
+# USAGE: ./ch-2.pl
+#
+# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-049/
+#
+# Write a script to demonstrate LRU Cache feature. It should support operations get and set. Accept the capacity of the LRU Cache as command line argument.
+#
+# OPTIONS: ---
+# REQUIREMENTS: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: Lubos Kolouch
+# ORGANIZATION:
+# VERSION: 1.0
+# CREATED: 02/29/2020 08:53:24 PM
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+use Cache::LRU;
+
+my $size = $ARGV[0] or die 'Usage: script size';
+
+my $cache = Cache::LRU->new(
+ size => $size
+);
+
+
+use Test::More;
+
+$cache->set(1=>3);
+$cache->set(2=>5);
+$cache->set(3=>7);
+
+is($cache->get(2),5);
+is($cache->get(1),3);
+is($cache->get(4),undef);
+$cache->set(4=>9);
+is($cache->get(3),undef);