이미지 평균


23

이미지는 다음과 같습니다.

%%%%%%%%%%%%%
% Hello,    %
%    world! %
%%%%%%%%%%%%%

그러나 크기가 작은 뇌가 계산하기에는 너무 혼란 스럽습니다. 그래서 우리는 이것을 다음과 같이 평균합니다 :

  1. 2 x 2 섹션으로 나눕니다. 섹션이 완성되기 전에 그림이 끝나면 공간이 있다고 상상해보십시오.

  2. 각 섹션에서 ASCII 문자의 값을 평균하십시오.

  3. 이 평균을 반올림하여 ASCII 문자로 변환하십시오.

  4. 마지막으로 섹션의 모든 문자를 평균 문자로 바꿉니다.

모든 섹션에 대해이 과정을 반복하십시오.

위의 이미지 평균은 다음과 같습니다.

$$>>II99######
$$>>II99######
$$##88KKGG####
$$##88KKGG####

작업 : ASCII 이미지를 입력으로 사용하여 평균을 출력하는 프로그램을 작성하십시오.

참고 정수는 함수 floor(x+0.5)또는 유사한 함수 로 반올림됩니다 . 즉, 반을 반올림합니다.


1
너비가 홀수이면 어떻게됩니까?
Leaky Nun

3
@KennyLau "섹션이 완성되기 전에 그림이 끝나는 경우 공간이 있다고 상상해보십시오." 너비가 홀수 인 경우를 포함한다고 생각합니다.)
Katenkyo

높이가 항상 일정하다고 가정 할 수 있습니까?
FliiFe

2
@DenkerAffe 아니오. 부정 행위 일 것입니다. : P

1
예상되는 동작을 명확히하기 위해 7x7 이미지가 아래쪽과 오른쪽 가장자리에 공백이있는 8x8 이미지로 작동합니까? 따라서 출력도 8x8입니까?
wnnmaw

답변:


7

자바 스크립트 (ES6), 159 바이트

document.write("<pre>"+(

// --- Solution ---
s=>s.replace(/./g,(c,i)=>(a=String.fromCharCode([t=0,1,l=s.search`
`+1,l+1].map(o=>t+=(n=s.charCodeAt(p=i+o-i%l%2-(i/l|0)%2*l))>32?n:32)|t/4+.5))+(++p%l?"":a))
// ----------------

)(`%%%%%%%%%%%%%
% Hello,    %
%    world! %
%%%%%%%%%%%%%`))

여러 줄 문자열을 입력으로받습니다.


Firefox에서 실행하면 잘못된 출력이 생성됩니다.
Trebuchette

@ Trebuchette 아, 나는 우주 규칙을 잘못 해석했습니다. 이제 수정되었습니다.
user81655

4

MATL , 32 30 바이트

2thZCO32XEoYmYocGZy2/Xke2t3$Y"

입력은 행으로 구분 된 2D 문자 배열 ;입니다.

온라인으로 사용해보십시오!

설명

2th     % push array [2 2]
ZC      % take input implicitly. Arrange distinct 2x2 blocks as columns, padding with 0
O32XE   % replace 0 by 32 (space)
oYm     % convert to number. Take mean of each column
Yoc     % round. Convert to char
GZy     % size of input in the 2 dimensions
2/Xk    % divide each dimension by 2, and round up to account for the padding
e       % reshape into image with half original size in each dimension
2t3$Y"  % replicate by a factor of 2 in each dimension. Display implicitly


1

루아, 382 376 367 353 348 바이트

r="\n"o=... n=o:find(r)-1
l=n+n%2
a=o:gsub(r,(n~=l and" "or"")..r).." "..(#o//(l+1)%2<1 and r..(" "):rep(l)or"")print(a:gsub("()([^\n])(.)",function(p,m,c)t=p//(l+1)%2==0return string.char(math.floor((m:byte()+c:byte()+(t and a:sub(p+l+1,p+l+1)or a:sub(p-l,p-l)):byte()+(t and a:sub(p+l+2,p+l+2)or a:sub(p-l-1,p-l-1)):byte())/4+.5)):rep(2)end).."")

명령 행에서 작동합니다. 테스트 케이스와 같은 문자열을 허용합니다.


ungolfed 버전을 포함 하시겠습니까?
Leaky Nun

0

루비, 235230 바이트

->i{i=i.split($/).map{|s|s.bytes+[s.size%2>0?32:0]}
w=i[0].size;h=i.size;h+=h%2;r=[[]]*h
(h/2).times{|y|y*=2
(w/2).times{|x|x*=2
c=((i[y][x,2]+(i[y+1]||[32]*w)[x,2]).inject(:+)/4.0).round.chr
r[y+1]=r[y]+=[c,c]}}
r.map(&:join)*$/}

0

파이썬, 319 바이트

def f(A):
 L,R,S=len,range,A.split('\n')
 if L(S[0])%2:S=[s+' 'for s in S]
 m=L(S[0])
 if L(S)%2:S+=[' '*m]
 C=[chr(int(sum(map(ord,[S[i][j],S[i+1][j],S[i][j+1],S[i+1][j+1]]))/4.0+0.5))for i in R(0,L(S),2)for j in R(0,m,2)]
 f=t='';i=0
 while i<L(C):
    t+=C[i]*2
    i+=1
    if i%(m/2)<1:f+=(t+'\n')*2;t=''
 f=f[:-1]
 print f

두 번째 들여 쓰기는 탭입니다.

전에 물건 C은 패딩이며, C단일 문자에 대한 평균 프로세스이며 나머지는 출력됩니다


0

R, 433 399 바이트

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")

이 일이 경쟁이 아닌 것처럼 보이기 때문에 필사적입니다. 인쇄

$$>>II99######
$$>>II99######
$$##88KKGG####
$$##88KKGG####

테스트 케이스.

7 × 3을 먹으면

%%%%%%%
Example
%%%%%%%

출력은

BBFFJJ33
BBFFJJ33
######!!
######!!

2 등으로 나눌 수 있기 때문에

언 골프 드 :

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)

이 멋진 예제를 어떻게 처리하는지보십시오 (chris.com 제공).

                                                M$$$$$$$$$$$$$$$$RMMMMM8MMX    
                                               <$$$$$$$$$$$$R????!!?MMMR$RMMh. 
                                              :M$$$$$$$R?!!~~~~!!!!!!!MMM$$$$X 
                                             :M$$$$$$$X!~~~   ~~~~~!!MM8$MM$$M!
                                           :!XM$$$$$$R!~~~~~  ~~~~~!!M$$$$$$$R!
                                          <!XM$$$$$$MR!~~~~ ~~ ~:!!<:!M$$$$$$$!
                                         '<!XMBQQRMMMMX:::~~~<!?!!~~!!!!$$$M!$X
                                         ~!!MM$$$$$M8R!!!?!:~!!M$f?!~~~!M$8HXX?
                                       <!!!XMM$$$$$MMRM$$!~!~~~~~~~~~~~!XM?!!M!
                                      <!!!!XMM$$M$$MM$M!!~~~ ~~~ ~  :~!!!X!~~R!
                                      !!!!XMMM$MMMMMMMM!!~~~ ~~~~  ~~~!!!X~~X!~
                                      '~~!!MMMM@MMMX!!MM!:~!!!~~  `~~~~!!XXXX~ 
                                        ~!!!XMMMMMMMM!MMM!~~~~:: <<~~~~!!$$R!  
                                        '!!!!MM888M$MXMMM!!!!()!!~~~~~<!X$$$>  
                                         ~!!!M???M$MRRMM$X<~!!!!~~~~~:!XN$$M   
                                          ~!!!!!M$$$$@$@$$!!~~'  ~~:XH8$$$WR   
                                          !!!!MM$RM$RRMMMM?t!:::XX8$$$$$$$$>   
                                         ~~!!MMM$$$$$WX!!!!!!$$$$$$$RR$$$R"    
                                       '  <!!MT!!!~~~!#BX!!!~~?T#?!!!M$$$X.    
                                         <!!!!~~~~~~~~~?$!!!~~~~~~:!M$$$$MXH:  
                                         ~~~~~~~~~~~ ~~!M&!!!~~~<!!X$$$$$$$R$W>
                                        <~~~~~~~~    '~~!$!!!!!!!!MMRM$R?#!!$N!
                                       x~~~~~~~~~    ~~~!MX!!!!!!?!M!M!~~:!!$B!
                                      M!~~~~~~~~~~  <~~:!$R!!!!!!!X!!!~~!!~!RR!
                                    :M!~~~~~~~~~~~ `~~~!X$R!!!!!!!!~~~:!!~~tMM!
                                   dR!!~~~~~~~~~~~~~~~~!M$R!!!!!!!~!!!!!!~~@$@~
                                  tR!!!~~~~~~~~~~~~~~~!!M$R!!!!!!!!!!!!!~~!$$E~
                                 d!~~~~~~~~~~~~~~~~~~~!!$$X!!!!!!!!!!!!~~~X$$!~
                                8R~~~~~~~~~~~~~~~~~~~<!X$$!!!!!!!!!!!<~~~!MR$~~
                               8$~~~~~~~!~~~~~~~~~~~<!!$$R!!!MX!!!!~~~~~<XR$!~<
                             :$$!~~~~~~!!~~~~~~~~~~~!!M$$!!!!MM!!!~~~~~<!8$F~<!
                          .x8$$$!~~~~::!~~~~~~~~~~~!!X$$$!!!!MM!!~~~~~!!M$R~~~!
               .::xxxnHW8$$$$$$$$$$$$$$!!~~~~~~~~~~<!@$$X!!!!MM~~~~~<!!X$E~~~~!
          :t$$$$$$$$$$$$$$$$$$$$$$$$$$$!!~~~~~~~~~~!X$$$X~!!!MX~~~~~!!X$$~~~~!!
       ~~~~#R$$$$$RR8$$$$$$$$$$$$$$$$$$!!~~~~~~~~~<!M$$$B~!!!M!~~~~~!X$$!~~~~!!
     ~~~~~~~~?$$$$$$$$$$$$$$$$$$$$$$$$$!!~~~~~~~~~!!$$$$$X!!X$!~~~~!X$$R~~~~<!f
  :~~~~~~~~~`~?$$$$$$$$$$$$$$$$$$$$$$$$!!~~~~~~~~!!X$$$$$$X!M$~~~<!W$$R~~~~~!! 
 ~~~~~~~~~~  ~~M$$$$$$$$$$$$$$$$$$$$$$$!!~~~~~~~~!!M$$$$$$$$$Bid$$$$$$!~~~~~!! 
!~~~~~~~~~~~~~~~$$$$$$$$$$$$$$$$$$$$$$$!~~~~~~~~~!!$$$$$$$$$$$$$$$$$$!~~~~~~!~ 
!~~~~~~~~~~~~~~~M$$$$$$$$$$$$$$$$$$$$$$!:~~~~~~~<!X$$$$$$$$$$$$$$$$$!~~~~~~!!  
~~~~~~~~~~~~~~!!!$$$$$$$$$$$$$$$$$$$$$R!!:~~~~~~!!M$$$$$$$$$$$$$$"XR~~~~~~~!!  
~~~~~~~~~~~~~!!!!$$$$$$$$$$$$$$$$$$$$$R!<!~~~~~!!!X$$$$$$$$$$$P~  !~~~~~~~!!   
~~~~~~~~~~~<!!!!!$$$$$$$$$$$$$$$$$$$$$X!!~~~~~<!!!@#""`           ~~~~~~~~!!   
~~~~~~~~~~~!!!!!X$$$$$$$$$$$$$$$$$$$$$X!~~~~~~!!!                '~~~~~~~!!    
~~~~~~~~~~~<!!!!M$$$$$$$$$$$$$$$$$$$$$X!~~~~~!!!f                '~~~~~~<!!    
~~~~~~~~~~~~~!!!$$$$$$$$$$$$$$$$$$$$$R!~~~~~~!!!                 '~~~~~<!!>    
~~~~~~~~~~~~~~!!M$$$$$$$$$$$$$$$$$$$" !~~~~~!!!!                 ~~~~~~!!!     
~~~~~~~~~~~~~~!!!$$$$$$$$$$$$$$$$$R~ .!~~~~~!!!                  ~~~~~!!!!     
~~~~~~~~~~~~~~~!!!$$$$$$$$$$$$$*?!!!~!!~~~~<!!~                  ~~~~!!!!!     
~~~~~~~~~~~~~~~~!!!$$$$$$$$*"~!!!!!!!!!~~~~!!!                  <~~~:!!!!!     
!~~~~~~~~~~~~~~~~!!M$$$$#~~~~~~~~~~~!!~~~~~!!                   ~~~~~~~!!!     
!<~~~~~~~~~~~~~~~!!!R"~~~~~~~~~~~~~!!!~~~~<!!                  '~~~~~~<!!      
!<~~~~~~~~~~~~~~~~!!!~~~~~~~~~~~~~~!!~~~~~!!!X:                ~~~~~~~!!~      
!!~~~~~~~~~~~~~~~~!!!!~~~~~~~~~~~~<!!~~~~!!!9$MX:              ~~~~~~<!!       
!!!!!~~~~~~~~~~~~~!!!!:~~~~~~~~~~~!!~~~~~!!X$$$X!~            '~~~~~~!!~       
!!!!!!~~~~~~~~~~~<!!!!!!~~~~~~~~~~!!~~~~!!!M$$R!~~~~          ~~~~~~!!!        
!!!!!!!<~~~~~~~~~~~!!!!!!!:<:~~~~~!!~~~~!!X$$R!~~~~~~         ~~~~~~!!         
!!!!!!!!~~~~~~~~~~<!!!!!!!!!!!!!<!!!~~~~!!@$$!~~~~~~~~        ~~~~~!!~         
!!!!!!!!!~~~~~~~~:<!!!!X!!!!!!!!!!!!~~~!!X$$!~~~~~~~~~~~~:   '~~~~~!!          
'!!!!!!!!!!~~~~~~~!!!!!!?!!!!!!!!!!!~~<!!M$M!~~~~~~~~~~~~~~~ '~~~~~!~          
 !!!!!!!!!!\~~~~~~~>!!!!  `"MMMHX!!~~~<!!$R!~~~~~~~~~~~~~~~~~<~~~~!!           
  !!!!!!!!!!<~~~~~<!!!!!   .::<!!!!<~~!!X8X!~~~~~~~~~~~~~~~~~~~~~~!!           
  `X!!!!!!!!~~~~~!<!!!!!!!!!!!!~~!!\~~!!M$MX!:~~~~~~~~~~~~~~~~<!~~!>           
  !X!!!!!!!!~!!:!!!!!!!!!!~!!!:~~!!~~~!!$M!~~!!<~~~~~~~~~~~~~~~!!!!            
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:!!~~:!9R!~~~~~~!~~~~~~~~~~~~~~<!!f            
 'CHAT!!!!!!!!!!!!!!!!!!!!!!!!!!!!~~~!!MX~~~~~~~~~~~~~~~~~~~~~~!!X             

후:

                                              ''..$$$$$$$$$$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  
~~~~~~~~~~~~gg!!##$$$$$$$$$$$$$$$$$$$$::..~~~~gg!!;;$$$$$$$$$$FF""RR~~~~~~88    
~~~~~~~~~~~~gg!!##$$$$$$$$$$$$$$$$$$$$::..~~~~gg!!;;$$$$$$$$$$FF""RR~~~~~~88    
~~~~~~~~~~VV!!!!00$$$$$$$$$$$$$$$$$$$$==gg~~~~((!!))!!00        ""~~~~~~gg!!    
~~~~~~~~~~VV!!!!00$$$$$$$$$$$$$$$$$$$$==gg~~~~((!!))!!00        ""~~~~~~gg!!    
~~~~~~~~~~nn88!!..$$$$$$$$$$$$$$$$$$00FF~~~~PP!!22              $$~~~~nn((((    
~~~~~~~~~~nn88!!..$$$$$$$$$$$$$$$$$$00FF~~~~PP!!22              $$~~~~nn((((    
~~~~~~~~~~~~~~!!..$$$$$$$$$$$$$$$$FF$$PP~~~~!!!!                OO~~~~88!!      
~~~~~~~~~~~~~~!!..$$$$$$$$$$$$$$$$FF$$PP~~~~!!!!                OO~~~~88!!      
~~~~~~~~~~~~~~gg!!##$$$$$$&&::$$))!!88PP~~VV!!88                VV~~??!!!!      
~~~~~~~~~~~~~~gg!!##$$$$$$&&::$$))!!88PP~~VV!!88                VV~~??!!!!      
??~~~~~~~~~~~~~~PP,,//QQgg~~~~~~~~gg!!~~~~??!!                ""~~~~~~??!!      
??~~~~~~~~~~~~~~PP,,//QQgg~~~~~~~~gg!!~~~~??!!                ""~~~~~~??!!      
((~~~~~~~~~~~~~~~~!!88~~~~~~~~~~~~??PP~~gg!!66@@''            OO~~~~nn!!88      
((~~~~~~~~~~~~~~~~!!88~~~~~~~~~~~~??PP~~gg!!66@@''            OO~~~~nn!!88      
!!!!88~~~~~~~~~~nn!!!!??~~~~~~~~~~!!~~~~88::$$<<ggOO          hh~~~~8888        
!!!!88~~~~~~~~~~nn!!!!??~~~~~~~~~~!!~~~~88::$$<<ggOO          hh~~~~8888        
!!!!!!((~~~~~~~~~~??!!!!!!..??PPVV!!~~~~!!88//gg~~~~gg        ~~~~gg88          
!!!!!!((~~~~~~~~~~??!!!!!!..??PPVV!!~~~~!!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            

0

루비 180 158 148 128 + 4 124 + 4 = 128 바이트

$ ruby -nl( -nl플래그에 +4 바이트)로 실행하십시오 . STDIN에서 입력을받습니다.

y,x=x,$_.scan(/..?/)
(puts [x.zip(y).map{|c|(("%2s"*2%c).bytes.reduce(:+)/4.0).round.chr*2}*""]*2
y,x=x,[])if$.%2<1||$<.eof?

ideone에서 참조하십시오 : http://ideone.com/brmP3L

언 골프 및 설명

man ruby-n플래그 "[C] auses 루비는 ... 스크립트의 주위에 다음과 같은 루프를 가정합니다 while gets ... end." 특수 변수 $_에는 마지막으로 읽은 행이 포함됩니다 gets. -l플래그를 제거 \n하는 것과, 각 라인에서 $_.chop!.

y, x = x, $_.scan(/..?/)

( puts [
    x.zip(y).map {|c|
      (("%2s" * 2 % c).bytes.reduce(:+) / 4.0).round.chr * 2
    } * ""
  ] * 2
  y, x = x, []
) if $. % 2 < 1 || $<.eof?

특수 변수 $.는 지금까지 읽은 행 수 $<이며 STDIN입니다. 두 번째 줄의 문자 쌍은 이전 줄의 문자와 압축됩니다. 형식 문자열 %2s%2s은 문자를 결합하고 공백으로 채운 다음 문자의 평균을냅니다.


1
w=s=~/$/초기 너비를 계산하는 데 더 짧습니다. 또한 출력으로 계산되기 때문에 인쇄 대신 계산 된 문자열을 반환하십시오.
Value Ink
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.