Its done!

**Concept**

Brute force. Calculate the route distance for every combination of persons to visit. Ignore the combinations that doesn't offer all the required tasks (A-F). Select the route with the lowest route distance.

**Implementation**

The idea is to use binary representation to reduce the maths required. Lets say each person is assigned 1 bit in an integer number e.g. 1001 means visit person 1 and person 4. So if we have 8 people, we have 2^8-1 = 255 combinations of people to visit. We'll make combinations in rows numbered 1..255.

Now we do the same for every person's assigned tasks. Task A is bit 1, B is bit 2... etc. So if person 010 offers tasks with a task mask (TM) of 0101, then person 2 offers A and C, and person 001 with TM 1000 offers only D.

If we plan to visit persons 011 (001 AND 010), then the combined tasks on offer are

```
=BITOR("TM for 001", "TM for 010") which will result in TM 1101 (tasks A, C, D)
```

The combined tasks on offer for everyone are

```
=BITOR("TM for 001", BITOR("TM for 010", BITOR("TM for 100",... "TM for 10000000"))))))))
```

So in order to tell what tasks are offered by some random combination of persons x, we need to BITOR together only the relevant TMs:

```
=BITOR("TM for 001" * x0, BITOR("TM for 010" * x1, BITOR("TM for 100" * x2,... "TM for 10000000" * x7))))))))
```

where xi is the i'th bit in x

```
=BITAND(1,BITRSHIFT(x,i))
```

Likewise to determine the total distance for person combination / route x

```
"Person 1 distance" * x0 + "Person 2 distance" * x1 +... "Person 8 distance" * x7
```

Now to determine if, for persons x with TM y, all the required tasks z can be done (i.e. a valid route):

```
=IF(BITAND(y,z) = z, "All tasks offered by x", "All tasks cannot be done")
And the distance for valid routes only
=IF(BITAND(y,z) = z, *distance calc above*,"") so invalid routes are blank ""
```

Now calculate this for every possible combination e.g. (1..255) and look for the minimum valid route distance with *MIN(...)*, then find the best route x with MATCH(MIN(...), *route distances column*, 0) that matches that minimum route distance. Break x apart into bits x0.. x7 and use conditional formatting to highlight each person in the best route.