Skip to content

Instantly share code, notes, and snippets.

@instinctive
Last active October 31, 2021 00:58
Show Gist options
  • Save instinctive/94ccb5bce9e41691ad31b91d32ff372a to your computer and use it in GitHub Desktop.
Save instinctive/94ccb5bce9e41691ad31b91d32ff372a to your computer and use it in GitHub Desktop.

The Any Worker Problem

19391D8D-B4ED-4D20-BC30-D12CA5EBC816

In The Manhattan Project (TMP) boardgame, you may use any three of your workers to run this mine.

There are effectively six kinds of workers in TMP, the cross-product of three occupations: Laborers, Engineers, and Scientists, and two types of employment: Full Time Employee (FTE) and Contractor. You may have up to 4 of each of these six kinds of workers at any time.

For example, you might have 3 FTE Laborers, 1 Contract Laborer, and 1 Contract Engineer.

Note that Engineers and Scientists should never be used if there is a Laborer of the same employment status.

The Problem

Write a function that takes as input a desired number of workers (3 in the Mine pictured above), and the number of FTE and Contract workers of each occupation.

The function should output all reasonable allocations to meet the desired number of workers.

Example

This example is in Haskell, but use whatever input and output format you want for your language!

-- anyWorker desired (FTE Lab, FTE Eng, FTE Sci) (Contract Lab, Con Eng, Con Sci)
> mapM_ print $ anyWorker 3 (3,0,0) (1,1,0)
((1,0,0),(1,1,0))
((2,0,0),(1,0,0))
((3,0,0),(0,0,0))

In this next example, note that the FTE Engineers and Scientists are never chosen, as there are enough FTE Laborers. The Contract Engineers and Scientists are used, but not unless the Contract Laborer is also used.

> mapM_ print $ anyWorker 3 (4,4,4) (1,1,1)
((0,0,0),(1,1,1))
((1,0,0),(1,0,1))
((1,0,0),(1,1,0))
((2,0,0),(1,0,0))
((3,0,0),(0,0,0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment