Skip to content

Instantly share code, notes, and snippets.

@saraswatmks
Created December 19, 2017 16:30
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 saraswatmks/94852ef0fe5bccfb63774dd92b134622 to your computer and use it in GitHub Desktop.
Save saraswatmks/94852ef0fe5bccfb63774dd92b134622 to your computer and use it in GitHub Desktop.
compare the triplets in R
# Enter your code here. Read input from STDIN. Print output to STDOUT
con <- file('stdin','r')
input <- readLines(con)
n1 <- input[[1]]
n2 <- input[[2]]
n1 <- as.numeric(unlist(strsplit(n1, ' ')))
n2 <- as.numeric(unlist(strsplit(n2, ' ')))
alice = 0
bob = 0
for(i in seq(n1))
{
if(n1[i] > n2[i])
{
alice = alice + 1
} else if(n1[i] < n2[i])
{
bob = bob + 1
} else {
next
}
}
result <- c(alice, bob)
cat(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment