Skip to content

Instantly share code, notes, and snippets.

@joncloud
Created September 1, 2016 20:39
Show Gist options
  • Save joncloud/e55ae76d6f319803de183575e348aa75 to your computer and use it in GitHub Desktop.
Save joncloud/e55ae76d6f319803de183575e348aa75 to your computer and use it in GitHub Desktop.

Undercover underground

As you help the rabbits establish more and more resistance groups to fight against Professor Boolean, you need a way to pass messages back and forth.

Luckily there are abandoned tunnels between the warrens of the rabbits, and you need to find the best way to use them. In some cases, Beta Rabbit wants a high level of interconnectedness, especially when the groups show their loyalty and worthiness. In other scenarios the groups should be less intertwined, in case any are compromised by enemy agents or zombits.

Every warren must be connected to every other warren somehow, and no two warrens should ever have more than one tunnel between them. Your assignment: count the number of ways to connect the resistance warrens.

For example, with 3 warrens (denoted A, B, C) and 2 tunnels, there are three distinct ways to connect them:

A-B-C A-C-B C-A-B

With 4 warrens and 6 tunnels, the only way to connect them is to connect each warren to every other warren.

Write a function answer(N, K) which returns the number of ways to connect N distinctly labelled warrens with exactly K tunnels, so that there is a path between any two warrens.

The return value must be a string representation of the total number of ways to do so, in base 10. N will be at least 2 and at most 20. K will be at least one less than N and at most (N * (N - 1)) / 2

Languages

To provide a Python solution, edit solution.py To provide a Java solution, edit solution.java

Test cases

Inputs: (int) N = 2 (int) K = 1 Output: (string) "1"

Inputs: (int) N = 4 (int) K = 3 Output: (string) "16"

Use verify [file] to test your solution and see how it does. When you are finished editing your code, use submit [file] to submit your answer. If your solution passes the test cases, it will be removed from your home folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment