[Haskell-cafe] Roman to Decimal Algorithms
Andrew Savige
ajsavige at yahoo.com.au
Sun Jun 7 18:47:23 EDT 2009
Martijn van Steenbergen wrote:
> Why not rename mod like so?
>
> (%)=mod
> rtoa c=10^(205558%ord c%7)%9995
Thanks Martijn. My first Haskell golfing tip. :)
I found I had to write it with an extra set of parens to get it to work:
rtoa c=(10^(205558%ord c)%7)%9995
Though it wasn't my original intention to play Haskell golf, assuming
upper case Roman Numerals, we can now write the whole thing as:
(%)=mod
romanToInt=foldl1(\t n->t+n-t%n*2).map(\c->(10^(205558%ord c)%7)%9995)
Can anyone shorten that further?
Thanks,
/-\
Need a Holiday? Win a $10,000 Holiday of your choice. Enter now.http://us.lrd.yahoo.com/_ylc=X3oDMTJxN2x2ZmNpBF9zAzIwMjM2MTY2MTMEdG1fZG1lY2gDVGV4dCBMaW5rBHRtX2xuawNVMTEwMzk3NwR0bV9uZXQDWWFob28hBHRtX3BvcwN0YWdsaW5lBHRtX3BwdHkDYXVueg--/SIG=14600t3ni/**http%3A//au.rd.yahoo.com/mail/tagline/creativeholidays/*http%3A//au.docs.yahoo.com/homepageset/%3Fp1=other%26p2=au%26p3=mailtagline
More information about the Haskell-Cafe
mailing list