Author | Message |
---|---|
rabbott
Posts: 1649
|
Posted 15:53 Sep 27, 2016 |
On Monday we talked about a solution to the Roman-to-Arabic problem. Here it is again translate :: Char -> Int translate 'I' = 1 translate 'V' = 5 translate 'X' = 10 translate 'L' = 50 translate 'C' = 100 translate 'D' = 500 translate 'M' = 1000
romanToArabic :: String -> Int romanToArabic "" = 0 romanToArabic [r] = translate r romanToArabic str = num + romanToArabic rest where (num, rest) = oneStep str
oneStep :: String -> (Int, String) oneStep (r1:r2:rest) | translate r1 < translate r2 = (translate r2 - translate r1, rest) | otherwise = (translate r1, r2:rest)
So far, this is the cleanest solution to this problem I have seen that uses only the constructs covered to the time the project was assigned. That doesn't mean there isn't an even better solution. But this is the best I've seen. I mention this because I want you to know that I value craftsmanship and code elegance. There is no definitive definition of what it means for code to be elegant. Here are a few attempts. When I talk to you about your code, one of the things I notice is whether you have attempted to make your code elegant. You don't have to achieve perfection, but when I see code that looks like you don't care about it, I downgrade my estimate of you. Among the basic things you should think about are:
I want to see that you have pride in your product. Unless it's clear that you have made the code as good as you can, you convey the impression that don't have pride in your product and don't care about your workmanship.
Last edited by rabbott at
15:53 Sep 27, 2016.
|