| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace D03._2
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length < 1) throw new ArgumentException();
- if (File.Exists(args[0]) == false) throw new FileNotFoundException();
- string text = "";
- using (var file = File.OpenText(args[0]))
- {
- text = file.ReadToEnd();
- }
- (int x, int y)[] pos = new[] { (0, 0), (0, 0) };
- var visited = new HashSet<(int, int)>
- {
- (0, 0)
- };
- int santas = 2, santaId = 0;
- foreach (var c in text)
- {
- santaId = (santaId + 1) % santas;
- switch (c)
- {
- case '>': pos[santaId].x++; break;
- case '<': pos[santaId].x--; break;
- case '^': pos[santaId].y--; break;
- case 'v': case 'V': pos[santaId].y++; break;
- default: continue;
- }
- visited.Add(pos[santaId]);
- }
- Console.WriteLine($"Answer is : {visited.Count}");
- }
- }
- }
|