instructions need to use f programming note your test cases should inc
Search for question
Question
INSTRUCTIONS
· Need to Use F# programming
. Note: Your test cases should include some indication of what the correct result is. You may choose to do this with a comment, by printing the correct result along with your result, by using an if statement, etc. But both the correct result and the actual result should be clear./nCS 341, Spring 2024
Overview
In this homework assignment, you are going to write three functions in F#.
The code containing your five functions must be in a file named: hw06.fs. The code is to be called from the F# code in a file named: main.fs. The file "main.fs" will act as the testing code that will contain all of the code needed to verify correct execution of the functions in the file "hw06.fs".
The initial code in "main.fs" only has one test case included. You are expected to create additional test cases in "main.fs" to verify the functionality of your functions in "hw06.fs". Note that the version of "main.fs" that is part of the autograder code is fairly long and contains quite a number of test cases. The test cases for the autograder will not be released. You are encouraged to be very thorough when creating your own test cases.
The functions that are to be written for this assignment are described below. Make sure you follow the directions specified in the comments for each function regarding the function's parameter(s), return value, implementation details, and helper functions. Some of the functions may expect you to create helper functions to make sure they run properly.
Exercise #1 - duplicateValues (tail recursive)
// duplicateValuesTR L
// Given a list L, create a new list that duplicates each element // in L.
// Example: duplicateValuesTR [1;2;3;3;7] => [1;1;2;2;3;3;3;3;7;7] Example: duplicateValuesTR ['a'; 'b';'a'; 'a' ]
=> ['a';'a'; 'b'; 'b'; 'a'; 'a'; 'a'; 'a']
// NOTE: write a tail-recursive version using a helper function; // do not change the API of the original duplicateValuesTR // function.
Exercise #2 - duplicateValues (higher-order approach)
// duplicateValuesHO L
// Given a list L, create a new list that duplicates each element // in L.
// Example: duplicateValuesHO [1;2;3;3;7] => [1;1;2;2;3;3;3;3;7;7] // Example: duplicateValuesHO ['a' ; 'b'; 'a'; 'a' ]
=> ['a';'a'; 'b'; 'b';'a';'a'; 'a'; 'a']
NOTE: write this using higher-order function(s).
Exercise #3 - shiftList
// shiftList L N
// Given a list L and an integer N, shift the list N places to // the left.
Example: shiftList [1; 2; 3; 4; 5; 6; 7; 8] 3 => [4; 5; 6; 7; 8; 1; 2; 3]
Example: shiftList ['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'] (-2) => ['g' ; 'h'; 'a'; 'b'; 'c'; 'd'; 'e'; 'f' ]
// You can solve using recursion or higher-order function(s).
// If you are solving recursively, tail recursion is required.
Extra Credit Exercise - leapYears
leapYears YR
// Given a year YR as an integer, create a list of integers of // all the leap years since that year, up until 2025, in order. // If the year given is a leap year, include that year. // A leap year in the Gregorian calendar occurs:
- in every year that is evenly divisible by 4
- if the year is evenly divisible by 100, it is only a leap year if the year is also evenly divisible by 400.
// The first year in the Gregorian calendar was in 1582, so you // do not need to worry about years before that.
// Example: leapYears 1998
=> [2000; 2004; 2008; 2012; 2016; 2020; 2024] Example: leapYears 2000
=> [2000; 2004; 2008; 2012; 2016; 2020; 2024] Example: leapYears 2025 => []
// You can solve using recursion or higher-order approaches. // If you are solving recursively, tail recursion is required. // You are not allowed to use the IsLeapYear () method.
Requirements
In order to earn full points for this homework assignment, your code must meet the following requirements:
· No variables (i.e. no use of the keyword mutable).
· No loops. Instead, use recursion or higher-order functions, e.g. List.map, List.iter, etc.
You must use recursion or higher-order programming as noted in the header comments for each of the functions. Failure to use the proper approach for each exercise will result in deduction of points after the assignment deadline.
Proper tail recursion is quite specific. Double check that any solutions you come up with really do use tail recursion. In previous semesters, many students submitted assignments that did in fact NOT implement proper tail recursion.
CS 341, Spring 2024
Submission
Login to Gradescope.com and look for the assignment "Homework 06".
Submit your F# program file "hw06.fs" and your testing file "main.fs". You have unlimited submissions. Keep in mind we grade your last submission unless you select an earlier submission for grading. If you do choose to activate an earlier submission, you must do so before the deadline.
Add your name to the header comment and comment any functions you write!
No late submissions will be accepted for this assignment.
We will be grading your submission as follows:
. The three functions required for "hw06.fs" will account for 60 points of the assignment. These will be graded via the autograder.
. The test cases you write in "main.fs" will account for 40 points of the assignment. These will be graded manually for correctness and thoroughness.
o Your test cases should include some indication of what the correct result is. You may choose to do this with a comment, by printing the correct result along with your result, by using an if statement, etc. But both the correct result and the actual result should be clear.
. The extra credit will be worth 10 additional points. Six of those ten points will be graded via the autograder, checking that your function works as intended. The other four points are for the test cases you write in "main.fs" for the extra credit exercise and will be graded manually.
Academic Integrity
All work is to be done individually - group work is not allowed.
While we encourage you to talk to your peers and learn from them, this interaction must be superficial with regards to all work submitted for grading. This means you cannot work in teams, you cannot work side-by-side, you cannot submit someone else's work (partial or complete) as your own, etc. The University's policy is available here: https://dos.uic.edu/community-standards/
In particular, note that you are guilty of academic dishonesty if you extend or receive any kind of unauthorized assistance. Absolutely no transfer of program code between students is permitted (paper or electronic), and you may not solicit code from family, friends, or online forums (e.g. you cannot download answers from Chegg). Other examples of academic dishonesty include emailing your program to another student, sharing your screen so that another student may copy your work, copying-pasting code from the internet, working together in a group, and allowing a tutor, TA, or another individual to write an answer for you.
CS 341, Spring 2024
Academic dishonesty is unacceptable, and penalties range from a letter grade drop to expulsion from the university; cases are handled via the official student conduct process described at the link above./n/n