This code takes a selection of numbers between 1 to 9 which could be 1,2,3,4,5,6,7,8,9 or 1,2,4 or 4,5,8,9, etc.Looks for every possible combination and compares them to a dice roll of two dicee.g. If the dice roll is 7 then can it be found in a list which contains 1,2,3,4,5,6,7,8,9  - (Yes, 7 and 5+2 and 3+4 etc)OR the list could contain1,3,4,8 - (Yes 3+4 only)OR 1,4,8,9 - (No)Note:remainder is the dice roll Binarypositions works out the different possibilities and returns a list of all the combinations available for checking    void gameovercheck(){        List <int> selection = new List <int> ();        bool found = false;        //Calculate number of possible combinations        int combination = (int)Mathf.Pow (2, blocklist.Count);        //Loop to step through each possible combination        for (int x = 0; x < combination; x++) {                     selection = ReturnBinary.Binarypositions (x, 8);            //string output = ;            int sum = 0;            for (int z = 0; z < selection.Count; z++) {                sum += blocklist [selection [z]];            }            if (sum == remainder)                found = true;        }        if (!found) {            gamerunning = false;        }}}to find out all the possible combinations I work out the binary positions using the following functionpublic static List<int> Binarypositions(int number,int bits){               List <int> newanswer = new List <int>();    int count = 0;    for (int y = 0; y < bits; y++) {        int answer = number >> y & 0x1;        if (answer==1) {            newanswer.Add (count);        }        count++;    }    //Output    return (newanswer);}I have to run this everytime I want to check if it can be found, so how can I optimise this for performance?
Finding dice roll results in a combinable list of numbers
c#;performance
You can make gameovercheck more efficient by returning as soon as sum equals remainder.  The standard naming convention is UpperCamelCase for methods and lowerCamelCase for variables.  It's good practice to not use class level variables in a method when possible so you can count on the method to return the same answer when given the same input.  I will change the class level variables to parameters and return a bool, which you can then assign to gamerunning  In Binarypositions, you declare count at the same time as y, and also increment it at the same time, so it's not necessary.  I prefer to have method names use a verb to describe what they are doing.  I think diceRoll is more descriptive than remainder.private bool CheckIfGameOver(List<int> blockList, int diceRoll){    //Calculate number of possible combinations    int combinations = (int)Mathf.Pow(2, blocklist.Count);    //Loop to step through each possible combination    for (int x = 0; x < combinations; x++) {                 List <int> selection = ReturnBinary.CalculateBinaryPositions(x, 8);        int sum = 0;        for (int z = 0; z < selection.Count; z++) {            sum += blockList[selection[z]];        }        if (sum == diceRoll)            return false;    }    return true;}public static List<int> CalculateBinaryPositions(int number, int bits){             List<int> newAnswer = new List<int>();    for (int y = 0; y < bits; y++) {        int answer = number >> y & 0x1;        if (answer == 1) {            newAnswer.Add(y);        }    }    //Output    return newAnswer;}I prefer using LINQ instead of loops when I can.  It probably won't affect performance that much, but it can make code safer, more readable, and shorter.private bool CheckIfGameOver(List<int> blockList, int diceRoll) {    //Calculate number of possible combinations    int combinations = (int)Mathf.Pow(2, blocklist.Count);    var gameOver = Enumerable        .Range(0, combinations)        .Select(x => ReturnBinary.CalculateBinaryPositions(x, 8).Sum(y => blockList[y]))        .All(x => x != diceRoll);    return gameOver;}public static List<int> CalculateBinaryPositions(int number, int bits){             return Enumerable.Range(0, bits).Where(x => (number >> x & 0x1) == 1).ToList();}Why do you set it at 8 bits?  Wouldn't that omit a bit if blockList has 9 items?An optimization you could make is to make a list of lists containing all possible binary position combinations.  Like [[],[1],[1,2],[1,3],[1,2,3],etc].  Then you could just take the number of combinations you need each time instead of calculating them.  I might try and code this optimization in the future.Another thing to try is to calculate all possible binary position combinations using recursion instead of bit manipulation.