Difference between revisions of "Z3 Exercises"

From ZCubes Wiki
Jump to navigation Jump to search
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
  
 
*[[Z^3 Language Documentation]]
 
*[[Z^3 Language Documentation]]
 +
 +
*[[  Z3/Z3Clarifications | Z3Clarifications]]
  
 
*[[ Z3 | << Back to Z3 home ]]
 
*[[ Z3 | << Back to Z3 home ]]
 +
 +
  
 
<pre>
 
<pre>
Line 44: Line 48:
 
Find the total precipitation for each month.
 
Find the total precipitation for each month.
 
Which day was the precipitation the most?
 
Which day was the precipitation the most?
Find total precipitation for the all months.
+
Find total precipitation for all the months.
  
  
Line 57: Line 61:
 
Sam    m        6      2
 
Sam    m        6      2
  
Extract rows having 2nd column as f
+
Extract rows having 2nd column value as f
 
Find the age of eldest female
 
Find the age of eldest female
 
Find average number of kids of males
 
Find average number of kids of males
Line 84: Line 88:
 
Assume wind speed is modeled as uniform distribution, random number varies between upper and lower limits.  
 
Assume wind speed is modeled as uniform distribution, random number varies between upper and lower limits.  
 
Lower limit is 10 mph. Upper limit is 20 mph.
 
Lower limit is 10 mph. Upper limit is 20 mph.
 +
 +
Find the solution.
 +
Plot the values.
 +
 +
22. Population growth formula is P= Po e^rt
 +
 +
Find population if
 +
 +
Population orginal Po = 1billion
 +
e  = euler number
 +
r = 1.2%
 +
t = 20 years
 +
 +
If a person's intake is 1.5 kg/day of food and 0.9l of water, how much food and water does the population need?
 +
 +
23. From a group of 7 men and 6 women, five persons are to be selected to form a committee so that at least 3 women are there on the committee. How can it be done?
 +
 +
24. In how many different ways can the letters of the word 'CORPORATION' be arranged so that the vowels always come together?
 +
 +
25. In a shop there are Jeans, Pants, Shirts and Tops of colors black, blue, grey etc and prices $20 to $200. Write a program for selection of Jeans, blue in color, that is priced between $50 and $100. If there are no Jeans, get grey color pants priced less than $50.
 +
 +
26. Out of 7 consonants and 4 vowels, how many words of 3 consonants and 2 vowels can be formed?
 +
 +
27. In the following paragraph,
 +
a) Find the number of instances of occurrence of word "string".
 +
b) Find occurrence of word "string" and a whole, not part of any other word.
 +
 +
"Parsing" is the process of taking a string from a file or the network or the user, and processing it to extract the information we want. Suppose we have a string that contains some text with a pair parenthesis somewhere inside of it, like this: "It was hot (darn hot!) I'm telling you". Suppose we want to fix the string so that the part in parenthesis is in all upper case. Given a string, check if it returns a substring made of repetitions of that string.
 +
 +
 +
28. Given a string like "a*pi=314 x-pi+ypi", compute a new string where all appearances of "pi" have been replaced by "3.14".
 +
 +
 +
29. Given a number n, create and return a new int array of length n, containing the numbers 0, 1, 2, ... n-1. The given n may be 0, in which case just return a length 0 array.
 +
 +
30. Given an array length 1 or more of ints, return the difference between the largest and smallest values in the array.
 +
 +
31. Return true if the array contains, somewhere, three increasing adjacent numbers like .... 4, 5, 6, ... or 23, 24, 25.
 +
 +
Example array - 3,2,1,2,3,5,67,32,4,5,6,8,2
 +
 +
32. Given an array of ints, return true if the array contains a 2 next to a 2 or a 4 next to a 4, but not both.
 +
 +
Example array -  4,3,2,2,4,5,6,3 or  4,3,2,2,4,5,4,4
 +
 +
33. Return an array that is "left shifted" by one -- so {7, 2, 5, 3} returns {2, 5, 3, 7}. You may modify and return the given array, or return a new array.
 +
 +
34. Given arrays nums1 and nums2 of the same length, for every element in nums1, consider the corresponding element in nums2 (at the same index). Return the count of the number of times that the two elements differ.
 +
 +
Example arrays -  4,3,2,2,4,5,6,3 or  4,3,2,2,5,5,3,3
 +
 +
35. Given an array of ints, return true if the sum of all the 3's in the array is exactly 9.
 +
 +
36. Return a version of the given array where all the 10's have been removed. The remaining elements should shift left towards the start of the array as needed, and the empty spaces a the end of the array should be 0. So {1, 10, 10, 2} yields {1, 2, 0, 0}.
 +
 +
37. Given an array of scores, return true if each score is equal or greater than the one before. The array will be length 2 or more.
 +
 +
38. Given an array of positive ints, return a new array of length "count" containing the first even numbers from the original array. The original array will contain at least "count" even numbers.
 +
 +
39. Given a string return the reverse of the string
 +
 +
40. Given number n, find sum of squares of all natural numbers from 1 to n
 +
 +
41. Given n, find leap years from 1 to n
 +
 +
42. Write a function to filter "false", "null", "0" and blank values from an array.
 +
 +
example :  apple, mango, false, grapes, null, , 0,
 +
 +
43. Write a function to merge two arrays and removes all duplicates elements
 +
 +
example :  [apple, mango, false, grapes, null]  [0, apple, mango, lemon, banana]
 +
 +
44. There are two arrays with individual values, write a z3 program to compute the sum of each individual index value from the given arrays.
 +
Example :
 +
array1 = [1,0,2,3,4];
 +
array2 = [3,5,6,7,8,13];
 +
Expected Output :
 +
[4, 5, 8, 10, 12, 13]
 +
 +
 +
45. Given 2 non-zero integers, find the greatest common divisor and LCM.
 +
  
 
</pre>
 
</pre>
  
 +
*[[  Z3/Z3Clarifications | Z3Clarifications]]
  
 
*[[  Z3/Answers | Z3 Exercise Answers]]
 
*[[  Z3/Answers | Z3 Exercise Answers]]
  
 
*[[ Z3 | << Back to Z3 home ]]
 
*[[ Z3 | << Back to Z3 home ]]

Latest revision as of 02:20, 30 August 2016



1. Given a number n, find all roots from 1 to n of a given number N.

2. Add these up.

3. Find the sum of 1 to n for all even numbers from 1 to 100. 
4. Find the factorial of reciprocals of a series of numbers from 1 to a large numbers and see how it compares to the value of e. 

5. Create 3x4x5x6 array and fill with numbers 1 to 100

6. Do same and fill with random numbers. 

7. Do same and fill with cube root of numbers 1 to 100

8. Create an equation or formula for surface area of a cylinder. Try to do with units. Do this as a function that converts and does it on units supplied by user automatically if possible. 

9. Create a function that given the radius and height of a cylinder, returns an array of radius height surface area and volume. Use Greek letters to be similar to formula that are generally used. 

10. Do the same for a cone as equations and as a function. 

11. Use array programming when needed. Notations can be as close to what are given in normal calculations in real situations.

12. A helium balloon with an internal pressure of 1.00 atm and a volume of 4.50 L at 20.00 C is released. 
What volume will the balloon occupy at an altitude where the pressure is 0.600 atm and the temperature is –20.00 C?

13. How many moles of gas occupy 98 L at a pressure of 2.8 atmospheres and a temperature of 292 K?

14. Following is precipitation data 
2016	Day 1	Day 2	Day 3	Day 4
January	0	0	0	0
February 4	12	4	3	
March	42	33	32	42
April	22	12	22	22
May	21	16	12	14
June	4	5	3	2

For the given days,
Find the total precipitation for each month.
Which day was the precipitation the most?
Find total precipitation for all the months.


15. A table has the following values.

Name   Gender  Age    Kids  

John 	m	3	5    	
Mary    f	12	4		
Sue	f	33	2
Kim	f	12	1
Sam     m        6      2

Extract rows having 2nd column value as f
Find the age of eldest female
Find average number of kids of males
Create a table with data sorted based on age

16. Find Square root of 1/2 + 0.0916 - absolute value of (-7) + natural logarithm of 10. Round this number to 2 decimals.


17. List SIN, COS, TAN values of 0, 30, 60, 90, 120, 150, 180, 210... to 360 degrees

18. Create an 4x4 matrix and fill with prime numbers between 100 and 10000

19. Convert $321 to British pounds, Indian rupee and Euro

20. Matrix

3	-4	2	
4	5	6
2	3	-2

Find the determinant
Find the sum of squares of all numbers
Find inverse

21. Generate random number sequence to simulate 1 hour of windspeed data. Updated every 30 seconds. 
Assume wind speed is modeled as uniform distribution, random number varies between upper and lower limits. 
Lower limit is 10 mph. Upper limit is 20 mph.

Find the solution.
Plot the values.

22. Population growth formula is P= Po e^rt

Find population if

Population orginal Po = 1billion
e  = euler number
r = 1.2%
t = 20 years 

If a person's intake is 1.5 kg/day of food and 0.9l of water, how much food and water does the population need?

23. From a group of 7 men and 6 women, five persons are to be selected to form a committee so that at least 3 women are there on the committee. How can it be done?

24. In how many different ways can the letters of the word 'CORPORATION' be arranged so that the vowels always come together?

25. In a shop there are Jeans, Pants, Shirts and Tops of colors black, blue, grey etc and prices $20 to $200. Write a program for selection of Jeans, blue in color, that is priced between $50 and $100. If there are no Jeans, get grey color pants priced less than $50.

26. Out of 7 consonants and 4 vowels, how many words of 3 consonants and 2 vowels can be formed?

27. In the following paragraph,
a) Find the number of instances of occurrence of word "string". 
b) Find occurrence of word "string" and a whole, not part of any other word. 

"Parsing" is the process of taking a string from a file or the network or the user, and processing it to extract the information we want. Suppose we have a string that contains some text with a pair parenthesis somewhere inside of it, like this: "It was hot (darn hot!) I'm telling you". Suppose we want to fix the string so that the part in parenthesis is in all upper case. Given a string, check if it returns a substring made of repetitions of that string.


28. Given a string like "a*pi=314 x-pi+ypi", compute a new string where all appearances of "pi" have been replaced by "3.14".


29. Given a number n, create and return a new int array of length n, containing the numbers 0, 1, 2, ... n-1. The given n may be 0, in which case just return a length 0 array.

30. Given an array length 1 or more of ints, return the difference between the largest and smallest values in the array. 

31. Return true if the array contains, somewhere, three increasing adjacent numbers like .... 4, 5, 6, ... or 23, 24, 25.

Example array - 3,2,1,2,3,5,67,32,4,5,6,8,2

32. Given an array of ints, return true if the array contains a 2 next to a 2 or a 4 next to a 4, but not both.

Example array -  4,3,2,2,4,5,6,3 or  4,3,2,2,4,5,4,4

33. Return an array that is "left shifted" by one -- so {7, 2, 5, 3} returns {2, 5, 3, 7}. You may modify and return the given array, or return a new array.

34. Given arrays nums1 and nums2 of the same length, for every element in nums1, consider the corresponding element in nums2 (at the same index). Return the count of the number of times that the two elements differ.

Example arrays -  4,3,2,2,4,5,6,3 or  4,3,2,2,5,5,3,3

35. Given an array of ints, return true if the sum of all the 3's in the array is exactly 9.

36. Return a version of the given array where all the 10's have been removed. The remaining elements should shift left towards the start of the array as needed, and the empty spaces a the end of the array should be 0. So {1, 10, 10, 2} yields {1, 2, 0, 0}. 

37. Given an array of scores, return true if each score is equal or greater than the one before. The array will be length 2 or more.

38. Given an array of positive ints, return a new array of length "count" containing the first even numbers from the original array. The original array will contain at least "count" even numbers.

39. Given a string return the reverse of the string

40. Given number n, find sum of squares of all natural numbers from 1 to n

41. Given n, find leap years from 1 to n

42. Write a function to filter "false", "null", "0" and blank values from an array.

example :  apple, mango, false, grapes, null, , 0, 

43. Write a function to merge two arrays and removes all duplicates elements

example :  [apple, mango, false, grapes, null]   [0, apple, mango, lemon, banana]

44. There are two arrays with individual values, write a z3 program to compute the sum of each individual index value from the given arrays. 
Example : 
array1 = [1,0,2,3,4];
array2 = [3,5,6,7,8,13];
Expected Output : 
[4, 5, 8, 10, 12, 13] 


45. Given 2 non-zero integers, find the greatest common divisor and LCM.