Created
January 15, 2020 17:33
-
-
Save KiaArmani/bfb26fb0c5cca2981876fdb9a069fef7 to your computer and use it in GitHub Desktop.
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; | |
using System.Globalization; | |
using System.IO; | |
using System.Linq; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Converters; | |
namespace TimelostReveal | |
{ | |
class Program | |
{ | |
public static int i = 0; | |
static void Main(string[] args) | |
{ | |
var jsonData = File.ReadAllText("data.json"); | |
var combinations = Combination.FromJson(jsonData); | |
int y = 2; | |
foreach (var combination in combinations) | |
{ | |
combination.Id = y; | |
y++; | |
} | |
foreach (var combination in combinations) | |
{ | |
FindChains(combination, combinations, new List<string>()); | |
} | |
Console.WriteLine("Done"); | |
Console.ReadKey(); | |
} | |
private static void FindWeirdShitForXerxes(Combination row) | |
{ | |
var openings = row.Openings.Split(','); | |
foreach (var opening in openings) | |
{ | |
string baseString; | |
switch (opening) | |
{ | |
case "1": | |
baseString = row.Link1; | |
break; | |
case "2": | |
baseString = row.Link2; | |
break; | |
case "3": | |
baseString = row.Link3; | |
break; | |
case "4": | |
baseString = row.Link4; | |
break; | |
case "5": | |
baseString = row.Link5; | |
break; | |
case "6": | |
baseString = row.Link6; | |
break; | |
default: | |
continue; | |
} | |
if(baseString.Equals("BBBBBBB")) | |
Console.WriteLine($"{row.Id} has an empty Opening Link"); | |
} | |
} | |
private static void FindChains(Combination row, List<Combination> combinations, List<string> output) | |
{ | |
var openings = row.Openings.Split(','); | |
foreach (var opening in openings) | |
{ | |
string baseString; | |
switch (opening) | |
{ | |
case "1": | |
baseString = row.Link1; | |
break; | |
case "2": | |
baseString = row.Link2; | |
break; | |
case "3": | |
baseString = row.Link3; | |
break; | |
case "4": | |
baseString = row.Link4; | |
break; | |
case "5": | |
baseString = row.Link5; | |
break; | |
case "6": | |
baseString = row.Link6; | |
break; | |
default: | |
continue; | |
} | |
if (String.IsNullOrEmpty(baseString) || baseString.Equals("BBBBBBB")) | |
continue; | |
var link1Combinations = combinations.Where(x => x.Link1 == baseString).ToArray(); | |
foreach (var comb in link1Combinations) | |
{ | |
if(comb.Id == row.Id || output.Contains(comb.Id.ToString())) | |
continue; | |
output.Add($"{comb.Id}({comb.Link1})"); | |
if(comb.Openings.Split(',').Length > 1) // Is Not Dead End | |
FindChains(comb, combinations, output); | |
} | |
var link2Combinations = combinations.Where(x => x.Link2 == baseString).ToArray(); | |
foreach (var comb in link2Combinations) | |
{ | |
if(comb.Id == row.Id || output.Contains(comb.Id.ToString())) | |
continue; | |
output.Add($"{comb.Id}({comb.Link2})"); | |
if(comb.Openings.Split(',').Length > 1) // Is Not Dead End | |
FindChains(comb, combinations, output); | |
} | |
var link3Combinations = combinations.Where(x => x.Link3 == baseString).ToArray(); | |
foreach (var comb in link3Combinations) | |
{ | |
if(comb.Id == row.Id || output.Contains(comb.Id.ToString())) | |
continue; | |
output.Add($"{comb.Id}({comb.Link3})"); | |
if(comb.Openings.Split(',').Length > 1) // Is Not Dead End | |
FindChains(comb, combinations, output); | |
} | |
var link4Combinations = combinations.Where(x => x.Link4 == baseString).ToArray(); | |
foreach (var comb in link4Combinations) | |
{ | |
if(comb.Id == row.Id || output.Contains(comb.Id.ToString())) | |
continue; | |
output.Add($"{comb.Id}({comb.Link4})"); | |
if(comb.Openings.Split(',').Length > 1) // Is Not Dead End | |
FindChains(comb, combinations, output); | |
} | |
var link5Combinations = combinations.Where(x => x.Link5 == baseString).ToArray(); | |
foreach (var comb in link5Combinations) | |
{ | |
if(comb.Id == row.Id || output.Contains(comb.Id.ToString())) | |
continue; | |
output.Add($"{comb.Id}({comb.Link5})"); | |
if(comb.Openings.Split(',').Length > 1) // Is Not Dead End | |
FindChains(comb, combinations, output); | |
} | |
var link6Combinations = combinations.Where(x => x.Link6 == baseString).ToArray(); | |
foreach (var comb in link6Combinations) | |
{ | |
if(comb.Id == row.Id || output.Contains(comb.Id.ToString())) | |
continue; | |
output.Add($"{comb.Id}({comb.Link6})"); | |
if(comb.Openings.Split(',').Length > 1) // Is Not Dead End | |
FindChains(comb, combinations, output); | |
} | |
} | |
if(output.Count > 0) | |
Console.WriteLine($"Chain found: {String.Join(", ", output.ToArray())}"); | |
} | |
} | |
} | |
public partial class Combination | |
{ | |
public int Id { get; set; } | |
[JsonProperty("Openings")] | |
public string Openings { get; set; } | |
[JsonProperty("Link1")] | |
public string Link1 { get; set; } | |
[JsonProperty("Link2")] | |
public string Link2 { get; set; } | |
[JsonProperty("Link3")] | |
public string Link3 { get; set; } | |
[JsonProperty("Link4")] | |
public string Link4 { get; set; } | |
[JsonProperty("Link5")] | |
public string Link5 { get; set; } | |
[JsonProperty("Link6")] | |
public string Link6 { get; set; } | |
} | |
public partial class Combination | |
{ | |
public static List<TimelostReveal.Combination> FromJson(string json) => JsonConvert.DeserializeObject<List<TimelostReveal.Combination>>(json, TimelostReveal.Converter.Settings); | |
} | |
public static class Serialize | |
{ | |
public static string ToJson(this List<TimelostReveal.Combination> self) => JsonConvert.SerializeObject(self, TimelostReveal.Converter.Settings); | |
} | |
internal static class Converter | |
{ | |
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings | |
{ | |
MetadataPropertyHandling = MetadataPropertyHandling.Ignore, | |
DateParseHandling = DateParseHandling.None, | |
Converters = | |
{ | |
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment