How to resolve the algorithm Square but not cube step by step in the Mathematica / Wolfram Language programming language
How to resolve the algorithm Square but not cube step by step in the Mathematica / Wolfram Language programming language
Table of Contents
Problem Statement
Show the first 30 positive integers which are squares but not cubes of such integers. Optionally, show also the first 3 positive integers which are both squares and cubes, and mark them as such.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Square but not cube step by step in the Mathematica / Wolfram Language programming language
-
s = Range[50]^2;
: This line creates a lists
of all the integers from 1 to 50 squared. So,s
contains the list [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401] -
c = Range[1, Ceiling[Surd[Max[s], 3]]]^3;
: This line creates a listc
of all the integers from 1 to the cube of the ceiling of the cube root of the maximum value ins
. The maximum value ins
is 2401, so the cube root of that is approximately 13.39. The ceiling of that is 14, so the cube of 14 is 2744. So,c
contains the list [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000, 1331, 1728, 2197, 2744] -
Take[Complement[s, c], 30]
: This line takes the first 30 elements of the complement ofs
andc
. The complement of two lists is the list of all the elements that are in the first list but not in the second list. So, the complement ofs
andc
is the list of all the integers from 1 to 2401 that are not cubes. The first 30 elements of this list are: [2, 3, 5, 6, 7, 10, 11, 13, 14, 17, 19, 21, 22, 23, 26, 28, 29, 30, 31, 33, 34, 35, 37, 38, 39, 40, 41, 42, 43] -
Intersection[s, c]
: This line finds the intersection ofs
andc
. The intersection of two lists is the list of all the elements that are in both lists. So, the intersection ofs
andc
is the list of all the integers from 1 to 2401 that are both squares and cubes. This list is: [1, 64, 729, 1296]
Source code in the wolfram programming language
s = Range[50]^2;
c = Range[1, Ceiling[Surd[Max[s], 3]]]^3;
Take[Complement[s, c], 30]
Intersection[s, c]
You may also check:How to resolve the algorithm Discordian date step by step in the AWK programming language
You may also check:How to resolve the algorithm Knuth shuffle step by step in the Racket programming language
You may also check:How to resolve the algorithm Wireworld step by step in the D programming language
You may also check:How to resolve the algorithm Call a foreign-language function step by step in the Julia programming language
You may also check:How to resolve the algorithm Pernicious numbers step by step in the Arturo programming language