Skip to content

Instantly share code, notes, and snippets.

@LS80
Last active September 12, 2023 07:34
Show Gist options
  • Save LS80/b37589586122e1e1e381198b64be1009 to your computer and use it in GitHub Desktop.
Save LS80/b37589586122e1e1e381198b64be1009 to your computer and use it in GitHub Desktop.

Loan Dashboard

We're a lending platform giving loans to businesses. We want to create a summary of loans by transforming input data.

Input Format

The input to this exercise is as follows:

Perky Blenders Coffee, 56101, 100000, B, 8%
Laird Hatters LTD, 14190, 25000, C, 15%, 75000, D, 20%

The input consists of rows that are separated by line-feeds/new-lines (\n).

Each row has fields that are separated by commas and each row can vary in length.

A row consists of the following fields:

  1. The business name.
  2. The main business nature code.
  3. A repeating set of triplets with the loan amount, risk band, and interest rate. There could be any number of these triplets.

For example, the following row is broken down as shown:

Laird Hatters LTD, 14190,     25000,        C,        15%,      75000,       D,        20%
|---------------||-------||-----------||---------||--------||-----------||---------||--------|
      NAME         CODE    LOAN AMOUNT  RISK BAND  INTEREST  LOAN AMOUNT  RISK BAND  INTEREST
                          |__________Triplet 1_____________||__________Triplet 2_____________|

Exercise

We want to show:

  • The total amount we have loaned.
  • Each business name with the average loan amount we have issued them.

You are allowed to feed the input into your solution however you prefer, e.g.:

  • a variable containing the data
  • a file
  • from stdin
  • a test harness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment