Omid - Challenge 12

data-challenges
advanced-exercises
🔰 The highlighted cell shows the result
Published

March 24, 2026

Illustration for Omid - Challenge 12

Challenge Description

🔰 The highlighted cell shows the result

Solutions

library(tidyverse)
library(readxl)

input = read_excel("files/CH-012.xlsx", range = "B3:G8", col_names = F)
test  = read_excel("files/CH-012.xlsx", range = "O3:T8", col_names = F)

result = input %>%
  mutate(across(everything(), ~ .x / sum(.x)))

# some cells in test were not correct to compare.

result %>% mutate(across(everything(), ~ round(.x * 100, 0)))

# # A tibble: 6 × 6
# ...1  ...2  ...3  ...4  ...5  ...6
# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#   1    13    29     4    27    22    20
#   2    29     8    21    29     4    23
#   3    21    27    34    11    10    22
#   4    26     4    22    17    19    19
#   5     4    20    11    14    21     9
#   6     7    12     8     3    23     6
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • Builds the intermediate columns that drive the final result

    • Parses the text patterns directly instead of relying on manual cleanup

  • 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

input_data = pd.read_excel("CH-012.xlsx", usecols="B:G", skiprows=2, nrows=6, header=None)
result = input_data.divide(input_data.sum(axis=0), axis=1)

print((result * 100).round(0))
# The R source notes that some workbook comparison cells are incorrect.
  • Logic:

    • Reads the workbook ranges needed for the challenge
  • 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.