Sort by

recency

|

205 Discussions

|

  • + 1 comment

    I didn't like this challenge. I wasn't sure how to approach this at first, then decided I should do it by base-10 number place values. I started with the ones and built up from there. After I thought the regex was about 80% complete, I submitted it to the HackerRank tester. It found a couple of problems, which took a few minutes more to fix.

    The regex is not exhaustive, but it passed all the HackerRank tests. I see others have posted more concise ones here, but are they exhaustive? Clearly, I have more to learn about regexes.

    regex_pattern = r"^(M{,3}(?=([^M]))){,1}(C{,1}M{,1}){,1}(C{,1}D{,3}){,1}(X{,1}C{,3}){,1}(X{,1}L{,1}){,1}(I{,1}X{,3}){,1}(I{1,3}[VX]{,1}|VI{,3}){,1}$"
    
    import re
    print(str(bool(re.match(regex_pattern, input()))))
    
  • + 0 comments
    regex_pattern = r"^M{,3}(CM|CD|D?C{,3})(XL|L?X{,3}|XC)(I{,3}|IV|V?I{,3}|IX)$"
    
    import re
    print(str(bool(re.match(regex_pattern, input()))))
    
  • + 0 comments

    Here is HackerRank Validating Roman Numerals in Python solution - https://programmingoneonone.com/hackerrank-validating-roman-numerals-solution-in-python.html

  • + 0 comments

    Interesting problem, and I learned a fine point or two about Roman numerals. :)

    My solution is a little different in that I didn't use any | alternatives:

    regex_pattern = r"^M{0,3}(CM)?(C?D)?C{0,3}(XC)?(X?L)?X{0,3}(IX)?(I?V)?I{0,3}$"

  • + 0 comments

    regex_pattern = r"^(M{0,3})(C{0,3}|CD|D|DC|DCC|DCCC|CM)(X{0,3}|XL|L|LX|LXX|LXXX|XC)(I{0,3}|IV|V|VI|VII|VIII|IX)$"

    import re print(str(bool(re.match(regex_pattern, input()))))