library(tidyverse)
library(readxl)
input = read_excel("files/CH-0010.xlsx", range = "B2:D17")
test = read_excel("files/CH-0010.xlsx", range = "G2:H7")
result = input %>%
mutate(requirements = case_when(
Material == "A" ~ 1,
Material == "B" ~ 2,
Material == "C" ~ 3
), product_available = Inventory%/%requirements) %>%
group_by(Date) %>%
mutate(min_available = min(product_available),
usage = min_available*requirements) %>%
summarise(usage = sum(usage),
inventory = sum(Inventory),
Efficiency_rate = usage/inventory)
identical(result$Efficiency_rate, test$`Efficeincy Rate`)
# [1] TRUEOmid - Challenge 10

Challenge Description
🔰 The question table shows inventory levels for materials required to produce products, with specific combinations (1 A, 2 B, 3 C per product).
Solutions
Logic:
Reads the workbook ranges needed for the challenge
Aggregates or ranks values at the relevant grouping level
Builds the intermediate columns that drive the final result
Strengths:
- The R solution stays close to the workbook rule and keeps the transformation compact.
Areas for Improvement:
- The code assumes the sheet structure and source ranges remain stable.
Gem:
- The strongest part of the solution is choosing the right intermediate representation before shaping the final output.
import pandas as pd
path = "CH-0010.xlsx"
input_data = pd.read_excel(path, usecols="B:D", skiprows=1, nrows=16)
test = pd.read_excel(path, usecols="G:H", skiprows=1, nrows=6)
requirements_map = {"A": 1, "B": 2, "C": 3}
result = input_data.assign(
requirements=lambda df: df["Material"].map(requirements_map),
product_available=lambda df: df["Inventory"] // df["requirements"],
)
result = (
result.groupby("Date", as_index=False)
.apply(
lambda g: pd.Series(
{
"usage": (g["product_available"].min() * g["requirements"]).sum(),
"inventory": g["Inventory"].sum(),
}
)
)
.reset_index(drop=True)
)
result["Efficiency_rate"] = result["usage"] / result["inventory"]
print(result["Efficiency_rate"].equals(test["Efficeincy Rate"]))Logic:
Reads the workbook ranges needed for the challenge
Aggregates or ranks values at the relevant grouping level
Builds the intermediate columns that drive the final result
Strengths:
- The Python version follows the same rule in a direct dataframe-oriented implementation.
Areas for Improvement:
- The code assumes the workbook layout remains stable, so any sheet redesign would require small adjustments.
Gem:
- The implementation stays close to the original workbook rule instead of adding unnecessary abstraction.
Difficulty Level
This task is moderate:
The core logic is clear, but the correct transformation pattern is not obvious from the raw input.
The challenge combines multiple reshaping, grouping, or parsing steps.