# Z3/Answers

Jump to navigation
Jump to search

1. Given a number n, find all roots from 1 to n of a given number N. ===Answer=== nrootsofn:=(1..n)√n; 2. Add these up. ===Answer=== nrootsofn:=(1..n)√n; SUM(nrootsofn(29)) 3. Find the sum of 1 to n for all even numbers from 1 to 100. ===Answer=== EVENS(1..100).$$(SUM) 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. ===Answer=== [https://en.wikipedia.org/wiki/E_(mathematical_constant) e] is defined as: <img src=https://wikimedia.org/api/rest_v1/media/math/render/svg/4ecf44cf7290248f810619067256c209975ad8e1> FACTORIAL(0)+Σ(SERIESOF("1/x!",100)) or SUM(SERIESOF("1/x!",100,0)) give the result as 2.7182818284590455 which is quite close to e value of 2.71828182845904523536028747135266249775724709369995... (sequence A001113 in OEIS). Σ(SERIESOF("1/x!",100)) ( 1 to 100 only) is missing the original 1, and hence can be written as Σ(SERIESOF("1/x!",100,0)) ∑(0..100@"1/x!") also works SUM((0..100).$("1/x!")) is another answer. 5. Create 3x4x5x6 array and fill with numbers 1 to 100 ===Answer=== |3x4x5x6|.fillwith(1..100) 6. Do same and fill with random numbers. ===Answer=== |3x4x5x6|.random(100) 7. Do same and fill with cube root of numbers 1 to 100 ===Answer=== |3x4x5x6|.fillwith(CUBEROOT(1..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. ===Answer=== Surface Area of a cylinder : 2πr(h+r) ar:=2<*>π<*>(r<>(cm))<*>((h<>(cm))<+>(r<>(cm))) ar(10,30) 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. ===Answer=== h = 0.05m a:= π<*>r<*>(r<+>(h^2<+>r^2)^0.5) v:= π<*>r^2<*>h</>3 x = ["r=" r; "h=" h; "area=" a(r,h); "volume=" v(r,h)] or x = [["r","h","area","volume"],[r,h,a(r,h),v(r,h)]] 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? ===Answer=== p1v1/nRt1=p2v2/nRt2 v2:=p1*v1*t2/t1*p2 v2:=((p1<>atm)*(v1<>l)*(t2<>K))/((t1<>K)*(p2<>atm)) v2(1,4.5,-20,20,0.6)<>l = 7.5l 13. How many moles of gas occupy 98 L at a pressure of 2.8 atmospheres and a temperature of 292 K? ===Answer=== P*V=n*R*T n=p*v/%gas*t n:=((p<>atm)*(v<>l))/(%gas*(t<>K)) n(2.8,98,298)<>moles = 0.11moles 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 the all 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. ===Answer=== ROUND((SQRT((1/2)+0.0916)-ABS(-7)+LN(10)),2) 17. List SIN, COS, TAN values of 0, 30, 60, 90, 120, 150, 180, 210... to 360 degrees ===Answer=== (0..360..30@[DSIN,DCOS,DTAN]) 18. Create an 4x4 matrix and fill with prime numbers between 100 and 10000 ===Answer=== |4|.fillwith(LISTPRIMES(1000,100)) 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 ===Answer=== A=[[3,-4,2],[4,5,6],[2,3,-2]] Determinant = MDETERM(A) = -159.99999 Sum of squares = SUMSQ(A) = 123 Inverse = MINVERSE(A) 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. ===Answer=== Time = 1 hour = 3600sec Interval = 30 sec Total Interval Numbers = 3600/30 = 120 Lower Limit =10 Upper Limit = 20 UNIFORMDISTRIBUTED(120,10,20). graphin() 22. Population growth formula is P= Po e^rt Find population if Population original 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? ===Answer=== P:=Po*%e^(r*t) Population=P(1000000000,0.012,20) Water=Population*0.9<>l 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? ===Answer=== The combination can be 2 men 3 women = COMBIN(7,2)*COMBIN(6,3) 1 men 4 women = COMBIN(7,1)*COMBIN(6,4) 0 men 5 women = COMBIN(7,0)*COMBIN(6,5) Total = COMBIN(7,2)*COMBIN(6,3)+COMBIN(7,1)*COMBIN(6,4)+COMBIN(7,0)*COMBIN(6,5) = 531 24. In how many different ways can the letters of the word 'CORPORATION' be arranged so that the vowels always come together? ===Answer=== word = "CORPORATION"; vowels ="AEIOU"; vowelsarray=vowels.split(""); wordletterswithoutvowels=word.split("").filter((x)=>!x.isin(vowelsarray)); vowellettersfromtheword=word.split("").filter((x)=>x.isin(vowelsarray)); length1=wordletterswithoutvowels.count(); length2=vowellettersfromtheword.count(); totalletters = length1+1; repeatedletters=2; repeatedvowelletters=3; TotalWords = (totalletters!/repeatedletters!)*(length2!/repeatedvowelletters!); TotalWords; 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? ===Answer=== Combination for 7 consonants = COMBIN(7,3) =35 Combination for 4 consonants = COMBIN(4,2) =12 Total groups = 35*12 = 210 Each group have 5 letter that can for 5! words = 120 So total number of words = 210*120 = 25200 words (COMBIN(7,3)*COMBIN(4,2))*5! = 25200 27. In the following paragraph, "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. a) Find the number of instances of occurrence of word "string". ===Answer=== Somepara= "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." SomeString= Somepara.split(/[ ,.:]+/).filter(function (x) { return(x.match(/string/)); }); SomeString.count() b) Find occurrence of word "string" and a whole, not part of any other word. SomeString= Somepara.split(/[ ,.:]+/).filter(function (x) { return(x.match(/^string?/gi)); }); SomeString.count() 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 ===Answer by Rajendu === function IsAdjacentNumber(somearray) { i=0; j=0; tempval = 0; for(i=0;i<somearray.length-1;i++) { (somearray[i]-tempval==1) :: { j++; tempval = somearray[i]; (j==2) :: { result = true; break; } }, { j=0; tempval =somearray[i]; result = false; } } return result ; } CALL Function like arr =[3,2,1,455,3,5,67,32,4,5,6,8,2] IsAdjacentNumber(arr) 39. Given a string return the reverse of the string ===Answer By Rajendu === function ReverseString(somestring) { somearray = somestring.split(""); return somearray.reverse().join('') } ReverseString("christmas"); 40. Given number n, find sum of squares of all natural numbers from 1 to n ===Answer By Rajendu === function ReturnSumOfSquares(SomeNumber) { return SUM(SQUARES(SomeNumber)); } ReturnSumOfSquares(12) - - - J We could also write SS:=SUM(SQUARES(n)); SS(10); 41. Given n, find leap years from 1 to n ===Answer By Rajendu === function GetLeapYear(SomeNumber) { someresult = ""; FOREACH(1..SomeNumber,function (x) { (ISLEAPYEAR(x)):: someresult+=x+","; }); return someresult.slice(0, -1); } GetLeapYear(100); 43. Write a function to merge two arrays and removes all duplicates elements example : [apple, mango, false, grapes, null] [0, apple, mango, lemon, banana] ===Answer By Rajendu === function RemoveDuplicates(SomeArray1,SomeArray2) { return UNIQUE($.merge( SomeArray1, SomeArray2 )); } RemoveDuplicates(['apple', 'mango', false, 'grapes', null] , [0, 'apple', 'mango', 'lemon', 'banana'])