Scheme代写 | COMP 3007 – Take-home Final

本次加拿大CS代写主要是Scheme相关的take home exam

Due: Tuesday April 27th @ 11:55pm (No late submissions!)

Take-home Exam Rules

    • Ensure that you have read and understood all of the instructions before you begin.
  • About Grading…
    • Submissions will be evaluated by a combination of automatic and manual grading.
    • Your answers to each coding problem must work as described by each question for all reasonable inputs within the given constraints of each problem.
    • There will be no part marks awarded to incomplete, incorrect, or partially correct solutions. (Test your solutions!)
    • There are no marks explicitly for documentation and testing, but documenting and testing your work is strongly encouraged.
  • Programming guidelines…
    • Ensure that you follow all prescribed file and function naming conventions.
    • Unless otherwise specified, you may assume inputs supplied are of the correct type.
    • Solutions must be coded in Scheme or Prolog (as specified), no other programming languages will be graded.
  • About built-ins and libraries…
    • You may use any built-in functions/operations/predicates you like, provided that they are not explicitly forbidden by a problem.
    • You may not use use any unauthorized imports in your solutions (core language features only).
  • About collaboration…
    • Absolutely no collaboration is allowed in the completion of this exam.
    • Any collaboration, sharing, or copying of solutions (whole or partial) from peers or the internet, will result in (at minimum) a grade of zero on the test, and a citation for academic misconduct.
    • If you use concepts from outside of the course in your solutions, you should cite your source.
    • Code copied from authorized sources (e.g. lecture notes) should be cited (e.g. “From course lecture notes, chapter 2”).
    • Do not post questions or answers from this test to any public forum, even after you have finished.

Part A

[42 marks total]

The Rules:

  • You may solve the questions of this Part using Scheme or Prolog (or both!).
  • Put all Scheme solutions in a file called parta_<yourid#>.scm.
  • Put all Prolog solutions in a file called parta_<yourid#>.pl.
  • Each question is denoted with a number of marks.
  • Correctly working answers will receive full marks.
  • Incorrect answers will receive zero marks.
  • Solve as many or as few as you’d like to fulfill the maximum grade above.
  • Correctly solving every question once will yeild full marks for this Part.
  • Solving a question in both languages is worth 1.5x the stated marks (total, not each).
  • If you earn more than the maximum grade for this Part, you will receive the maximum grade.
  • Tip: Be sure to read the usage examples for both languages (even if you’re solving in just one).

The Questions:

  1. [5 marks] Write a function/predicate called split that takes a key and a list as arguments and splits the input list into a list of sublists between each instance of key.
    E.g., (split 'c '(a b c d e)) → ((a b)(d e))
    E.g., (split '0 '(1 0 1 1 0 2 0 0 1)) → ((1)(1 1)(2)(1))
    E.g., ?-split(x,[1,2,x,4,5],R). → R = [[1,2],[4,5]].
    E.g., ?-split(z,[8,3,2,6,1,4],R). → R = [[8,3,2,6,1,4]].
  2. [4 marks] Write a function/predicate called slice that takes a list and two integer indices as arguments and returns a sublist of the input list between the indices start (inclusive) and end (exclusive). If either of the given indices are out of bounds, then the returned sublist should include any existing values in the given ranges.
    E.g., (slice '(0 1 2 3 4 5 6 7 8 9) 3 8) → (3 4 5 6 7)
    E.g., (slice '(a b c d e f g h i j) 5 25) → (f g h i j)
    E.g., ?-slice([a,b,c,d,e,f,g],1,3,R). → R = [b,c].
    E.g., ?-slice([0,1,2,3,4,5],-10,3,R). → R = [0,1,2].
  3. [5 marks] Write a function/predicate called infuse that takes the following as arguments: an input list, an integer index, a non-negative integer n, and a list of new items. The infuse function should remove n items from the input list at the given index, and insert all of the new items at that location.
    Note: the number of elements removed should be at most the provided number, if fewer target items are available then fewer will be removed.
    Note: Invalid indices should result in the input list being unaltered.
    E.g., (infuse '(a b c d e) 2 1 '(x y)) → (a b x y d e)
    E.g., (infuse '(1 2 3 4 5) 2 0 '(x y)) → (1 2 x y 3 4 5)
    E.g., (infuse '(a b c d e) 2 1 '()) → (a b d e)
    E.g., ?-infuse([1,2,3],1,1,[a,b,c],R). → R = [1,a,b,c,3].
    E.g., ?-infuse([1,2,3],3,1,[a,b],R). → R = [1,2,3].
    E.g., ?-infuse([0,1,2,3,4,5,6,7],4,2,[],R). → R = [0,1,2,3,6,7].
  4. [5 marks] Write a function/predicate called fold_once that takes a list of numbers as argument and returns a list of the following sums: first_element + last_element, second_element + second_last_element, etc…
    If there is a singular middle element, do not add anything to it.
    E.g., (fold_once '(6 2.5 9 1 5 7 8 4)) → (10 10.5 16 6)
    E.g., ?-fold_once([1,2,3.5,4,5],R). → R = [6,6,3.5]
  5. [3 marks] Write a function/predicate called pos_diffs that takes a list of zero or more numbers as argument and returns the list of the differences between each successive element in the list, but without any of the negative differences.
    E.g., (pos_diffs '(6 2 9 1 5 7 8)) → (-4 7 -8 4 2 1) → (7 4 2 1)
    E.g., (pos_diffs '(1)) → ()
    E.g., ?-pos_diffs([1,2,3,4,4,6],R). → R = [1,1,1,0,2].
  6. [4 marks] Write a function/predicate called globs that takes a list of symbols(/atoms) as argument and returns a list where sequences of consecutive values from the input list are stored as a pair (2-element list) of the value and the count of that value.
    E.g., (globs '(a a g g a a a a t c)) → ((a 2) (g 2) (a 4) (t 1) (c 1))
    E.g., globs([t,t,t,a,a,c,g,t],R). → R = [[t,3],[a,2],[c,1],[g,1],[t,1]].
  7. [6 marks] Write a function/predicate called all_sums that takes two non-negative integers k and n as arguments, and returns a list of all k-digit integers whose digits sum to n, in ascending order. Note: leading zeroes should not be considered digits for this problem.
    E.g., (all_sums 2 7) → (16 25 34 43 52 61 70)
    E.g., (all_sums 3 0) → ()
    E.g., ?-all_sums(3,4,R). → R = [103,112,121,130,202,211,220,301,310,400]
  8. [5 marks] Write a function/predicate called prune that takes a tree (nested list) as argument and removes all empty lists from inside the provided tree. The resulting tree should contain all non-empty-list elements from the input tree in their original order and structure.
    E.g., (prune '(1 2 () 3 4)) → (1 2 3 4)
    E.g., (prune '(a (b () (c () d))()()(()) e)) → (a (b (c d)) e)
    E.g., (prune '()) → ()
    E.g., ?-prune([1,2,[],3,4],R). → R = [1,2,3,4].
    E.g., ?-prune([[],[],[[],1,[[]]]],R). → R = [[1]].
  9. [5 marks] Write a function/predicate called minima that takes a list of numbers as argument and returns a list of the indices of all local minima in the list. For the sake of this problem, a local minima is defined as any element which is smaller than both of its immediately neighbouring elements. Any indices outside of the input list should be considered to have a value of 0.
    E.g., (minima '(1 5 9 3 5 4 8)) → (3 5)
    E.g., (minima '(-42 25 -1)) → (0 2)
    E.g., ?-minima([0,1,0,0,0,-1,1,1,-1,1,0,1],R). → R = [5,8,10].
    E.g., ?-minima([6,4,2,1,3,5],R). → R = [3].

Part B

Answer all problems from this part in their own (specified) files.

    1. [6 marks] In a file called partb1_generator.scm, write a Scheme function called list-generator that takes two functions (a predicate and a mutator) as argument and returns a list-making function. The returned list-making function should take three integers (a start value, a stop value, and a step value) as arguments, and return a list of values based on all of the provided information. The resulting lists should contain the result of applying the mutator function to all of the integers in the given range for which the predicate function returns true. Any calls that would result in an invalid or empty range should return an empty list.
      E.g., (define f (list-generator (lambda(x)#t) (lambda(x)x)))
      f → #<procedure:...>

           (f 0 10 2) → (0 2 4 6 8 10)
      E.g., ((list-generator odd? (lambda(x)(* x 2))) 1 20 3) → (2 14 26 38)
      E.g., ((list-generator (lambda(x)#t)(lambda(x)x)) 16 0 -4) → (16 12 8 4 0)

  1. [7 marks] In a file called partb2_contour.scm, write a Scheme program that will execute to create the environment state depicted in the following contour diagram.
    Notes:

    • There are many possible solutions to this problem, you need only find one.
    • Any lines of code not described by the diagram may be filled as you see fit (i.e., lines of code, comments, or whitespace can be used to align your solution with the provided line numbers)
    • Lines of your solution must be on the correct line in the file to be considered correct (with the first line of the file being line 1).
    • Your solution to this problem must function without error (outputs are not specified by the diagram).
    • Each correctly written detail of the solution is worth some amount of the total mark. Part marks will be possible.

     


程序代写代做C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


blank

本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: itcsdx@outlook.com  微信:itcsdx


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank

发表评论