# Hack Code
We get a file with a lot of routes (given as lists of routers), andare asked to find a small subset of routers to tap so that we have atleast one tap on each route. We will ignore the topology of thenetwork and the order of routers in the paths, and will treat this asa set cover problem: the routes are sets, and we need to pick a smallset of elements (routers) such that we cover all routes.
We can start with a simple randomised solution: iterate through allsets, and if no elements in the set are in the current solution, pickone at random and insert it. This will produce solutions with around200 elements -- not enough to get any flags, but it is a start.
Next, we can try to improve this (again, at random) with the followingalgorithm:
* pick a random router not yet in the solution* insert it in the solution* for each other router, see if we can remove it without "breaking"  our solution (so all sets are still covered) and remove it if we can* if we couldn't remove anything, remove the new router
Sometimes we will add a router and remove multiple old routers, sothis will slowly improve the solution, and after a minute or two wewill have one that is good enough to get the first flag. 
A small optimisation to the algorithm will make it run significantlyfaster: instead of checking all routers in each iteration, only lookat those for which we could have made a difference -- those that arein one of the sets covered by the new entry. With this optimisation,in a few minutes we get a solution with 126 routers, which is enoughto get all flags (and the best the organisers found).
My code that solves this (note: written in a rush during the CTF andpresented here without any cleanup) can be found[here](https://de298.user.srcf.net/writeups/insa/hackcode.py).