Spooky Sale: 10% off Premium yearly · $118.80 for the first year · until Nov 6Get it

Deep-ML
Learn
Problems1,200+ hands-on ML problemsLearning PathA guided route through the fundamentalsLabsInteractive labs on real techniquesProjectsBuild a GPT, an RL agent, CUDA kernelsCollectionsCurated problem sets and videosMathPen-and-paper math for MLIntuitionInvent the idea behind the formula yourselfPlaylistsYour own problem lists, shareableStudy AssistantAn AI teacher that knows your progress
Interview Prep
Compete
ContestsFresh problem sets, ranked liveLeaderboardWhere you stand, globallyBuddiesSolve with a friend: streaks, a weekly board, chat
Discuss
Deep-Path
Premium
      Intuition
      29 of 102

      Leave room

      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.

      fence A: [1, 0, −3], the line x − 3 = 0the fence[1, 0, −3]how safely does it keep them apart??fence B: [1, 0, −3.9], the line x − 3.9 = 0the fence[1, 0, −3.9]how safely does it keep them apart??
      how safely does each fence keep them apart? that’s for you to work out
      Your functionsafety(points, labels, line)
      points[x, y] for each animale.g. [[1, 2], [2, 1], [1, 4], [4, 4], [5, 2], […
      labels+1 for a sheep, -1 for a goate.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]
      returnshow safely the fence separates them, negative if any are on the wrong side
      solution.pyLoading Python
      Sign in for an AI hint
      ← Two pizza shopsScores into chances →