helenamunoz / ColorsChallenge

Portchain colors challenge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Portchain Paint Shop problem

A solution to the Paint Shop problem described here

This solution is implemented with Node.js + Typescript + Jest.

Dependencies

Node.js is the only thing needed for running the code. Version used: 10.15.0

Running the solution

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.

  1. Redirect a file as input of the node process:

node build/src/main.js < <file.txt>

  1. 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

tests

npm run test

A report including the coverage is printed.

The algorithm

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

About

Portchain colors challenge


Languages

Language:TypeScript 94.0%Language:JavaScript 6.0%