library(tidyverse)
library(readxl)
path = "files/200-299/291/CH-291 Randomly Reorder Columns.xlsx"
input = read_excel(path, range = "B2:E9")
result = input %>%
select(sample(everything()))Omid - Challenge 291
data-challenges
advanced-exercises
🔰 Write a formula to randomly shuffle the columns of the Question table, so that their order changes each time the formula recalculates.

Challenge Description
🔰 Write a formula to randomly shuffle the columns of the Question table, so that their order changes each time the formula recalculates.
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
path = "200-299/291/CH-291 Randomly Reorder Columns.xlsx"
input = pd.read_excel(path, usecols="B:E", skiprows=1, nrows=8)
result = input.sample(frac=1, axis=1)
print(result)Logic:
- 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.