[go: up one dir, main page]

0% found this document useful (0 votes)
6 views2 pages

Programming Assessment Formatted

The document outlines a programming assessment consisting of four questions. Question 1 requires a function to parse a config language into a dictionary and checksum, while Question 2 involves designing a plugin system with auto-registration and a pipeline. Questions 3 and 4 focus on interpreting a numeric array as a torus and processing sales data with applicable promotions, respectively.

Uploaded by

musaqureshi524
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Programming Assessment Formatted

The document outlines a programming assessment consisting of four questions. Question 1 requires a function to parse a config language into a dictionary and checksum, while Question 2 involves designing a plugin system with auto-registration and a pipeline. Questions 3 and 4 focus on interpreting a numeric array as a torus and processing sales data with applicable promotions, respectively.

Uploaded by

musaqureshi524
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Programming Assessment

Question 1
Write a function `parse_config(text: str) -> tuple[dict[str, str], int]` that parses a tiny config l
anguage and returns:
- a dictionary of key→value (strings), and
- a checksum: XOR of the Unicode code points of all characters of the canonicalized values only (not
keys, whitespace, or comments).

Rules:
- Each non-empty logical line is `key = value`.
- Lines may end with a trailing backslash `\` to continue onto the next line.
- Leading/trailing whitespace around keys and values is ignored after handling continuations.
- `#` begins a comment unless inside double quotes.
- Values can be:
* unquoted text (stop before unescaped `#`), or
* double-quoted strings with escapes: `\"`, `\\`, `\n`, `\t`, `\xHH` (two hex digits).
- Duplicate keys keep the last occurrence.
- Invalid lines must raise `ValueError` mentioning the 1-based line number.

Canonicalization:
- For checksum, use the final unescaped value only.
- Do not include quotes.

Example:
```
user = "Ada Lovelace" # pioneer
greeting="Hello,\nworld" \"!" # continuation
path = C:\Users\Public
hex = "\x41\x42" # -> "AB"
note=unquoted # comment starts here
```

Question 2
Design a plugin system:
- Define a base class with attributes `name` and `priority`, and an abstract `handle` method.
- Subclasses auto-register unless marked abstract.
- A pipeline function executes plugins in descending priority order. Each may mutate the command or
return `None` to stop the pipeline.
- A context manager `mute_plugins(*names)` temporarily disables selected plugins.

Demo scenario:
- `AuthPlugin` adds `authenticated=True`.
- `AuditPlugin` appends `seen:<name>` to an audit log list.
- `KillSwitch` stops processing if the command contains `kill=1`.

Question 3
Implement a function that interprets a 1D numeric array of length R*C as an R×C torus (wrap-around i
n both directions).
For each cell, return the sum of values in its Chebyshev-≤k neighborhood.
Constraints:
- No explicit element-wise loops; use vectorized operations.
- Complexity should be near O(R*C).
- Preserve numeric dtype where possible.
- `k=0` should return the original array.

Quick check:
For R=3, C=5, k=1, with values `0..14`, the result at position (0,0) should equal the sum of its 3×3
toroidal neighborhood.

Question 4
You are given two sets of data:

A) Sales, each with an ID, SKU, timestamp, and quantity.


B) Promotions with half-open intervals [start, end) containing price, campaign, and priority.

Tasks:
1) For each sale, attach the applicable promotion where start ≤ ts < end and SKU matches. If multipl
e apply, select the one with highest priority; break ties by the latest start. If none apply, mark p
rice as missing.
2) For each SKU, produce a daily snapshot of the effective price at 00:00:00Z across the date range
covered. Apply the same precedence rules as above.
3) Compute revenue per sale as `qty * matched price`. If no price, revenue is missing.

Quick checks:
- A sale at 01:50Z with two overlapping promos should pick the higher-priority one.
- A sale at 02:10Z should select the later valid promo.
- The daily snapshot at midnight should reflect the correct interval-based price.

You might also like