This repository has been archived by the owner on Mar 18, 2020. It is now read-only.
An algorithm for a special case of the hamilton path problem
License
sadanjon/duct
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Solution to the 'Datacenter Cooling" problem: ============================================ This problem is on the quora.com 'job challenges': We have some rooms in our datacenter, and we need to connect them all with a single cooling duct. Here are the rules: 1. The datacenter is represented by a 2D grid. 2. Rooms we own are represented by a 0. 3. Rooms we do not own are represented by a 1. 4. The duct has to start at the air intake valve, which is represented by a 2. 5. The duct has to end at the air conditioner, which is represented by a 3. 6. The duct cannot go in multiple directions out of the intake or the AC - they must be the two endpoints of the duct. 7. The duct must pass through each room exactly once. 8. The duct cannot pass through rooms we do not own. 9. The duct can connect between rooms horizontally or vertically but not diagonally. The challenge is "How many ways are there to pass the duct?" Instructions: ============ Written and tested on Linux machines. :) Written in C with no dependencies. Just run make, and run the executable 'duct'. Usage: ./duct < <grid file> The grid file describes the grid as follows: A list of integers separated by whitespace. The first two are the width and height in that order. And then a width*height integers that describe the grid as follows: 0 - Rooms owned by us 1 - Rooms not owned by us 2 - Start room 3 - End room The program just prints out one integer. If you want it to print out solutions as it finds them compile with option '-DPRINT'. Just add it to the makefile variable CFLAGS. There's a 'sample' file with the program for an example input. The 'quora_sample' file is the input quora.com suggested. (very complex) Comment: ======== This solution ran just under one minute for the input Quora gave on their website, on a 2.4 GHz linux machine. You can reach me at: sadanjon at gmail dot com Files ===== |-- duct.c |-- duct.h |-- grid.c |-- grid.h |-- Makefile |-- node.c |-- node.h |-- queue.c |-- queue.h |-- sample |-- README `-- util.h
About
An algorithm for a special case of the hamilton path problem
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published