Even and Odd Counting In many cases, it is useful to determine if a number is ev
ID: 3639104 • Letter: E
Question
Even and Odd Counting
In many cases, it is useful to determine if a number is even or odd. Maple provides a function called type that can be used to determine this feature of a number. The same function can be used to tell if a number is prime.
Here are some examples,
type(2,even); #Is true if 2 is even
type(5,odd); #Is true if 5 is odd
type(a,prime); #Is true if the number assigned to the variable a is prime
In this question, you will use the type command to count elements in a list. The goal is to find out how many elements have a special property.
L1[i] gets the ith element in the list L1.
nops(L1) tells you the number of elements in the list L1.
L1:=[1,2,3];
for i from 1 to nops(L1) do
L1[i];
end do;
L1:=[3311, 2077, 1784, 2893, 7571, 440, 7660, 2203, 1064, 1949, 7338, 2432, 775, 7339, 3166, 7776, 6991, 3168, 3441, 7724, 3970, 7716, 1328, 5214, 3988, 3555, 5349, 7901, 8855, 1089, 7374, 6044, 8086, 4965, 2973, 4760, 4263, 8853, 186, 7021, 5769, 713, 2020, 7076, 1249, 8988, 4131, 2765, 5869, 354, 3871, 7647, 2544, 4530, 5065, 6846, 1744, 6757, 1910, 821, 5864, 7259, 3196, 715, 7652, 4483, 1828, 8193, 6094, 3930, 3679, 5209, 1952, 2672, 3911, 6470, 1531, 894, 6725, 3083, 7621, 7160, 866, 1713, 2890, 7897, 2721, 5631, 5846, 1622, 6702, 3729, 6330, 6968, 2245, 2852, 1581, 545, 8800, 8010, 8978, 6509, 6544, 7218, 143, 4222, 2193, 3354, 7765, 1413, 3099, 4434, 3254, 71, 3621, 627, 4250, 6372, 8184, 8280, 3801, 6499, 8979, 8350, 3248, 123, 8277, 4413, 7841, 3519, 2250, 8918, 6213, 8508, 1478, 7889, 3054, 6273, 6642, 861, 2441, 6510, 6017, 3025, 5451, 8699, 3260, 7610, 1602, 4041, 7616, 3597, 181, 1989, 2643, 671, 8381, 8739, 8136, 1517, 4831, 4084, 1415, 1206, 7197, 2944, 5753, 4958, 5242, 5202, 7919, 8857, 3477, 419, 315, 7157, 718, 8314, 5623, 1928, 3251, 4759, 80, 6584, 3531, 7524, 1434, 3023, 6115, 3192, 316, 3229, 1096, 5367, 7631, 2441, 1643, 8764, 3244, 7979];
(a) Determine how many elements in L1 are prime?
L2:=[2891, 8096, 2742, 2961, 1123, 6655, 8179, 2098, 3376, 7324, 8591, 5200, 1130, 2699, 7871, 7205, 1188, 8327, 1607, 8273, 7306, 1417, 6316, 2560, 6735, 2100, 8701, 4810, 3143, 1273, 4283, 718, 6786, 8298, 8153, 8963, 8625, 3548, 6970, 6481, 3872, 8251, 5573, 1146, 5361, 2238, 8169, 1334, 5017, 8933, 8194, 8369, 8349, 2477, 6093, 3148, 1361, 4276, 2073, 499, 1658, 3575, 3732, 2174, 4049, 6046, 6742, 1722, 4760, 2428, 1305, 3881, 4155, 5032, 5539, 2448, 6769, 8963, 2245, 6276, 8671, 3983, 462, 4881, 1382, 1080, 2784, 7736, 1843, 7885, 1627, 5721, 138, 6763, 4758, 1554, 8934, 861, 379, 6631, 4219, 6784, 3919, 2994, 5148, 5926, 6931, 6126, 1601, 1137, 701, 3299, 8173, 5760, 5970, 5443, 4344, 4010, 4971, 1579, 2887, 7168, 4897, 6491, 7732, 8375, 7847, 1310, 4292, 2743, 7172, 370, 8934, 1242, 980, 5388, 1076, 712, 7505, 7957, 8057, 8436, 3593, 2219, 8325, 4388, 7140, 3902, 5000, 8680, 5512, 2860, 3393, 4060, 8554, 2061, 2463, 3334, 1128, 2969, 478, 4265, 4703, 4431, 5897, 1668, 3664, 1149, 2033, 4773, 4210, 4161, 1599, 916, 321, 222, 3474, 7886, 8428, 3429, 6017, 3551, 4622, 5761, 3031, 8509, 8703, 4540, 3444, 7516, 379, 5410, 3502, 8901, 2474, 2598, 5850, 17, 1529, 2249];
(b) Determine how many elements in L2 are even?
Even and Odd Counting
In many cases, it is useful to determine if a number is even or odd. Maple provides a function called type that can be used to determine this feature of a number. The same function can be used to tell if a number is prime.
Here are some examples,
type(2,even); #Is true if 2 is even
type(5,odd); #Is true if 5 is odd
type(a,prime); #Is true if the number assigned to the variable a is prime
In this question, you will use the type command to count elements in a list. The goal is to find out how many elements have a special property.
In this question, we need to look at every element in a list. The following code just prints every element in the list L1. It gives an example of some of the important commands for using lists.L1[i] gets the ith element in the list L1.
nops(L1) tells you the number of elements in the list L1.
L1:=[1,2,3];
for i from 1 to nops(L1) do
L1[i];
end do;
L1:=[3311, 2077, 1784, 2893, 7571, 440, 7660, 2203, 1064, 1949, 7338, 2432, 775, 7339, 3166, 7776, 6991, 3168, 3441, 7724, 3970, 7716, 1328, 5214, 3988, 3555, 5349, 7901, 8855, 1089, 7374, 6044, 8086, 4965, 2973, 4760, 4263, 8853, 186, 7021, 5769, 713, 2020, 7076, 1249, 8988, 4131, 2765, 5869, 354, 3871, 7647, 2544, 4530, 5065, 6846, 1744, 6757, 1910, 821, 5864, 7259, 3196, 715, 7652, 4483, 1828, 8193, 6094, 3930, 3679, 5209, 1952, 2672, 3911, 6470, 1531, 894, 6725, 3083, 7621, 7160, 866, 1713, 2890, 7897, 2721, 5631, 5846, 1622, 6702, 3729, 6330, 6968, 2245, 2852, 1581, 545, 8800, 8010, 8978, 6509, 6544, 7218, 143, 4222, 2193, 3354, 7765, 1413, 3099, 4434, 3254, 71, 3621, 627, 4250, 6372, 8184, 8280, 3801, 6499, 8979, 8350, 3248, 123, 8277, 4413, 7841, 3519, 2250, 8918, 6213, 8508, 1478, 7889, 3054, 6273, 6642, 861, 2441, 6510, 6017, 3025, 5451, 8699, 3260, 7610, 1602, 4041, 7616, 3597, 181, 1989, 2643, 671, 8381, 8739, 8136, 1517, 4831, 4084, 1415, 1206, 7197, 2944, 5753, 4958, 5242, 5202, 7919, 8857, 3477, 419, 315, 7157, 718, 8314, 5623, 1928, 3251, 4759, 80, 6584, 3531, 7524, 1434, 3023, 6115, 3192, 316, 3229, 1096, 5367, 7631, 2441, 1643, 8764, 3244, 7979];
(a) Determine how many elements in L1 are prime?
L2:=[2891, 8096, 2742, 2961, 1123, 6655, 8179, 2098, 3376, 7324, 8591, 5200, 1130, 2699, 7871, 7205, 1188, 8327, 1607, 8273, 7306, 1417, 6316, 2560, 6735, 2100, 8701, 4810, 3143, 1273, 4283, 718, 6786, 8298, 8153, 8963, 8625, 3548, 6970, 6481, 3872, 8251, 5573, 1146, 5361, 2238, 8169, 1334, 5017, 8933, 8194, 8369, 8349, 2477, 6093, 3148, 1361, 4276, 2073, 499, 1658, 3575, 3732, 2174, 4049, 6046, 6742, 1722, 4760, 2428, 1305, 3881, 4155, 5032, 5539, 2448, 6769, 8963, 2245, 6276, 8671, 3983, 462, 4881, 1382, 1080, 2784, 7736, 1843, 7885, 1627, 5721, 138, 6763, 4758, 1554, 8934, 861, 379, 6631, 4219, 6784, 3919, 2994, 5148, 5926, 6931, 6126, 1601, 1137, 701, 3299, 8173, 5760, 5970, 5443, 4344, 4010, 4971, 1579, 2887, 7168, 4897, 6491, 7732, 8375, 7847, 1310, 4292, 2743, 7172, 370, 8934, 1242, 980, 5388, 1076, 712, 7505, 7957, 8057, 8436, 3593, 2219, 8325, 4388, 7140, 3902, 5000, 8680, 5512, 2860, 3393, 4060, 8554, 2061, 2463, 3334, 1128, 2969, 478, 4265, 4703, 4431, 5897, 1668, 3664, 1149, 2033, 4773, 4210, 4161, 1599, 916, 321, 222, 3474, 7886, 8428, 3429, 6017, 3551, 4622, 5761, 3031, 8509, 8703, 4540, 3444, 7516, 379, 5410, 3502, 8901, 2474, 2598, 5850, 17, 1529, 2249];
(b) Determine how many elements in L2 are even?
Explanation / Answer
a) Here is the code you can use count := 0; for i to nops(L1) do if type(L1[i], prime) then count := count+1 end if; end do; count; It gives a result of 27 b) do the same thing but with even so the code is count := 0; for i to nops(L2) do if type(L2[i], even) then count := count+1 end if end do; count this will give an answer of 96
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.