Created
December 11, 2017 10:44
-
-
Save lemmit/eac0a2cc147adbe2f57316e7a8adf794 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.Linq; | |
using System.Collections.Generic; | |
public class Test | |
{ | |
public static int[] ReadInput(){ | |
string line; | |
var elems = new List<int>(); | |
while ((line = System.Console.ReadLine()) != null) | |
{ | |
elems.Add(int.Parse(line)); | |
} | |
return elems.ToArray(); | |
} | |
public static void Main() | |
{ | |
var input = ReadInput(); | |
int pos = 0; | |
int steps = 0; | |
while(true){ | |
var new_pos = input[pos]; | |
if(new_pos >= 3){ //part 2 | |
input[pos]--; | |
}else{ | |
input[pos]++; | |
} | |
pos += new_pos; | |
steps++; | |
if(pos < 0 || pos >= input.Length){ | |
System.Console.WriteLine(steps); | |
return; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment