aboutsummaryrefslogtreecommitdiff
path: root/challenge-080
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-10-06 07:17:04 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-10-06 07:17:04 +0100
commitb3b9af80f5679b950347ba3aa18afbe2155ddfc4 (patch)
tree98498f5707578fb380f50cdddc527415d3d25630 /challenge-080
parent81b40342068e97f24f9ddc1b94359ae52eb9f8f2 (diff)
downloadperlweeklychallenge-club-b3b9af80f5679b950347ba3aa18afbe2155ddfc4.tar.gz
perlweeklychallenge-club-b3b9af80f5679b950347ba3aa18afbe2155ddfc4.tar.bz2
perlweeklychallenge-club-b3b9af80f5679b950347ba3aa18afbe2155ddfc4.zip
- Added solution 80 and 81 by Pete Houston.
Diffstat (limited to 'challenge-080')
-rw-r--r--challenge-080/pete-houston/perl/ch-1.pl29
-rw-r--r--challenge-080/pete-houston/perl/ch-2.pl35
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-080/pete-houston/perl/ch-1.pl b/challenge-080/pete-houston/perl/ch-1.pl
new file mode 100644
index 0000000000..bf161999be
--- /dev/null
+++ b/challenge-080/pete-houston/perl/ch-1.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: 8001.pl
+#
+# USAGE: ./8001.pl N ...
+#
+# DESCRIPTION: Print the smallest missing positive int from the
+# argument list
+#
+# REQUIREMENTS: Params::Util
+# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk
+# ORGANIZATION: Openstrike
+# VERSION: 1.0
+# CREATED: 28/09/20
+#===============================================================================
+
+use strict;
+use warnings;
+use Params::Util '_POSINT';
+
+# Build the hash from only the positive integers
+my %pos;
+$pos{$_} = 1 for grep { _POSINT ($_) } @ARGV;
+
+# Find the lowest missing value
+my $lowest = 1;
+$lowest++ while $pos{$lowest};
+print "$lowest\n";
diff --git a/challenge-080/pete-houston/perl/ch-2.pl b/challenge-080/pete-houston/perl/ch-2.pl
new file mode 100644
index 0000000000..fc2eecd92b
--- /dev/null
+++ b/challenge-080/pete-houston/perl/ch-2.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: 8002.pl
+#
+# USAGE: ./8002.pl N ...
+#
+# DESCRIPTION: Candy counting
+#
+# OPTIONS: ---
+# REQUIREMENTS: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk
+# ORGANIZATION: Openstrike
+# VERSION: 1.0
+# CREATED: 28/09/20 15:44:45
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+
+# Logic:
+# if we have n canditates, that's a minimum of n candies.
+my $tot = scalar @ARGV;
+
+# Then we have n-1 pairs. If each pair has the same ranking, there is no
+# addition. If each pair has a different ranking, there is one extra
+# candy awarded.
+for my $i (1 .. $#ARGV) {
+ $tot++ unless $ARGV[$i] == $ARGV[$i-1];
+}
+
+print "$tot\n";