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
      27 of 102

      The best single direction

      A map of towns, each at [x, y]. You may keep one straight road, and every town moves onto it, to its shadow (as in “The shadow”). Write main_direction(points): which way the road should run to keep the towns as spread out as possible, as an arrow [dx, dy] of length 1. Where the road sits doesn’t matter, only its direction, and either sign is fine: [1, 0] and [-1, 0] are the same road.

      A county of 14 towns can afford one straight main road, and every town gets a side road built straight out to it. The less side road to build, the better the main road is placed. Build it where you like.

      The county can afford one straight main road.east–west road, 0°: 12.4 kmnorth–south road, 90°: 18.8 km
      Your functionmain_direction(points)
      points[x, y] for each towne.g. [[0.5, 1], [2, 4], [3, 6], [1, 2], [4, 8]]
      returnsthe road's direction [dx, dy], length 1, that keeps
      solution.pyLoading Python
      Sign in for an AI hint
      ← The direction that survivesTwo pizza shops →