Post History
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...
Answer
#3: Post edited
# [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
- # [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
# [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")