Detect Circular Pattern Match

Code

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

uint8_t is_circular_match(uint16_t reg, uint16_t target) {
    // Your code here
    int count = 1;
    uint16_t pp;
    int found = 0;
    while(reg)
    {
        // pp = reg  & target;
        if(reg == target)
        {
            found++;
            break;
        }
        reg = ((reg << count) | (reg >> (16- count)));
        // printf("\n %d", reg);
        count++;
    }
    // printf("%d", found);
    return found;
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

45056 11

Expected Output

1