Find those 2 digits to 5 digits numbers whose cube results into numbers where frequency of appearing digits are same. Ex. 1694 => 1694^3 => 4861163384 => Digits appearing here are 4, 8, 6, 1, 3 and frequency of all these digits is 2.
📌 Challenge Details and Links
ExcelBI Excel Challenge Number: 659
Challenge Difficulty: ⭐️⭐️
📥Download Sample File
📥Link to the solutions on LinkedIn
Solving the challenge of Cube With Equal Digits with Power Query
Power Query solution 1 for Cube With Equal Digits, proposed by Abdallah Ally:
let
SameFrequency = (num) =>
[
a = Text.ToList(Text.From(Number.Power(num, 3))),
b = List.Transform(a, each List.Count(List.Select(a, (x) => x = _))),
c = List.Count(List.Distinct(b)) = 1
][c],
Result = Table.FromColumns(
{
List.RemoveNulls(
List.Generate(
() => [num = 10, cond = SameFrequency(num)],
each Text.Length(Text.From([num])) < 6,
each [num = [num] + 1, cond = SameFrequency(num)],
each if [cond] then [num] else null
)
)
},
{"Answer Expected"}
)
in
Result
Power Query solution 2 for Cube With Equal Digits, proposed by Rafael González B.:
let
L = {10..99999},
LS = List.Select(L, each
let
T = Number.Power(_, 3),
LS = Text.ToList(Text.From(T)),
LM = List.Sort(List.Modes(LS)),
LD = List.Sort(List.Distinct(LS)),
Ch = LM = LD
in
Ch)
in
LS
🧙♂️ 🧙♂️ 🧙♂️
Power Query solution 3 for Cube With Equal Digits, proposed by Alexandre Garcia:
let x = Text.ToList(Text.From(Number.Power(_,3))) in if List.Modes(x) = List.Distinct(x) then _ else null))},{"Answer"})
Power Query solution 4 for Cube With Equal Digits, proposed by Tyler N.:
let l=Text.ToList( Text.From(Number.Power(_,3))),d=List.Distinct,t=List.Transform(d(l),(j)=>List.Count(List.Select(l,(k)=>k=j))),z=d(t)={t{0}} in z)},{"ans"})
Solving the challenge of Cube With Equal Digits with Excel
Excel solution 1 for Cube With Equal Digits, proposed by Bo Rydobon 🇹🇭:
=TOCOL(
MAP(
SEQUENCE(
10^5,
,
10
),
LAMBDA(
q,
LET(
n,
q^3,
m,
--MID(
n,
SEQUENCE(
LEN(
n
)
),
1
),
f,
FREQUENCY(
m,
m
),
g,
FILTER(
f,
f
),
q/AND(
@g=g
)
)
)
),
3
)
Excel solution 2 for Cube With Equal Digits, proposed by Rick Rothstein:
=LET(
s,
SEQUENCE(
99989,
,
11
),
q,
s^3,
FILTER(
s,
LEN(
BYROW(
LEN(
q
)-LEN(
SUBSTITUTE(
q,
MID(
q,
SEQUENCE(
,
16
),
1
),
""
)
),
LAMBDA(
r,
CONCAT(
UNIQUE(
r,
1
)
)
)
)
)=2
)
)
Excel solution 3 for Cube With Equal Digits, proposed by Kris Jaganah:
=TOCOL(MAP(SEQUENCE(
99989,
,
11
),
LAMBDA(x,
LET(a,
--REGEXEXTRACT(
x^3,
"[0-9]",
1
),
x/((ROWS(
UNIQUE(
DROP(
FREQUENCY(
a,
UNIQUE(
a,
1
)
),
-1
)
)
))=1)))),
3)
Excel solution 4 for Cube With Equal Digits, proposed by Timothée BLIOT:
=LET(A,SEQUENCE(10^5-10,,10),FILTER(A,MAP(A^3,LAMBDA(x, LET(B,LEN(x), C,B-LEN(SUBSTITUTE(x,UNIQUE(MID(x,SEQUENCE(B),1)),"")), PRODUCT(--(TAKE(C,1)=C)))))))
Excel solution 5 for Cube With Equal Digits, proposed by Duy Tùng:
=LET(
u,
SEQUENCE(
10^5,
,
11
),
FILTER(
u,
MAP(
u,
LAMBDA(
x,
LET(
a,
x^3,
b,
--MID(
a,
SEQUENCE(
LEN(
a
)
),
1
),
c,
DROP(
GROUPBY(
b,
b,
ROWS,
,
0,
-2
),
,
1
),
TAKE(
c,
1
)=TAKE(
c,
-1
)
)
)
)
)
)
Excel solution 6 for Cube With Equal Digits, proposed by Sunny Baggu:
=LET(
num,
SEQUENCE(
80000,
,
10
),
FILTER(
num,
MAP(
num ^ 3,
LAMBDA(
n,
LET(
_m,
MID(
n,
SEQUENCE(
LEN(
n
)
),
1
),
_um,
UNIQUE(
_m
),
_c,
MAP(
_um,
LAMBDA(
a,
SUM(
N(
_m = a
)
)
)
),
AND(
_c = TAKE(
_c,
1
)
)
)
)
)
)
)
Excel solution 7 for Cube With Equal Digits, proposed by LEONARD OCHEA 🇷🇴:
=TOCOL(MAP(SEQUENCE(
10^5,
,
10
),
LAMBDA(x,
LET(e,
TOCOL(
REGEXEXTRACT(
x^3,
".",
1
)
),
x/(COUNT(
UNIQUE(
DROP(
GROUPBY(
e,
e,
COUNTA,
,
0
),
,
1
)
)
)=1)))),
2)
Excel solution 8 for Cube With Equal Digits, proposed by Md. Zohurul Islam:
=LET(sq,SEQUENCE(99999,,11),z,sq^3,u,MAP(z,LAMBDA(x,LET(a,--MID(x,SEQUENCE(LEN(x)),1),b,DROP(FREQUENCY(a,UNIQUE(a)),-1),d,UNIQUE(b),e,IF(ROWS(d)=1,1,0),e))),v,FILTER(sq,u=1),v)
Excel solution 9 for Cube With Equal Digits, proposed by ferhat CK:
=TOCOL(MAP(SEQUENCE(10^5,,10),LAMBDA(x,LET(a,REGEXEXTRACT(x^3,".",1),b,TOCOL(a),IF(ROWS(UNIQUE(DROP(GROUPBY(b,b,COUNTA,,0),,1)))=1,x,1/0)))),3)
Excel solution 10 for Cube With Equal Digits, proposed by Jaroslaw Kujawa:
=DROP(
REDUCE(
"";
SEQUENCE(
10^5-9;
;
10
);
LAMBDA(
a;
x;
LET(
b;
MID(
x^3;
SEQUENCE(
LEN(
x^3
)
);
1
);
c;
GROUPBY(
b;
b;
COUNTA;
;
0
);
IF(
1=ROWS(
UNIQUE(
TAKE(
c;
;
-1
)
)
);
VSTACK(
a;
x
);
a
)
)
)
);
1
)
Excel solution 11 for Cube With Equal Digits, proposed by JvdV -:
=TOCOL(
MAP(
ROW(
10:99999
),
LAMBDA(
s,
IFS(
LET(
x,
TOCOL(
REGEXEXTRACT(
s^3,
".",
1
)
),
y,
DROP(
GROUPBY(
x,
x,
ROWS
),
-1,
1
),
AND(
y=@y
)
),
s
)
)
),
2
)
Excel solution 12 for Cube With Equal Digits, proposed by Jorge Alvarez:
=ENCOL(LET(_num;
SECUENCIA(
100000;
;
10
);
MAP(_num;
LAMBDA(v;
LET(vcubo;
v^3;
ca;
EXTRAE(
vcubo;
SECUENCIA(
LARGO(
vcubo
)
);
1
);
_f;
BYCOL(--(TRANSPONER(
UNICOS(
ca
)
)=ca);
SUMA);
uf;
ELEGIRCOLS(
_f;
1
);
SI(Y(MAP(_f;
LAMBDA(a;
(a=uf))));
v;
1/0)))));
2)
Solving the challenge of Cube With Equal Digits with Python
Python solution 1 for Cube With Equal Digits, proposed by Konrad Gryczan, PhD:
import pandas as pd
path = "659 Cube Frequency of All Digits Same.xlsx"
test = pd.read_excel(path, usecols="A", nrows=81)
def find_numbers(min_n=10, max_n=99999):
return pd.DataFrame(
[num for num in range(min_n, max_n + 1)
if len(set(str(num ** 3).count(digit) for digit in set(str(num ** 3)))) == 1],
columns=["Answer Expected"]
)
result = find_numbers()
print(result.equals(test)) # True
Python solution 2 for Cube With Equal Digits, proposed by Abdallah Ally:
function main(workbook: ExcelScript.Workbook) {
function sameCubeFrequency(num: number): boolean {
let str_cube = '' + (num ** 3);
let counts = Array.from(str_cube).map(s => str_cube.split(s).length - 1);
return new Set(counts).size === 1;
}
// Perform data manipulation
let curCell = workbook.getActiveCell();
curCell.setValue('Answer Expected')
let num = 10;
let move = 1;
while (num.toString().length < 6) {
if (sameCubeFrequency(num)) {
curCell.getOffsetRange(move, 0).setValue(num);
move++;
}
num++;
}
}
Python solution 3 for Cube With Equal Digits, proposed by Abdallah Ally:
import pandas as pd
def same_cube_freq(number):
str_cube = str(number ** 3)
counts = [str_cube.count(s) for s in str_cube]
return len(set(counts)) == 1
# Perform data manipulation
numbers = []
number = 10
while len(str(number)) < 6:
if same_cube_freq(number):
numbers.append(number)
number += 1
df = pd.DataFrame(data = {'Answer Expected': numbers})
df
Solving the challenge of Cube With Equal Digits with Python in Excel
Python in Excel solution 1 for Cube With Equal Digits, proposed by Aditya Kumar Darak 🇮🇳:
from collections import Counter
results = [n for n in range(10, 100000) if len(set(Counter(str(n**3)).values())) == 1]
results
Solving the challenge of Cube With Equal Digits with R
R solution 1 for Cube With Equal Digits, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
path = "Excel/659 Cube Frequency of All Digits Same.xlsx"
test = read_excel(path, range = "A1:A81")
find_numbers <- function(min_n = 10, max_n = 99999) {
nums <- min_n:max_n
keep(nums, ~ length(unique(table(str_split(as.character(.x^3), "", simplify = TRUE)))) == 1) &%>%
enframe(name = NULL, value = "Answer Expected")
}
result <- find_numbers()
all.equal(result, test)
#> [1] TRUE
&&
