Omid - Challenge 183

data-challenges
advanced-exercises
🔰 Match Dates!
Published

March 24, 2026

Illustration for Omid - Challenge 183

Challenge Description

🔰 Match Dates!

Solutions

library(tidyverse)
library(readxl)
library(anytime)

path = "files/CH-183 Match the Dates.xlsx"
input = read_excel(path, range = "C2:C29")
test  = read_excel(path, range = "I2:I14")

result = input %>%
  mutate(date = anytime(Date),
         dateymd = ymd(Date),
         result = coalesce(date, dateymd)) %>%
  select(result) %>%
  distinct()

all.equal(anydate(result$result), anydate(test$Date))
# [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
from dateutil.parser import parse

path = "CH-183 Match the Dates.xlsx"

input = pd.read_excel(path, usecols="C", skiprows=1, nrows=28)
test = pd.read_excel(path, usecols="I", skiprows=1, nrows=12).rename(columns=lambda x: x.split('.')[0])

def parse_date(date_str):
    try:
        return parse(date_str, fuzzy=True, yearfirst=True)
    except ValueError:
        return None

input['Parsed Date'] = input.iloc[:, 0].apply(parse_date).dt.date
result = pd.DataFrame(input['Parsed Date'].drop_duplicates().unique(), columns=['Date'])

print(all(result['Date'] == test['Date'])) # True
  • 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 business rule is readable, but the workbook still requires careful implementation to reach the expected layout.