473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

generate numbers combinations

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
Jun 28 '08 #1
7 2499
JosAH
11,448 Expert 8TB
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
Jun 28 '08 #2
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.

Expand|Select|Wrap|Line Numbers
  1. Code removed, see posting guidelines
  2.  
Jun 28 '08 #3
JosAH
11,448 Expert 8TB
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
Jun 28 '08 #4
JosAH: thanks, but i dont understand "just replace a bit"...where?
deepak1706:thanks, but which software can run this code ? i never made it
Jun 29 '08 #5
JosAH
11,448 Expert 8TB
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
Jun 29 '08 #6
iconma
2
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...
Jun 30 '08 #7
JosAH
11,448 Expert 8TB
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
Jun 30 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
2
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...
8
by: mortb | last post by:
Hi, How do I write a GenerateHashcode function that will generate guaranteed unique hashcodes for my classes? cheers, mortb
14
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...
6
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...
9
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...
3
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);...
10
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...
24
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 ...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.