R, 379 caracteres; 1000-379 + 170 = 791 puntos
Versión que pregunta a los usuarios cómo proceder cuando se detecta un bucle
library(XML);w="http://en.wikipedia.org";W="/wiki/";n=1;A=c(scan(,""));while(A[n]!="Philosophy"){a=paste0(w,W,A[n]);d=sapply(strsplit(grep(W,sapply(xpathApply(xmlParse(readLines(a)),"//p/a[@href]|//ul/li/a[@href]",xmlAttrs),`[`,'href'),v=T),"/"),`[`,3);B=d[-grep(":",d)];n=n+1;if(B[1]%in%A)if(readline("Loop!2nd link?")=="n")break;A[n]=head(B[!B%in%A],1);cat(A[n],"\n")};cat(n-1)
Con muescas y comentarios:
library(XML) #Uses package XML
w="http://en.wikipedia.org"
W="/wiki/"
n=1
A=c(scan(,"")) #Stdin + makes it a vector so we can store each iteration
while(A[n]!="Philosophy"){
a=paste0(w,W,A[n])
d=sapply(strsplit(grep(W,sapply( #The heart of the program
xpathApply(xmlParse(readLines(a)),"//p/a[@href]|//ul/li/a[@href]",xmlAttrs),
`[`,'href'),v=T),"/"),`[`,3)
B=d[-grep(":",d)] #get rid of Templates, Files ,etc...
n=n+1
#Ask user if should proceed when loop encountered
#(any answer other than "n" is considered agreement):
if(B[1]%in%A)if(readline("Loop!2nd link?")=="n")break
A[n]=head(B[!B%in%A],1) #Take the first link that is not redundant
cat(A[n],"\n")
}
cat(n-1)
Ejemplo de ejecución:
> library(XML);w="http://en.wikipedia.org";W="/wiki/";n=1;A=c(scan(,""));while(A[n]!="Philosophy"){a=paste(w,W,A[n],sep="");d=sapply(strsplit(grep(W,sapply(xpathApply(xmlParse(readLines(a)),"//p/a[@href]|//ul/li/a[@href]",xmlAttrs),`[`,'href'),v=T),"/"),`[`,3);B=d[-grep(":",d)];n=n+1;if(B[1]%in%A)if(readline("Loop!2nd link?")=="n")break;A[n]=head(B[!B%in%A],1);cat(A[n],"\n")};cat(n-1)
1: Extended_ASCII
2:
Read 1 item
Eight-bit
Computer_architecture
Computer_science
Science
Logic
List_of_aestheticians
Art
Human_behavior
Behavior
Organism
Biology
Loop!2nd link?y
Mathematics
Quantity
Property_(philosophy)
Modern_philosophy
Philosophy
16
R, 325 caracteres; ??? puntos
Versión que, por defecto, toma el primer enlace no redundante (es decir, sin bucle).
library(XML);w="http://en.wikipedia.org";W="/wiki/";n=1;A=c(scan(,""));while(A[n]!="Philosophy"){a=paste0(w,W,A[n]);d=sapply(strsplit(grep(W,sapply(xpathApply(xmlParse(readLines(a)),"//p/a[@href]|//ul/li/a[@href]",xmlAttrs),`[`,'href'),v=T),"/"),`[`,3);B=d[-grep(":",d)];n=n+1;A[n]=head(B[!B%in%A],1);cat(A[n],"\n")};cat(n-1)