[LRUG] Recursion diversion

Roland Swingler roland.swingler at gmail.com
Fri Oct 25 07:07:30 PDT 2013


This solves the problem https://gist.github.com/knaveofdiamonds/7155189 -
I'm pretty sure it can be made about half as long. This better not be an
interview test!!

I kind of wish there was a more declarative way to say that things in an
array should be in order rather than comparing with sorting, but hey ho.

Cheers,
Roland


On Fri, Oct 25, 2013 at 2:21 PM, Andrew Stewart
<boss at airbladesoftware.com>wrote:

> Hello El Rug,
>
> Given two strings a and b, I would like to find all the occasions where
> the letters of b appear in the same order in a.  The result should be an
> array of arrays where each inner array contains the indices of b's matches
> in a.
>
> a: 'hello world'
> b: 'e'
> result: [ [1] ]
>
> a: 'hello world'
> b: 'l'
> result: [ [2,3,9] ]
>
> a: 'hello world'
> b: 'el'
> result: [ [1,2], [1,3], [1,9] ]
>
> a: 'hello world'
> b: 'lo'
> result: [ [2,4], [2,7], [3,4], [3,7] ]
>
> a: 'hello world'
> b: 'lod'
> result: [ [2,4,10], [2,7,10], [3,4,10], [3,7,10] ]
>
> Hope that makes sense ;)
>
> I've been trying this for ages, with iteration and recursion, and I keep
> getting close...but not quite there.
>
> Any takers?
>
> Cheers,
> Andy Stewart
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20131025/232cb5c0/attachment-0003.html>


More information about the Chat mailing list