using System.Collections.Generic;
public static readonly string TheInput =
public static Operation[] Operations = null;
public static void Main()
var visited = new List<int>();
while (!visited.Contains(currentIndex))
if (currentIndex >= Operations.Length)
string op = Operations[currentIndex].Op;
int val = Operations[currentIndex].Val;
if ((exitValue == 0) && (op != "acc"))
exitValue = IfSwitchGivesWayOut(currentIndex, amount, visited.ToList());
visited.Add(currentIndex);
case "acc" : amount += val; currentIndex++; break;
case "jmp" : currentIndex += val; break;
case "nop" : currentIndex ++; break;
Console.WriteLine($"Result 1: {amount}");
Console.WriteLine($"Result 2: {exitValue}");
public static int IfSwitchGivesWayOut(int currentIndex, int amount, List<int> visited)
while (!visited.Contains(currentIndex))
if (currentIndex >= Operations.Length)
string op = Operations[currentIndex].Op;
int val = Operations[currentIndex].Val;
visited.Add(currentIndex);
op = ((op == "jmp") ? "nop" : "jmp");
case "acc" : amount += val; currentIndex++; break;
case "jmp" : currentIndex += val; break;
case "nop" : currentIndex ++; break;
private static void GetOperations()
var ops = new List<Operation>();
foreach (var line in TheInput.Split('\n'))
var parts = line.Split(' ').Select(x => x.Trim()).ToArray();
ops.Add(new Operation(parts[0], Int32.Parse(parts[1])));
Operations = ops.ToArray();
public string Op { get; set; }
public int Val { get; set; }
public Operation(string op, int val)