interviews-in23/desc.md

1.9 KiB

Insurance networks

The following grammar:

<lines> ::= <line> | <line> "\n" <lines>
<line> ::= <insurer-id> ":" <percent> <optional-exprs>
<optional-exprs> ::= "" | "if" <exprs>
<exprs> ::= <expr> | <expr> "and" <exprs>
<expr> ::= <lesser-than> | <greater-than> | <equals> | <insurer-id>
<lesser-than> ::= "<" <integer>
<greater-than> ::= ">" <integer>
<equals> ::= "=" <integer>
<insurer-id> ::= "I" <integer>
<percent> ::= <integer> "%"
<integer> ::= <digit> | <non-zero-digit> <integer>
<digit> ::= "0" | <non-zero-digit>
<non-zero-digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

is used to represents insurance networks.

Given a single input of type Int, the job of these networks is to provide, if possible, exactly 100% underwriting capital using the fewest insurers possible. Each insurer contributes their percentage only if their respective conditions are met.

Below is a simple example of such a network:

I1: 50%
I2: 50% if <5
I3: 40% if I1
I4: 30% if I2 and <5
I5: 10% if I3 and I4
I6: 10% if I3

where:

  • Insurer I1 contributes 50% unconditionally, for any input
  • I2 contributes 50% only if the input is <5
  • I3 contributes 40% only if I1 contributes
  • etc...

Given the above, your task is to write a small command line program that takes 2 parameters:

  • the path to a file that defines a network
  • an integer input to the network

and outputs a list of the fewest contributing insurers (by their integer ids).

Eg. if your program was given the above example network and:

  • input 3 then it would output [1, 2] (representing insurers I1 and I2)
  • input 6 then it would output [1, 3, 6]

If a network is unable to collect exactly 100% for a given input then your program should output [].

Please create a new private github repository named artificial-network, commit all your code there and once finished please invite me, pwm, so we can check your solution.

Good luck!