[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [QUIZ] Word Blender (#108

Daniel Finnie

1/8/2007 12:41:00 AM

Oops, that doesn't match {3,6} just {6}.

>> regex =
/^([a-z])(?!\1)([a-z])(?!\1|\2)([a-z])(?:(?!\1|\2|\3)([a-z]))?(?:(?!\1|\2|\3|\4)([a-z]))?(?:(?!\1|\2|\3|\4|\5)([a-z]))?$/
=> [a-z]1[a-z]12[a-z]:123[a-z]:1234[a-z]:12345[a-z]
>> regex.match 'hhh'
=> nil
>> regex.match 'hal'
=> #<MatchData:0xb7cfb7d0>
>> regex.match 'sos'
=> nil
>> regex.match 'sauce'
=> #<MatchData:0xb7c12bac>
>> regex.match 'hatoff'
=> nil
>>

That's a better one.

Daniel Finnie wrote:
> Here is a version of the regex that works around that:
> regex =
> /^([a-z])(?!\1)([a-z])(?!\1|\2)([a-z])(?!\1|\2|\3)([a-z])(?!\1|\2|\3|\4)([a-z])(?!\1|\2|\3|\4|\5)([a-z])$/
>
>
> Some examples:
> >> regex.match 'abcdef'
> => #<MatchData:0xb7b46a18>
> >> regex.match 'abcdefg'
> => nil
> >> regex.match 'abcddf'
> => nil
> >> regex.match 'abbdtf'
> => nil
> >> regex.match 'Abbdtf'
> => nil
> >> regex.match 'awesom'
> => #<MatchData:0xb7b3a5b0>
> >> regex.match 'hollow'
> => nil
>
> Fedor Labounko wrote:
>> On 1/7/07, Daniel Finnie <danfinnie@optonline.net> wrote:
>>
>>> # Find words that use the same letters
>>> selectedWords = dict.scan(/^[#{baseWord}]{3,6}$/)
>>
>>
>> I was really impressed when I first saw this. It doesn't quite work if
>> you
>> want to exclude reusing the same letter more than once
>> ("hhh".scan(/^[hello]{3,6}$/) => ["hhh"]) but it comes so close to
>> something
>> I've only ever thought about implementing as a recursive method.
>> Unfortunately I don't know much about this but now I wonder if it's
>> possible
>> to find all partial permutations of a word with a regexp.
>>
>
>

1 Answer

James Gray

1/10/2007 3:13:00 PM

0

On Jan 7, 2007, at 6:41 PM, Daniel Finnie wrote:

> Oops, that doesn't match {3,6} just {6}.
>
> >> regex = /^([a-z])(?!\1)([a-z])(?!\1|\2)([a-z])(?:(?!\1|\2|\3)([a-
> z]))?(?:(?!\1|\2|\3|\4)([a-z]))?(?:(?!\1|\2|\3|\4|\5)([a-z]))?$/

Wow. That's darn clever, but probably over abusing regular
expressions a bit, don't you think? ;)

James Edward Gray II