library(tidyverse)
library(readxl)
path = "files/300-399/306/CH-306 Increasing Pair Sum Finder.xlsx"
input = read_excel(path, range = "B1:B10")
test = read_excel(path, range = "E1:E10")
df = input %>% mutate(id = row_number())
result = expand_grid(a = df$id, b = df$id) %>%
left_join(df, by = c("a" = "id")) %>%
left_join(df, by = c("b" = "id"), suffix = c(".a", ".b")) %>%
filter(a < b, Question.a < Question.b, Question.a + Question.b >= 12) %>%
transmute(Result = paste(Question.a, Question.b, sep = ","))
all.equal(result, test)
# [1] TRUEOmid - Challenge 306
data-challenges
advanced-exercises
🔰 Increasing Pair Sum Finder

Challenge Description
🔰 Increasing Pair Sum Finder
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
from itertools import combinations
path = "300-399/306/CH-306 Increasing Pair Sum Finder.xlsx"
input = pd.read_excel(path, usecols="B", nrows=10)
test = pd.read_excel(path, usecols="E", nrows=10)
ids = range(1, len(input) + 1)
vals = input['Question'].values
pairs = [(a, b) for a, b in combinations(ids, 2) if vals[a-1] < vals[b-1] and vals[a-1] + vals[b-1] >= 12]
result = pd.DataFrame([f"{vals[a-1]},{vals[b-1]}" for a, b in pairs], columns=['Result'])
print(result.equals(test)) # 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.