library(tidyverse)
library(readxl)
path = "files/CH-128 Cartesian Product.xlsx"
test = read_excel(path, range = "C1:C65")
lets = c("A","B","C","D")
result = expand.grid(lets,lets, lets) %>%
unite("result", Var1:Var3, sep = "") %>%
arrange(result)
all.equal(result$result, test$Result)
#> [1] TRUEOmid - Challenge 128
data-challenges
advanced-exercises
🔰 Result AAA AAB AAC AAD ABA ABB ABC

Challenge Description
🔰 Result AAA AAB AAC AAD ABA ABB ABC
Solutions
Logic:
- Reads the workbook ranges needed for the challenge
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 itertools
import pandas as pd
path = "CH-128 Cartesian Product.xlsx"
test = pd.read_excel(path, usecols = "C")
lets = ["A","B","C","D"]
combs = [''.join(p) for p in itertools.product(lets, repeat=3)]
print(all(combs == test["Result"])) # TrueLogic:
Reads the workbook ranges needed for the challenge
Applies the rule iteratively until the output stabilizes
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.