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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I don't really understand why a number would be "unknown", and consequently can't address where to place "?" characters. But that aside, this looks to me like a problem of enumerating all possible bit patterns for a ten-bit register. And since ten bits is within the realm of simple Perl integers, you can just iterate over every value from 0 through 2**11-1 and inflate its bit pattern into your original ATATGCGCAT string. This will assure that all possible combinations are enumerated. Here's one way to do that:

use strict; use warnings; my $string = 'ATATGCGCAT'; for my $num (0 .. 2**11 - 1) { print "$num: ", join('', map { substr($string, $_, 1) . ($num & (2**(9 - $_)) ? '2' : '1' +); } 0 .. 9 ), "\n"; }

Here we're running through two loops. The outer loop simply iterates over every integer from 0 through 2 ** 11 - 1. That's how we generate our bit patterns. Then another loop maps the bit values into the original string. Finally, each pattern is printed.

The output will look like this:

2039: A2T2A2T2G2C2G1C2A2T2 2040: A2T2A2T2G2C2G2C1A1T1 2041: A2T2A2T2G2C2G2C1A1T2 2042: A2T2A2T2G2C2G2C1A2T1 2043: A2T2A2T2G2C2G2C1A2T2 2044: A2T2A2T2G2C2G2C2A1T1 2045: A2T2A2T2G2C2G2C2A1T2 2046: A2T2A2T2G2C2G2C2A2T1 2047: A2T2A2T2G2C2G2C2A2T2

I hope I understood the problem. ;)


Dave


In reply to Re: How can one get all possible combinations of a string without changing positions & using window size? by davido
in thread How can one get all possible combinations of a string without changing positions & using window size? by supriyoch_2008

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found