Sheep (+1) and goats (−1) share a field, each animal at a spot [x, y]. A straight fence line = [w1, w2, b] splits it: a spot is on the sheep side when w1 * x + w2 * y + b is positive and on the goat side when it’s negative. Write safety(points, labels, line): how safely the fence keeps the herds apart. Negative if any animal is on the wrong side.
Sheep (●) and goats (○) share a field. Two fences both keep them apart, but the second brushes past a sheep.
safety(points, labels, line)| points | [x, y] for each animal | e.g. [[1, 2], [2, 1], [1, 4], [4, 4], [5, 2], [… |
| labels | +1 for a sheep, -1 for a goat | e.g. [−1, −1, −1, 1, 1, 1, 1] |
| line | [w1, w2, b], the fence w1*x + w2*y + b = 0 (positive side = sheep) | e.g. [1, 0, −3] |
| returns | how safely the fence separates them, negative if any are on the wrong side | |