Omid - Challenge 293

data-challenges
advanced-exercises
🔰 Question Result Product ID MN-11 MN-12 MN-13 MN-14 MN-15
Published

March 24, 2026

Illustration for Omid - Challenge 293

Challenge Description

🔰 Question Result Product ID MN-11 MN-12 MN-13 MN-14 MN-15

Solutions

library(tidyverse)
library(readxl)

path = "files/200-299/293/CH-293 Advanced Sorting.xlsx"
input = read_excel(path, range = "B2:D8")
test  = read_excel(path, range = "F2:H8")

result = input %>%
  arrange(fct_relevel(Size, "S", "M", "L", "XL", "XXL", "XXXL")) 

all.equal(result, test)
# [1] TRUE
  • Logic:

    • Reads the workbook ranges needed for the challenge
  • 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 = "200-299/293/CH-293 Advanced Sorting.xlsx"
input = pd.read_excel(path, usecols="B:D", skiprows=1, nrows=7)
test = pd.read_excel(path, usecols="F:H", skiprows=1, nrows=7).rename(columns=lambda col: col.replace('.1', ''))

sizes = ["S", "M", "L", "XL", "XXL", "XXXL"]
result = input.sort_values("Size", key=lambda x: x.map({s: i for i, s in enumerate(sizes)})).reset_index(drop=True)

print(result.equals(test)) # True
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • Applies the rule iteratively until the output stabilizes

  • 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.