Omid - Challenge 206

data-challenges
advanced-exercises
🔰 Question Result ID ABC A1B2C3 MNXLP QRW32 X1Y2Z3
Published

March 24, 2026

Illustration for Omid - Challenge 206

Challenge Description

🔰 Question Result ID ABC A1B2C3 MNXLP QRW32 X1Y2Z3

Solutions

library(tidyverse)
library(readxl)

path = "files/CH-206 Column Splitting.xlsx"
input = read_excel(path, range = "B2:B7")
test  = read_excel(path, range = "D2:E7")

result = input %>%
  mutate(rn = row_number()) %>%
  separate_rows(ID, sep = "") %>%
  filter(ID != "") %>%
  mutate(pos = ifelse(row_number() %% 2 == 0, "Even Positions", "Odd Positions"), .by = rn) %>%
  pivot_wider(names_from = pos, values_from = ID, values_fn = ~ paste0(.x, collapse = "")) %>%
  select(-rn)

all.equal(result, test, check.attributes = FALSE)
# There is one mistake in result provided.
  • 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-206 Column Splitting.xlsx"
input = pd.read_excel(path, usecols="B", skiprows=1, nrows=6)
test = pd.read_excel(path, usecols="D:E", skiprows=1, nrows=6)

def split_even_odd_chars(series):
    return series.apply(lambda x: pd.Series([''.join(str(x)[::2]), ''.join(str(x)[1::2])], index=['Odd Positions', 'Even Positions']))

result = split_even_odd_chars(input.iloc[:, 0])


print(test)
print(result)
  • 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.