Created
August 21, 2012 17:46
-
-
Save Koitaro/3417801 to your computer and use it in GitHub Desktop.
R: Project Euler 70-79
This file contains hidden or 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
| 2 + (1000000-5) %/% 7 * 3 |
This file contains hidden or 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(partitions) | |
| P(100) |
This file contains hidden or 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(igraph) | |
| g <- graph.empty() + vertices(0:9) | |
| for (line in strsplit(readLines("keylog.txt"), "")) { | |
| n <- as.numeric(line) + 1 | |
| g <- g + edges(c(n[1], n[2], n[2], n[3])) | |
| } | |
| vs <- numeric(0) | |
| for (v in V(g)) { | |
| if (length(neighbors(g, v, mode="all")) == 0) vs <- c(vs, v) | |
| } | |
| g <- g - vertices(vs) | |
| V(g)[topological.sort(g)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment