tracks/csharp/exercises/word-search/Example.cs in trackler-2.0.8.14 vs tracks/csharp/exercises/word-search/Example.cs in trackler-2.0.8.15
- old
+ new
@@ -1,72 +1,70 @@
using System;
using System.Collections.Generic;
-using System.Drawing;
using System.Linq;
public class WordSearch
{
private readonly string[] rows;
private readonly int width;
private readonly int height;
- private static readonly Point[] Directions =
+ private static readonly Tuple<int, int>[] Directions =
{
- new Point( 1, 0),
- new Point( 0, 1),
- new Point(-1, 0),
- new Point( 0, -1),
- new Point( 1, 1),
- new Point( 1, -1),
- new Point(-1, 1),
- new Point(-1, -1)
+ new Tuple<int, int>( 1, 0),
+ new Tuple<int, int>( 0, 1),
+ new Tuple<int, int>(-1, 0),
+ new Tuple<int, int>( 0, -1),
+ new Tuple<int, int>( 1, 1),
+ new Tuple<int, int>( 1, -1),
+ new Tuple<int, int>(-1, 1),
+ new Tuple<int, int>(-1, -1)
};
public WordSearch(string puzzle)
{
rows = puzzle.Split('\n');
width = rows[0].Length;
height = rows.Length;
}
- public Tuple<Point, Point> Find(string word)
+ public Tuple<Tuple<int, int>, Tuple<int, int>> Find(string word)
{
return
Positions()
.SelectMany(position => Directions.SelectMany(direction => Find(word, position, direction)))
.FirstOrDefault();
}
- private IEnumerable<Tuple<Point, Point>> Find(string word, Point position, Point direction)
+ private IEnumerable<Tuple<Tuple<int, int>, Tuple<int, int>>> Find(string word, Tuple<int, int> position, Tuple<int, int> direction)
{
var current = position;
foreach (var letter in word)
{
if (FindChar(current) != letter)
{
yield break;
}
- current.X += direction.X;
- current.Y += direction.Y;
+ current = new Tuple<int, int>(current.Item1 + direction.Item1, current.Item2 + direction.Item2);
}
- yield return Tuple.Create(position, new Point(current.X - direction.X, current.Y - direction.Y));
+ yield return Tuple.Create(position, new Tuple<int, int>(current.Item1 - direction.Item1, current.Item2 - direction.Item2));
}
- private char? FindChar(Point coordinate)
+ private char? FindChar(Tuple<int, int> coordinate)
{
- if (coordinate.X > 0 && coordinate.X <= width && coordinate.Y > 0 && coordinate.Y <= height)
+ if (coordinate.Item1 > 0 && coordinate.Item1 <= width && coordinate.Item2 > 0 && coordinate.Item2 <= height)
{
- return rows[coordinate.Y - 1][coordinate.X - 1];
+ return rows[coordinate.Item2 - 1][coordinate.Item1 - 1];
}
return null;
}
- private IEnumerable<Point> Positions()
+ private IEnumerable<Tuple<int, int>> Positions()
{
return Enumerable.Range(1, width).SelectMany(x =>
- Enumerable.Range(1, height).Select(y =>new Point(x, y)));
+ Enumerable.Range(1, height).Select(y => new Tuple<int, int>(x, y)));
}
}
\ No newline at end of file