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

      Two pizza shops

      Every home orders pizza from whichever shop is nearest. Write move_shops(homes, shops): move every shop once, to the spot where its own customers’ walks, each one squared (as in “How wrong is the forecast?”), add up to the least. A shop nobody orders from stays put. Return the new spots, one [x, y] per shop, in the same order.

      Eight homes and two pizza shops. Every home orders from whichever shop is nearest. Each shop wants to move to where its own customers’ walks, each squared, add up to the least.

      eight homes, two shops12shop 14 customers[2, 2] → ?shop 24 customers[6, 6] → ?
      drag a shop · click a home to see how far it is from each shopwhere should each shop go? that’s for you to work out
      Your functionmove_shops(homes, shops)
      homes[x, y] for each home; each orders from its nearest shope.g. [[0, 1], [2, 1], [1, 0], [1, 2], [6, 5], […
      shops[x, y] for each pizza shop move every shop once so its customers' squared walks add up to the leaste.g. [[1, 1], [7, 5]]
      returnsthe new [x, y] of each shop
      solution.pyLoading Python
      Sign in for an AI hint
      ← The best single directionLeave room →