R 379 символов; 1000-379 + 170 = 791 баллов
Версия, которая спрашивает пользователей, как действовать при обнаружении зацикливания
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)
С отступами и комментариями:
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)
Пример выполнения:
> 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 знаков; ??? точки
Версия, которая по умолчанию принимает первую не избыточную ссылку (т.е. не зацикливающуюся).
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)