• + 1 comment

    Here is a c# way that doesn't do uneeded additions or comparisons.

    Console.WriteLine(apples.Where(x => HitHouse(s,t,a,x)).Count());
    Console.WriteLine(oranges.Where(x => HitHouse(s,t,b,x)).Count());
    

    With the comparison function:

        static bool HitHouse(int houseStart, int houseEnd, int treeLoc, int objectLoc)
        {
            int loc = treeLoc + objectLoc;
            return !(loc < houseStart || loc > houseEnd);
        }