Omid - Challenge 112

data-challenges
advanced-exercises
🔰 Result Question Rank Product A B C D
Published

March 24, 2026

Illustration for Omid - Challenge 112

Challenge Description

🔰 Result Question Rank Product A B C D

Solutions

library(tidyverse)
library(readxl)

path = "files/CH-112 Custom Rank.xlsx"

input = read_excel(path, range = "C2:E6")
test  = read_excel(path, range = "J2:K6")

result = input %>%
  mutate(Rank = rank(desc(`2023` - `2022`))) %>%
  arrange(Rank) %>% 
  select(Rank, Product)

identical(result, test)
# [1] TRUE
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • 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-112 Custom Rank.xlsx"
input = pd.read_excel(path, usecols="C:E", skiprows=1)
input.columns = ["Product", "Y2022", "Y2023"]
test  = pd.read_excel(path, usecols="J:K", skiprows=1)
test.columns = ["Rank", "Product"]

result = input.copy()
result = input.assign(diff=input["Y2023"] - input["Y2022"])\
    .assign(Rank=lambda x: x["diff"]\
    .rank(ascending=False).astype(int))\
    .sort_values("Rank")[["Rank", "Product"]]\
    .reset_index(drop=True)

print(all(result == test)) # True
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • 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 business rule is readable, but the workbook still requires careful implementation to reach the expected layout.