Challenge Description
Easy Sunday Excel Challenge
⭐
Solutions
library(tidyverse)
library(readxl)
path <- "2025-11-30/Challenge 81.xlsx"
input <- read_excel(path, range = "B2:B6")
test <- read_excel(path, range = "D2:D6")
result = input %>%
mutate(across(everything(), ~ str_remove_all(., "<.*?>"))) %>%
mutate(across(everything(), ~ str_replace_all(., " ", ""))) %>%
mutate(across(everything(), ~ str_squish(.)))
all.equal(result$Problem, test$Solution)
# [1] TRUE
Logic:
Reads the workbook range needed for the challenge
Builds the intermediate helper columns that drive the final answer
Uses direct text-pattern extraction instead of manual cleanup
Strengths:
- The R solution stays compact and mirrors the workbook logic closely.
Areas for Improvement:
- The code assumes the workbook layout and named ranges remain stable.
Gem:
- The best part of the solution is choosing a tidy intermediate shape before producing the final answer.
import pandas as pd
import re
path = "2025-11-30/Challenge 81.xlsx"
input = pd.read_excel(path, usecols="B", nrows = 4, skiprows = 2)
test = pd.read_excel(path, usecols="D", nrows=4, skiprows=2).rename(columns=lambda c: c.replace('.1', ''))
def clean_text(s):
return s if pd.isnull(s) else " ".join(re.sub(r"<.*?>", "", str(s)).replace(" ", "").split())
result = input.map(clean_text)
print(result.equals(test)) # True
Logic:
Strengths:
- The Python version keeps the same rule in a direct pandas-oriented workflow.
Areas for Improvement:
- As with the R version, any workbook layout change would require small adjustments.
Gem:
- The implementation stays close to the stated challenge instead of adding unnecessary complexity.
Difficulty Level
This task is moderate:
It combines familiar Excel-style logic with at least one non-trivial reshape, grouping, or parsing step.
The answer depends on getting the output layout exactly right.
|