library(tidyverse)
library(readxl)
path = "Excel/700-799/749/749 Portmanteau Words v2.xlsx"
input1 = read_excel(path, range = "A1:A10")
input2 = read_excel(path, range = "B1:C10")
test = read_excel(path, range = "D1:D6")
get_all_substrings = function(x) {
if (is.na(x) || x == "") return(character(0))
len = nchar(x)
unique(c(substring(x, 1, 1:len), substring(x, len:1, len)))
}
result = input2 %>%
mutate(port1 = map2(Word1, Word2, ~ {
s1 = get_all_substrings(.x)
s2 = get_all_substrings(.y)
ports = as.vector(outer(s1, s2, paste0))
intersect(ports, input1$Word)
})) %>%
select(port1) %>%
unnest(port1) %>%
arrange(port1)
all.equal(result$port1, test$`Answer Expected`, check.attributes = FALSE)
# [1] TRUEExcel BI - Excel Challenge 749
excel-challenges
excel-formulas
🔰 List Portmanteau words

Challenge Description
🔰 List Portmanteau words
Solutions
- Logic: Read the workbook ranges needed for the challenge; Derive the required intermediate columns.
- Strengths: The code maps the workbook rule into a compact, reproducible pipeline.
- Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
- Gem: The elegant part is how little code is needed once the correct intermediate representation is chosen.
import pandas as pd
path = "700-799/749/749 Portmanteau Words v2.xlsx"
input1 = pd.read_excel(path, usecols="A", nrows=10)
input2 = pd.read_excel(path, usecols="B:C", nrows=10)
test = pd.read_excel(path, usecols="D", nrows=5)
def get_all_substrings(x):
if not isinstance(x, str) or not x:
return []
return list({x[:i] for i in range(1, len(x)+1)} | {x[i-1:] for i in range(len(x), 0, -1)})
ports = [
word
for _, row in input2.iterrows()
for word in set(
a + b
for a in get_all_substrings(row['Word1'])
for b in get_all_substrings(row['Word2'])
) & set(input1.iloc[:, 0])
]
result = pd.DataFrame({'port1': sorted(ports)})
print(test['Answer Expected'].equals(result['port1']))
# TrueThe Python version keeps the algorithm explicit, which helps when the challenge depends on a greedy or iterative rule.
Difficulty Level
Easy / Medium
The business rule is clear, though the workbook still needs a few transformation steps to reach the expected output.