diff options
| -rw-r--r-- | challenge-049/southpawgeek/ch-1.pl | 13 | ||||
| -rw-r--r-- | challenge-049/southpawgeek/ch-2.pl | 33 |
2 files changed, 46 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..8f7c7dce76 --- /dev/null +++ b/challenge-049/southpawgeek/ch-1.pl @@ -0,0 +1,13 @@ +#!/usr/bin/perl +use strict; +use warnings; +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++){ + my $bin = sprintf("%b", $i); + say "$bin is the smallest 0/1 multiple of $int" and last unless $bin % $int; +} diff --git a/challenge-049/southpawgeek/ch-2.pl b/challenge-049/southpawgeek/ch-2.pl new file mode 100644 index 0000000000..d2488c6d53 --- /dev/null +++ b/challenge-049/southpawgeek/ch-2.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature qw/say/; + +my ($size) = @ARGV; +die "$size isn't an int! \n" if $size =~ /\D/; +$size = 3 unless $size; +say "set cache size to $size"; + +set(1, 3); +set(2, 5); +set(3, 7); +get(2); +get(1); +get(4); +set(4, 9); +get(3); + +my (%cache, @keys); + +sub set { + my ($key, $value) = @_; + push @keys, $key; + $cache{$key} = $value; + say "key order.. @keys"; +} + +sub get { + my $key = shift; + say $cache{$key}; + say "key order.. @keys"; +} |
