Skip to content

Instantly share code, notes, and snippets.

@lemmit
Created December 11, 2017 10:44
Show Gist options
  • Save lemmit/eac0a2cc147adbe2f57316e7a8adf794 to your computer and use it in GitHub Desktop.
Save lemmit/eac0a2cc147adbe2f57316e7a8adf794 to your computer and use it in GitHub Desktop.
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