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

  • SEARCH
  • Home
  • 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 9170511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:01:54+00:00 2026-06-17T16:01:54+00:00

I need a function that will take a list of (list of items), and

  • 0

I need a function that will take a list of (list of items), and enumerate all possible combinations of every item in every list. so

someCombo :: [[a]] -> [[a]]
someCombo = undefined

If I have something like this

[ 
 [a1,b1],
 [a2,b2,c2],
 [a3,b3]
]

I want to spit out an answer like this, where very element of each list is matched with every element of every other list. Presumably in this case there’d be 12 elements to the final list.

[
  [a1,a2,a3],[a1,a2,b3],[a1,b2,a3],[a1,b2,b3],...,[b1,c2,b3]
]

There could be an arbitrary number of lists in the main argument. This seems like it should be really simple, but I can’t quite wrap my head around it. I can do it for two or three lists, but I can’t make it work recursively an arbitrary number of lists. Oh and I don’t care about the order of the resulting list, as long as I have all 12 (or whatever) of them.

If anyone is curious what this is for, it is the last piece I need to implement an algorithm which determines what order I would put plates onto a barbell before each lift that would minimize the amount of plate shuffling I would do from exercise to exercise. I figure this might save me a couple minutes per workout. In order to do that I need to enumerate all possible workouts that involve a specific set of plates for each lift and then find the combination of plate orders for each lift that results in the least amount of shuffling.

  • 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-06-17T16:01:55+00:00Added an answer on June 17, 2026 at 4:01 pm
    import Control.Monad
    
    someCombo = sequence
    

    Let’s try it:

    >>> someCombo [[1, 2], [3, 4]]
    [[1,3],[1,4],[2,3],[2,4]]
    

    To understand this, you will need to understand list comprehensions or the list monad. sequence effectively does this:

    sequence [[1, 2], [3, 4]]
    = do x <- [1, 2]
         y <- [3, 4]
         return [x, y]
    

    You can think of that as saying “Let x range over 1 and 2, let y range over 3 and 4, now return all permutations of x and y“.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will take in a list of characters and numbers,
I need a function that will take a bitmap and return the bitmap with
I need a VBA function that will perform the following: Find all unique values
I need a function that will convert a type to a string, for example:
I need a function to return a string that will only be accessed read-only.
I need a regex or a function in PHP that will validate a string
I need to create a function that uses a loop. This function will open
I have a list of items and would like to generate all possible subsets.
I'm attempting to write a function that will take a string and create a
I have an application where I need to take the items from a list

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.