List all decimal numbers whose Roman equivalents are Palindromic. List the Roman number also for these Palindromic numbers.
📌 Challenge Details and Links
ExcelBI Excel Challenge Number: 410
Challenge Difficulty: ⭐️⭐️
📥Download Sample File
📥Link to the solutions on LinkedIn
Solving the challenge of Roman Palindromic Numbers with Excel
Excel solution 1 for Roman Palindromic Numbers, proposed by Bo Rydobon 🇹🇭:
=LET(
z,
A3:A10,
r,
{"I";"V";"X";"L";"C";"D";"M"},
t,
REPT(
r,
2
),
p,
VSTACK(
t,
REDUCE(
t,
SEQUENCE(
3
),
LAMBDA(
a,
v,
UNIQUE(
TOCOL(
IF(
ISEVEN(
LEN(
a
)
),
REPLACE(
a,
LEN(
a
)/2+1,
0,
TOROW(
REPT(
r,
{1,
2}
)
)
),
a
)
)
)
)
)
),
b,
ARABIC(
p
),
y,
MAP(
A3:A10,
LAMBDA(
n,
TEXTJOIN(
", ",
,
FILTER(
p,
b=n
)
)
)
),
FILTER(
HSTACK(
z,
y
),
ISTEXT(
y
)
)
)
Excel solution 2 for Roman Palindromic Numbers, proposed by Bo Rydobon 🇹🇭:
=LET(z,
A3:A10,
y,
MAP(z,
LAMBDA(a,
LET(d,
10^(LEN(
a
)-1),
b,
CEILING(
a,
2*d
),
r,
ROMAN(
b-a
),
m,
IFERROR(
MID(
r,
SEQUENCE(
LEN(
r
)
),
1
),
""
),
g,
GROUPBY(
m,
m,
ROWS,
0,
0
),
n,
MOD(
DROP(
g,
,
1
),
2
),
I,
SORTBY(
g,
-n
),
IF(
SUM(
N(
1=n
)
)<2,
REDUCE(
,
VSTACK(
REPT(
TAKE(
I,
,
1
),
DROP(
I,
,
1
)
),
REPT(
ROMAN(
d
),
LEFT(
b
)
)
),
LAMBDA(
a,
v,
REPLACE(
v,
LEN(
v
)/2+1,
0,
a
)
)
)
)))),
FILTER(
HSTACK(
z,
y
),
ISTEXT(
y
)
))
Excel solution 3 for Roman Palindromic Numbers, proposed by Bo Rydobon 🇹🇭:
=LET(
z,
A3:A10,
r,
ROMAN(
z
),
FILTER(
HSTACK(
z,
r
),
MAP(
r,
LAMBDA(
r,
CONCAT(
MID(
r,
10-SEQUENCE(
,
9
),
1
)
)=r
)
)
)
)
Excel solution 4 for Roman Palindromic Numbers, proposed by Rick Rothstein:
=LET(
r,
A3:A10,
FILTER(
HSTACK(
r,
ROMAN(
r
)
),
MAP(
r,
LAMBDA(
a,
LET(
x,
ROMAN(
a
),
CONCAT(
MID(
x,
LEN(
x
)-SEQUENCE(
LEN(
x
),
,
0
),
1
)
)=x
)
)
)
)
)
Excel solution 5 for Roman Palindromic Numbers, proposed by Rick Rothstein:
=LET(
r,
SEQUENCE(
3999
),
FILTER(
HSTACK(
r,
ROMAN(
r
)
),
MAP(
r,
LAMBDA(
a,
LET(
x,
ROMAN(
a
),
CONCAT(
MID(
x,
LEN(
x
)-SEQUENCE(
LEN(
x
),
,
0
),
1
)
)=x
)
)
)
)
)
And this formula will find all the palindromic Roman Numbers consisting of two or more characters...
=LET(r,
SEQUENCE(
3999
),
FILTER(HSTACK(
r,
ROMAN(
r
)
),
MAP(r,
LAMBDA(a,
LET(x,
ROMAN(
a
),
(LEN(
x
)>1)*(CONCAT(
MID(
x,
LEN(
x
)-SEQUENCE(
LEN(
x
),
,
0
),
1
)
)=x))))))
Excel solution 6 for Roman Palindromic Numbers, proposed by John V.:
=LET(
n,
A3:A10,
r,
ROMAN(
n
),
FILTER(
HSTACK(
n,
r
),
BYROW(
MID(
r,
10-COLUMN(
A:I
),
1
),
CONCAT
)=r
)
)
Excel solution 7 for Roman Palindromic Numbers, proposed by محمد حلمي:
=LET(
d,
A3:A10,
r,
ROMAN(
d
),
FILTER(
HSTACK(
d,
r
),
MAP(
r,
LAMBDA(
a,
a=CONCAT(
MID(
a,
20-SEQUENCE(
19
),
1
)
)
)
)
)
)
Excel solution 8 for Roman Palindromic Numbers, proposed by Kris Jaganah:
=LET(
a,
ROMAN(
A3:A10
),
FILTER(
a,
MAP(
a,
LAMBDA(
x,
CONCAT(
MID(
x,
SEQUENCE(
LEN(
x
),
,
LEN(
x
),
-1
),
1
)
)
)
)=a
)
)
Excel solution 9 for Roman Palindromic Numbers, proposed by Julian Poeltl:
=LET(
N,
A3:A10,
R,
ROMAN(
N
),
IP,
BYROW(
R,
LAMBDA(
A,
L_ISPalindrome(
A
)
)
),
F,
FILTER(
N,
IP=TRUE
),
HSTACK(
F,
ROMAN(
F
)
)
)
I've used pre-programmed Lambdas:
L_ISPalindrome =LAMBDA(PAL?,
LET(Text,
PAL?,
L,
LEFT(Text,
ROUNDUP((LEN(
Text
)-1)/2,
0)),
R,
CONCAT(L_ReverseHorizontalArray(MID(RIGHT(Text,
ROUNDUP((LEN(
Text
)-1)/2,
0)),
SEQUENCE(,
LEN(RIGHT(Text,
ROUNDUP((LEN(
Text
)-1)/2,
0)))),
1))),
RES,
L=R,
RES))
L_ReverseHorizontalArray
=LAMBDA(
Array,
TRANSPOSE(
INDEX(
TRANSPOSE(
Array
),
SEQUENCE(
ROWS(
TRANSPOSE(
Array
)
),
1,
ROWS(
TRANSPOSE(
Array
)
),
-1
),
SEQUENCE(
1,
COLUMNS(
TRANSPOSE(
Array
)
)
)
)
)
)
Excel solution 10 for Roman Palindromic Numbers, proposed by Timothée BLIOT:
=LET(
D,
A3:A10,
R,
ROMAN(
D
),
FILTER(
HSTACK(
D,
R
),
MAP(
R,
LAMBDA(
x,
CONCAT(
MID(
x,
LEN(
x
)+1-SEQUENCE(
LEN(
x
)
),
1
)
)=x
)
)
)
)
Excel solution 11 for Roman Palindromic Numbers, proposed by Hussein SATOUR:
=LET(
d,
A3:A10,
a,
ROMAN(
d
),
FILTER(
HSTACK(
d,
a
),
a=MAP(
a,
LAMBDA(
x,
CONCAT(
MID(
x,
SEQUENCE(
LEN(
x
),
,
LEN(
x
),
-1
),
1
)
)
)
)
)
)
Excel solution 12 for Roman Palindromic Numbers, proposed by Sunny Baggu:
=LET(
_v,
ROMAN(
A3:A10
),
_b,
MAP(
_v,
LAMBDA(b,
LET(
_e1,
LAMBDA(
a,
CONCAT(
MID(
a,
LEN(
a
) + 1 - SEQUENCE(
LEN(
a
)
),
1
)
)
),
_e1(b)
)
)
),
FILTER(_v,
(_v = _b))
)
Excel solution 13 for Roman Palindromic Numbers, proposed by Charles Roldan:
=LET(isPal,
LAMBDA(
f,
f(
f
)
)(LAMBDA(f,
LAMBDA(x,
IF(LEN(
x
) < 2,
TRUE,
IF(LEFT(
x
) = RIGHT(
x
),
f(
f
)(MID(
x,
2,
LEN(
x
) - 2
))))))),
Subset,
LAMBDA(
f,
LAMBDA(
x,
FILTER(
x,
MAP(
x,
f
)
)
)
),
p,
Subset(
isPal
)(ROMAN(
A3:A10
)),
HSTACK(
ARABIC(
p
),
p
))
Excel solution 14 for Roman Palindromic Numbers, proposed by Nicolas Micot:
=LET(
_decimalNumbers;
A3:A10;
_romanNumbers;
ROMAIN(
_decimalNumbers
);
_romanReverse;
MAP(
_romanNumbers;
LAMBDA(
l_roman;
CONCAT(
STXT(
l_roman;
SEQUENCE(
NBCAR(
l_roman
);
;
NBCAR(
l_roman
);
-1
);
1
)
)
)
);
_table;
ASSEMB.H(
_decimalNumbers;
_romanNumbers
);
FILTRE(
_table;
_romanNumbers=_romanReverse
)
)
Excel solution 15 for Roman Palindromic Numbers, proposed by Ernesto Vega Castillo:
=LET(
list,
A3:A10,
ara,
FILTER(
ROMAN(
list
),
BYROW(
list,
LAMBDA(
nRom,
TEXTJOIN(
"",
1,
MID(
ROMAN(
nRom
),
SEQUENCE(
LEN(
ROMAN(
nRom
)
),
,
LEN(
ROMAN(
nRom
)
),
-1
),
1
)
)
)
)=ROMAN(
list
)
),
HSTACK(
ARABIC(
ara
),
(
ara
)
)
)
Versión en Español
=LET(
list,
A3:A10,
ara,
FILTRAR(
NUMERO.ROMANO(
list
),
BYROW(
list,
LAMBDA(
nRom,
UNIRCADENAS(
"",
1,
EXTRAE(
NUMERO.ROMANO(
nRom
),
SECUENCIA(
LARGO(
NUMERO.ROMANO(
nRom
)
),
,
LARGO(
NUMERO.ROMANO(
nRom
)
),
-1
),
1
)
)
)
)=NUMERO.ROMANO(
list
)
),
APILARH(
NUMERO.ARABE(
ara
),
& (
ara
)
)
)
Excel solution 16 for Roman Palindromic Numbers, proposed by Tyler Cameron:
=VSTACK(
{"Decimal Number",
"Roman Number"},
LET(
u,
HSTACK(
A3:A10,
MAP(
ROMAN(
A3:A10
),
LAMBDA(
x,
IF(
CONCAT(
MID(
x,
SEQUENCE(
ROUNDDOWN(
LEN(
x
)/2,
0
),
,
LEN(
x
),
-1
),
1
)
) = CONCAT(
MID(
x,
SEQUENCE(
ROUNDDOWN(
LEN(
x
)/2,
0
)
),
1
)
),
x,
""
)
)
)
),
FILTER(
u,
CHOOSECOLS(
u,
2
)<>""
)
)
)
Solving the challenge of Roman Palindromic Numbers with Python
Python solution 1 for Roman Palindromic Numbers, proposed by Giorgi Goderdzishvili:
import roman
def convert(n):
return roman.toRoman(n)
def is_pal(rom):
return rom == rom[::-1]
df = pd.read_clipboard()[["Decimal"]]
df["Roman Number"] = df["Decimal"].apply(convert)
df[df["Roman Number"].apply(is_pal)]
Python solution 2 for Roman Palindromic Numbers, proposed by Cristobal Salcedo Beltran:
https://github.com/cristobalsalcedo90/BI_Challenges
code:
import pandas as pd
def to_roman(num):
val = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
syms = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
roman_num = ''
i = 0
while num > 0:
for _ in range(num // val[i]):
roman_num += syms[i]
num -= val[i]
i += 1
return roman_num
def is_palindrome(s):
return s == s[::-1]
file_path = "/lakehouse/default/Files/Challenge/Excel_Challenge_410 - Palindromic Roman Numerals.xlsx"
df = pd.read_excel(file_path, usecols=[0], header=1)
df['Roman Numeral'] = df.apply(lambda row: to_roman(row[df.columns[0]]), axis=1)
df['Is Palindrome'] = df['Roman Numeral'].apply(is_palindrome)
result_df = df[df['Is Palindrome'] == True]
final_df = result_df[['Decimal Number', 'Roman Numeral']]
print(final_df)
Solving the challenge of Roman Palindromic Numbers with R
R solution 1 for Roman Palindromic Numbers, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
library(stringi)
input = read_excel("Excel/410 Palindromic Roman Numerals.xlsx", range = "A2:A10")
test = read_excel("Excel/410 Palindromic Roman Numerals.xlsx", range = "B2:C5")
to_roman <- function(number) {
if (!is.numeric(number) || number <= 0 || number != as.integer(number)) {
return(NA)
}
roman_symbols <- c("M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I")
arabic_values <- c(1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
numeral <- ""
for (i in seq_along(roman_symbols)) {
while (number >= arabic_values[i]) {
numeral <- paste0(numeral, roman_symbols[i])
number <- number - arabic_values[i]
}
}
return(numeral)
}
is_palindrome = function(string) {
string == stri_reverse(string)
}
result = input %>%
mutate(roman = map_chr(`Decimal Number`, to_roman)) %>%
mutate(palindrome = map_lgl(roman, is_palindrome)) %>%
filter(palindrome) %>%
select(`Decimal Number`, `Roman Number` = roman)
&&
