[LRUG] Recursion diversion

Dominic Baggott dominic.baggott at gmail.com
Fri Oct 25 13:19:25 PDT 2013


Here's a recursive version, using Roland's tests (with an amended example 2): https://gist.github.com/evilstreak/7161191 

Dom 


On Friday, 25 October 2013 at 14:21, Andrew Stewart 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 (mailto:Chat at lists.lrug.org)
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org






More information about the Chat mailing list