Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- private static List<List<int>> cornerPossibilities = null;
- private static List<List<int>> trianglePossibilities = null;
- static void Main(string[] args)
- {
- SetupCornerPossibilities();
- SetupTrianglesPossibilities();
- var blocks = new List<bool> { false, true, false, true, true, false, false, false, false };
- var foundCorners = HasCornerPossibility(blocks);
- var foundTriangles = HasTrianglePossibility(blocks);
- if (foundCorners != null)
- {
- // do stuff 1
- }
- else if (foundTriangles != null)
- {
- // do stuff 2
- }
- }
- private static List<int> HasCornerPossibility(List<bool> blocks)
- {
- return HasPossibility(blocks, cornerPossibilities);
- }
- private static List<int> HasTrianglePossibility(List<bool> blocks)
- {
- return HasPossibility(blocks, trianglePossibilities);
- }
- private static List<int> HasPossibility(List<bool> blocks, List<List<int>> possibilities)
- {
- foreach (var possibility in cornerPossibilities)
- {
- var scopedBlocks = GetByIndexes(blocks, possibility);
- if (scopedBlocks.All(b => b))
- return possibility;
- }
- return null;
- }
- private static IEnumerable<bool> GetByIndexes(List<bool> blocks, List<int> indexes)
- {
- // stackoverflow magic
- return blocks
- .Where((element, index) => indexes.Contains(index));
- }
- private static void SetupCornerPossibilities()
- {
- cornerPossibilities = new List<List<int>>
- {
- new List<int> { 1,3,4 },
- new List<int> { 3,4,6 },
- new List<int> { 4,5,7 }
- };
- }
- private static void SetupTrianglesPossibilities()
- {
- trianglePossibilities = new List<List<int>>
- {
- new List<int> { 7,3,1 },
- new List<int> { 3,7,5 },
- new List<int> { 3,1,5 },
- new List<int> { 1,5,7 }
- };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement