library(tidyverse)
library(readxl)
input = read_excel("files/CH-067 Index Selections.xlsx", range = "B2:H17")
test = read_excel("files/CH-067 Index Selections.xlsx", range = "J2:J7")
result = input %>%
rowwise() %>%
filter(sum(c_across(2:7) <= 7, na.rm = TRUE) >= 2) %>%
ungroup() %>%
select(`Selected Indexes` = 1)
identical(result, test)
#> [1] TRUEOmid - Challenge 67
data-challenges
advanced-exercises
🔰 Question ID Ref 1 Ref 2 Ref 3 Ref 4 Ref 5 Ref 6 Index 1

Challenge Description
🔰 Question ID Ref 1 Ref 2 Ref 3 Ref 4 Ref 5 Ref 6 Index 1
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 pandas as pd
input = pd.read_excel("CH-067 Index Selections.xlsx", usecols="B:H", skiprows= 1, nrows = 15)
test = pd.read_excel("CH-067 Index Selections.xlsx", usecols="J", skiprows=1, nrows = 5)
result = input[(input.iloc[:, 1:6] <= 7).sum(axis=1) >= 2].iloc[:,0].reset_index(drop=True)
print(result.tolist() == test.iloc[:,0].tolist()) # 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.