List the first 20 numbers which are both perfect square and perfect cube.
📌 Challenge Details and Links
ExcelBI Excel Challenge Number: 648
Challenge Difficulty: ⭐️
📥Download Sample File
📥Link to the solutions on LinkedIn
Solving the challenge of Perfect Square And Cube with Power Query
Power Query solution 1 for Perfect Square And Cube, proposed by Alejandro Simón 🇵🇦 🇪🇸:
let
Source = {1 .. 8000},
#"3" = List.Transform(Source, each Number.Power(_, 3)),
#"2" = List.Transform(Source, each Number.Power(_, 2)),
Sol = List.FirstN(List.Intersect({#"3", #"2"}), 20)
in
Sol
Power Query solution 2 for Perfect Square And Cube, proposed by Abdallah Ally:
let
Source = List.Transform({1 .. 20}, each Number.Power(_, 6))
in
Source
Power Query solution 3 for Perfect Square And Cube, proposed by Peter Krkos:
PowerQuery solution:
List.Transform({1..20}, (x)=> Number.Power(x, 6))
Solving the challenge of Perfect Square And Cube with Excel
Excel solution 1 for Perfect Square And Cube, proposed by Bo Rydobon 🇹🇭:
=LET(n,
SEQUENCE(
10^6
),
s,
n^(2/3),
TOCOL(
IFS(
INT(
s
)=s,
n^2
),
3
))
Excel solution 2 for Perfect Square And Cube, proposed by Rick Rothstein:
=SEQUENCE(
20
)^6
I see others have also posted this formula so,
given that I was a math major in college (and hence,
a nerd at heart),
I thought I would explain the logic behind it. It is actually quite simple. If you take a number and square it,
then cube it,
or alternately cube it,
then square it,
that is the same as raising it to the 6th power.
(x^2)^3 = x^6
(x^3)
Excel solution 3 for Perfect Square And Cube, proposed by John V.:
=ROW(1:20)
Excel solution 4 for Perfect Square And Cube, proposed by Kris Jaganah:
=LET(
a,
SEQUENCE(
10000
),
TAKE(
XLOOKUP(
a^3,
a,
a^2
),
20
)
)
Excel solution 5 for Perfect Square And Cube, proposed by Alejandro Campos:
== n and round(n ** (1/3)) ** 3 == n
numbers = []
i = 1
while len(
numbers
) < 20:
if is_perfect_square_and_cube(
i
):
numbers.append(
i
)
Excel solution 6 for Perfect Square And Cube, proposed by Timothée BLIOT:
=LET(A,SEQUENCE(10^4),TAKE(FILTER(A^2,MAP(A,LAMBDA(x,SUM(--((x^3)=(A^2)))))),20))
Excel solution 7 for Perfect Square And Cube, proposed by Hussein SATOUR:
=SEQUENCE(
20
)
Excel solution 8 for Perfect Square And Cube, proposed by Sunny Baggu:
=LET(
n, 20,
(SEQUENCE(n) ^ 2 * SEQUENCE(n)) ^ 2
)
Excel solution 9 for Perfect Square And Cube, proposed by Sunny Baggu:
=LET(n, 20, (SEQUENCE(n) ^ 6))
Excel solution 10 for Perfect Square And Cube, proposed by Sunny Baggu:
=LET(
n, SEQUENCE(10000),
sq, n ^ 2,
cu, sq ^ (1 / 3),
cri, MAP(cu, LAMBDA(a, a = INT(a))),
TAKE(FILTER(sq, cri), 20)
)
Excel solution 11 for Perfect Square And Cube, proposed by Anshu Bantra:
=LET(
cubes_, POWER( SEQUENCE(400), 3),
squares_, POWER(cubes_, 1/2),
FILTER(cubes_, squares_=INT(squares_))
)
Excel solution 12 for Perfect Square And Cube, proposed by Hamidi Hamid:
=LET(z,
SEQUENCE(
9000
),
x,
z^3,
y,
z^2,
TAKE((FILTER(
x,
y
)*FILTER(
x,
x
)),
20))
Excel solution 13 for Perfect Square And Cube, proposed by ferhat CK:
=TOCOL(
VLOOKUP(
SEQUENCE(
400
)^3,
SEQUENCE(
8000
)^2,
1,
0
),
2
)
Excel solution 14 for Perfect Square And Cube, proposed by Seokho MOON:
=SEQUENCE(
20
)
Excel solution 15 for Perfect Square And Cube, proposed by Peter Bartholomew:
= LET(
k, SEQUENCE(20),
return, k^6,
return
)
Excel solution 16 for Perfect Square And Cube, proposed by Peter Bartholomew:
= LET(
k, SEQUENCE(20,,2),
header, {"Integer","Square root","Cube root"},
result, POWER(k,{6,3,2}),
VSTACK(header, result)
)
Excel solution 17 for Perfect Square And Cube, proposed by Ernesto Vega Castillo:
=SEQUENCE(
20,
,
1
)
Excel solution 18 for Perfect Square And Cube, proposed by Gabriel Pugliese:
=(SEQUENCE(20)^3)^2
is the same of
=(SEQUENCE(20)^2)
Excel solution 19 for Perfect Square And Cube, proposed by Stefan Alexandrov:
=LET(_square,SEQUENCE(10000)^2,
_cube,SEQUENCE(10000)^3,
_match,MATCH(_square,_cube,0),
_filter, FILTER(_square,NOT(ISNA(_match))),
TAKE(_filter,20)
)
Excel solution 20 for Perfect Square And Cube, proposed by Shane Devenshire:
=SEQUENCE(20,,0)
Solving the challenge of Perfect Square And Cube with Python
Python solution 1 for Perfect Square And Cube, proposed by Abdallah Ally:
import pandas as pd
# Perform data manipulation
df = pd.DataFrame(
data={'Answer Expected': [x ** 6 for x in range(1, 21)]}
)
df
&&&
