Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions