Simple Compression

Count the same character in a string of one line. 
Output it with a number you count the back of the character. 
If the character is 1 character, should be output as it is.

IN

aaaaaaaaaabbbbbbbbbbbbcccccccddddddddddeeeeeeefffffffffghiiiiiiiii

OUT

a10b12c7d10e7f9ghi9

IN

http://www.google.co.jp/

OUT

ht2p:/2w3.go2gle.co.jp/

IN

ASCII art (((((((( ;°A°))))))) Nooooo(°A°;)ooooh!!!!

OUT

ASCI2 art (8 ;°A°)7 No5(°A°;)o4h!4
Login to submit solution


15 symbols pyth
Mon Sep 19 14:24:24 2016 Sait2000
Vrz8peNp?thNhNk
25 symbols perl
Fri Sep 26 16:40:15 2014 vakorol
#!/usr/bin/perl -p
s/(.)\1+/$1.length$&/ge
25 symbols perl
Tue Oct 14 00:34:54 2014 maxymania
#!/usr/bin/perl -p
s,(.)\1+,$1.length$&,eg
26 symbols perl
Wed Sep 24 21:06:45 2014 vakorol
#!/usr/bin/perl -p
s/(.)\1+/$1.length$&/ge
27 symbols perl
Fri Sep 26 00:33:17 2014 gabrielmad
#!/usr/bin/perl -p
s/((.)\2+)/$2.length$1/ge
29 symbols perl
Sun Aug 24 12:09:08 2014 gabrielmad
#!/usr/bin/perl -p
s/((.)\2+)/$2.(length$1)/ge
31 symbols perl
Tue Jun 24 10:44:25 2014 avkhozov
#!/usr/bin/perl -p
s/(.)(\1+)/$1.(1+length$2)/ge
38 symbols perl
Tue Sep 23 01:47:49 2014 maxymania
$_=<>;s{((.)\2+)}{$2.length$1}eg;print
58 symbols bash
Thu Aug 18 22:26:01 2016 hidefromkgb
eval echo \"`sed 's/\(.\)\1\1*/\1$[$(wc -m<<<"&")-1]/g'`\"
87 symbols python2
Wed Oct 19 08:57:56 2016 Sait2000
n=1
p=s=''
for c in raw_input()+' ':
 if c!=p:s+=`n`*(n>1)+c;n=0
 n+=1;p=c
print s[:-1]
93 symbols python2
Mon Aug 11 13:01:05 2014 xsot
n=1
p=s=''
for c in raw_input()+' ':
 if c!=p:s+=`n`*(n>1)+c;n=1
 else:n+=1
 p=c
print s[:-1]
94 symbols python3
Sat Aug 9 01:02:11 2014 z423x5c6
a=input()
b=0
c=a[0]
for i in a+' ':
 if i==c:b+=1
 else:print(c+str(b)*(b!=1),end='');b=1;c=i
102 symbols haskell
Wed Mar 18 07:04:43 2015 YoshikuniJujo
import Data.List
main=interact$concatMap s.map(\x->(head x,length x)).group
s(c,1)=[c]
s(c,n)=c:show n
112 symbols python3
Fri Aug 8 13:37:31 2014 vik
r=input()
s,h,i="",r[0],0
for c in r:
 if c==h:i+=1
 else:s+=h+str(i)*(i!=1);i=1;h=c
s+=h+str(i)*(i!=1)
print(s)
115 symbols python2
Fri Aug 8 13:00:53 2014 PFischbeck
r=raw_input()
s=""
h=r[0]
i=0
for c in r:
 if c==h:i+=1
 else:s+=h+str(i)*(i!=1);i=1;h=c
s+=h+str(i)*(i!=1)
print s
120 symbols python3
Fri Aug 8 05:22:25 2014 vik
r,s=input(),""
h,i=r[0],0
for c in r:
 if c==h:i+=1
 else:s+=h+str(i)*(i!=1);i,h=1,c
s+=h+str(i)*(i!=1);i,h=1,c
print(s)
123 symbols python2
Fri Aug 8 04:12:38 2014 PFischbeck
r=raw_input()
s=""
h=r[0]
i=0
for c in r:
 if c==h:i+=1
 else:s+=h+str(i)*(i!=1);i=1;h=c
s+=h+str(i)*(i!=1);i=1;h=c
print s
123 symbols python2
Fri Aug 8 05:21:43 2014 vik
r,s=raw_input(),""
h,i=r[0],0
for c in r:
 if c==h:i+=1
 else:s+=h+str(i)*(i!=1);i,h=1,c
s+=h+str(i)*(i!=1);i,h=1,c
print s
125 symbols python3
Sat Aug 9 00:58:35 2014 z423x5c6
a=input()
b=0
c=a[0]
p=print
for i in a+' ':
 if i==c:b+=1
 else:
  if b==1:p(c,end='')
  else:p(c+str(b),end='')
  b=1
  c=i
132 symbols haskell
Thu Jun 26 23:56:32 2014 salvipeter
import Control.Arrow
import Data.List
x(a,1)=[a]
x(a,n)=[a]++show n
main=do{s<-getLine;putStr$concat$map(x.(head&&&length))$group s}

View all solutions