int solve(int x, int y)
 {
 int temp,i,j;
 for(i=0;i<9;i++)
 for(j=0;j<9;j++)
 if(output[i][j]>9||output[i][j]<0)
 return 0;
 if (output[x][y] == 0)
{

  for (i = 1; i < 10; i++)
 {
   temp = input_value(x,y,i);
   if (temp > 0)
{
    output[x][y] = temp;

    if (x == 8 && y == 8)
 {
      return 1;
    }
 else if (x == 8)
 {
      if (solve(0,y+1)) return 1;
    }
else
{
      if (solve(x+1,y)) return 1 ;
    }
      }
    }
  if (i == 10)
 {
      if (output[x][y] !=  input[x][y]) output[x][y] = 0;
   return 0;
    }
 }
 else
 {
  if (x == 8 && y == 8)
{
   return 1;
  }
 else if (x == 8)
{
    if (solve(0,y+1)) return 1;
  }
 else
 {
   if (solve(x+1,y)) return 1;
    }
 }

}
Example #2
0
void screen_type_event(Screen *scr, TxProfile *txp, Event *e)
{
    if (e->type == EVENT_ANALOG_DOWN || e->type == EVENT_ANALOG_UP) {
        if (e->v.analog.number == 2) {
            int8_t v = (e->v.analog.position - 128)/64; // -7 .. +7
            input_value(v);
            if (v) {
                SET_PROFILE_DIRTY();
            }

        }
    }
    else
    if (e->type == EVENT_CLICK) {
        input_next();
        _cursor = 0;
    }
    else
    if (e->type == EVENT_LONG_CLICK) {
        if (txp->tx_mode == TX_MODE_ACRO) {
            screen_change(SCREEN_NAME);
        }
        else {
            screen_change(SCREEN_CURVE);
        }

    }
    else
    if (e->type == EVENT_DOUBLE_CLICK) {
        save_or_abort();
    }
    else {
        return; //ignore any other event
    }

    scr->is_dirty=1;

}
Example #3
0
int backtrack(int x, int y)
{
    int temp, i;
    if (outputArray[x][y] == 0) {
        for (i = 1; i < 10; i++) {
            temp = input_value(x, y, i);
            if (temp > 0) {
                outputArray[x][y] = temp;
                if (x == 8 && y == 8) {
                    return 1;
                } else if (x == 8) {
                    if (backtrack(0, y + 1))
                        return 1;
                } else {
                    if (backtrack(x + 1, y))
                        return 1;
                }
            }
        }
        if (i == 10) {
            if (outputArray[x][y] != array[x][y])
                outputArray[x][y] = 0;
            return 0;
        }
    } else {
        if (x == 8 && y == 8) {
            return 1;
        } else if (x == 8) {
            if (backtrack(0, y + 1))
                return 1;
        } else {
            if (backtrack(x + 1, y))
                return 1;
        }
    }
    return 0;
}
Example #4
0
static int config_stream_roi(int stream_id)
{
	int back2main = 0, i;
	char opt, input[16];
	VERIFY_STREAMID(stream_id);
	while (back2main == 0) {
		show_stream_menu(stream_id);
		printf("Your choice: ");
		fflush(stdin);
		scanf("%s", input);
		opt = input[0];
		tolower(opt);
		switch(opt) {
		case '1':
			if (check_for_qp_roi(stream_id) < 0)
				break;
			if (get_quality_level(stream_id) < 0)
				break;
			printf("\nCurrent quality level is 1:[%d], 2:[%d], 3:[%d].\n",
					stream_roi[stream_id].qp_delta[0],
					stream_roi[stream_id].qp_delta[1],
					stream_roi[stream_id].qp_delta[2]);
			i = 0;
			do {
				printf("Input QP delta (-51~51) for level %d: ", i+1);
				stream_roi[stream_id].qp_delta[i] = input_value(-51, 51);
			} while (++i < 3);
			set_quality_level(stream_id);
			break;
		case '2':
		case '3':
			if (check_for_qp_roi(stream_id) < 0)
				break;
			printf("\nInput ROI offset x (0~%d): ", stream_roi[stream_id].encode_width - 1);
			qp_roi[stream_id].start_x = input_value(0, stream_roi[stream_id].encode_width - 1);
			printf("Input ROI offset y (0~%d): ", stream_roi[stream_id].encode_height - 1);
			qp_roi[stream_id].start_y = input_value(0, stream_roi[stream_id].encode_height -1);
			printf("Input ROI width (1~%d): ", stream_roi[stream_id].encode_width
		        - qp_roi[stream_id].start_x);
			qp_roi[stream_id].width = input_value(1, stream_roi[stream_id].encode_width
				- qp_roi[stream_id].start_x);
			printf("Input ROI height (1~%d): ", stream_roi[stream_id].encode_height
			    - qp_roi[stream_id].start_y);
			qp_roi[stream_id].height = input_value(1, stream_roi[stream_id].encode_height
				- qp_roi[stream_id].start_y);
			if (opt == '2') {
				printf("Input ROI quality level (1~3): ");
				qp_roi[stream_id].quality_level = input_value(1, 3);
			} else
				qp_roi[stream_id].quality_level = 0;
			set_qp_roi(stream_id);
			break;
		case '4':
			if (check_for_qp_roi(stream_id) < 0)
				break;
			clear_qp_roi(stream_id);
			break;
		case '5':
			if (check_for_qp_roi(stream_id) < 0)
				break;
			display_qp_roi(stream_id);
			break;
		case 'q':
			back2main = 1;
			break;
		default:
			printf("Unknown option %d.", opt);
			break;
		}
	}
	return 0;
}
Example #5
0
/**
 * Test generation of permutation using halmd::radix_sort on GPU.
 */
static void test_permutation_gpu(int count, int repeat)
{
    std::vector<unsigned int> input_key = make_uniform_array(count);
    cuda::vector<unsigned int> g_input_key(count);
    BOOST_CHECK( cuda::copy(
        input_key.begin()
      , input_key.end()
      , g_input_key.begin()) == g_input_key.end()
    );
    std::vector<unsigned int> result(input_key.begin(), input_key.end());
    std::sort(result.begin(), result.end());

    std::vector<unsigned int> input_value(count);
    std::iota(input_value.begin(), input_value.end(), 0);
    cuda::vector<unsigned int> g_input_value(count);
    BOOST_CHECK( cuda::copy(
        input_value.begin()
      , input_value.end()
      , g_input_value.begin()) == g_input_value.end()
    );

    BOOST_TEST_MESSAGE( "  " << count << " elements" );
    BOOST_TEST_MESSAGE( "  " << repeat << " iterations" );

    halmd::accumulator<double> elapsed;
    for (int i = 0; i < repeat; ++i) {
        cuda::vector<unsigned int> g_output_key(count);
        BOOST_CHECK( cuda::copy(
            g_input_key.begin()
          , g_input_key.end()
          , g_output_key.begin()) == g_output_key.end()
        );

        cuda::vector<unsigned int> g_output_value(count);
        BOOST_CHECK( cuda::copy(
            g_input_value.begin()
          , g_input_value.end()
          , g_output_value.begin()) == g_output_value.end()
        );

        {
            halmd::scoped_timer<halmd::timer> t(elapsed);
            BOOST_CHECK( halmd::radix_sort(
                g_output_key.begin()
              , g_output_key.end()
              , g_output_value.begin()) == g_output_value.end()
            );
        }

        cuda::host::vector<unsigned int> h_output_key(count);
        BOOST_CHECK( cuda::copy(
            g_output_key.begin()
          , g_output_key.end()
          , h_output_key.begin()) == h_output_key.end()
        );
        BOOST_CHECK_EQUAL_COLLECTIONS(
            h_output_key.begin()
          , h_output_key.end()
          , result.begin()
          , result.end()
        );

        cuda::host::vector<unsigned int> h_output_value(count);
        BOOST_CHECK( cuda::copy(
            g_output_value.begin()
          , g_output_value.end()
          , h_output_value.begin()) == h_output_value.end()
        );
        auto value_to_key = [&](unsigned int value) {
            return input_key[value];
        };
        BOOST_CHECK_EQUAL_COLLECTIONS(
            boost::make_transform_iterator(h_output_value.begin(), value_to_key)
          , boost::make_transform_iterator(h_output_value.end(), value_to_key)
          , result.begin()
          , result.end()
        );
    }
    BOOST_TEST_MESSAGE( "  " << mean(elapsed) * 1e3 << " ± " << error_of_mean(elapsed) * 1e3 << " ms per iteration" );
}