Skip to content

Instantly share code, notes, and snippets.

@itsthomson
Created April 15, 2012 00:01
Show Gist options
  • Save itsthomson/2388793 to your computer and use it in GitHub Desktop.
Save itsthomson/2388793 to your computer and use it in GitHub Desktop.
Google Code Jam 2012, Qual A
cipher <-
c("y",
"h",
"e",
"s",
"o",
"c",
"v",
"x",
"d",
"u",
"i",
"g",
"l",
"b",
"k",
"r",
"z",
"t",
"n",
"w",
"j",
"p",
"f",
"m",
"a",
"q")
goog <- data.frame(orig = letters, ciph = cipher)
goog <- rbind(goog, c(" ", " "))
# i don't even
example <- "rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"
roflcopter <- read.delim("A-small-attempt0.in",header=FALSE,colClasses="character")
counter <- as.numeric(roflcopter[1,])
lollerskates <- function(input){
temp <- strsplit(input,"")[[1]]
for (i in 1:length(strsplit(input,"")[[1]])){
temp[i] <- as.character(goog[goog$orig == temp[i],2])
}
temp <- paste(temp,collapse="")
temp <- gsub("NA", " ", temp)
return(temp)
}
output <- NA
for (j in 1:counter){
temp <- lollerskates(roflcopter[j+1,])
output <- rbind(output,paste("Case #", j, ": ", temp, sep=""))
}
output <- output[-1]
write.table(file="output.txt", output, quote=FALSE,
row.names=FALSE,col.names=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment