blob: fc2eecd92b54167e01b74f81d73c90245f404f6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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";
|