`

Invert Bit

//Return x with the n bits that begin at position p inverted (i.e. turn 0 into 1 and vice versa)
int invert (int x, int p, int n) {
  
}

Bit And

int bitAnd (int x, int y) {
    // implement x & y without using &
}

Bit XOR

int bitXor (int x, int y) {
  //implement x ^ y using only ~ and | ()
}

Sign

int sign(int x) {
    //return 1 if positive, 0 if zero, and –1 if negative. ops allowed: ! ~ & ^ | + << >> ()
}

Conditional

int conditional(int x, int y, int z) {
    // if x is present return y if x is 0 return z. Or implment return x ? y : z. Ops allowed ! ~ & ^ | + << >> ()
}

Not without !

int bang(int x) {
    // bang(3)=0, bang(0)=1 ops allowed : ~ & ^ | + << >> ()
}

Implement Base64 encoder and decoder in C

Algo

Puzzle: King, spy, prisoners and 1000 barrels of wine

A king is planning a party in 7 days where he intends to use 1,000 barrels of wine, stored in a secret location. A spy from a neighboring country was caught adding poison to one of the barrels and was subsequently killed by the security guards. Here are the key points:

Help the security guards devise a strategy to identify and isolate the poisoned barrel.

Puzzle: 10 prisoners and hats

There are 10 prisoners who are shown a box containing an infinite number of white and black hats. They are informed that the next morning, they will participate in an exercise:

As one of the prisoners, you need to devise a strategy to maximize the number of people who can be saved. One possible strategy is for each person in an even-numbered position to state the color of the hat of the person directly in front of them. Meanwhile, each person in an odd-numbered position will repeat what the previous person said. This approach can save at least five people, and with further improvements, it could potentially save even more.