int check5(float *number3, int *oper3){
	int y,n,z,w;
	float num5[5];
	float num4[4];
	float num3[3];
	float num2[2];
	int op5[4];
	int op4[3];
	int op3[2];
	int op2[1];
	for (y=0; y<4; y++){
		copy_arrays(number3,num5,oper3,op5,5);
		num5[y+1] = calc(num5[y],num5[y+1],op5[y]);
		shift_array(num5,op5,y,5);
		for (n=0; n<3; n++){
			copy_arrays(num5,num4,op5,op4,4);
			num4[n+1] = calc(num4[n],num4[n+1],op4[n]);
			shift_array(num4,op4,n,4);
			for (z=0; z<2; z++){
				copy_arrays(num4,num3,op4,op3,3);
				num3[z+1] = calc(num3[z],num3[z+1],op3[z]);
				shift_array(num3,op3,z,3);
				for (w=0; w<1; w++){
					copy_arrays(num3,num2,op3,op2,2);
					num2[w+1] = calc(num2[w],num2[w+1],op2[w]);
					shift_array(num2,op2,w,2);
					if (num2[0]==100){
						return 1;
					}
				}
			}
		}
	}
	return 0;
}
Exemplo n.º 2
0
/** add a list of ids to the scrubbing array */
static int add_id_list(const wagon_t *list, unsigned int count)
{
    /* always add at the beginning to have LIFO behavior */

    /* is there enough room before the first item ? */
    if (count <= array_first) {
        /* copy it just before the head (entries must be consecutive) */
        copy_arrays(list, dir_array, array_first - count, count);

        array_first -= count;

#ifdef _DEBUG_ID_LIST
        printf("1)...<new_ids:%u-%u><ids:%u-%u>...(len=%u)\n",
               array_first, array_first + count - 1,
               array_first + count, array_len - 1, array_len);
#endif
    }
    /* is the array empty ? */
    else if ((array_used == 0) && (count <= array_len)) {
        /* copy from the beginning */
        copy_arrays(list, dir_array, array_len - count, count);
        array_first = array_len - count;

#ifdef _DEBUG_ID_LIST
        printf("2) <new_ids:%u-%u>...(len=%u)\n",
               array_first, array_len - 1, array_len);
#endif
    } else {    /* increase array size */

        wagon_t *dir_array_new;
        size_t new_len = what_2_power(array_len + count);

        dir_array_new = MemAlloc(new_len * sizeof(wagon_t));
        if (!dir_array_new)
            return -ENOMEM;

        /* First, transfer current ids and names */
        if (dir_array) {
            if (array_used)
                memcpy(&dir_array_new[new_len - array_used],
                       &dir_array[array_first], array_used * sizeof(wagon_t));
            MemFree(dir_array);
        }

        /* update array info */
        dir_array = dir_array_new;
        array_first = new_len - array_used;
        array_len = new_len;

        /* Then copy new ids */
        copy_arrays(list, dir_array, array_first - count, count);
        array_first -= count;

#ifdef _DEBUG_ID_LIST
        printf("3)...<ids:%u-%u>...(len=%u)\n",
               array_first, array_len - 1, array_len);
#endif
    }
    return 0;
}
int lucky(char *argn){
	int i,j;
	long int input = atol(argn);
	int length = find_length(input);
	float *number = (float *)malloc(length*sizeof(float));
	init(number,length,input);
	float *number1 = (float *)malloc(length*sizeof(float));
	int **oper2;
	oper2 = (int **)malloc(Pow(4,(length-1))*sizeof(int *));	
	for (i=0; i<Pow(4,(length-1)); i++){
		oper2[i] = (int *)malloc(length*sizeof(int));
	}
	int *oper3 = (int *)malloc(length*sizeof(int));
	float *number3 = (float *)malloc(length*sizeof(float));
	create_opers(oper2,length);
	int length1;
	for (i=0; i<Pow(2,(length-1)); i++){
		length1 = create_group(i,number,length,number1);
		for (j=0; j<Pow(4,(length1-1)); j++){
			copy_arrays(number1,number3,oper2[j],oper3,length1);
			if (check(length1,number3,oper3)){
				return 0;
			}
		}
	}
	return 1;
}
int check6(float *number3, int *oper3){
	int m,y,n,z,w;
	float num6[6];
	float num5[5];
	float num4[4];
	float num3[3];
	float num2[2];
	int op6[5];
	int op5[4];
	int op4[3];
	int op3[2];
	int op2[1];
	for (m=0; m<5; m++){	//(2 - (7 * (((1 / 3) - 5) * 3)))
		copy_arrays(number3,num6,oper3,op6,6);
		num6[m+1] = calc(num6[m],num6[m+1],op6[m]);
		shift_array(num6,op6,m,6);
		for (y=0; y<4; y++){
			copy_arrays(num6,num5,op6,op5,5);
			num5[y+1] = calc(num5[y],num5[y+1],op5[y]);
			shift_array(num5,op5,y,5);
			for (n=0; n<3; n++){
				copy_arrays(num5,num4,op5,op4,4);
				num4[n+1] = calc(num4[n],num4[n+1],op4[n]);
				shift_array(num4,op4,n,4);
				for (z=0; z<2; z++){
					copy_arrays(num4,num3,op4,op3,3);
					num3[z+1] = calc(num3[z],num3[z+1],op3[z]);
					shift_array(num3,op3,z,3);
					for (w=0; w<1; w++){
						copy_arrays(num3,num2,op3,op2,2);
						num2[w+1] = calc(num2[w],num2[w+1],op2[w]);
						shift_array(num2,op2,w,2);
						if (num2[0]==100){
							return 1;
						}
					}
				}
			}
		}
	}
return 0;
}
int check3(float *number3, int *oper3){
	int z,w;
	float num3[3];
	float num2[2];
	int op3[2];
	int op2[1];
	for (z=0; z<2; z++){
		copy_arrays(number3,num3,oper3,op3,3);
		num3[z+1] = calc(num3[z],num3[z+1],op3[z]);
		shift_array(num3,op3,z,3);
		for (w=0; w<1; w++){
			copy_arrays(num3,num2,op3,op2,2);
			num2[w+1] = calc(num2[w],num2[w+1],op2[w]);
			shift_array(num2,op2,w,2);
			if (num2[0]==100)
				return 1;
		}
	}
	return 0;
}
int check8(float *number3, int *oper3){
	int k,l,m,y,n,z,w;
	float num8[8];
	float num7[7];
	float num6[6];
	float num5[5];
	float num4[4];
	float num3[3];
	float num2[2];
	int op8[7];
	int op7[6];
	int op6[5];
	int op5[4];
	int op4[3];
	int op3[2];
	int op2[1];
	for (k=0; k<7; k++){
		copy_arrays(number3,num8,oper3,op8,8);
		num8[k+1] = calc(num8[k],num8[k+1],op8[k]);
		shift_array(num8,op8,k,8);
		for (l=0; l<6; l++){
			copy_arrays(num8,num7,op8,op7,7);
			num7[l+1] = calc(num7[l],num7[l+1],op7[l]);
			shift_array(num4,op4,l,7);
			for (m=0; m<5; m++){
				copy_arrays(num7,num6,op7,op6,6);
				num6[m+1] = calc(num6[m],num6[m+1],op6[m]);
				shift_array(num6,op6,m,6);
				for (y=0; y<4; y++){
					copy_arrays(num6,num5,op6,op5,5);
					num5[y+1] = calc(num5[y],num5[y+1],op5[y]);
					shift_array(num5,op5,y,5);
					for (n=0; n<3; n++){
						copy_arrays(num5,num4,op5,op4,4);
						num4[n+1] = calc(num4[n],num4[n+1],op4[n]);
						shift_array(num4,op4,n,4);
						for (z=0; z<2; z++){
							copy_arrays(num4,num3,op4,op3,3);
							num3[z+1] = calc(num3[z],num3[z+1],op3[z]);
							shift_array(num3,op3,z,3);
							for (w=0; w<1; w++){
								copy_arrays(num3,num2,op3,op2,2);
								num2[w+1] = calc(num2[w],num2[w+1],op2[w]);
								shift_array(num2,op2,w,2);
								if (num2[0]==100)
									return 1;
							}
						}
					}
				}
			}
		}
	}
	return 0;
}
int check2(float *number3, int *oper3){
	int w;
	float num2[2];
	int op2[1];
	for (w=0; w<1; w++){
		copy_arrays(number3,num2,oper3,op2,2);
		num2[w] = calc(num2[w],num2[w+1],op2[w]);
		shift_array(num2,op2,w,2);
		if (num2[0]==100)
			return 1;
	}
	return 0;
}