Sunteți pe pagina 1din 9

System Dependencies

Instructions

Firstly, thank you for taking the time to do this exercise.  Hopefully, you'll have some fun
showing off your skills.  Our goal is to see some code, not for a perfect solution.  You have
2 hours for the exercise but most people do not finish in that time, so please don't feel
stressed if you're not getting through it all.  We are way more interested in the approach you
take and the quality of your code, than we are about you beating the clock.  

Please read the following carefully and then implement your solution in any language you
feel comfortable with.

We will look at your solution in terms of the completeness of implementation and the ap-
proach taken. If after 2 hours you wish you had more time, we'd appreciate it if you spend an
extra 15 minutes writing an overview of what your next steps would have been and include
that in the email attaching your challenge.  

Please deliver your code in a compressed email attachment along with the output
your code produced against the sample input.  If your solution requires any setup (ie,
'[pip3|bundle|npm|yarn] install', etc) please include a README with instructions on how to
run your program. Please do not post your solution publicly so that future candidates can't
see your amazing solution.

Thanks for taking the time to go through our challenge!

Code challenge

Context:
Components of computer systems often have dependencies—other components that must
be installed before they will function properly. Today we're going to implement a simplified
package manager.

Requirements: 
Our simple package manager should be able to track and manage dependencies. This in-
cludes implicitly installing necessary dependencies and removing components when they are
no longer necessary. At any point our manager should also be able to output the currently
installed programs.

To do this we will maintain a record of installed components and component dependencies.


A component can be installed explicitly in response to a command (unless it is already in-
stalled), or implicitly if it is needed for some other component being installed. Likewise, a
component explicitly installed can be explicitly removed in response to a command (if it is
not needed to support other components) or implicitly removed if it is no longer needed to
support another component.

Command Structure:

DEPEND <package> <dependency1> [<additional dependencies>]


Takes 2+ arguments. The first argument, <package>, depends on all of the remaining argu-
ments. Note that all depend commands will appear at the beginning of any input file and tar-
gets of dependencies will not be repeated (if DEPEND A B was submitted, then there won't be
any more commands that begin with DEPEND A ...).

Example:

     DEPEND a b c
     — <a> depends on <b> and <c>.

INSTALL <package>
Takes 1 argument. Implicitly install any unmet dependencies, and then explicitly install <pack-
age>. If <package> is already installed, echo that feedback.
Example:     

     DEPEND a b
     INSTALL a

     —  implicitly install <b>. Explicitly install <a>

REMOVE <package>
Takes 1 argument. If <package> is not installed, echo that feedback. If <package> is still
needed as a dependency for other installed packages, echo that feedback, and do not remove
<package>. Otherwise, remove <package>. Afterward, remove any implicitly installed packages
that are no longer needed by the system.
Examples:

     DEPEND a b
     INSTALL a
     REMOVE b
    — echo that <b> is still needed

~~~~
     DEPEND a b
     INSTALL a
     REMOVE a

     — uninstall <a>. Now that <b> is no longer needed, remove <b>.

~~~~

     DEPEND a b
     INSTALL a
     INSTALL b
     REMOVE a

     — uninstall <a>. <b> is no longer needed for <a>, but was explicitly installed, so we do not


remove it.

LIST
Takes no arguments. List all currently installed programs
Example:

    DEPEND a b
    INSTALL a
    LIST

     — <a> and <b> are installed. echo each package on a new line.

END
The end of the input is marked by a line containing only the word END.

Output:
Your package manager should first echo each line of input. Follow each echoed INSTALL or
REMOVE line with the actions taken in response, making certain that the actions are given
in the proper order. Also identify exceptional conditions (see Expected Output, below, for
examples of all cases). For the LIST command, display the names of the currently installed
components. No output, except the echo, is produced for a DEPEND command or the line
containing END.

Sample Input:
DEPEND TCPIP NETCARD
DEPEND TELNET TCPIP SOCKET
DEPEND DNS TCPIP
DEPEND HTML REGEX XML
DEPEND REGEX PARSING
DEPEND BROWSER DNS TCPIP HTML CSS
INSTALL TCPIP
REMOVE NETCARD
REMOVE TCPIP
REMOVE NETCARD
INSTALL TCPIP
LIST
INSTALL TCPIP
INSTALL foo
REMOVE TCPIP
INSTALL NETCARD
INSTALL TCPIP
REMOVE TCPIP
LIST
INSTALL TCPIP
INSTALL NETCARD
REMOVE TCPIP
LIST
REMOVE NETCARD
INSTALL BROWSER
LIST
REMOVE BROWSER
LIST
INSTALL HTML
INSTALL TELNET
REMOVE SOCKET
INSTALL DNS
INSTALL BROWSER
REMOVE NETCARD
LIST
REMOVE BROWSER
LIST
END

Expected Output:

DEPEND TCPIP NETCARD


DEPEND TELNET TCPIP SOCKET
DEPEND DNS TCPIP
DEPEND HTML REGEX XML
DEPEND REGEX PARSING
DEPEND BROWSER DNS TCPIP HTML CSS
INSTALL TCPIP
   Installing NETCARD
   Installing TCPIP
REMOVE NETCARD
   NETCARD is still needed.
REMOVE TCPIP
   Removing TCPIP
   Removing NETCARD
REMOVE NETCARD
   NETCARD is not installed.
INSTALL TCPIP
   Installing NETCARD
   Installing TCPIP
LIST
    NETCARD
    TCPIP
INSTALL TCPIP
   TCPIP is already installed.
INSTALL foo
   Installing foo
REMOVE TCPIP
   Removing TCPIP
   Removing NETCARD
INSTALL NETCARD
   Installing NETCARD
INSTALL TCPIP
   Installing TCPIP
REMOVE TCPIP
   Removing TCPIP
LIST
    NETCARD
    foo
INSTALL TCPIP
   Installing TCPIP
INSTALL NETCARD
   NETCARD is already installed.
REMOVE TCPIP
   Removing TCPIP
LIST
    NETCARD
    foo
REMOVE NETCARD
   Removing NETCARD
INSTALL BROWSER
   Installing CSS
   Installing NETCARD
   Installing TCPIP
   Installing DNS
   Installing PARSING
   Installing REGEX
   Installing XML
   Installing HTML
   Installing BROWSER
LIST
    BROWSER
    CSS
    DNS
    HTML
    NETCARD
    PARSING
    REGEX
    TCPIP
    XML
    foo
REMOVE BROWSER
   Removing BROWSER
   Removing CSS
   Removing DNS
   Removing HTML
   Removing REGEX
   Removing TCPIP
   Removing XML
   Removing NETCARD
   Removing PARSING
LIST
    foo
INSTALL HTML
   Installing PARSING
   Installing REGEX
   Installing XML
   Installing HTML
INSTALL TELNET
   Installing SOCKET
   Installing NETCARD
   Installing TCPIP
   Installing TELNET
REMOVE SOCKET
   SOCKET is still needed.
INSTALL DNS
   Installing DNS
INSTALL BROWSER
   Installing CSS
   Installing BROWSER
REMOVE NETCARD
   NETCARD is still needed.
LIST
    BROWSER
    CSS
    DNS
    HTML
    NETCARD
    PARSING
    REGEX
    SOCKET
    TCPIP
    TELNET
    XML
    foo
REMOVE BROWSER
   Removing BROWSER
   Removing CSS
LIST
    DNS
    HTML
    NETCARD
    PARSING
    REGEX
    SOCKET
    TCPIP
    TELNET
    XML
    foo
END

S-ar putea să vă placă și