Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 465555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:23:21+00:00 2026-05-12T23:23:21+00:00

I have been trying to wrap my head around this for a while now

  • 0

I have been trying to wrap my head around this for a while now but have not been able to come up with a good solution. Here goes:

Given a number of sets:

set1: A, T
set2: C
set3: A, C, G
set4: T
set5: G

I want to generate all possible sequences from a list of sets. In this example the length of the sequence is 5, but it can be any length up to around 20. For position 1 the possible candidates are ‘A’ and ‘T’ respectively, for position 2 the only option is ‘C’ and so on.

The answer for the example above would be:

ACATG, ACCTG, ACGTG, TCATG, TCCTG, TCGTG

I am doing this in ruby and I have the different sets as arrays within a master array:

[[A, T], [C], [A, C, G], [T], [G]]

At first I thought a recursive solution would be best but I was unable figure out how to set it up properly.

My second idea was to create another array of the same size with an index for each set. So 00000 would correspond to the first sequence above ‘ACATG’ and 10200 would correspond to ‘TCGTG’. Beginning with 00000 I would increase the last index by one and modulo it with the length of the set in question (2 for set1, 1 for set2 above) and if the counter wrapped around I would zero it and increase the previous one by one.

But the more I thought about this solution it seemed too complex for this very small problem. There must be a more straight-forward solution that I am missing. Could anyone help me out?

/Nick

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:23:21+00:00Added an answer on May 12, 2026 at 11:23 pm

    The Array class in Ruby 1.8.7 has an Array#product method, which returns the cartesian product of the arrays in question.

    irb(main):001:0> ['A', 'T'].product(['C'], ['A', 'C', 'G'], ['T'], ['G'])
    => [["A", "C", "A", "T", "G"], ["A", "C", "C", "T", "G"], ["A", "C", "G", "T", "G"],     ["T", "C", "A", "T", "G"], ["T", "C", "C", "T", "G"], ["T", "C", "G", "T", "G"]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 316k
  • Answers 316k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer All modern frameworks follow router ideology. So for this task… May 13, 2026 at 11:35 pm
  • Editorial Team
    Editorial Team added an answer It's impossible to tell without seeing your declaration for the… May 13, 2026 at 11:35 pm
  • Editorial Team
    Editorial Team added an answer ACE calls this "Thread Specific Storage". Check this out: ACE_TSS.… May 13, 2026 at 11:35 pm

Related Questions

For sometime now, I have been trying to wrap my head around the reason
I'm trying to wrap my head around reflection, so I decided to add plugin
I'm trying to write a filtering function for an image, but I can't seem
I am preparing to move my team's source control from VSS over to TFS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.