Omid - Challenge 92

data-challenges
advanced-exercises
🔰 In the question table, some cells (highlighted) are missing, but a character determines how to fill them based on the following rule:
Published

March 24, 2026

Illustration for Omid - Challenge 92

Challenge Description

🔰 In the question table, some cells (highlighted) are missing, but a character determines how to fill them based on the following rule:

Solutions

library(tidyverse)
library(readxl)

path = "files/CH - 92 Missing value.xlsx"
input = read_excel(path, range = "C2:F12", col_names = F) %>% as.matrix()
test  = read_excel(path, range = "K2:N12", col_names = F) %>% as.matrix()

replace_values = function(x) {
  for (i in 1:nrow(x)) {
    for (j in 1:ncol(x)) {
      if (x[i,j] == "D") {
        x[i,j] = x[i + 1,j]
      } else if (x[i,j] == "U") {
        x[i,j] = x[i - 1,j]
      } else if (x[i,j] == "R") {
        x[i,j] = x[i,j + 1]
      } else if (x[i,j] == "L") {
        x[i,j] = x[i,j - 1]
      }
    }
  }
  return(x)
}

result = replace_values(input)
all.equal(result, test) # TRUE
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • Applies the rule iteratively until the output stabilizes

  • 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

path = "CH-92 Missing value.xlsx"
input = pd.read_excel(path, usecols="C:F", skiprows= 1, header=None).values
test = pd.read_excel(path, usecols= "K:N", skiprows= 1, header=None).values

def replace_values(x):
    for i in range(x.shape[0]):
        for j in range(x.shape[1]):
            if x[i, j] == "D":
                x[i, j] = x[i+1, j]
            elif x[i, j] == "U":
                x[i, j] = x[i-1, j]
            elif x[i, j] == "R":
                x[i, j] = x[i, j+1]
            elif x[i, j] == "L":
                x[i, j] = x[i, j-1]
    return x

result = replace_values(input)

print((result == test).all()) # True
  • 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 business rule is readable, but the workbook still requires careful implementation to reach the expected layout.