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

Rust, 258 254 bytes Saved four bytes thanks to trichoplax. fn v(s:&str)->&str{for b in "CCCC CCD CCM CDC CMC CMD CMM DCD DCM DD DM IC ID IIII IIV IIX IL IM IVI I...

posted 5mo ago by Sylvester‭  ·  edited 5mo ago by Sylvester‭

Answer
#3: Post edited by user avatar Sylvester‭ · 2024-06-15T19:43:42Z (5 months ago)
Saved four bytes.
  • # [Rust](https://rust-lang.org), 258 bytes
  • ```rust
  • fn v(s:&str)->&str{for b in "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".split("."){if s.contains(b){return b}}"G"}
  • ```
  • I tried using a closure instead of a function, but I got lifetime errors which, by the time they're fixed, probably wouldn't make the code any shorter.
  • [Try it online!](https://tio.run/##LVBBSgQxELzvK2IfJAHtByh4SUACnWvogxdHHBhYs0uS9RLy9rFGLahUugoqoeut9X1fi/m27em@9eoeXw4Z66WaxWzFkAfY@wAm9gH3dBBzShzgB/gBkjh6joEjgCODylE4IshwFKkeCkuRqrJ4lsAiLIkFuSBLAGfPOXBGSUZJFs7wMCgrfqN4Vb2ACYSHUSCYUKIoUYC4Xc9bt8Tkxraaxh@X0t@30uziRv3st1rMMie90jxW8IXIOjNOBrjWrfRzubM05lv5Iz1gTRTJ/arI/@VYkCfnnk9z/wE "Rust – Try It Online")
  • # [Rust](https://rust-lang.org), <s>258</s> 254 bytes
  • - Saved four bytes thanks to [trichoplax](https://codegolf.codidact.com/users/53890).
  • ```rust
  • fn v(s:&str)->&str{for b in "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".lines(){if s.contains(b){return b}}""}
  • ```
  • I tried using a closure instead of a function, but I got lifetime errors which, by the time they're fixed, probably wouldn't make the code any shorter.
  • [Try it online!](https://tio.run/##LVCxakQhEOz3K4xFUEjuAxJIo42wtrJFmrxwD4SLd6iXRvz2lzHJwDi7M7Dq1nvrx7EX9W3ay2Pr1T6/LRn7tapN5aK0A8g5D0ZyHnVcRB8jefgevodECo6CpwDgSKBQYAoIEhxBKkthCVIRYkfsiZk4EiNnZBGg5Ch5ShiSMCQxJXhohASvEdwqjsEIwkPLEHQYIhgigD5dcjk3Y0feVTt9Xkv/yKWZzY567vda1Dan1nN9/wuJsWqQAm41l34pD0aP@V7@qJ@wIh20/VXm/2Itx2lrX2kePw "Rust – Try It Online")
#2: Post edited by user avatar Sylvester‭ · 2024-06-15T19:39:14Z (5 months ago)
Fixed a typo.
  • # [Rust](https://rust-lang.org), 258 bytes
  • ```rust
  • fn v(s:&str)->&str{for b in "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".split("."){if s.contains(b){return s}}"G"}
  • ```
  • I tried using a closure instead of a function, but I got lifetime errors which, by the time they're fixed, probably wouldn't make the code any shorter.
  • [Try it online!](https://tio.run/##HVCxakQhEOzvK8wWQSHZD0ggjUIQ1la2SJMLeSBcvEO9NOK3v8zLwDjuDIyy7d7Hvm/V/Nr@8thHc89vh8zt2szZlGrIA@x9ABP7gHs6iDklDvAD/ABJHD3HwBHAkUHlKBwRZDiKVA@FpUhVWTxLYBGWxIJckCWAs@ccOKMkoyQLZ3gYlBW/UbyqXsAEwsMoEEwoUZQoQNxvlzIsMblZNtP561rHZ6ndnt1s3@Pequlr0TutYwU/iKwz82SAWyt1XOqDpbk@6lz0hBVRJPevIuTc62ntfw "Rust – Try It Online")
  • # [Rust](https://rust-lang.org), 258 bytes
  • ```rust
  • fn v(s:&str)->&str{for b in "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".split("."){if s.contains(b){return b}}"G"}
  • ```
  • I tried using a closure instead of a function, but I got lifetime errors which, by the time they're fixed, probably wouldn't make the code any shorter.
  • [Try it online!](https://tio.run/##LVBBSgQxELzvK2IfJAHtByh4SUACnWvogxdHHBhYs0uS9RLy9rFGLahUugoqoeut9X1fi/m27em@9eoeXw4Z66WaxWzFkAfY@wAm9gH3dBBzShzgB/gBkjh6joEjgCODylE4IshwFKkeCkuRqrJ4lsAiLIkFuSBLAGfPOXBGSUZJFs7wMCgrfqN4Vb2ACYSHUSCYUKIoUYC4Xc9bt8Tkxraaxh@X0t@30uziRv3st1rMMie90jxW8IXIOjNOBrjWrfRzubM05lv5Iz1gTRTJ/arI/@VYkCfnnk9z/wE "Rust – Try It Online")
#1: Initial revision by user avatar Sylvester‭ · 2024-06-15T11:09:25Z (5 months ago)
# [Rust](https://rust-lang.org), 258 bytes

```rust
fn v(s:&str)->&str{for b in "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".split("."){if s.contains(b){return s}}"G"}
```

I tried using a closure instead of a function, but I got lifetime errors which, by the time they're fixed, probably wouldn't make the code any shorter.

[Try it online!](https://tio.run/##HVCxakQhEOzvK8wWQSHZD0ggjUIQ1la2SJMLeSBcvEO9NOK3v8zLwDjuDIyy7d7Hvm/V/Nr@8thHc89vh8zt2szZlGrIA@x9ABP7gHs6iDklDvAD/ABJHD3HwBHAkUHlKBwRZDiKVA@FpUhVWTxLYBGWxIJckCWAs@ccOKMkoyQLZ3gYlBW/UbyqXsAEwsMoEEwoUZQoQNxvlzIsMblZNtP561rHZ6ndnt1s3@Pequlr0TutYwU/iKwz82SAWyt1XOqDpbk@6lz0hBVRJPevIuTc62ntfw "Rust – Try It Online")