Last active
August 2, 2017 20:24
-
-
Save managedkaos/764960e19c04581de0e9aadfd7eb38b8 to your computer and use it in GitHub Desktop.
Solution for "Compare the Triplets" https://www.hackerrank.com/challenges/compare-the-triplets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"; |
Author
managedkaos
commented
Aug 2, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment