Skip to content

Instantly share code, notes, and snippets.

@managedkaos
Last active August 2, 2017 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save managedkaos/764960e19c04581de0e9aadfd7eb38b8 to your computer and use it in GitHub Desktop.
Save managedkaos/764960e19c04581de0e9aadfd7eb38b8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
# read the input file
@input = <>;
# initialize the scores
@score = qw(0 0);
# split the input into arrays
foreach $i (0..1) {
@{ $data[$i] } = split(' ', $input[$i]);
}
# compare each element of the triplet
for $i (0..2) {
# increment the score of the larger element
$score[0]++ if ( $data[0][$i] > $data[1][$i] );
$score[1]++ if ( $data[1][$i] > $data[0][$i] );
}
# print the output
print join(" ",@score),"\n";
@managedkaos
Copy link
Author

$ cat alice-bob.txt
5 6 7
3 6 10

$ ./compare-the-triplets.pl < alice-bob.txt
1 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment