Cody

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.

Access the figure here: https://drive.google.com/open?id=19M-3AZ0aqmJs2vKL-EKoJ0z59RvURukg

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

38.89% Correct | 61.11% Incorrect
Last Solution submitted on Jul 09, 2020