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

60%
+1 −0
Challenges The 50 substrings that validate any string of Roman numerals

Bash, 205 bytes for s in C{C{CC,D,M},DC,MC} {CM,DC,D}{D,M} I{C,D,I{II,V,X},L,M,VI,X{C,I,L,V,X}} L{C,D,L,M,XC,XL} MMMM V{C,D,IV,IX,L,M,V,X} X{C{C,D,L,M,X},D,LX,M,X{C,L,XX}} do echo $1|grep -q $s...

posted 5mo ago by celtschk‭

Answer
#1: Initial revision by user avatar celtschk‭ · 2024-06-30T18:29:42Z (5 months ago)
# [Bash], 205 bytes

<!-- language-all: lang-bash -->

<pre><code>for s in C{C{CC,D,M},DC,MC} {CM,DC,D}{D,M} I{C,D,I{II,V,X},L,M,VI,X{C,I,L,V,X}} L{C,D,L,M,XC,XL} MMMM V{C,D,IV,IX,L,M,V,X} X{C{C,D,L,M,X},D,LX,M,X{C,L,XX}}
do echo $1|grep -q $s&amp;&amp;echo $s&amp;&amp;exit
done
echo T

</code></pre>

The golfing is done mostly in the list of 50 strings. Other than that, the code is pretty straightforward, with the only additional golfing being the removal of unnecessary whitespace and use of a single-letter variable name.

[Try it online!][TIO-ly1vrj7j]

[Bash]: https://www.gnu.org/software/bash/
[TIO-ly1vrj7j]: https://tio.run/##NY09DsMwCIX3nIIhykSHngEvSGarLNb@pE2WpE06VHJ9dhcSFZbHx3twOa9Drfd5gRXGCShbEwaUgoFQqEAmcRlKdgqcfc2ZGRNqwYiCiVENsw3OCsTN5Csl1FhArCDt0YSse8y8oP7xby4u1JWxiGq3mtsM/XWYoT1@H0v/hMML2rXrdubiM77NNPXNhk5NrTUEYVYlIQok8gM "Bash – Try It Online"