Last active
November 29, 2016 18:24
-
-
Save Xmerr/971c66a92f420993e687d8820bd3b509 to your computer and use it in GitHub Desktop.
Reddit Easy Challenge #293
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace BombDefusing | |
{ | |
class Program | |
{ | |
static Dictionary<string, Predicate<string>> boomConditions = new Dictionary<string, Predicate<string>> | |
{ | |
{ "white", cut => cut != "white" && cut != "black" }, | |
{ "black", cut => cut != "white" && cut != "green" && cut != "orange" }, | |
{ "red", cut => cut == "green" }, | |
{ "orange", cut => cut == "red" || cut == "black" }, | |
{ "green", cut => cut == "orange" || cut == "white" }, | |
{ "purple", cut => cut != "purple" && cut != "green" && cut != "orange" && cut != "white" } | |
}; | |
static void Main(string[] args) | |
{ | |
string line, | |
lastCut = null; | |
bool boom = false; | |
while(!string.IsNullOrEmpty(line = Console.ReadLine())) | |
{ | |
if (boomConditions.ContainsKey(line)) { | |
if (lastCut != null && !boomConditions[lastCut](line)) | |
{ | |
boom = true; | |
break; | |
} | |
lastCut = line; | |
} | |
else | |
Console.WriteLine("Invalid Wire"); | |
} | |
Console.WriteLine(boom ? "BOOM!!!!!!!!!!" : "Defused"); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For reddit easy Challenge #293