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 6942929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:05:22+00:00 2026-05-27T13:05:22+00:00

Note: This is a ‘sequel’ question to my previous permutations question . I would

  • 0

Note: This is a ‘sequel’ question to my previous permutations question.

I would like to generate all permutations of a list in Erlang, but I would like to filter out some of the permutations before they are added to the stack or stored anywhere.

I will filter out the permutations based on some custom ad-hoc rules (let’s call them “Filter”).

In other words, I would like to generate a list of permutations of a large list (50-300 elements), but I would like to throw out most of the generated permutations right during the process (I know that the full number of permutations is N!).

steenslag has given me a nice solution in Ruby:

res = [1,2,3,4].permutation(3).reject do |perm|
  perm.first.even? #Filter: if this line is true, the perm will be rejected
end

How can I write something similar in Erlang?

(I have my Filter functions already written in Erlang, so I would like to do some code reuse).

By the way, can the desired Erlang solution be ‘intrinsically parallel’?

  • 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-27T13:05:23+00:00Added an answer on May 27, 2026 at 1:05 pm

    I did a possible implementation for the problem:

    -module(perm).
    
    -export([pred_perms/2, pred/1]).
    
    pred(L = [H | _T]) when H > 1 ->
        L;
    pred(_L) ->
        [].
    
    do_pred_perms([], _Pred) -> 
        [[]];
    do_pred_perms(L, Pred)  -> 
        [Pred([H|T]) || H <- L, T <- do_pred_perms(L--[H], Pred)].
    
    pred_perms(List, Pred) ->
        Res = do_pred_perms(List, Pred),
        lists:filter(fun(E) -> E =/= [] end, Res).
    

    It uses empty lists as placeholders for lists that must be discarded. If this is not acceptable, you can change the implementation to not use list compreension.

    The pred/1 function is just an example function to use as predicate.

    Hope this helps.

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

Sidebar

Related Questions

NOTE: This question is written in a C# like pseudo code, but I am
Note: This might seem like a Super User question at first, but please read
Note: This is a sequel to my previous question about powersets. I have got
Note: This question has broadened in scope from previous revisions. I have tried to
Note: This question uses jQuery but the question has nothing to do with jQuery
NOTE: This is a long question. I've explained all the 'basics' at the top
NOTE: This question is only loosely related to tinyxml, however including details like that
Note: This question originally applied to Xapian , but due to cross-platform issues and
Note This originally started as a question about 404 errors, but now it's a
Note: this is NOT like this question I've been tasked to construct a survey

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.