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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:07:41+00:00 2026-06-12T14:07:41+00:00

Apologies if this looks like another problem – there are quite a lot of

  • 0

Apologies if this looks like another problem – there are quite a lot of solutions and I didn’t find what I’m looking for, but I may well have missed it. Also apologies if title isn’t best description – not sure how else to word it.

I have five ‘features’ as strings, e.g.:

$height $width $depth $length $colour

I want to get all the different unique combinations starting with 5 and going down to 1 e.g.:

5: $height $width $depth $length $colour
4: $height $width $depth $length 
4: $height $width $depth $colour
4: $height $width $length $colour
4: $height $depth $length $colour
4: $width $depth $length $colour
...
and so on 
...
1: $height 
1: $width 
1: $depth 
1: $length 
1: $colour

I don’t know if it makes a difference, but in code I plan to use && and !$string, e.g.:

4: $height && $width && $depth && $length && !$colour 
4: $height && $width && $depth && !$length && $colour
4: $height && $width && !$depth && $length && $colour
4: $height && !$width && $depth && $length && $colour
4: !$height && $width && $depth && $length && $colour
and so on.

I was fine doing this by hand when I had 4 features, but with 5 it’s too much!
I thought putting the variables in a hash would may be good starting point, but as for the actual algorithm… Any help appreciated!

Edit: just realised it may not be clear, but I want to be able to ‘query’ each combination as they will be in if/elsif statements, so if (h && w && !d ...)

  • 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-12T14:07:42+00:00Added an answer on June 12, 2026 at 2:07 pm

    Encode a configuration as a 5 bit integer and just iterate from 0 to 25-1.

    for ($i = 0; $i < 1<<5; $i++) {
    
        my @output;
        push @output,  $i & 1  ? '$height' : '!$height';
        push @output,  $i & 2  ? '$width' : '!$width';
        push @output,  $i & 4  ? '$depth' : '!$depth';
        push @output,  $i & 8  ? '$length' : '!$length';
        push @output,  $i & 16 ? '$colour' : '!$colour';
    
        print join(' && ', @output), "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize if this code looks a bit like a mess (considering the length);
Apologies if this was already asked but, I have had a look and can't
Apologies if this is a duplicate, 20 minutes of searching didn't yield this exact
Apologies if this is answered elsewhere; couldn't find enough information to convince myself of
Apologies if this is a repost, I could not find the search terms to
Apologies if this conflicts with a previous post of mine, but I am pretty
I have a model called Action. It looks like this: class Action < ActiveRecord::Base
I have searched this web looking for an answer, but it seems that this
This seems like a simple question to ask but, is it generally a good
The question says it all, really. I know a (Scala) Monad looks like this:

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.