Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How can one generate all possible combinations with reference to string positions?

by kennethk (Monsignor)
on Feb 20, 2013 at 17:59 UTC ( #1019816=note: print w/ replies, xml ) Need Help??


in reply to How can one generate all possible combinations with reference to string positions?

I observe that your L's and H's don't move, and that the last two terms are dictated by the first two. This means your pattern can be generated fairly simply with

#!/usr/bin/perl -w use strict; for my $h (1 .. 2) { for my $l (1 .. 2) { printf "L%dH%dL%dH%d\n", $l, $h, 3-$l, 3-$h; } }

Obviously, scaling this up to 500 positions and 10 groups is non-trivial, but should be doable similarly. If you need arbitrary complexity, you'll probably want to generate a work queue rather than having fixed nested for loops.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: How can one generate all possible combinations with reference to string positions?
Download Code
Re^2: How can one generate all possible combinations with reference to string positions?
by supriyoch_2008 (Scribe) on Feb 23, 2013 at 02:29 UTC

    Hi kenneth,

    Thanks for the script. It works nicely. I shall be glad if you kindly explain how to use and change the code 3-$l, 3-$h. Does it have any relationship with the number of L and H in the string following printf? Do the $h (1..2) and $l (1..2) refer to 2 levels each for H and L? Actually I tried to learn making some alterations in the script like 4-$l, 5-$h, $h(1..3), $l(1..4) etc.in appropriate places but I could not understand. This is because I donot know why the terms are used and how to change them. I hope you won't mind explain the terms. Please suggest me some reference texts for further study.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019816]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2014-12-19 17:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (90 votes), past polls