The last remaining bit is to scan the instructions array for groups of consecutive entries. My current plan is to start with probably 4 instructions and scan forward for the same consecutive set occurring again; if the count of other occurrences ever dips below 3, drop the most recently added set of 2 and pull the remaining entries into program A. Then repeat for programs B and C, and check that the list of instructions is now empty. Finally, compare each chunk successively to the full string of instructions to produce some combination of A,B,Cs to satisfy the requirements, and feed all that into the program's inputs.
77 lines
1.3 KiB
Go
77 lines
1.3 KiB
Go
package utilities
|
|
|
|
import "math"
|
|
|
|
type Vec2[T Number] struct {
|
|
X T
|
|
Y T
|
|
}
|
|
|
|
type Vec3[T Number] struct {
|
|
X T
|
|
Y T
|
|
Z T
|
|
}
|
|
|
|
type Vec2i Vec2[int]
|
|
|
|
func (v Vec2[T]) Dot(other Vec2[T]) T {
|
|
return (v.X * other.X) + (v.Y * other.Y)
|
|
}
|
|
|
|
func (v Vec2[T]) Len() T {
|
|
return T(math.Sqrt(float64(v.LenSquared())))
|
|
}
|
|
|
|
func (v Vec2[T]) LenSquared() T {
|
|
return (v.X * v.X) + (v.Y * v.Y)
|
|
}
|
|
|
|
func (v Vec2[T]) To(other Vec2[T]) Vec2[T] {
|
|
return Vec2[T]{
|
|
X: v.X - other.X,
|
|
Y: v.Y - other.Y,
|
|
}
|
|
}
|
|
|
|
func (v Vec2[T]) AngleBetween(other Vec2[T]) float64 {
|
|
rad := math.Atan2(float64(other.Y-v.Y), float64(other.X-v.X))
|
|
return rad * 180 / math.Pi
|
|
}
|
|
|
|
func (v Vec2[T]) Equals(other Vec2[T]) bool {
|
|
return v.X == other.X &&
|
|
v.Y == other.Y
|
|
}
|
|
|
|
func VecBetween[T Number](a, b Vec2[T]) Vec2[T] {
|
|
return Vec2[T]{
|
|
X: a.X - b.X,
|
|
Y: a.Y - b.Y,
|
|
}
|
|
}
|
|
|
|
func (v Vec3[T]) Dot(other Vec3[T]) T {
|
|
return (v.X * other.X) + (v.Y * other.Y) + (v.Z * other.Z)
|
|
}
|
|
|
|
func (v Vec3[T]) Len() T {
|
|
return T(math.Sqrt(float64(v.LenSquared())))
|
|
}
|
|
|
|
func (v Vec3[T]) LenSquared() T {
|
|
return (v.X * v.X) + (v.Y * v.Y) + (v.Z * v.Z)
|
|
}
|
|
|
|
func (v *Vec3[T]) Add(other Vec3[T]) {
|
|
v.X += other.X
|
|
v.Y += other.Y
|
|
v.Z += other.Z
|
|
}
|
|
|
|
func (v Vec3[T]) Equals(other Vec3[T]) bool {
|
|
return v.X == other.X &&
|
|
v.Y == other.Y &&
|
|
v.Z == other.Z
|
|
}
|