A solution to the Paint Shop problem described here
This solution is implemented with Node.js + Typescript + Jest.
Node.js is the only thing needed for running the code. Version used: 10.15.0
npm install
npm run build
This command will create the build folder that contians the main.js file used to run the script.
There are two ways of running it.
- Redirect a file as input of the node process:
node build/src/main.js < <file.txt>
- Using CLI. After the last preference line, include an extra enter. The program will then print the result. For example:
node build/src/main.js
5
1 M 3 G 5 G
2 G 3 M 4 G
5 M
G G G G M
npm run test
A report including the coverage is printed.
A recursive algorithm was used.
Base step
If there is any customer without preferences
There is no solution, there is no way of satisfying that customer
Base step
If all customers have at least one gloss finish preference
All present colors can be marked as gloss and satisfy all customers
Recursive step
If there is any customer that has only one preference and it's mate
Mark that color as mate
Remove the color from all customers preferences, remove the customer
Make the recursive call