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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:51:54+00:00 2026-05-30T21:51:54+00:00

Oftentimes, you have a problem where property A can be either true or false,

  • 0

Oftentimes, you have a problem where property A can be either true or false, property B also either true or false, and so on. We want to test every combination of A being true while B being false, and so on. So for example we might need the following list:

[true,true,true]
[true,true,false]
[true,false,true]
[true,false,false]
[false,true,true]
[false,true,false]
[false,false,true]
[false,false,false]

In Haskell or Python, this can be done by a list product function.

My question is, what’s the simplest and/or quickest way to generate this? I have always done this by converting a number to binary, then converting the binary into an array. But this seems cumbersome because decimal to binary conversion isn’t completely trivial, and also we need to worry about padding the binary with leading zeroes to fill up the array properly.

I have implemented and re-implemented this kind of function in different contexts enough times to wonder, is there a way simple enough that you can implement it from scratch when necessary — without really having to think?

  • 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-30T21:51:56+00:00Added an answer on May 30, 2026 at 9:51 pm

    I’m not exactly sure of the code but something along these lines should work.

    for( int i = 0; i < 8; i++ ){
      printf( "[%s, %s, %s]\n", (i & 0x1)?"True":"False", ((i & 0x2) >> 1)?"True":"False" , ((i & 0x4) >> 2)?"True":"False" );
    }
    

    I’m iterating through the numbers 0 to 7 (000 to 111 respectively) and isolating each bit to identify the boolean value.

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

Sidebar

Related Questions

Often times in applications I have a property that would normally .animate(), but every
So sometimes (oftentimes!) you want to target a specific .NET version (say 3.0), but
Oftentimes, when using git, I find myself in this situation: I have changes to
I have a select that I want to run various functions on depending on
I will try to explain as best as I can what I realy want
oftentimes I have this kind of usage scenario: entity A is connected to B
I have two tables (subjects and pages) in one-to-many relations. I want to add
So oftentimes, while editing with Vim, I'll get into a variety of situations where
Have a n-tire web application and search often times out after 30 secs. How
Oftentimes a developer will be faced with a choice between two possible ways to

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.