Hi users,
i need to generate all possible combinations of number 1 and 2 with lenght 6
for example: 111111, 111112, 111121, 111211...............222221,222222
is there any way to do it ?
thank to all very much
7 2499
Hi users,
i need to generate all possible combinations of number 1 and 2 with lenght 6
for example: 111111, 111112, 111121, 111211...............222221,222222
is there any way to do it ?
thank to all very much
If you can count from zero (inclusive) to sixtyfour (exclusive) you can list your
combinations, just replace a bit 0 ---> 1 and a bit 1 --> 2.
kind regards,
Jos
Replacing the bits is a possible solution.
But i am not sure to accomplish that.
But u can use the bruteforce method.
Simply generate from 111111 to 222222 then check if the bits are 1 or 2 then print it if it complies.
Here is the loop. -
Code removed, see posting guidelines
-
So instead of 2^6 = 64 possible solutions you want to check 222222+1-111111=111112
possibilities? I don't think that is a smart thing to do.
kind regards,
Jos
JosAH: thanks, but i dont understand "just replace a bit"...where?
deepak1706:thanks, but which software can run this code ? i never made it
JosAH: thanks, but i dont understand "just replace a bit"...where?
Simply count from 0 ... 63. For every number in binary representation replace
a 0 by 1 and replace a 1 by 2; that's all.
kind regards,
Jos
Simply count from 0 ... 63. For every number in binary representation replace
a 0 by 1 and replace a 1 by 2; that's all.
kind regards,
Jos
just replace 2 instead of 0 is okay...
just replace 2 instead of 0 is okay...
Yep, that'd be a nice little micro-optimisation. I didn't think of that one ;-)
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Laphan |
last post by:
Hi All
This is a strange request, but I just cannot fathom how to do it.
In theory the requirement is very basic, but in practise its a noodle!!
I have 10 team names like so:
Team A
Team...
|
by: Peter R |
last post by:
Hi,
Probably this question was asked before, but what is the algorithm to
generate all combinations based on N numbers?
For example, for 3 elements = {1,2,3}, I'd like to generate a list of...
|
by: mortb |
last post by:
Hi,
How do I write a GenerateHashcode function that will generate guaranteed
unique hashcodes for my classes?
cheers,
mortb
|
by: Anthony Liu |
last post by:
I am at my wit's end.
I want to generate a certain number of random numbers.
This is easy, I can repeatedly do uniform(0, 1) for
example.
But, I want the random numbers just generated sum up...
|
by: Anamika |
last post by:
I am doing a project where I want to generate random numbers for say n
people....
These numbers should be unique for n people.
Two people should not have same numbers....
Also the numbers...
|
by: Robert Mago |
last post by:
Is there a way to create a 10 characthers or less, alph-numeric string which
is unique. I can't use the guid since its longer then 10 characthers. Also i
cannot use a random number, since being...
|
by: Bill Woessner |
last post by:
I'm trying to replace a loop with a call to std::generate and I'm
about at wits end. Here's the working code:
std::vector<double>::iterator it;
std::vector<doubledata(100);...
|
by: Killer42 |
last post by:
We have received what looks to me like quite an interesting question in the Visual Basic forum concerning how to check all possible combinations of numbers in a list for those where the sum matches a...
|
by: pereges |
last post by:
I need to generate two uniform random numbers between 0 and 1 in C ?
How to do it ?
I looked into rand function where you need to #define RAND_MAX as 1
but will this rand function give me ...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |