[Haskell-cafe] Roman Numerals and Haskell Syntax abuse

ajb at spamcop.net ajb at spamcop.net
Mon Jul 5 22:35:16 EDT 2004

G'day all.

Quoting George Russell <ger at informatik.uni-bremen.de>:

> The following declaration for a function for converting positive
> integers to Roman numerals is 181 characters long.
> Is there a shorter one?

Being a judge, I can't write your obfuscated haskell contest entry for
you.  However, as a suggestion, you may be able to merge the if-then-else
with the guard syntax.  That should save a few characters.

> roman=f[(i-j,i)|i<-[2,4..8],j<-[2,1]]where
> f(d@((a,b):c))n|n<1=""|n>=t!!a=s!!a:f d(n-t!!a)|1>0=if n+t!!b>=t!!a then
> s!!b:f d(n+t!!b)else f c n;s="mdclxvi";t=[1000,500,100,50,10,5,1]

Andrew Bromage

More information about the Haskell-Cafe mailing list