R,195个字符
A=strsplit(scan(,""),"")[[1]];cat(A[order(sapply(A,function(x){png('a',a='none',fa='monospace');frame();text(0,0,x);dev.off();sum(apply(png::readPNG('a'),c(1,2),function(x)any(x!=1)))}))],sep="")
缩进注释:
A=strsplit(scan(,""),"")[[1]] #Take characters as strings and split into single chars
cat(A[order(sapply(A,function(x){ #Apply the following function to each char and order accordingly
png('a',a='none',fa='monospace'); #Open empty png without antialiasing and with monospace font
frame(); #create empty plot
text(0,0,x); #add the char as text to the plot
dev.off(); #close png device
sum(apply(png::readPNG('a'), #read it back as rbga 3d matrix
c(1,2), #check every layer (R, G, B, A)
function(x)any(x!=1))) #if any are not 1, send TRUE
}))], #Sum all TRUEs
sep="") #Prints to output
例:
> A=strsplit(scan(,""),"")[[1]];cat(A[order(sapply(A,function(x){png('a',a='none',fa='monospace');frame();text(0,0,x);dev.off();sum(apply(png::readPNG('a'),c(1,2),function(x)any(x!=1)))}))],sep="")
1: @+.0
2:
Read 1 item
.+0@
> A=strsplit(scan(,""),"")[[1]];cat(A[order(sapply(A,function(x){png('a',a='none',fa='monospace');frame();text(0,0,x);dev.off();sum(apply(png::readPNG('a'),c(1,2),function(x)any(x!=1)))}))],sep="")
1: 1234567890
2:
Read 1 item
1723450689
R图形中字体的字体依赖于平台,我不能保证它可以在PC上运行,但可以在Mac上运行(OS X 10.7.5,R 2.14.2)。