Hello there
I'd like to build that function for you, there is a small problem with your conditions, though:
If every team is allowed only 2 home games, that means there can be a total of 24 home games (assuming 12 teams) - 24 games total, since after this every team will have exhausted its 2 home games - the number of REQUIRED games however is 66. This condition can never be met for 12 teams. (It works out for some of the lower number but not all.)
Joshua