Question: Please implement in rust language 1 === Implement function 'attempt 2 4 Function 'attempt' accepts 3 arguments: - 'available' - array of available values 'allowed

Please implement in rust language

 Please implement in rust language 1 === Implement function 'attempt 2

1 === Implement function 'attempt 2 4 Function 'attempt' accepts 3 arguments: - 'available' - array of available values 'allowed array of allowed values 'preferred' - array of preferred values 5 6 7 8 9 10 11 12 13 Function 'attempt' returns the list of values that satisfy the criteria of the request. The algorithm chooses values from the array of available values and returns an array of values that fits. If the algorithm can not return the preferred value, it tries to return the closest value not smaller than preferred, if can't then the closest smaller value. The algorithm returns only values that are allowed and available. The algorithm returns an empty array if no option is left. Returned array does not have repeated elements. Elements of returned array grow in value. 14 15 16 17 18 19 20 = Example available : [ 240, 360, 720 ] allowed : [ 360, 720 ] preferred : [ 1080 ] returns : [ 360 ] = Example available : [ 240, 720 ] allowed : [ 360, 720 ] preferred : [ 1080 ] returns : [ 720 ] 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 = Example. available : [ 240 ] allowed : [ 360, 720 ] preferred : [ 1080 ] returns: [] = Example available : [ 240, 360, 720 ] allowed : [ 240, 360, 720, 1080 ] preferred : [ 240, 360 ] returns : [ 240, 360 ] 41 42 43 = Example available : [ 240, 720 ] allowed : [ 240, 360, 720, 1080 ] preferred : [ 240, 360 ] returns : [ 240, 720 ] 44 45 46 47 48 49 50 = Example available : [ 240, 720 ] allowed : [ 240, 360, 1080 ] preferred : [ 240, 360 ] returns : [ 240 ] 51 52 53 54 55 56 57 58 59 = Example available : [ 720 ] allowed : [ 240, 360, 1080 ] preferred : [ 240, 360 ] returns: [] 60 61 62 = Example available : [ 240, 360 ] allowed : [ 240, 360 ] preferred : [ 720, 1080 ] returns : [ 360 ] == Special value 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 Also, arrays 'allowed' and 'preferred' may have the element "any". "any" in the array of 'allowed' values means that any value is allowed. "any" in the array of 'preferred' values means that any value is preferred. "any" , - . "any" , . = Example available : [ 240, 360, 720 ] allowed : [ 360, 'any' ] preferred : [ 360, 720 ] returns : [ 360, 720 ] 78 79 80 81 82 83 = Example available : [ 240, 360, 720 ] allowed : [ 240, 360, 720 ] preferred : [ 'any', 720 ] returns : [ 240, 360, 720 ] 84 85 = Example. available : [ 240, 360, 720 ] allowed : [ 360, 1080 ] preferred : [ 'any', 720 ] returns : [ 360 ] 86 87 88 89 90 91 92 93 94 95 96 97 = Example. available : [ 240, 360, 720 ] allowed : [ 1080 ] preferred : [ 'any', 720 ] returns: []

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!