[ create a new paste ] login | about

Link: http://codepad.org/rHQkYCcv    [ raw code | output | fork ]

C++, pasted on Jun 6:
#include <iostream>
#include <stdio.h>
#include <vector>
int NUM=17;
using namespace std;
const int arr[3][3]={{10,5,8},{10,7,11},{9,3,11}};
int used[3][3]={{0,0,0},{0,0,0},{0,0,0}};
void testdiv(int a, int b, int c){//tests all possible division options
	if(   	a+ b +c ==NUM) 				printf("%d:%d+%d+%d\n"  ,NUM,a,b,c);
	if(	   (a+ b)/c ==NUM&&(a+ b)%c==0) printf("%d:(%d+%d)/%d\n",NUM,a,b,c);
	if(		a/ b +c ==NUM&& 	a%b==0)	printf("%d:%d/%d+%d\n"  ,NUM,a,b,c);
	if((b+c)&&a/(b+c)==NUM&& a%(b+c)==0)printf("%d:%d/(%d+%d)\n",NUM,a,b,c);
	if(		a+ b /c ==NUM&& 	b%c==0) printf("%d:%d+%d/%d\n"  ,NUM,a,b,c);
}
void testmul(int a, int b, int c){//tests all possible options involving multiplication
	if(a*b+c	==NUM)					printf("%d:%d*%d+%d\n"  ,NUM,a,b,c);
	if((a*b)/c	==NUM&&(a*b)%c	==0)	printf("%d:(%d*%d)/%d\n"  ,NUM,a,b,c);
	if(a+b*c	==NUM&&b%c		==0)	printf("%d:%d+%d*%d\n"  ,NUM,a,b,c);
	if(a/b*c	==NUM&&a%b		==0)	printf("%d:%d/%d*%d\n"  ,NUM,a,b,c);
	if(a/(b*c)	==NUM&&a%(b*c)	==0)	printf("%d:%d/(%d*%d)\n"  ,NUM,a,b,c);
}
void testdm(int a, int b, int c){//tests all possible division/multiplication/addition options
	testdiv(a,b,c);
	testmul(a,b,c);
}
void test(vector<int>& str){//generates all possible negative/positive combinations
	testdm(+str[0],+str[1],+str[2]);
	testdm(+str[0],+str[1],-str[2]);
	testdm(+str[0],-str[1],+str[2]);
	testdm(+str[0],-str[1],-str[2]);
	testdm(-str[0],+str[1],+str[2]);
	testdm(-str[0],+str[1],-str[2]);
	testdm(-str[0],-str[1],+str[2]);
	testdm(-str[0],-str[1],-str[2]);
}
void gensubstr(int x, int y,int depth, vector<int> str){//generates 3-substrings
	int i,j;
	used[x][y]=1;
	str.push_back(arr[x][y]);
	if(depth==3){
		test(str);
		used[x][y]=0;
		return;
	}
	for(i=-1;i<=1;i+=2){
		if(x+i>=3 || x+i<0) continue;
		if(used[x+i][y]) continue;
		gensubstr(x+i,y,depth+1,str);
	}
	for(i=-1;i<=1;i+=2){
		if(y+i>=3 || y+i<0) continue;
		if(used[x][y+i]) continue;
		gensubstr(x,y+i,depth+1,str);
	}
	used[x][y]=0;
}
int main(){
	vector<int> str;
	for(NUM=7;NUM<=18;++NUM)
		for(int i=0;i<3;++i)
			for(int j=0;j<3;++j)
				gensubstr(i,j,1,str);
	return 0;
}


Output:
7:10/10*7
7:10+-10+7
7:10/-10*-7
7:-10+10+7
7:-10/10*-7
7:-10/-10*7
7:10+5+-8
7:8+11/-11
7:8+-11/11
7:-8+5+10
7:10+9/-3
7:10+-9/3
7:-7+3+11
7:(7*10)/10
7:7+10+-10
7:7+-10+10
7:(7*-10)/-10
7:(-7*10)/-10
7:(-7*-10)/10
7:7/(10+-9)
7:-7/(-10+9)
7:(7*11)/11
7:7+11+-11
7:7+-11+11
7:(7*-11)/-11
7:(-7*11)/-11
7:(-7*-11)/11
7:11+-7+3
7:3+-7+11
7:11/-11+8
7:-11/11+8
7:11/11*7
7:11+-11+7
7:11/-11*-7
7:-11+11+7
7:-11/11*-7
7:-11/-11*7
7:11+3+-7
8:10/-10+9
8:-10/10+9
8:10/10+7
8:-10/-10+7
8:10+5+-7
8:5+-7+10
8:5+-8+11
8:(8*11)/11
8:8+11+-11
8:8+-11+11
8:(8*-11)/-11
8:(-8*11)/-11
8:(-8*-11)/11
8:10+10/-5
8:10+-10/5
8:10+-7+5
8:-10+7+11
8:-7+5+10
8:7+10/10
8:7+-10/-10
8:7+10+-9
8:7+11/11
8:7+-11/-11
8:11+-8+5
8:11+7+-10
8:9+10/-10
8:9+-10/10
8:-9+10+7
8:9/-3+11
8:-9/3+11
8:11/11*8
8:11+-11+8
8:11/-11*-8
8:-11+11+8
8:-11/11*-8
8:-11/-11*8
8:11/11+7
8:-11/-11+7
9:10/10*9
9:10+-10+9
9:10/-10*-9
9:-10+10+9
9:-10/10*-9
9:-10/-10*9
9:10/5+7
9:-10/-5+7
9:5+7+-3
9:5+-7+11
9:8+11/11
9:8+-11/-11
9:11+-7+5
9:(9*10)/10
9:9+10+-10
9:9+-10+10
9:(9*-10)/-10
9:(-9*10)/-10
9:(-9*-10)/10
9:-3+7+5
9:11/11+8
9:-11/-11+8
10:10/10+9
10:10/(10+-9)
10:-10/-10+9
10:-10/(-10+9)
10:10/5+8
10:-10/-5+8
10:-8+11+7
10:8+-5+7
10:7+-5+8
10:7*3+-11
10:-7*-3+-11
10:7+11+-8
10:9+10/10
10:9+-10/-10
10:9/3+7
10:-9/-3+7
10:3*7+-11
10:-3*-7+-11
11:10+10+-9
11:-9+10+10
11:3*7+-10
11:-3*-7+-10
12:10+-5+7
12:-5+7+10
12:8+11+-7
12:10+10/5
12:10+-10/-5
12:10+7+-5
12:7+-5+10
12:7*3+-9
12:-7*-3+-9
12:-7+10+9
12:-7+11+8
12:9+10+-7
13:10+10+-7
13:10+-5+8
13:-5+7+11
13:8+-5+10
13:10+9/3
13:10+-9/-3
13:7+-3+9
13:-7+10+10
13:11+7+-5
13:9+-3+7
14:10/5*7
14:10/-5*-7
14:-10/5*-7
14:-10/-5*7
14:-5+8+11
14:-8+11+11
14:(10*7)/5
14:(10*-7)/-5
14:(-10*7)/-5
14:(-10*-7)/5
14:10+7+-3
14:10+-7+11
14:11+8+-5
14:11+-7+10
14:9/3+11
14:-9/-3+11
14:-3+7+10
14:11+11+-8
15:5+7+3
15:-5+10+10
15:10+10+-5
15:7+-3+11
15:-7+11+11
15:11+7+-3
15:3+7+5
15:-3+7+11
15:11+11+-7
15:11+-3+7
16:10/5*8
16:10/-5*-8
16:-10/5*-8
16:-10/-5*8
16:10+9+-3
16:9*3+-11
16:-9*-3+-11
16:3*7+-5
16:-3*-7+-5
16:-3+9+10
17:-10+9*3
17:-10+-9*-3
17:9+-3+11
17:3*9+-10
17:-3*-9+-10
17:11+-3+9


Create a new paste based on this one


Comments: