Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.facebook.com/AminproPastebin
- // Credits to Wei Wen through Joshua Soo for solving the distinct check using bitmap.
- #include <stdio.h>
- #define LIMIT 10
- typedef unsigned int set;
- int main(){
- set master;
- set guess;
- int a, b, c, d;
- master = (1<<1)|(1<<0)|(1<<2)|(1<<6); //
- while(1){
- int i;
- int hits =0;
- int flag = 0;
- guess = (0<<0)|(0<<1)|(0<<2)|(0<<3)|(0<<4)|(0<<5)|(0<<6)|(0<<7)|(0<<8)|(0<<9);
- printf("Guess: ");
- scanf("%d%d%d%d", &a, &b, &c, &d );
- guess = (1<<a)|(1<<b)|(1<<c)|(1<<d);
- for(i=0;i<LIMIT;i++){
- if((1<<i)&guess){
- flag++;
- }
- }
- if(flag >= 4){
- for(i=0; i<LIMIT; i++){
- if ((1<<i) &guess &master){
- hits++;
- }
- }
- printf("%d hit(s)\n", hits);
- }
- else
- printf("Your guess must contain 4 distinct numbers\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement