mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
refactor a little
This commit is contained in:
parent
054d372470
commit
401bd4201b
@ -18,22 +18,20 @@ func Solve(buf []byte) (int, error) {
|
|||||||
|
|
||||||
var total int
|
var total int
|
||||||
for _, m := range machines {
|
for _, m := range machines {
|
||||||
denominator := ((m.A.X * m.B.Y) - (m.B.X * m.A.Y))
|
denominator := m.A.X*m.B.Y - m.B.X*m.A.Y
|
||||||
a_numerator := ((m.Prize.X * m.B.Y) - (m.Prize.Y * m.B.X))
|
a_numerator := m.Prize.X*m.B.Y - m.Prize.Y*m.B.X
|
||||||
b_numerator := ((m.Prize.Y * m.A.X) - (m.Prize.X * m.A.Y))
|
b_numerator := m.Prize.Y*m.A.X - m.Prize.X*m.A.Y
|
||||||
|
|
||||||
a := float64(a_numerator) / float64(denominator)
|
a := float64(a_numerator) / float64(denominator)
|
||||||
b := float64(b_numerator) / float64(denominator)
|
b := float64(b_numerator) / float64(denominator)
|
||||||
|
|
||||||
if a != math.Round(a) || b != math.Round(b) {
|
if a != math.Round(a) || a < 0 || b != math.Round(b) || b < 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug(a, b)
|
log.Debug(a, b)
|
||||||
|
|
||||||
if a > 0 && b > 0 {
|
total += 3*int(a) + int(b)
|
||||||
total += 3*int(a) + int(b)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return total, nil
|
return total, nil
|
||||||
|
@ -23,22 +23,20 @@ func Solve(buf []byte) (int, error) {
|
|||||||
m.Prize.X += augment
|
m.Prize.X += augment
|
||||||
m.Prize.Y += augment
|
m.Prize.Y += augment
|
||||||
|
|
||||||
denominator := ((m.A.X * m.B.Y) - (m.B.X * m.A.Y))
|
denominator := m.A.X*m.B.Y - m.B.X*m.A.Y
|
||||||
a_numerator := ((m.Prize.X * m.B.Y) - (m.Prize.Y * m.B.X))
|
a_numerator := m.Prize.X*m.B.Y - m.Prize.Y*m.B.X
|
||||||
b_numerator := ((m.Prize.Y * m.A.X) - (m.Prize.X * m.A.Y))
|
b_numerator := m.Prize.Y*m.A.X - m.Prize.X*m.A.Y
|
||||||
|
|
||||||
a := float64(a_numerator) / float64(denominator)
|
a := float64(a_numerator) / float64(denominator)
|
||||||
b := float64(b_numerator) / float64(denominator)
|
b := float64(b_numerator) / float64(denominator)
|
||||||
|
|
||||||
if a != math.Round(a) || b != math.Round(b) {
|
if a != math.Round(a) || a < 0 || b != math.Round(b) || b < 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug(a, b)
|
log.Debug(a, b)
|
||||||
|
|
||||||
if a > 0 && b > 0 {
|
total += 3*int(a) + int(b)
|
||||||
total += 3*int(a) + int(b)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return total, nil
|
return total, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user