Omid - Challenge 53

data-challenges
advanced-exercises
🔰 The On-Line Encyclopedia of Integer Sequences presents several number sequences based on specific rules.
Published

March 24, 2026

Illustration for Omid - Challenge 53

Challenge Description

🔰 The On-Line Encyclopedia of Integer Sequences presents several number sequences based on specific rules.

Solutions

library(tidyverse)
library(readxl)

input = read_excel("files/CH-053 OEIS Sequence.xlsx", range = "B2:C12")
test  = read_excel("files/CH-053 OEIS Sequence.xlsx", range = "G2:G67")

range = data.frame(number = 0:100 %>% as.numeric())

are_digits_alphabetical = function(number) {
  digits = as.character(number) %>% strsplit("") %>% unlist()
  replaced = map_chr(digits, ~input$Text[match(.x, input$Number)] %>% as.character())
  all(replaced == sort(replaced))
}

result = range %>% 
  mutate(alphabetical = map_lgl(number, are_digits_alphabetical)) %>%
  filter(alphabetical) %>%
  select(number)

identical(result$number, test$Customer)
#> [1] TRUE
  • 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

input = pd.read_excel("CH-053 OEIS Sequence.xlsx", usecols="B:C", skiprows=1, nrows=10)
test = pd.read_excel("CH-053 OEIS Sequence.xlsx", usecols="G:G", skiprows=1)

range = pd.DataFrame({"number": range(101)})

def are_digits_alphabetical(number):
    digits = list(str(number))
    replaced = [input.loc[input["Number"] == int(digit), "Text"].values[0] for digit in digits]
    return replaced == sorted(replaced)

range["is_alphabetical"] = range["number"].apply(are_digits_alphabetical)
range = range[range["is_alphabetical"]].reset_index(drop=True)
range = range["number"]

print(range.equals(test["Customer"])) # 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.