Omid - Challenge 161

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

March 24, 2026

Illustration for Omid - Challenge 161

Challenge Description

🔰 Question Result Date Product A B C D

Solutions

library(tidyverse)
library(readxl)

path = "files/CH-161 Custom Index Column.xlsx"
input = read_excel(path, range = "B2:C11")
test  = read_excel(path, range = "E2:H6")

result = input %>%
  mutate(rn = row_number(), .by = Product) %>%
  pivot_wider(names_from = Product, values_from = Date) %>%
  select(-rn)

all.equal(result, test, check.attributes = FALSE)
#> [1] TRUE
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • Reshapes the data into the grain required by the task

    • 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-161 Custom Index Column.xlsx"
input = pd.read_excel(path, usecols="B:C", skiprows=1, nrows=10)
test = pd.read_excel(path, usecols="E:H", skiprows=1, nrows=4)

result = input.assign(rn=input.groupby('Product').cumcount() + 1) \
               .pivot(index='rn', columns='Product', values='Date') \
               .reset_index(drop=True).rename_axis(None, axis=1)

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

    • Reads the workbook ranges needed for the challenge

    • Reshapes the data into the grain required by the task

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