Created
April 28, 2013 16:15
-
-
Save kuniyoshi/5477372 to your computer and use it in GitHub Desktop.
CodeIQ《ピッグデータ》に負けないで! - https://codeiq.jp/ace/yuki_hiroshi/q303
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
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