[Haskell-cafe] Re: Roman Numerals and Haskell Syntax abuse

Christian Maeder maeder at tzi.de
Tue Jul 6 05:39:55 EDT 2004


> George Russell wrote (snipped):
> 
> Now 145.
> roman=(0#);a#n|n<1=""|n>=t!!a=s!!a:a#(n-t!!a)|n+t!!b>=t!!a=s!!b:a#(n+t!!b)|1>0=(a+1)#n 
> where b=2*div a 2+2;s="mdclxvi";t=[1000,500,100,50,10,5,1]

138
roman=(!6);n!a|n<1=""|n>=t=s!!a:(n-t)!a|n+c>=t=s!!(2*e):(n+c)!a|1>0=n!(a-1)where(d,m)=a`divMod`2;e=d+m-1;s="ivxlcdm";c=10^e;t=10^d*(1+4*m)



More information about the Haskell-Cafe mailing list