diff --git a/src/17.cs b/src/17.cs index 64b18d6..d983d08 100644 --- a/src/17.cs +++ b/src/17.cs @@ -113,21 +113,21 @@ internal class Day17 : Day { if (canMove(rockIdx, rockPos, grid, ivec2.RIGHT)) { - rockPos.x++; + rockPos = new ivec2(rockPos.x + 1, rockPos.y); } } else { if (canMove(rockIdx, rockPos, grid, ivec2.LEFT)) { - rockPos.x--; + rockPos = new ivec2(rockPos.x - 1, rockPos.y); } } // inverted up/down for this... if (canMove(rockIdx, rockPos, grid, ivec2.UP)) { - rockPos.y--; + rockPos = new ivec2(rockPos.x, rockPos.y - 1); } else { @@ -174,21 +174,21 @@ internal class Day17 : Day { if (canMove(rockIdx, rockPos, grid, ivec2.RIGHT)) { - rockPos.x++; + rockPos = new ivec2(rockPos.x + 1, rockPos.y); } } else { if (canMove(rockIdx, rockPos, grid, ivec2.LEFT)) { - rockPos.x--; + rockPos = new ivec2(rockPos.x - 1, rockPos.y); } } // inverted up/down for this... if (canMove(rockIdx, rockPos, grid, ivec2.UP)) { - rockPos.y--; + rockPos = new ivec2(rockPos.x, rockPos.y - 1); } else { diff --git a/src/22.cs b/src/22.cs index f8c537c..f08407c 100644 --- a/src/22.cs +++ b/src/22.cs @@ -536,11 +536,11 @@ internal class Day22 : Day { if (inst.turn == 'R') { - facing.RotateRight(); + facing = facing.GetRotatedRight(); } else if (inst.turn == 'L') { - facing.RotateLeft(); + facing = facing.GetRotatedLeft(); } } } @@ -591,11 +591,11 @@ internal class Day22 : Day { if (inst.turn == 'R') { - facing.RotateRight(); + facing = facing.GetRotatedRight(); } else if (inst.turn == 'L') { - facing.RotateLeft(); + facing = facing.GetRotatedLeft(); } } } diff --git a/src/Util/Vec2.cs b/src/Util/Vec2.cs index 83fc11d..f4e1654 100644 --- a/src/Util/Vec2.cs +++ b/src/Util/Vec2.cs @@ -1,9 +1,9 @@ namespace aoc2022.Util; -public struct ivec2 : IEquatable, IComparable, IComparable +public readonly struct ivec2 : IEquatable, IComparable, IComparable { - public long x = 0; - public long y = 0; + public readonly long x = 0; + public readonly long y = 0; public static readonly ivec2 ZERO = new ivec2(0, 0); public static readonly ivec2 ONE = new ivec2(1, 1); @@ -27,10 +27,8 @@ public struct ivec2 : IEquatable, IComparable, IComparable public long MaxElement => System.Math.Max(x, y); public ivec2 GetRotatedLeft() => new ivec2(y, -x); - public void RotateLeft() => this = GetRotatedLeft(); public ivec2 GetRotatedRight() => new ivec2(-y, x); - public void RotateRight() => this = GetRotatedRight(); public long Dot(ivec2 v) => (x * v.x) + (y * v.y); public long LengthSquared => (x * x) + (y * y); diff --git a/src/Util/Vec3.cs b/src/Util/Vec3.cs index 7e1eabc..9cc38c4 100644 --- a/src/Util/Vec3.cs +++ b/src/Util/Vec3.cs @@ -1,10 +1,10 @@ namespace aoc2022.Util; -public struct ivec3 : IEquatable, IComparable, IComparable +public readonly struct ivec3 : IEquatable, IComparable, IComparable { - public long x = 0; - public long y = 0; - public long z = 0; + public readonly long x = 0; + public readonly long y = 0; + public readonly long z = 0; public static readonly ivec3 ZERO = new ivec3(0, 0, 0); public static readonly ivec3 ONE = new ivec3(1, 1, 1); @@ -31,10 +31,8 @@ public struct ivec3 : IEquatable, IComparable, IComparable public long MinElement => System.Math.Min(x, System.Math.Min(y, z)); public ivec3 GetRotatedLeft() => new ivec3(y, -x, z); - public void RotateLeft() => this = GetRotatedLeft(); public ivec3 GetRotatedRight() => new ivec3(-y, x, z); - public void RotateRight() => this = GetRotatedRight(); public long Dot(ivec3 v) => (x * v.x) + (y * v.y) + (z * v.z); public long LengthSquared => (x * x) + (y * y) + (z * z);