R,454 421
r=as.integer(commandArgs(T)[1])-1;p=function(...){paste(...,sep='')};a='answer ';b='accept';e='ed';f='d';v='vote';d=p('down',v);u=p('up',v);q='question ';z=c();t=r%/%15;if(t>0){z=c(p(t,' ',a,b));r=r%%15;};if(r%in%(8:12))z=c(z,p(a,u));if(r%in%(3:7))z=c(z,p(q,u));if(r%in%c(1,2,6,7,11,12))z=c(z,p(a,b,e));if(r%in%(13:14))z=c(z,p(a,b));if(r%in%c(3,8,13))z=c(z,p(a,d));if(r%in%c(1,4,6,9,11,14))z=c(z,p(a,d,f));cat(z,sep=', ')
感谢Dennis 的回答,这对我很有帮助。
非高尔夫版本
# read input
r = as.integer(commandArgs(T)[1]) - 1
# shortcut to join strings (... will pass the parameter to paste() *as is*)
p = function(...) {paste(..., sep = '')}
# strings
a = 'answer '; b = 'accept'; e = 'ed'; f = 'd'
v = 'vote'; d = p('down',v); u = p('up',v)
q = 'question '
z = c()
# +15
t = r %/% 15;
if (t > 0) {
z = c(p(t,' ',a,b))
r = r %% 15
}
if (r %in% (8:12)) z = c(z,p(a,u)); # answer upvote
if (r %in% (3:7)) z = c(z,p(q,u)); # question upvote
if (r %in% c(1,2,6,7,11,12)) z = c(z,p(a,b,e)); # answer accepted
if (r %in% (13:14)) z = c(z,p(a,b)); # answer accept
if (r %in% c(3,8,13)) z = c(z,p(a,d)); # answer downvote
if (r %in% c(1,4,6,9,11,14)) z = c(z,p(a,d,f)); # answer downvoted
# print operations
cat(z,sep = ', ')