Problem 45397. Assess the scatter of wind turbines in a field

The renewable energy industry is on the rise in many countries--- and one of the key players is wind energy.
It is believed that the layout of a wind farm can influence its ability to harness energy. One assumption is that the more scattered the turbines are in the field, the higher the energy yield. Hence, we need to determine how many turbines in a wind farm are in a good position.
You are given the positions of 8 wind turbines in a field rendered as an 8-by-8 grid of cells. For this problem, a wind turbine is defined to be in a good position if there are no other turbines in its immediate vicinity of adjacent cells in the grid. Otherwise, it is in a bad position. An illustration of these two cases is further explained in the figure below.
Write a function that accepts a MATLAB variable, POS. You are ensured that POS is always a row vector of 8 elements, and each element satisfies 1 <= POS(i) <= 8. This vector represents the wind farm layout: POS(i) is the row position of the sole wind turbine in column i. Given the layout, output the number of wind turbines in good position.
As seen in the examples from the figure above, we have 4 turbines in good position for POS = [8 1 6 3 6 7 3 4]; 6 turbines for POS = [3 1 5 2 8 7 4 6]; and, 2 turbines for POS = [4 5 7 7 3 2 6 8].

Solution Stats

45.07% Correct | 54.93% Incorrect
Last Solution submitted on Dec 06, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers59

Suggested Problems

More from this Author19

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!