target/whirl.c
static bool should_switch(int cur_pos, int target_pos, RingDirection dir) {
    int ones_required;

    if (dir == CLOCKWISE) {
        ones_required = target_pos - cur_pos;
    }
    else {
        ones_required = cur_pos - target_pos;
    }

    if (ones_required < 0) {
        ones_required += NUM_CMDS_PER_RING;
    }

    return ones_required > (NUM_CMDS_PER_RING / 2);
}
// Returns whether we should switch the direction of the current ring, based on
// which direction would generate shorter code for the target command we want
Returns whether we should switch the direction of the current ring, based on
which direction would generate shorter code for the target command we want
Returns whether we should switch the direction of the current ring based on which direction would generate shorter code for the target command we want
static bool should_switch(int cur_pos, int target_pos, RingDirection dir) {
    int ones_required;
    if (dir == CLOCKWISE) {
        ones_required = target_pos - cur_pos;
    }
    else {
        ones_required = cur_pos - target_pos;
    }
    if (ones_required < 0) {
        ones_required += NUM_CMDS_PER_RING;
    }
    return ones_required > (NUM_CMDS_PER_RING / 2);
}
static bool should_switch ( int cur_pos , int target_pos , RingDirection dir ) { int ones_required ; if ( dir == CLOCKWISE ) { ones_required = target_pos - cur_pos ; } else { ones_required = cur_pos - target_pos ; } if ( ones_required < 0 ) { ones_required += NUM_CMDS_PER_RING ; } return ones_required > ( NUM_CMDS_PER_RING / 2 ) ; }
Returns whether we should switch the direction of the current ring, based on
which direction would generate shorter code for the target command we want
Returns whether we should switch the direction of the current ring based on which direction would generate shorter code for the target command we want