escaping regex to do math on backreferences

2009-04-12 Thread Andrew Fithian
Hello everyone, I have a program that needs to find straights in a hand of cards. The hand is a string with no whitespace sorted by the cards' ranks, eg "9d10cJhQsKd". How can I identify if that hand contains a straight with a single regex? Is that even possible? Is there a way to escape the regex

enumerating subarrays

2009-04-04 Thread Andrew Fithian
What's a slick way to enumerate all subarrays of length n from a master array of length m? For example I've been enumerating all possible two card hands from a deck of 52 cards (n=2, m<=52) using nested for loops: for ( $i = 0 ; $i < $#deck ; $i++ ) { for ( $j = $i+1 ; $j <= $#deck ; $j++