Need help figuring out how to write a certain probability simulator

i need to write a program that will calculate every possible arrangmen

Page 1 of 1

5 Replies - 3524 Views - Last Post: 03 July 2007 - 01:52 PM Rate Topic: -----

#1 superlaxstar112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-July 07

Need help figuring out how to write a certain probability simulator

Posted 03 July 2007 - 12:00 PM

Alright, this is my first topic, and my first time using these forums. I have read the rules, and I have searched for similiar problems/solutions. I am fluent in Basic, and I know a enough of C++ and C to get by.

The problem: I need to write a program that will calculate every possible arrangment of 7 items and order matters (letters, numbers, colors; doesnt matter)

Now I sat down, like I usually do before starting a program, and tried to think of how to approach this problem. After about 2 hours I gave up. I tried writing it in basic, and I was still facing the same problem, how to have the computer do out each combination. I am very frustrated that I cannot figure this out. Now I dont want anyone to completely solve this for me, as I would like to do it myself. But any suggestions or ideas on how to set up a function or method to calculate all of the combos would be greately appreciated.

NOTE: I am not trying to find out how many combos possible, (as this is 7! + 7p6 + 7p5 + 7p4...7p1 = 13,650 different combos), I am trying to find a way to have the computer list them.

The final program is basically going to recieve each combination, and click a series of buttons in that order. I have no problem translating a combo into a click order, I just need help figuring out how to have the computer figure out the combinations. Thanks! and please dont flame me :(

and I have no code because I have no idea where to start :(

Is This A Good Question/Topic? 0
  • +

Replies To: Need help figuring out how to write a certain probability simulator

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,455
  • Joined: 10-May 07

Re: Need help figuring out how to write a certain probability simulator

Posted 03 July 2007 - 12:12 PM

Is this something like what you are after....

#include <stdio.h>

#define MAX 7
int main(void) {
  char numb[MAX];
  int i=0,j=0;

  numb[0]='a';
  numb[1]='b';
  numb[2]='c';
  numb[3]='d';
  numb[4]='e';
  numb[5]='f';
  numb[6]='g';

  for(;i<MAX;i++) {
	//printf("%c : ",numb[i]);
	for(;j<MAX;j++) printf("%c: %c\n",numb[i],numb[j]);
	j=0;
	printf("\n");
  }

  return 0;
}



This produces output like so:
a: a
a: b
a: c
a: d
a: e
a: f
a: g

b: a
b: b
b: c
b: d
b: e
b: f
b: g

c: a
c: b
c: c
c: d
c: e
c: f
c: g

& so on.
Was This Post Helpful? 0
  • +
  • -

#3 superlaxstar112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-July 07

Re: Need help figuring out how to write a certain probability simulator

Posted 03 July 2007 - 12:25 PM

Thank you for your response. And well I tried what you had suggested, and it isnt exactly what I need, although it is a start.

I need something that prints like

a,b,c,d,e,f,g << where this is combo 1
a,b,c,d,e,g,f combo 2
a,b,c,d,f,e,g combo 3
and so on, until all 13,650 combos have been printed
however, not only do I need to find all of the permutations for 7 letters, i need to find them for 6, 5, 4, 3, 2, 1 letters as well. :-/
Was This Post Helpful? 0
  • +
  • -

#4 superlaxstar112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-July 07

Re: Need help figuring out how to write a certain probability simulator

Posted 03 July 2007 - 01:23 PM

OK so I figured out how to do the permutations:

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cstdlib>
#include <ctime>
#include <windows.h>

using namespace std;


//using pointers
void display(char* c_str)
{
  cout<<c_str<<endl;
}

int main()
{
  char ca[]="1234567";
  
  display(ca);
  for(int i=0;i<5040;++i)
  {
	next_permutation(ca,ca+7);	
	display(ca);
  }

  Sleep(99999);
  return 0;
}



I just had to use the next_permutation function in the algorithms header. So i decided to store the different permutations in a char array, or i might even store them in a string array.

each string from the array has 7 "slots" I guess. So like "1234657" has 1 in the first slot, 2 in the second slot, 6 in the 5th slot, and so on... how do i check to find what numbers are in each "slot" given just a string?
Was This Post Helpful? 0
  • +
  • -

#5 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Need help figuring out how to write a certain probability simulator

Posted 03 July 2007 - 01:46 PM

God bless the STL...why reinvent the wheel? :)

Do you need to find which numbers are in each slot? If so, do you need them as numbers? Or can you just compare in char format?
Was This Post Helpful? 0
  • +
  • -

#6 superlaxstar112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-July 07

Re: Need help figuring out how to write a certain probability simulator

Posted 03 July 2007 - 01:52 PM

Ha ha yea, exactly. I was all frustrated when It was already in the STL. And I need them as numbers, so like i need to check what number is in slot 1, slot 2, slot 3 and so on until i check all 7 slots. What i want to eventually do, is have it check each slot, then click the button assosiated with that number. so if slot 1 contains 5 it will click the button that goes with 5. Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1