Skip to content

Instantly share code, notes, and snippets.

@Xmerr
Last active November 29, 2016 18:24
Show Gist options
  • Save Xmerr/971c66a92f420993e687d8820bd3b509 to your computer and use it in GitHub Desktop.
Save Xmerr/971c66a92f420993e687d8820bd3b509 to your computer and use it in GitHub Desktop.
Reddit Easy Challenge #293
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();
}
}
}
@Xmerr
Copy link
Author

Xmerr commented Nov 29, 2016

For reddit easy Challenge #293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment