R, 433 399 bytes
y=scan(,'',sep="\n")
h=nchar(y[1])
v=length(y)
p=function(x)paste(x,collapse="")
if(h%%2){y=sapply(y,function(x)paste0(x," "));h=h+1}
if(v%%2){y=c(y,p(rep(" ",h)));v=v+1}
z=matrix(unlist(lapply(y,function(x)strtoi(charToRaw(x),16))),ncol=h,byrow=T)
a=array(,c(v,h))
for(i in 1:(v/2)){for(j in 1:(h/2)){r=2*i-1:0;s=2*j-1:0;a[r,s]=rawToChar(as.raw(floor(mean(z[r,s])+.5)))}}
cat(apply(a,1,p),sep="\n")
Me estoy desesperando porque esta cosa parece no competir como diablos. Se imprime
$$>>II99######
$$>>II99######
$$##88KKGG####
$$##88KKGG####
para el caso de prueba.
Si te alimentas en el 7 × 3
%%%%%%%
Example
%%%%%%%
la salida será
BBFFJJ33
BBFFJJ33
######!!
######!!
debido a la divisibilidad por 2 etc. etc.
Sin golf:
y <- scan(, '', sep="\n") # Read STDIN and make it a character vector
h <- nchar(y[1]) # Get line width: how many chars per line
v <- length(y) # Get array height: how many lines
p <- function(x) paste(x, collapse="") # A function that merges a vector of strings
if (h%%2) {y <- sapply(y, function(x) paste0(x, " ")); h=h+1} # If height is odd, add an empty line
if (v%%2) {y <- c(y, p(rep(" ", h))); v=v+1} # If width is odd, add an empty column
z <- matrix(unlist(lapply(y, function(x) strtoi(charToRaw(x), 16))), ncol=h, byrow=T)
# z now stores ASCII codes in a matrix; analogous to C strtol
a <- array(, dim=c(v,h)) # Reserve an array for the final result
for (i in 1:(v/2)) {
for(j in 1:(h/2)) {
r <- 2*i - 1:0 # Range of rows to average
s <- 2*j - 1:0 # Range of columns to average
a[r, s] <- rawToChar(as.raw(floor(mean(z[r, s]) + .5))) # Average, round, convert the ASCII codes
} # and write them to the same place as in the original array
}
cat(apply(a, 1 , p), sep="\n") # Prints the array row-wise (index 1 for rows)
Solo mire cómo maneja este magnífico ejemplo (cortesía de chris.com):
M$$$$$$$$$$$$$$$$RMMMMM8MMX
<$$$$$$$$$$$$R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
!!!!!!!!!!\~~~~~~~>!!!! `"MMMHX!!~~~<!!$R!~~~~~~~~~~~~~~~~~<~~~~!!
!!!!!!!!!!<~~~~~<!!!!! .::<!!!!<~~!!X8X!~~~~~~~~~~~~~~~~~~~~~~!!
`X!!!!!!!!~~~~~!<!!!!!!!!!!!!~~!!\~~!!M$MX!:~~~~~~~~~~~~~~~~<!~~!>
!X!!!!!!!!~!!:!!!!!!!!!!~!!!:~~!!~~~!!$M!~~!!<~~~~~~~~~~~~~~~!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:!!~~:!9R!~~~~~~!~~~~~~~~~~~~~~<!!f
'CHAT!!!!!!!!!!!!!!!!!!!!!!!!!!!!~~~!!MX~~~~~~~~~~~~~~~~~~~~~~!!X
Después:
''..$$$$$$$$$$662266??MMIIDDEE66
''..$$$$$$$$$$662266??MMIIDDEE66
''>>$$$$$$<<WWOOOOggPP88,,HH99..;;
''>>$$$$$$<<WWOOOOggPP88,,HH99..;;
..HH..$$$$EEPP~~ggOOggVV??22..$$$$00!!
..HH..$$$$EEPP~~ggOOggVV??22..$$$$00!!
99((PP77;;CCII5555VVVV4433WWPP88..<<==66
99((PP77;;CCII5555VVVV4433WWPP88..<<==66
..!!==MM$$..99DD8899gggg~~ggOOmm88HH@@PP!!
..!!==MM$$..99DD8899gggg~~ggOOmm88HH@@PP!!
::88EEMM@@MMPP77BB??gg88~~88__~~88==kkTT88
::88EEMM@@MMPP77BB??gg88~~88__~~88==kkTT88
::!!EEHHCCCCEEMM77PPQQ00??nn~~??0000((
::!!EEHHCCCCEEMM77PPQQ00??nn~~??0000((
8888,,00??..BB@@11??PP""ggmmVV55//GG
8888,,00??..BB@@11??PP""ggmmVV55//GG
8888,,MM00..HHEE77==((//>>));;$$00))
8888,,MM00..HHEE77==((//>>));;$$00))
""''((,,\\PP~~ggII00!!~~ddXX''88$$;;<<''
""''((,,\\PP~~ggII00!!~~ddXX''88$$;;<<''
VV~~~~~~ggOO99gg..!!88PP((EE::00++..;;((
VV~~~~~~ggOO99gg..!!88PP((EE::00++..;;((
BB~~~~~~~~gg VVmm--;;!!!!))::,,gg??88CC!!
BB~~~~~~~~gg VVmm--;;!!!!))::,,gg??88CC!!
11??PP~~~~~~~~~~__~~PP;;::!!!!!!PPPP''PPll@@88
11??PP~~~~~~~~~~__~~PP;;::!!!!!!PPPP''PPll@@88
11YYPPgg~~~~~~~~~~~~~~!!..;;!!!!!!!!!!88~~00,,OO
11YYPPgg~~~~~~~~~~~~~~!!..;;!!!!!!!!!!88~~00,,OO
&&KK~~~~~~gg~~~~~~~~~~FF0000!!,,//!!88VV~~MMEEPP??
&&KK~~~~~~gg~~~~~~~~~~FF0000!!,,//!!88VV~~MMEEPP??
::..$$PP~~mm??gg~~~~~~~~gg//..##!!777788~~~~??33OOnn!!
::..$$PP~~mm??gg~~~~~~~~gg//..##!!777788~~~~??33OOnn!!
<<""&&//NNLL::))$$$$$$$$$$$$##PP~~~~~~~~VV77$$TT!!77hh~~~~((==CC~~gg!!
<<""&&//NNLL::))$$$$$$$$$$$$##PP~~~~~~~~VV77$$TT!!77hh~~~~((==CC~~gg!!
88gg~~ggMM$$$$;;))$$$$$$$$$$$$$$$$##PP~~~~~~~~((..$$OO!!;;PP~~gg==00gg~~??22
88gg~~ggMM$$$$;;))$$$$$$$$$$$$$$$$##PP~~~~~~~~((..$$OO!!;;PP~~gg==00gg~~??22
88mm~~~~~~gg__LL$$$$$$$$$$$$$$$$$$$$$$##PP~~~~~~PP::$$$$$$0066rrAA00$$\\~~~~!!
88mm~~~~~~gg__LL$$$$$$$$$$$$$$$$$$$$$$##PP~~~~~~PP::$$$$$$0066rrAA00$$\\~~~~!!
PP~~~~~~~~~~~~~~..$$$$$$$$$$$$$$$$$$$$##mm~~~~~~??00$$$$$$$$$$$$$$$$99~~~~gg88
PP~~~~~~~~~~~~~~..$$$$$$$$$$$$$$$$$$$$##mm~~~~~~??00$$$$$$$$$$$$$$$$99~~~~gg88
~~~~~~~~~~~~g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VV!!~~~~!!88//gg~~~~gg ~~~~gg88
##!!!!!!88gg~~~~mm((!!//))!!!!!!!!!!~~??::..PP~~~~~~~~~~mmOO$$~~~~PP88
##!!!!!!88gg~~~~mm((!!//))!!!!!!!!!!~~??::..PP~~~~~~~~~~mmOO$$~~~~PP88
!!!!!!!!00nn~~~~FF!!!! 44DD==//??~~((55;;~~~~~~~~~~~~~~~~nn~~~~!!
!!!!!!!!00nn~~~~FF!!!! 44DD==//??~~((55;;~~~~~~~~~~~~~~~~nn~~~~!!
LL!!!!!!!!ggVV88((!!!!!!88!!VVPPGG~~!!99QQ??VV~~~~~~~~~~~~~~??PP((
LL!!!!!!!!ggVV88((!!!!!!88!!VVPPGG~~!!99QQ??VV~~~~~~~~~~~~~~??PP((
""3366!!!!!!!!!!!!!!!!!!!!!!!!!!''ggVV22RR~~~~~~gg~~~~~~~~~~~~VV//22
""3366!!!!!!!!!!!!!!!!!!!!!!!!!!''ggVV22RR~~~~~~gg~~~~~~~~~~~~VV//22