Skip to content

Instantly share code, notes, and snippets.

@avipars
Created November 9, 2021 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avipars/90ac17fcfdea410fd8927247f706d79f to your computer and use it in GitHub Desktop.
Save avipars/90ac17fcfdea410fd8927247f706d79f to your computer and use it in GitHub Desktop.
I needed a quick solution to check permutations and substitutions
using namespace std;
bool isEq = false;
int equ = 0;
int isOne(bool number)
{
if (number)
{
return 1;
}
else
{
return 0;
}
}
bool isOne(int number)
{
if (number >= 1)
{
return true;
}
else
{
return false;
}
}
//permutations
void permutate(int a, int b, int c, int d)
{
cout << " " << a << " " << b << " " << c << " " << d << endl;
int cnot, dnot;
cnot = (c == 0) ? cnot = 1 : cnot = 0;
dnot = (d == 0) ? dnot = 1 : dnot = 0;
int totleft = isOne(a * b) + isOne(a * cnot) + isOne(c * d);
bool toLeft = isOne(totleft);
cout << "Total Left: " << toLeft << endl;
int totRight = isOne(cnot * dnot);
bool toRight = isOne(totRight);
cout << "Total Right: " << toRight << endl;
if (toLeft == toRight) {
cout << "is equivelent " << endl;
isEq = true;
equ++;
}
else {
cout << "is not equivelent " << endl;
isEq = false;
}
return;
}
int main()
{
permutate(1, 0, 0, 0);
permutate(0, 1, 0, 0);
permutate(0, 0, 1, 0);
permutate(0, 0, 0, 1);
permutate(1, 1, 0, 0);
permutate(0, 1, 1, 0);
permutate(0, 0, 1, 1);
permutate(1, 0, 1, 0);
permutate(1, 0, 0, 1);
permutate(0, 1, 1, 0);
permutate(0, 1, 0, 1);
permutate(1, 0, 1, 1);
permutate(1, 1, 0, 1);
permutate(1, 1, 1, 0);
permutate(1, 1, 1, 1);
permutate(0, 0, 0, 0);
cout << "old total equiv: " << equ << endl;
equ = 0;
cout << "NEW" << endl;
permutate(0, 0, 0, 0);
permutate(0, 0, 0, 1);
permutate(0, 0, 1, 0);
permutate(0, 0, 1, 1);
permutate(0, 1, 0, 0);
permutate(0, 1, 0, 1);
permutate(0, 1, 1, 0);
permutate(0, 1, 1, 1);
permutate(1, 0, 0, 0);
permutate(1, 0, 0, 1);
permutate(1, 0, 1, 0);
permutate(1, 0, 1, 1);
permutate(1, 1, 0, 0);
permutate(1, 1, 0, 1);
permutate(1, 1, 1, 0);
permutate(1, 1, 1, 1);
cout << "new total equiv: " << equ << endl;
return 0;
}
@avipars
Copy link
Author

avipars commented Nov 9, 2021

using namespace std;

bool isEq = false;
int equ = 0;
int isOne(bool number)
{
if (number)
{
return 1;
}
else
{
return 0;
}
}

bool isOne(int number)
{
if (number >= 1)
{
return true;
}
else
{
return false;
}

}
//permutations
void permutate(int a, int b, int c, int d)
{
cout << " " << a << " " << b << " " << c << " " << d << endl;
int cnot, dnot;
cnot = (c == 0) ? cnot = 1 : cnot = 0;
dnot = (d == 0) ? dnot = 1 : dnot = 0;

int totleft = isOne(a * b) + isOne(a * cnot) + isOne(c * d);
bool toLeft = isOne(totleft);
cout << "Total Left: " << toLeft << endl;
int totRight = isOne(cnot * dnot);
bool toRight = isOne(totRight);

cout << "Total Right: " << toRight << endl;

if (toLeft == toRight) {
    cout << "is equivelent " << endl;
    isEq = true;
    equ++; 
}
else {
    cout << "is not equivelent " << endl;
    isEq = false; 
}

return;

}

//permutations
void newPermute(int a, int b)
{
cout << "newPermute " << a << " " << b << endl;
int anot, dnot;
anot = (a == 0) ? anot = 1 : anot = 0;

int totleft = isOne(anot) + isOne(a * b);
bool toLeft = isOne(totleft);
cout << "Total Left: " << toLeft << endl;
int totRight = isOne(0);
bool toRight = isOne(totRight);

cout << "Total Right: " << toRight << endl;

if (toLeft == toRight) {
    cout << "is equivelent " << endl;
    isEq = true;
    equ++;
}
else {
    cout << "is not equivelent " << endl;
    isEq = false;
}

return;

}

//permutations
void thirdPermute(int a, int b, int c)
{
cout << "3perm " << a << " " << b << " " << c << endl;

int totleft = isOne(a*b);
bool toLeft = isOne(totleft);
cout << "Total Left: " << toLeft << endl;
int totRight = isOne(a*c);
bool toRight = isOne(totRight);

cout << "Total Right: " << toRight << endl;

if (toLeft == toRight) {
    cout << "is equivelent " << endl;
    isEq = true;
    equ++;
}
else {
    cout << "is not equivelent " << endl;
    isEq = false;
}

return;

}

int main()
{
/* permutate(1, 0, 0, 0);
permutate(0, 1, 0, 0);
permutate(0, 0, 1, 0);
permutate(0, 0, 0, 1);
permutate(1, 1, 0, 0);
permutate(0, 1, 1, 0);
permutate(0, 0, 1, 1);
permutate(1, 0, 1, 0);
permutate(1, 0, 0, 1);
permutate(0, 1, 1, 0);
permutate(0, 1, 0, 1);
permutate(1, 0, 1, 1);
permutate(1, 1, 0, 1);
permutate(1, 1, 1, 0);
permutate(1, 1, 1, 1);
permutate(0, 0, 0, 0);*/
//cout << "old total equiv: " << equ << endl;
//equ = 0;

cout << "NEW" << endl; 

/* permutate(0, 0, 0, 0);
permutate(0, 0, 0, 1);
permutate(0, 0, 1, 0);
permutate(0, 0, 1, 1);
permutate(0, 1, 0, 0);
permutate(0, 1, 0, 1);
permutate(0, 1, 1, 0);
permutate(0, 1, 1, 1);
permutate(1, 0, 0, 0);
permutate(1, 0, 0, 1);
permutate(1, 0, 1, 0);
permutate(1, 0, 1, 1);
permutate(1, 1, 0, 0);
permutate(1, 1, 0, 1);
permutate(1, 1, 1, 0);
permutate(1, 1, 1, 1);*/

//newPermute(0, 1);
//newPermute(1, 1);
//newPermute(1, 0);
//newPermute(0, 0);


thirdPermute(0, 0, 0);
thirdPermute(1, 0, 0);
thirdPermute(0, 1, 0);
thirdPermute(0, 0, 1);
thirdPermute(1, 1, 0);
thirdPermute(0, 1, 1);
thirdPermute(1, 0, 1);
thirdPermute(1, 1, 1);
cout << "new total equiv: " << equ <<  endl;


return 0;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment