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

50%
+0 −0
Challenges Merge two strings

Ruby, 40 bytes f=->a,b{b.index(a)==0?b:a[/./m]+f[$',b]} Attempt This Online! If we could assume that string contains only letters and numbers (or to be more specific, no characters like \t\...

posted 3y ago by radarek‭  ·  edited 3y ago by radarek‭

Answer
#4: Post edited by user avatar radarek‭ · 2022-01-21T17:22:20Z (almost 3 years ago)
  • # [Ruby](https://www.ruby-lang.org/), 40 bytes
  • ```ruby
  • f=->a,b{b.index(a)==0?b:a[/./m]+f[$',b]}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWNzXSbHXtEnWSqpP0MvNSUis0EjVtbQ3sk6wSo_X19HNjtdOiVdR1kmJrIepvMXqXpBaXKNgq6NoVG-ooFBvpKKRWFKQml6SmKKTkcykoFJSWFCsohQAVZealKyhXFxsCDS4GqajVAXGN4FygEUABjaLU4tIckIlp0RATYzURSpSrYdK2CHvsFdT9vdUVrBTUXYOC_IPUa5W4UvNSuLhALotWd3RydnF1U9cByrq5e3iCGBAhECcWpggMwHKOWNixCLNA4oZGxlBjQCyYJNxkBANJnwtMFE4j6wPjWEiYwuICAA)
  • If we could assume that string contains only letters (or to be more specific, no characters like `\t
  • \v\f \#$()*+-.?[\\]^{|}`) then it could be improved to 36 bytes:
  • ```ruby
  • f=->a,b{b=~/^#{a}/?b:a[/./]+f[$',b]}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWN1XSbHXtEnWSqpNs6_TjlKsTa_Xtk6wSo_X19GO106JV1HWSYmsham8xepekFpco2Cro2hUb6igUG-kopFYUpCaXpKYopORzKSgUlJYUKyiFABVl5qUrKFcXG-pl5hWDVNTqgLhGcC7QCKCARlFqcWkOyMS0aIiJsZoIJcrVMGlbhD32Cur-3uoKVgrqrkFB_kHqtUpcqXkpXFwgl0WrOzo5u7i6qesAZd3cPTxBDIgQiBMLUwQGYDlHLOxYhFkgcUMjY6gxIBZMEm4ygoGkzwUmCqeR9YFxLCRMYfEAAA)
  • # [Ruby](https://www.ruby-lang.org/), 40 bytes
  • ```ruby
  • f=->a,b{b.index(a)==0?b:a[/./m]+f[$',b]}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWNzXSbHXtEnWSqpP0MvNSUis0EjVtbQ3sk6wSo_X19HNjtdOiVdR1kmJrIepvMXqXpBaXKNgq6NoVG-ooFBvpKKRWFKQml6SmKKTkcykoFJSWFCsohQAVZealKyhXFxsCDS4GqajVAXGN4FygEUABjaLU4tIckIlp0RATYzURSpSrYdK2CHvsFdT9vdUVrBTUXYOC_IPUa5W4UvNSuLhALotWd3RydnF1U9cByrq5e3iCGBAhECcWpggMwHKOWNixCLNA4oZGxlBjQCyYJNxkBANJnwtMFE4j6wPjWEiYwuICAA)
  • If we could assume that string contains only letters and numbers (or to be more specific, no characters like `\t
  • \v\f \#$()*+-.?[\\]^{|}`) then it could be improved to 36 bytes:
  • ```ruby
  • f=->a,b{b=~/^#{a}/?b:a[/./]+f[$',b]}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWN1XSbHXtEnWSqpNs6_TjlKsTa_Xtk6wSo_X19GO106JV1HWSYmsham8xepekFpco2Cro2hUb6igUG-kopFYUpCaXpKYopORzKSgUlJYUKyiFABVl5qUrKFcXG-pl5hWDVNTqgLhGcC7QCKCARlFqcWkOyMS0aIiJsZoIJcrVMGlbhD32Cur-3uoKVgrqrkFB_kHqtUpcqXkpXFwgl0WrOzo5u7i6qesAZd3cPTxBDIgQiBMLUwQGYDlHLOxYhFkgcUMjY6gxIBZMEm4ygoGkzwUmCqeR9YFxLCRMYfEAAA)
#3: Post edited by user avatar radarek‭ · 2022-01-21T17:01:28Z (almost 3 years ago)
  • # [Ruby](https://www.ruby-lang.org/), 40 bytes
  • ```ruby
  • f=->a,b{b.index(a)==0?b:a[/./m]+f[$',b]}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWNzXSbHXtEnWSqpP0MvNSUis0EjVtbQ3sk6wSo_X19HNjtdOiVdR1kmJrIepvMXqXpBaXKNgq6NoVG-ooFBvpKKRWFKQml6SmKKTkcykoFJSWFCsohQAVZealKyhXFxsCDS4GqajVAXGN4FygEUABjaLU4tIckIlp0RATYzURSpSrYdK2CHvsFdT9vdUVrBTUXYOC_IPUa5W4UvNSuLhALotWd3RydnF1U9cByrq5e3iCGBAhECcWpggMwHKOWNixCLNA4oZGxlBjQCyYJNxkBANJnwtMFE4j6wPjWEiYwuICAA)
  • If we could assume that string contains only letters (or to be more specific, no characters like `\t
  • \v\f \#$()*+-.?[\\]^{|}` then it could be improved to 36 bytes:
  • ```ruby
  • f=->a,b{b=~/^#{a}/?b:a[/./]+f[$',b]}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWN1XSbHXtEnWSqpNs6_TjlKsTa_Xtk6wSo_X19GO106JV1HWSYmsham8xepekFpco2Cro2hUb6igUG-kopFYUpCaXpKYopORzKSgUlJYUKyiFABVl5qUrKFcXG-pl5hWDVNTqgLhGcC7QCKCARlFqcWkOyMS0aIiJsZoIJcrVMGlbhD32Cur-3uoKVgrqrkFB_kHqtUpcqXkpXFwgl0WrOzo5u7i6qesAZd3cPTxBDIgQiBMLUwQGYDlHLOxYhFkgcUMjY6gxIBZMEm4ygoGkzwUmCqeR9YFxLCRMYfEAAA)
  • # [Ruby](https://www.ruby-lang.org/), 40 bytes
  • ```ruby
  • f=->a,b{b.index(a)==0?b:a[/./m]+f[$',b]}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWNzXSbHXtEnWSqpP0MvNSUis0EjVtbQ3sk6wSo_X19HNjtdOiVdR1kmJrIepvMXqXpBaXKNgq6NoVG-ooFBvpKKRWFKQml6SmKKTkcykoFJSWFCsohQAVZealKyhXFxsCDS4GqajVAXGN4FygEUABjaLU4tIckIlp0RATYzURSpSrYdK2CHvsFdT9vdUVrBTUXYOC_IPUa5W4UvNSuLhALotWd3RydnF1U9cByrq5e3iCGBAhECcWpggMwHKOWNixCLNA4oZGxlBjQCyYJNxkBANJnwtMFE4j6wPjWEiYwuICAA)
  • If we could assume that string contains only letters (or to be more specific, no characters like `\t
  • \v\f \#$()*+-.?[\\]^{|}`) then it could be improved to 36 bytes:
  • ```ruby
  • f=->a,b{b=~/^#{a}/?b:a[/./]+f[$',b]}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWN1XSbHXtEnWSqpNs6_TjlKsTa_Xtk6wSo_X19GO106JV1HWSYmsham8xepekFpco2Cro2hUb6igUG-kopFYUpCaXpKYopORzKSgUlJYUKyiFABVl5qUrKFcXG-pl5hWDVNTqgLhGcC7QCKCARlFqcWkOyMS0aIiJsZoIJcrVMGlbhD32Cur-3uoKVgrqrkFB_kHqtUpcqXkpXFwgl0WrOzo5u7i6qesAZd3cPTxBDIgQiBMLUwQGYDlHLOxYhFkgcUMjY6gxIBZMEm4ygoGkzwUmCqeR9YFxLCRMYfEAAA)
#2: Post edited by user avatar radarek‭ · 2022-01-21T17:01:06Z (almost 3 years ago)
  • # [Ruby](https://www.ruby-lang.org/), 40 bytes
  • ```ruby
  • f=->a,b{b.index(a)==0?b:a[/./m]+f[$',b]}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWNzXSbHXtEnWSqpP0MvNSUis0EjVtbQ3sk6wSo_X19HNjtdOiVdR1kmJrIepvMXqXpBaXKNgq6NoVG-ooFBvpKKRWFKQml6SmKKTkcykoFJSWFCsohQAVZealKyhXFxsCDS4GqajVAXGN4FygEUABjaLU4tIckIlp0RATYzURSpSrYdK2CHvsFdT9vdUVrBTUXYOC_IPUa5W4UvNSuLhALotWd3RydnF1U9cByrq5e3iCGBAhECcWpggMwHKOWNixCLNA4oZGxlBjQCyYJNxkBANJnwtMFE4j6wPjWEiYwuICAA)
  • # [Ruby](https://www.ruby-lang.org/), 40 bytes
  • ```ruby
  • f=->a,b{b.index(a)==0?b:a[/./m]+f[$',b]}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWNzXSbHXtEnWSqpP0MvNSUis0EjVtbQ3sk6wSo_X19HNjtdOiVdR1kmJrIepvMXqXpBaXKNgq6NoVG-ooFBvpKKRWFKQml6SmKKTkcykoFJSWFCsohQAVZealKyhXFxsCDS4GqajVAXGN4FygEUABjaLU4tIckIlp0RATYzURSpSrYdK2CHvsFdT9vdUVrBTUXYOC_IPUa5W4UvNSuLhALotWd3RydnF1U9cByrq5e3iCGBAhECcWpggMwHKOWNixCLNA4oZGxlBjQCyYJNxkBANJnwtMFE4j6wPjWEiYwuICAA)
  • If we could assume that string contains only letters (or to be more specific, no characters like `\t\n\v\f\r \#$()*+-.?[\\]^{|}` then it could be improved to 36 bytes:
  • ```ruby
  • f=->a,b{b=~/^#{a}/?b:a[/./]+f[$',b]}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWN1XSbHXtEnWSqpNs6_TjlKsTa_Xtk6wSo_X19GO106JV1HWSYmsham8xepekFpco2Cro2hUb6igUG-kopFYUpCaXpKYopORzKSgUlJYUKyiFABVl5qUrKFcXG-pl5hWDVNTqgLhGcC7QCKCARlFqcWkOyMS0aIiJsZoIJcrVMGlbhD32Cur-3uoKVgrqrkFB_kHqtUpcqXkpXFwgl0WrOzo5u7i6qesAZd3cPTxBDIgQiBMLUwQGYDlHLOxYhFkgcUMjY6gxIBZMEm4ygoGkzwUmCqeR9YFxLCRMYfEAAA)
#1: Initial revision by user avatar radarek‭ · 2022-01-21T16:55:01Z (almost 3 years ago)
# [Ruby](https://www.ruby-lang.org/), 40 bytes

```ruby
f=->a,b{b.index(a)==0?b:a[/./m]+f[$',b]}
```

[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWNzXSbHXtEnWSqpP0MvNSUis0EjVtbQ3sk6wSo_X19HNjtdOiVdR1kmJrIepvMXqXpBaXKNgq6NoVG-ooFBvpKKRWFKQml6SmKKTkcykoFJSWFCsohQAVZealKyhXFxsCDS4GqajVAXGN4FygEUABjaLU4tIckIlp0RATYzURSpSrYdK2CHvsFdT9vdUVrBTUXYOC_IPUa5W4UvNSuLhALotWd3RydnF1U9cByrq5e3iCGBAhECcWpggMwHKOWNixCLNA4oZGxlBjQCyYJNxkBANJnwtMFE4j6wPjWEiYwuICAA)