Currency exchange rate

STDIN contains the exchange rate of 1 USD against other currencies.
STDOUT should contain a cross-table relationships each currency for each.

The columns should be sorted the same way as in the original list, table cells should be separated by two spaces.

IN

1 USD
0.82 EUR
1.23 AUD
0.99 CHF
1.32 SGD
52.03 RUB

OUT

\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1

IN

1 USD
0.82 EUR

OUT

\    USD   EUR
USD  1     0.82
EUR  1.22  1

IN

1 USD

OUT

\    USD
USD  1
Login to submit solution


53 symbols pyth
Wed Nov 23 18:17:56 2016 Sait2000
ACJcR;.zj*3d+"\ "Hj.brj*2d+Ym?qNd+1*3;%"%.2f"cvdvNG6J
53 symbols pyth
Wed Nov 23 18:25:25 2016 Sait2000
.vCim-id64^964 2cCM"瞻瞺䃴㢲榰⿵仓埳忋㰊㯲翺㟂熻曽䴁寴㣁㟃䢵⾵㯂玲焆爆寗䏚"3^4 8
54 symbols pyth
Thu Nov 3 19:04:03 2016 Sait2000
.vCim-id64^964 2cCM"瞾茂瞺㿴㣵曽䴁痩熻㺺䃋㊲㊾㿶⿳菴菸曗䏓仓竳熹㰊瞺䃴㢲榰⿘"3^4 8
54 symbols pyth
Wed Nov 23 18:12:44 2016 Sait2000
ACJcR;.zj*3d+"\ "HF,kbJrj*2d+bm?qkd+1*3;%"%.2f"cvdvkG6
55 symbols pyth
Tue Sep 27 05:24:30 2016 Sait2000
ACJmcd).zj*3d+"\ "HF,kbJrj*2d+bm?qkd+1*3;%"%.2f"cvdvkG6
154 symbols perl
Tue Jan 13 16:34:47 2015 vakorol
#!/usr/bin/perl -p
/\S+$/;$s||='\ ';push@n,$&;push@v,$`;$s.="   $&"}{$s.="\n$n[$i]",(map{$s.=sprintf$_-$v[$i]?"  %.2f":"  1   ",$_/$v[$i]}@v),$i++while$i<@n;$_=$s;s/ +.$//
155 symbols perl
Tue Jan 13 12:28:25 2015 vakorol
#!/usr/bin/perl -p
/\S+$/;$s||='\ ';push@n,$&;push@v,$`;$s.="   $&"}{$s.="\n$n[$i]",(map{$s.=sprintf$_==$v[$i]?"  %-4i":"  %.2f",$_/$v[$i]}@v),$i++while$i<@n;$_=$s;s/ +.$//
166 symbols perl
Sun Jan 11 20:27:21 2015 danieljabailey
#!/usr/bin/perl -n
s/(\D{3})$//;push@c,$1;$m{$1}=$_}{sub p{print@_}p"\\ ";p"   $_"for@c;p$/;for(@c){p$_;$v=$_;$v eq$_?p$c[-1]ne$v?"  1   ":"  1":printf"  %.2f",$m{$_}/$m{$v}for@c;p$/}
168 symbols python2
Wed Oct 12 07:57:02 2016 Sait2000
import sys
z=map(str.split,sys.stdin)
d,l=zip(*z)
print'\    '+'   '.join(l)
for p,i in z:print'  '.join([i]+['%%-.42.ff'[p!=q::2]%(eval(q)/eval(p))for q in d]).strip()
169 symbols perl
Sun Jan 4 01:47:43 2015 vakorol
#!/usr/bin/perl -p
/\S+$/;$s||='\ ';push@n,$&;push@v,$`;$s.="   $&"}{$s.="\n";$s.=$n[$i],(map{$s.=sprintf$_==$v[$i]?"  %-4i":"  %.2f",$_/$v[$i]}@v),$s.="\n",$i++while$i<@n;$_=$s;s/ +.$//
170 symbols perl
Sun Jan 4 01:46:13 2015 vakorol
#!/usr/bin/perl -ap
/\S+$/;$s||='\ ';push@n,$&;push@v,$`;$s.="   $&"}{$s.="\n";$s.=$n[$i],(map{$s.=sprintf$_==$v[$i]?"  %-4i":"  %.2f",$_/$v[$i]}@v),$s.="\n",$i++while$i<@n;$_=$s;s/ +.$//
170 symbols python2
Wed Oct 12 07:53:02 2016 Sait2000
import sys
z=map(str.split,sys.stdin)
d,l=zip(*z)
print'\    '+'   '.join(l)
for p,i in z:print'  '.join([i]+['%%-.42.ff'[p!=q::2]%(float(q)/float(p))for q in d]).strip()
171 symbols python2
Fri Sep 23 09:29:27 2016 Sait2000
import sys
z=map(str.split,sys.stdin)
d,l=zip(*z)
print'   '.join(('\ ',)+l)
for p,i in z:print'  '.join([i]+[['%.2f'%(float(q)/float(p)),'1   '][p==q]for q in d]).strip()
175 symbols python2
Fri Sep 23 09:22:23 2016 Sait2000
import sys
d,l=zip(*map(str.split,sys.stdin));d=map(float,d)
print'   '.join(('\ ',)+l)
for p,i in zip(d,l):print'  '.join([i]+[['%.2f'%(q/p),'1   '][p==q]for q in d]).strip()
180 symbols perl
Mon Dec 29 20:14:09 2014 danieljabailey
sub p{print@_}for(<>){s/(\D{3})$//;push@c,$1;$m{$1}=$_}p"\\ ";for(@c){p"   ",$_}p$/;for(@c){p$_;$v=$_;for(@c){($v eq$_)?p$c[-1]ne$v?"  1   ":"  1":printf"  %.2f",$m{$_}/$m{$v}}p$/}
186 symbols python2
Fri Sep 23 09:14:51 2016 Sait2000
import sys
d,l={},[]
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=b,
print'   '.join(['\ ']+l)
for i in l:print'  '.join([i]+[['%.2f'%(d[j]/d[i]),'1'+'   '*(i!=b)][i==j]for j in l])
195 symbols python2
Fri Sep 23 09:10:22 2016 Sait2000
import sys
d,l={},[]
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=b,
print'   '.join(['\ ']+l)
for i in l:print'  '.join([i]+[['{0:.2f}'.format(d[j]/d[i]),'1'+'   '*(i!=b)][i==j]for j in l])
203 symbols python2
Fri Oct 9 20:01:11 2015 BogdanShevchenko
import sys
d,l={},[]
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join(['\ ']+l)
for i in l:print '  '.join([i]+[["{0:.2f}".format(d[j]/d[i]),'1'+'   '*(i!=l[-1])][i==j] for j in l])
227 symbols python2
Mon Dec 29 17:24:54 2014 PFischbeck
import sys
c=[]
d=[]
for s in sys.stdin:
 [a,b]=s.split()
 d+=[float(a)]
 c+=[b]
print"\\    "+"   ".join(c)
l=range(len(c))
for i in l:print"  ".join([c[i]]+[("%.2f"%(d[j]/d[i]),"1"+"   "*(not(i==j==l[-1])))[i==j] for j in l])
267 symbols haskell
Sun Mar 15 12:57:53 2015 YoshikuniJujo
import Numeric
import Data.List
m=map
a=reverse
main=interact$unlines.m(a.dropWhile(==' ').a.intercalate"  ").s.m((\[r,n]->(read r,n)).words).lines
s e=("\\  ":m((++" ").snd)e):zipWith(:)(m snd e)(m(m i.((\x->m((/x).fst)e).fst))e)
i 1="1   "
i x=showFFloat(Just 2)x""

View all solutions