Skip to content

Instantly share code, notes, and snippets.

@kuniyoshi
Created April 28, 2013 16:15
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 kuniyoshi/5477372 to your computer and use it in GitHub Desktop.
Save kuniyoshi/5477372 to your computer and use it in GitHub Desktop.
CodeIQ《ピッグデータ》に負けないで! - https://codeiq.jp/ace/yuki_hiroshi/q303
library(digest)
# R's index starts with 1, not 0
getdata <- function(index) {
q <- floor(index / 10)
r <- index %% 10
digest.raw <- digest(as.character(q), algo="sha1", serialize=FALSE, raw=TRUE)
data <- sum(as.numeric(digest.raw)[c(2 * r + 1, 2 * r + 1 + 1)] * c(256, 1))
return(data)
}
getsign <- function(count, skips) {
data <- sapply(0:(count - 1), getdata)
target <- seq(0, count - 1, by=skips)
return(sum(data[order(data)][target + 1]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment