library(tidyverse)
library(readxl)
library(Ryacas)
library(rootSolve)
path = "files/200-299/270/CH-270 Solving equations.xlsx"
input = read_excel(path, range = "B2:C7")
test = read_excel(path, range = "E2:F7")
eval_lag = function(eq) yac_str(paste0("Solve(", eq, ", X)")) %>%
y_rmvars() %>% yac_str() %>% yac_expr() %>% eval()
is_transcendental = function(eq) str_detect(eq, "\\^X")
result = input %>%
mutate(Equation = str_replace_all(Equation, "=", "==")) %>%
rowwise() %>%
mutate(
Solution = list(
if (is_transcendental(Equation))
uniroot.all(function(X) eval(parse(text = str_remove(Equation, "==0"))), c(-10, 10))
else
eval_laq(Equation)
)
) %>%
ungroup()Omid - Challenge 270
data-challenges
advanced-exercises
🔰 The Question table contains a list of equations.

Challenge Description
🔰 The Question table contains a list of equations.
Solutions
Logic:
Reads the workbook ranges needed for the challenge
Builds the intermediate columns that drive the final result
Parses the text patterns directly instead of relying on manual cleanup
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.
from sympy import symbols, Eq, solve, sympify
import pandas as pd
path = "200-299/270/CH-270 Solving equations.xlsx"
input = pd.read_excel(path, usecols="B:C", nrows=5, skiprows=1)
test = pd.read_excel(path, usecols="E:F", nrows=5, skiprows=1)
X = symbols('X')
eqs = input.iloc[:, 1]
solutions = [
[round(float(sol.evalf()), 4) for sol in solve(sympify(eq.replace('=', '-(') + ')'), X)]
for eq in eqs
]
input['Solution'] = solutions
print(input)Logic:
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 core logic is clear, but the correct transformation pattern is not obvious from the raw input.
The challenge combines multiple reshaping, grouping, or parsing steps.