Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges The 50 substrings that validate any string of Roman numerals

Python, 344 bytes 534 bytes: This is not golfed in any way. But it's the current winner! def validate_roman_numeral(candidate): invalid_strings = ["CCCC", "CCD", "CCM", "CDC", "CMC", "CMD",...

posted 8mo ago by daviewales‭  ·  edited 5mo ago by daviewales‭

Answer
#5: Post edited by user avatar daviewales‭ · 2024-07-09T04:00:58Z (5 months ago)
  • # [Python](https://python.org), 344 bytes
  • **534 bytes**:
  • This is _not_ golfed in any way. But it's the current winner!
  • ``` python
  • def validate_roman_numeral(candidate):
  • invalid_strings = ["CCCC", "CCD", "CCM", "CDC", "CMC", "CMD", "CMM", "DCD", "DCM", "DD", "DM", "IC", "ID", "IIII", "IIV", "IIX", "IL", "IM", "IVI", "IXC", "IXI", "IXL", "IXV", "IXX", "LC", "LD", "LL", "LM", "LXC", "LXL", "MMMM", "VC", "VD", "VIV", "VIX", "VL", "VM", "VV", "VX", "XCC", "XCD", "XCL", "XCM", "XCX", "XD", "XLX", "XM", "XXC", "XXL", "XXXX"]
  • for invalid_string in invalid_strings:
  • if invalid_string in candidate:
  • return invalid_string
  • return "VALID"
  • ```
  • **379 bytes**:
  • Here's a minimal effort golf of the above:
  • ``` python
  • def v(c):
  • i=['DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','CCCC','IIII','MMMM','XXXX']
  • for s in i:
  • if s in c:
  • return s
  • return "VALID"
  • ```
  • **344 bytes**:
  • A little more effort:
  • ``` python
  • def v(c):
  • o="VALID"
  • for s in 'DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','C'*4,'I'*4,'M'*4,'X'*4:
  • if s in c:
  • o=s
  • return o
  • ```
  • # [Python](https://python.org), 344 bytes
  • **534 bytes**:
  • This is _not_ golfed in any way. ~~But it's the current winner!~~
  • ``` python
  • def validate_roman_numeral(candidate):
  • invalid_strings = ["CCCC", "CCD", "CCM", "CDC", "CMC", "CMD", "CMM", "DCD", "DCM", "DD", "DM", "IC", "ID", "IIII", "IIV", "IIX", "IL", "IM", "IVI", "IXC", "IXI", "IXL", "IXV", "IXX", "LC", "LD", "LL", "LM", "LXC", "LXL", "MMMM", "VC", "VD", "VIV", "VIX", "VL", "VM", "VV", "VX", "XCC", "XCD", "XCL", "XCM", "XCX", "XD", "XLX", "XM", "XXC", "XXL", "XXXX"]
  • for invalid_string in invalid_strings:
  • if invalid_string in candidate:
  • return invalid_string
  • return "VALID"
  • ```
  • **379 bytes**:
  • Here's a minimal effort golf of the above:
  • ``` python
  • def v(c):
  • i=['DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','CCCC','IIII','MMMM','XXXX']
  • for s in i:
  • if s in c:
  • return s
  • return "VALID"
  • ```
  • **344 bytes**:
  • A little more effort:
  • ``` python
  • def v(c):
  • o="VALID"
  • for s in 'DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','C'*4,'I'*4,'M'*4,'X'*4:
  • if s in c:
  • o=s
  • return o
  • ```
#4: Post edited by user avatar trichoplax‭ · 2024-06-28T16:36:12Z (5 months ago)
Fix heading so that the leaderboard picks up the language correctly
  • # [Python](https://python.org) (344 bytes)
  • **534 bytes**:
  • This is _not_ golfed in any way. But it's the current winner!
  • ``` python
  • def validate_roman_numeral(candidate):
  • invalid_strings = ["CCCC", "CCD", "CCM", "CDC", "CMC", "CMD", "CMM", "DCD", "DCM", "DD", "DM", "IC", "ID", "IIII", "IIV", "IIX", "IL", "IM", "IVI", "IXC", "IXI", "IXL", "IXV", "IXX", "LC", "LD", "LL", "LM", "LXC", "LXL", "MMMM", "VC", "VD", "VIV", "VIX", "VL", "VM", "VV", "VX", "XCC", "XCD", "XCL", "XCM", "XCX", "XD", "XLX", "XM", "XXC", "XXL", "XXXX"]
  • for invalid_string in invalid_strings:
  • if invalid_string in candidate:
  • return invalid_string
  • return "VALID"
  • ```
  • **379 bytes**:
  • Here's a minimal effort golf of the above:
  • ``` python
  • def v(c):
  • i=['DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','CCCC','IIII','MMMM','XXXX']
  • for s in i:
  • if s in c:
  • return s
  • return "VALID"
  • ```
  • **344 bytes**:
  • A little more effort:
  • ``` python
  • def v(c):
  • o="VALID"
  • for s in 'DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','C'*4,'I'*4,'M'*4,'X'*4:
  • if s in c:
  • o=s
  • return o
  • ```
  • # [Python](https://python.org), 344 bytes
  • **534 bytes**:
  • This is _not_ golfed in any way. But it's the current winner!
  • ``` python
  • def validate_roman_numeral(candidate):
  • invalid_strings = ["CCCC", "CCD", "CCM", "CDC", "CMC", "CMD", "CMM", "DCD", "DCM", "DD", "DM", "IC", "ID", "IIII", "IIV", "IIX", "IL", "IM", "IVI", "IXC", "IXI", "IXL", "IXV", "IXX", "LC", "LD", "LL", "LM", "LXC", "LXL", "MMMM", "VC", "VD", "VIV", "VIX", "VL", "VM", "VV", "VX", "XCC", "XCD", "XCL", "XCM", "XCX", "XD", "XLX", "XM", "XXC", "XXL", "XXXX"]
  • for invalid_string in invalid_strings:
  • if invalid_string in candidate:
  • return invalid_string
  • return "VALID"
  • ```
  • **379 bytes**:
  • Here's a minimal effort golf of the above:
  • ``` python
  • def v(c):
  • i=['DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','CCCC','IIII','MMMM','XXXX']
  • for s in i:
  • if s in c:
  • return s
  • return "VALID"
  • ```
  • **344 bytes**:
  • A little more effort:
  • ``` python
  • def v(c):
  • o="VALID"
  • for s in 'DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','C'*4,'I'*4,'M'*4,'X'*4:
  • if s in c:
  • o=s
  • return o
  • ```
#3: Post edited by user avatar daviewales‭ · 2024-03-18T12:19:28Z (8 months ago)
  • **534 bytes**:
  • This is _not_ golfed in any way. But it's the current winner!
  • ``` python
  • def validate_roman_numeral(candidate):
  • invalid_strings = ["CCCC", "CCD", "CCM", "CDC", "CMC", "CMD", "CMM", "DCD", "DCM", "DD", "DM", "IC", "ID", "IIII", "IIV", "IIX", "IL", "IM", "IVI", "IXC", "IXI", "IXL", "IXV", "IXX", "LC", "LD", "LL", "LM", "LXC", "LXL", "MMMM", "VC", "VD", "VIV", "VIX", "VL", "VM", "VV", "VX", "XCC", "XCD", "XCL", "XCM", "XCX", "XD", "XLX", "XM", "XXC", "XXL", "XXXX"]
  • for invalid_string in invalid_strings:
  • if invalid_string in candidate:
  • return invalid_string
  • return "VALID"
  • ```
  • **379 bytes**:
  • Here's a minimal effort golf of the above:
  • ``` python
  • def v(c):
  • i=['DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','CCCC','IIII','MMMM','XXXX']
  • for s in i:
  • if s in c:
  • return s
  • return "VALID"
  • ```
  • **344 bytes**:
  • A little more effort:
  • ``` python
  • def v(c):
  • o="VALID"
  • for s in 'DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','C'*4,'I'*4,'M'*4,'X'*4:
  • if s in c:
  • o=s
  • return o
  • ```
  • # [Python](https://python.org) (344 bytes)
  • **534 bytes**:
  • This is _not_ golfed in any way. But it's the current winner!
  • ``` python
  • def validate_roman_numeral(candidate):
  • invalid_strings = ["CCCC", "CCD", "CCM", "CDC", "CMC", "CMD", "CMM", "DCD", "DCM", "DD", "DM", "IC", "ID", "IIII", "IIV", "IIX", "IL", "IM", "IVI", "IXC", "IXI", "IXL", "IXV", "IXX", "LC", "LD", "LL", "LM", "LXC", "LXL", "MMMM", "VC", "VD", "VIV", "VIX", "VL", "VM", "VV", "VX", "XCC", "XCD", "XCL", "XCM", "XCX", "XD", "XLX", "XM", "XXC", "XXL", "XXXX"]
  • for invalid_string in invalid_strings:
  • if invalid_string in candidate:
  • return invalid_string
  • return "VALID"
  • ```
  • **379 bytes**:
  • Here's a minimal effort golf of the above:
  • ``` python
  • def v(c):
  • i=['DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','CCCC','IIII','MMMM','XXXX']
  • for s in i:
  • if s in c:
  • return s
  • return "VALID"
  • ```
  • **344 bytes**:
  • A little more effort:
  • ``` python
  • def v(c):
  • o="VALID"
  • for s in 'DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','C'*4,'I'*4,'M'*4,'X'*4:
  • if s in c:
  • o=s
  • return o
  • ```
#2: Post edited by user avatar daviewales‭ · 2024-03-18T12:15:19Z (8 months ago)
  • **534 bytes**:
  • This is _not_ golfed in any way. But it's the current winner!
  • ``` python
  • def validate_roman_numeral(candidate):
  • invalid_strings = ["CCCC", "CCD", "CCM", "CDC", "CMC", "CMD", "CMM", "DCD", "DCM", "DD", "DM", "IC", "ID", "IIII", "IIV", "IIX", "IL", "IM", "IVI", "IXC", "IXI", "IXL", "IXV", "IXX", "LC", "LD", "LL", "LM", "LXC", "LXL", "MMMM", "VC", "VD", "VIV", "VIX", "VL", "VM", "VV", "VX", "XCC", "XCD", "XCL", "XCM", "XCX", "XD", "XLX", "XM", "XXC", "XXL", "XXXX"]
  • for invalid_string in invalid_strings:
  • if invalid_string in candidate:
  • return invalid_string
  • return "VALID"
  • ```
  • **375 bytes**:
  • Here's a minimal effort golf of the above:
  • ``` python
  • def v(c):
  • i=['DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','CCCC','IIII','MMMM','XXXX']
  • for s in i:
  • if s in c:
  • return s
  • return "VALID"
  • ```
  • **534 bytes**:
  • This is _not_ golfed in any way. But it's the current winner!
  • ``` python
  • def validate_roman_numeral(candidate):
  • invalid_strings = ["CCCC", "CCD", "CCM", "CDC", "CMC", "CMD", "CMM", "DCD", "DCM", "DD", "DM", "IC", "ID", "IIII", "IIV", "IIX", "IL", "IM", "IVI", "IXC", "IXI", "IXL", "IXV", "IXX", "LC", "LD", "LL", "LM", "LXC", "LXL", "MMMM", "VC", "VD", "VIV", "VIX", "VL", "VM", "VV", "VX", "XCC", "XCD", "XCL", "XCM", "XCX", "XD", "XLX", "XM", "XXC", "XXL", "XXXX"]
  • for invalid_string in invalid_strings:
  • if invalid_string in candidate:
  • return invalid_string
  • return "VALID"
  • ```
  • **379 bytes**:
  • Here's a minimal effort golf of the above:
  • ``` python
  • def v(c):
  • i=['DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','CCCC','IIII','MMMM','XXXX']
  • for s in i:
  • if s in c:
  • return s
  • return "VALID"
  • ```
  • **344 bytes**:
  • A little more effort:
  • ``` python
  • def v(c):
  • o="VALID"
  • for s in 'DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','C'*4,'I'*4,'M'*4,'X'*4:
  • if s in c:
  • o=s
  • return o
  • ```
#1: Initial revision by user avatar daviewales‭ · 2024-03-18T12:01:15Z (8 months ago)
**534 bytes**:

This is _not_ golfed in any way. But it's the current winner!

``` python
def validate_roman_numeral(candidate):
    invalid_strings = ["CCCC", "CCD", "CCM", "CDC", "CMC", "CMD", "CMM", "DCD", "DCM", "DD", "DM", "IC", "ID", "IIII", "IIV", "IIX", "IL", "IM", "IVI", "IXC", "IXI", "IXL", "IXV", "IXX", "LC", "LD", "LL", "LM", "LXC", "LXL", "MMMM", "VC", "VD", "VIV", "VIX", "VL", "VM", "VV", "VX", "XCC", "XCD", "XCL", "XCM", "XCX", "XD", "XLX", "XM", "XXC", "XXL", "XXXX"]
    for invalid_string in invalid_strings:
        if invalid_string in candidate:
            return invalid_string
    return "VALID"
```

**375 bytes**:
Here's a minimal effort golf of the above:

``` python
def v(c):
i=['DD','DM','IC','ID','IL','IM','LC','LD','LL','LM','VC','VD','VL','VM','VV','VX','XD','XM','CCD','CCM','CDC','CMC','CMD','CMM','DCD','DCM','IIV','IIX','IVI','IXC','IXI','IXL','IXV','IXX','LXC','LXL','VIV','VIX','XCC','XCD','XCL','XCM','XCX','XLX','XXC','XXL','CCCC','IIII','MMMM','XXXX']
    for s in i:
        if s in c:
            return s
    return "VALID"
```