C++ :: Algorithm For All Possible Combinations?
Mar 7, 2013
A few days ago I got a "bright idea" to see if I could match a string, with an arbitrary length from 1 to 12, to its formulated sequence by using an algorithm to find all possible combinations of the integer combinations from 0 to 9 at each length (1 to 12).
Example: Desired numerical combinations from integers 1 to 3:
At Length 1:
1, 2, 3
At Length 2:
11, 12, 13, 21, 22, 23, 31, 32, 33
At Length 3:
111, 112, 113, 121, 122, 123, 131, 132, 133, 211, 212, 213, 221, 222, 223, 231, 232, 233, 311, 312, 313, 321, 322, 323, 331, 332, 333
And so on until the nth length (in my case a length of 12).
First off, I would like to say that this is not as easy as I thought. I clearly underestimated the problem seeing as I've spent hours attempting to write a working algorithm, but feel like I've made no progress.
Here are a few of my attempts:
Attempt 1:
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
[Code]....
I can't exactly explain this one. It works if the length is 2 or less; however, the order of the output is horrendous.
Attempt 3: I tried using recursion, but only found myself getting more and more lost the further I tried developing my function. Cannot find my work for this attempt.
I would really like to figure this out on my own, but I am very stuck as you can see. I also lack time that I can spend working on this since im a full time student.
View 14 Replies
ADVERTISEMENT
Mar 4, 2014
I need to create a function that outputs all possible binary combinations. I'm really stumped on this. I have to do it with nested loops, and am not sure how to go about it. Below is what I tried so far.
The output should look like this:
00000000
00000001
00000010
00000011
00000100
...
11111110
11111111
Code:
void outputBinary(){
int a[2][2][2][2][2][2][2][2];
for (int i = 0; i < 2; i++){
for (int j = 0; j < 2; j++){
[Code] .....
View 2 Replies
View Related
Nov 27, 2013
I wanted to create a 5, 3 combinations. i know how to calculate to get the number of combinations 5 3 would have (which is ten), but it seem it's a bit harder for me to print those data ...
View 2 Replies
View Related
Feb 26, 2015
How to find all possible combinations of coordinates on a 2d grid with a given sum. The sum is not fixed!
E.g. N=nxm=25 thats our grid.
The sum=distance between points on a grid.
For two points distance=|(x1-x2)+(y1-y2)| point A(X1,Y1) B(X1,Y1)
My interest is to know how to find the combinations of coordinates with a given sum, it doesn't matter how many points are there.
If i enter the sum e.g sum=7 and the program has to show all possible combinations which gives the sum of 7 the number of point does not play in row they might be two or maybe more.
View 4 Replies
View Related
Jan 25, 2013
Code:
#include<stdio.h>
#include<string.h>
#define a 15
[Code]....
I am trying to print all combinations of a string but I couldn't figure out how to do loop for it. Code works only 2-3-4 letters words
View 4 Replies
View Related
Feb 17, 2013
I am trying to write a program for printing all the combinations of a string. Why this program is giving the error message.
"First-chance exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4..
Unhandled exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4.." when i try to run this in MVS 2010
#include<iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<conio.h>
void combination(std::string input,int length,std::string buffer,int allowedno)
[Code] .....
View 1 Replies
View Related
Jun 23, 2014
How to get all the possible combinations for 4 digits from a 5 digit number. I need a pair that has both 5 digits and four digits. their sum must be equal to a five digit user input. i.e.
user input : 14690
output:
14690 has pairs 12345 + 2345
2345 came from 12345
lets say that x = 12345 and y =2345
besides y == x%10000
other formula can i have since if i use % and / i will have a lot of declarations....
View 2 Replies
View Related
Feb 14, 2013
I have an integer vector of size "n".
e.g.
std::vector<int> vec;
vec.pushback(0);
vec.pushback(1);
vec.pushback(2);
vec.pushback(3);
Now I want to generate all possible combinations of size = {0, 1, 2, ... , n}.
{0, 1, 3} is not equal to {3, 1, 0} or {1, 0, 3} or {3, 0, 1}
View 7 Replies
View Related
Jan 12, 2015
how to write a password cracking program that will try all possible char combinations for just two chars (without duplicating any combination guesses). Obviously, there would only be 4 possible truth table combinations for two boolean values, but how would a person calculate the number of all possible combinations for two values with 70 different possible chars?
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
/*
Boolean Truth Table for two values:
p q
-----
T T
T F
F T
F F
Note that there are 70 chars in all specified above.
It will require much more than a simple truth table to try every possible char combination (especially if the password to be cracked is 2 or more chars). Using this guy's code: [URL] ..... as a starting point, I'm writing a program that will crack a password with a length of just 2 chars.
*/
int stringLength = 2;
char genRandom() {
return alphanum[rand() % stringLength];
}
int main() {
std::string password = "Sp";
srand(time(0));
std::string Str;
[code]....
View 19 Replies
View Related
Apr 4, 2014
The first line of my input file is going to contain some number "T" which will represent the "combination length" of a list of random words. (In this case, they are Taco Bell items). The first number on the second line represents the number of unique items on the menu to get, and the second number on the second line represents the number of unique items that are supposed to be bought.
Basically the input will look like this: 2 3 2 taco burrito nacho
And the output looks like this: burritos nachos nacho taco burrito taco
This is what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
int main(void){
int N, T, K;
char menu[N][20];
[Code] .....
What I am trying to get working right now is just to scan a file and put the strings into an array so then I can work on sorting the array. How can I add strings from a file into an array?
View 4 Replies
View Related
Mar 6, 2015
Coding for- To print all combinations of numbers that can compose a given number..
View 3 Replies
View Related
Dec 24, 2014
I've been experimenting a bit and can't find a decent way to make a brute forcing script that accepts a password from standard input, and goes through all possible combinations until it is matched. How to structure the code?
View 1 Replies
View Related
Dec 22, 2013
I need a list generated of all possible subset combinations for the set 1,2,3,4,5,6,7,8,9,10,12. Select six. Numbers cannot repeat.
Example subset: 1,2,3,4,5,6 (six selected, no repeats).
Example of what I dont need: 1,1,2,2,3,3,4,4,5,5,12,12 or 1,1,1,1,1,6.
I will also need the opposites removed, meaning...if I have 1,3,5,7,9,11 then I need 2,4,6,8,10,12 eliminated from the final list.
This is for a game, where you must select all numbers right or no numbers right.
View 2 Replies
View Related
Sep 21, 2014
The code below will generate combinations of numbers from 1 to 25 in an 15 numbers array. The only filter I've applied is that the sum of all the numbers in the vectors divided by 15 needs to be between 13 and 14.
I would like to count how many consecutive numbers there are in one combination, so that later i can apply another filter.. for example:
1 3 4 5 6 8 10 13 14 16 17 18 19 20 25
3 + 4 = 1
4 + 5 = 1
5 + 6 = 1
13 + 14 = 1
16 + 17 = 1
17 + 18 = 1
18 + 19 = 1
19 + 20 = 1
_____________
Count = 8, in this case..
I think it's not very difficult to do, but i just can't see how to do it.
#include <iostream>
#include <vector>
#include <numeric>
[Code]....
View 3 Replies
View Related
Apr 9, 2014
I am writing a simple console-based tic-tac-toe game. I am trying to write a function to check whether someone has won the game.
The board data is saved in an array called board: Code: int board[3][3] with each element corresponding either to an empty spot, an X, or an O, using the numbers 0, 1, and 2, respectively. For clarity:
Code:
#define EMPTY 0
#define X 1
#define O 2 Here is my function: Code: int check_state(int board[3][3]) {
int winner = 0;
[Code].....
View 1 Replies
View Related
Jul 24, 2013
I wrote a version of find_all() which searches through containers for matches and returns another container that holds iterators pointing to each match. When I compared what I wrote to what the authors of Professional C++ wrote, I found the two find_all() functions to be very different.Here they are:
//Mine
template<typename Iterator, typename Predicate>
std::list<Iterator> find_all
(Iterator front, Iterator back, const Predicate& match) {
std::list<Iterator> toreturn;
for(; front != back; ++front) if(*front == match) toreturn.push_back(front);
[code]...
View 5 Replies
View Related
Jun 27, 2014
I have VRP algorithm written in C++, run with command prompt Windows. input (command line) -> VRP.exe -> output (txt file)
Now I want to built a website to run it as SaaS. How to run an exe application(compiled c++) in server used as Saas? What kind of programming do I have to use? Ruby or html5 or others? I don't know how to start.
View 3 Replies
View Related
Aug 27, 2013
i was trying to achieve a better way of game looping. so i have a game loop algrithm. but i dont think its quite good. i want it to be better.
here is my algorithm
bool quit = false;
while(quit == false) {
while(blah blah events)//here we hold events {
if(the user want to quits) {
quit = true;
[code]....
View 2 Replies
View Related
May 12, 2014
To construct and write down algorithm of determination of the sum of squares of consecutive integers with recursion use. I tried to do something:
public static int RecSumSquare(int x, int n)
{
if (n < 0) throw new ArgumentException("n should be greater than zero");
if (n == 0) return 0;
else return x*x+RecSumSquare(x, n - 1);
}
But I don't know as the beginning and the end of this algorithm will look.
View 2 Replies
View Related
Mar 10, 2014
I'm still a beginner at C++ programming, I have tried to implement some optimization algorithms (related to database) in C++, I cannot say it is going as far as I thought it will be, some errors does not even make sense, I will cut to the chase, I need to implement SA (Simulated Annealing) in C++, SA, which is an example of the Randomized Algorithms, functions on the concept of randomness and probability. In addition, I searched the internet with no (let say "accurate") code that might give me insight on how to begin, I only found one code for SA that I could understand, and edited it (which will be shown below), still looking to enhance and correct it more.
The code for SA is as follows:
Code:
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <cmath>
[Code] .....
If the concept of Simulated Annealing is not clear, you may refer to the following papers which can be found in a simple Google search: Simulated Annealing Algorithms: an overview.An Introduction to Interacting Simulated Annealing. Query Optimization (there is a sub-section for Simulated Annealing in this paper that explains SA briefly) ....
View 6 Replies
View Related
Sep 17, 2014
I'm trying to draw and pivot a rectangle. How to get the new coordinates if I turn it 90 degree for example?
From this:
To this:
This is not good because it will reduce it in size.
Code:
int size = 50;
if(b) // draw rectangle
{
POINT points[4] =
{{xCoord, yCoord},
[Code] ....
View 7 Replies
View Related
Jun 3, 2013
Trying to multiply to matrixes using the following algorithm,
Code:
ABrec(A,B)
n=A.rows; //n must be multiple of 2
C is a new n*n matrix.
if(n==1)
C[0][0]=A[0][0]*B[0][0];
[Code] ....
but the code doesn't work !!!
View 4 Replies
View Related
Aug 3, 2014
Now I know there's a simple way to calculate highest value. But here i have this algorithm which i understood part of it.
I know that *largest is point to the first element of begin which is 5. so in the first if statement its 5<5 at the first iteration ?
// i marked the parts i didnt understand with " //"
Code:
#include <stdio.h>
int *print(int *begin ,int *end ){
if(begin==end)
return 0;
int *largest = begin;
[Code] ....
View 10 Replies
View Related
Dec 24, 2014
i can't seem to get this merge sort to work. running through gdb though;
Code:
*Filename: mergeSort.c
*Usage: This implements merge sort algorithm to sort and array of numbers.
*/
#include <stdio.h>
#include <stdlib.h>
}
[code]...
View 2 Replies
View Related
Jul 22, 2014
write an algorithm using stack to determine if an input of string is in the form xCy where y is the reverse of x.x and y are strings of A and B. eg : AABACABAA
View 8 Replies
View Related
Mar 25, 2013
I'm trying to implement the flocking algorithm in C++. I've tried to implement it myself by making all the particles 'home-in' on the player. When 2 particles then collide within their larger bounding boxes they home-in to each other. And when the 2 particles are actually touching they repel each other until they are outside of their bounding boxes and find another particle to home-into.when I run my application the particles all home into the player and come to a stand still along the Y-axis above the player.
All the particles in question are stored in a Vector, with a pos and velocity.
for(int i = 0; i < swarm.size(); i++) {
for (int j = 0; j < swarm.size(); j++) {
if (swarm.at(i)->getParticleModel()->getPosition().x < gameObjects.front()->getParticleModel()->getPosition().x) {
if (swarm.at(i)->getParticleModel()->getTouching() == false)
[code]....
View 5 Replies
View Related