library(tidyverse)
library(readxl)
path <- "300-399/333/CH-333 Pattern Combinations.xlsx"
input <- read_excel(path, range = "B2:D8")
test <- read_excel(path, range = "F2:F8")
roll_column <- function(column, steps) {
n <- length(column)
c(tail(column, n - steps %% n), head(column, steps %% n))
}
result = input %>%
mutate(
`Column 1` = `Column 1`,
`Column 2` = roll_column(`Column 2`, 1),
`Column 3` = roll_column(`Column 3`, 2)
) %>%
unite("Combinations", `Column 1`:`Column 3`, sep = "")
all.equal(result, test)
# [1] TRUEOmid - Challenge 333
data-challenges
advanced-exercises
🔰 Question Table Result Table Column 1 Column 2 A X C B

Challenge Description
🔰 Question Table Result Table Column 1 Column 2 A X C B
Solutions
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
import numpy as np
path = "300-399/333/CH-333 Pattern Combinations.xlsx"
input = pd.read_excel(path, usecols="B:D", skiprows=1, nrows=7)
test = pd.read_excel(path, usecols="F", skiprows=1, nrows=7)
def shift_column(s, n):
return np.roll(s.to_numpy(), -n)
input['Column 2'] = shift_column(input['Column 2'], 1)
input['Column 3'] = shift_column(input['Column 3'], 2)
input['Combinations'] = input.astype(str).agg(''.join, axis=1)
print(input['Combinations'].equals(test['Combinations'])) # TrueLogic:
- 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.