void solve_board(board_t* board) { stats.solve++; if (is_complete(board)) { printf("SOLVED!\n"); print_board(board); print_stats(stats); assert(0); } else if (is_dead_end(board)) { debugf("dead end, skip\n"); } else { size_t i_row, i_col; digits_t digits; find_next_continuation(board, &i_row, &i_col, &digits); debugf("best continuation [%lu,%lu]\n", i_row, i_col); size_t i; for (i = 1; i < NDIGITS; i++) { if (0 == digits.digits[i]) { debugf("extending [%lu,%lu] <- %lu\n", i_row, i_col, i); board_t* new_board = copy_board(board); set_digit(new_board, i_row, i_col, i); solve_board(new_board); free(new_board); } } } }
static void update_time() { // Get a tm structure time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); // Write the current hours and minutes into a buffer static char s_buffer[8]; strftime(s_buffer, sizeof(s_buffer), clock_is_24h_style() ? "%H%M" : "%I%M", tick_time); // Display this time on screen set_digit(topleft_image, s_buffer[0], true); set_digit(topright_image, s_buffer[1], false); set_digit(bottomleft_image, s_buffer[2], true); set_digit(bottomright_image, s_buffer[3], false); center(); }
/* Checks if an integer is composable pandigitally using the given set of digits. * Returns: * -1 on failure (unavailable digit, multiples of digit, or 0 used) * 0 on exact match * 1 on a match which does not use all digits */ int composable(dmask m, int c) { int n; for (n = c; n != 0; n = n / 10) { int d = n % 10; if (d == 0) { return -1; } if (check_digit(m, d) == true) { return -1; } m = set_digit(m, d); } return m == FULL_DMASK ? 0 : 1; }
void round_hex_string(char *hex_str,int index) { /** Unused function */ int idx=index-1 ; if ( get_digit(hex_str[idx]) > 7 ) { idx-- ; if (get_digit(hex_str[idx]) == 15) { ; } else { hex_str[idx]=set_digit(get_digit(hex_str[idx])+1) ; } } hex_str[index-1]='\0' ; return ; }
void inttobin(long long int_to_bin,char *bin_str) { unsigned int i=0 ; char *bin_str_saved=malloc(128) ; memset(bin_str_saved,'\0',128) ; _Bool is_negativ=false ; if (int_to_bin == 0) { /** Case value to convert in binar string is null */ strcpy(bin_str,"0") ; return ; } if (int_to_bin < 0) { /** Case value to convert in binar string is negativ */ is_negativ=true ; int_to_bin=fabs(int_to_bin) ; } while (int_to_bin != 0) { bin_str[i]= set_digit(int_to_bin % 2) ; /** set the binar digit */ int_to_bin /= 2 ; i++ ; } /** reversing the result string */ unsigned int ii ; bin_str[i]='\0' ; for (i=0,ii=strlen(bin_str)-1 ; i < strlen(bin_str) ; i++,ii--) { bin_str_saved[i]=bin_str[ii] ; } bin_str_saved[i]='\0' ; /** Copy the result to pointer giving as argument ; */ if (is_negativ) { strcpy(bin_str,"-") ; strcat(bin_str,bin_str_saved) ; } else { strcpy(bin_str,bin_str_saved) ; } return ; }
void main (void) { int i, j; setup_display_abcdef_dp (); setup_set_digit (); for (;;) for (i = 0;; i = (i + 1) % 4) { set_digit (i + 1); for (j = 0; j < 16; j++) { display_digit (j); delay (10); } } }
/** * Change the digits in given column. * @param col column to change. * @param numTime one of the hhmm (time) digits. * @param numTop one of the ddmm (date) digits. * @param numBtm one of the year digits. **/ void change_digits(int col, int numTime, int numTop, int numBtm) { change_digit(col, numTime, numTop, -2); change_digit(col, numTime, numBtm, 2); set_digit(col, numTime); }
int main(void) { // Set pins as ouputs DDRB |= 0x0F; DDRD |= 0xE0; // Enable pull-up resistors PORTC |= ( 1 << PC2 ); PORTC |= ( 1 << PC4 ); char status; // checks which switch is activated char count = 0; // set counter // turn off display set_digit(10); while(1) { if ( (PINC & ( 1 << PC2 )) == 0 ) { status = 'u'; // count up } if ( (PINC & (1 << PC4)) == 0 ) { status = 'd'; // count down } // counts up if ( status == 'u' ) { while ( count <= 9 ) { set_digit(count); _delay_ms(500); count++; if ( (PINC & (1 << PC4)) == 0 ) // checks if the up switch is pressed { break; status = 'd'; } if ( count > 9 ) { count = 0; } } } // counts down if ( status == 'd' ) { while ( count >= 0 ) { set_digit(count); _delay_ms(500); count--; if ( (PINC & (1 << PC2)) == 0 ) // checks if the down switch is pressed { break; status = 'u'; } if ( count < 0) { count = 9; } } } } return 0; /* never reached */ }
void display_digit(int value, int position) { select_digit(position); set_digit(value); }
dmask set_digits(dmask m, int n) { for (; n != 0; n = n / 10) { m = set_digit(m, n % 10); } return m; }