using System.Collections.Generic;
public static void Main(string[] args)
Random random = new Random();
bool[] bottle = new bool[1021];
for (int i = 0; i < bottle.Length; i++)
int indexOfPoisoned = random.Next(bottle.Length);
bottle[indexOfPoisoned] = false;
bool[] alive = new bool[10];
for (int i = 0; i < alive.Length; i++)
for (int i = 0; i < bottle.Length; i++)
string s = Convert.ToString(i, 2);
int[] bits = s.PadLeft(10, '0').Select(c => int.Parse(c.ToString())).ToArray();
for (int q = bits.Length; q > 0; q--)
if (bits[bits.Length - q] == 1)
alive[bits.Length - q] &= bottle[i];
int ans = BoolArrayToInt(alive.ToArray());
Console.WriteLine("Assumed: " + (1023 - BoolArrayToInt(alive.Reverse().ToArray())) + "\r\nCorrect: " + indexOfPoisoned);
static int BoolArrayToInt(bool[] arr)
throw new ApplicationException("too many elements to be converted to a single int");
for (int i = 0; i < arr.Length; ++i)
if (arr[i]) val |= 1 << i;