All submissions

Detect Circular Pattern Match

Code

#include <stdio.h>
#include <stdint.h>

#define N_BIT_REGISTER 16

uint8_t is_circular_match(uint16_t reg, uint16_t target) {
    uint16_t shifted_left_reg;
    uint16_t shifter_right_reg;
    uint16_t rotated_reg;

    for (uint8_t rotation = 0; rotation < N_BIT_REGISTER; ++rotation) {
        shifted_left_reg = reg << rotation;
        shifter_right_reg = (reg >> (N_BIT_REGISTER - rotation));
        rotated_reg = shifted_left_reg | shifter_right_reg;

        if (target == rotated_reg) {
            return 1;
        }
    }

    return 0;
}

int main() {
    uint16_t reg, target;
    scanf("%hu %hu", &reg, &target);
    printf("%hhu", is_circular_match(reg, target));
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

45056 11

Expected Output

1