All submissions

Detect Circular Pattern Match

Code

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

uint8_t is_circular_match(uint16_t reg, uint16_t target) {
  bool circular = false;
  int i = 0;

  while (i < 16 && !circular) {
    reg = (reg << 1) | (reg >> (16 - 1));

    if (reg == target) {
      circular = true;
    }

    i += 1;
  }

  return circular;
}

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