CCPS506 Project Description
Operations on Integer Intervals
Copyright By PowCoder代写 加微信 powcoder
You will complete the same project using three of the four languages we study this semester.
If you submit the assignment in all four languages, your top three submissions will be taken.
In addition to the general requirements of the project, each language comes with its own
language-specific constraints. These specify the format of the input and output, as well as
submission instructions for each language. Aside from these, anything you do inside your
program is up to you. Use as many helper functions or methods as you want, use any syntax
you find useful whether we covered it in class or not. There is one exception to this: you may
not use any functionality that is not part of the base installation of each language. No 3rd party
libraries. I will be testing your code using out-of-the-box installations of each language.
Integer interval description
An interval of consecutive positive integers can be represented concisely as a string using an
upper and lower bound separated by a dash. For example, the interval containing the
integers 2,3,4,5,6 would have the string representation “2-6”. An interval containing
the single integer 42 would simply be represented as “42”.
We can also represent multiple intervals in a comma-separated fashion. The integers 4, 5, 6,
10, 11, 12, 16 would be represented as the string “4-6,10-12,16”.
The requirements of this project involve operating on strings of integer intervals.
General project description
You will write functions for operating on strings of integer intervals. These required
functions are described below in the general sense, with language specific requirements
provided further down.
For each of the functions described below, you may assume that where an interval string is
provided as input, it will be in ascending order and there will be no overlap between the
intervals. Where a list of integers is provided, that list will also be in ascending order, and
there will be no duplicate entries. Conversely, if you are required to return an interval
string, it must be strictly ascending and contain no overlapping intervals. If you are required
to return a list of integers, it must be ascending and contain no duplicates.
1) expand (intervals)
This function accepts a string of intervals as input and return a list of integers
representing the expansion of those intervals. Several examples can be seen in the table
below. Notice that an empty string is perfectly legitimate as input and should result in
an empty list being returned.
Intervals: Expected result:
“” (empty string) [] (empty list)
“4-5” [4, 5]
“4-6,10-12,16” [4, 5, 6, 10, 11, 12, 16]
“1,3-5,12-14,9999” [1, 3, 4, 5, 12, 13, 14, 9999]
2) collapse (items)
This function performs the inverse of the function above. Given a list of ascending
integers with no duplication, return an interval string.
Items: Expected result:
[ ] (empty list) “” (empty string)
[1, 2, 4, 5, 6, 8, 9, 12] “1-2,4-6,8-9,12”
[1, 2, 3, 4, 5, 6, 7, 8, 9] “1-9”
[2, 4, 6, 8, 10] “2,4,6,8,10”
3) union (intervals_1, intervals_2)
This function accepts two interval strings as input and returns their union. The meaning
of union has the same meaning as it does between sets.
Intervals_1: Intervals_2: Expected result:
“2,4,6” “1,3,5” “1-6”
“1-3” “4-6” “1-6”
“1-9” “10” “1-10”
“4-6,10-12,16” “1,3-5,12-14” “1,3-6,10-14,16”
4) intersection (intervals_1, intervals_2)
This function accepts two interval strings as input and returns their intersection.
Intervals_1: Intervals_2: Expected result:
“2,4,6” “1,3,5” “”
“2,4,6” “4-8” “4,6”
“4-6,10-12,16” “1,3-5,12-14” “4-5,12”
5) difference (intervals_1, intervals_2)
This function returns the difference between intervals_1 and intervals_2. This is
calculated by removing the elements of intervals_2 from intervals_1 if they exist.
Intervals_1: Intervals_2: Expected result:
“1-5,7-9” “4-8” “1-3,9”
“4-8” “1-5,7-9” “6”
“” “10” “”
6) is_disjoint (intervals_1, intervals_2)
Returns true if the intervals are disjoint (no elements in common) and false otherwise.
Intervals_1: Intervals_2: Expected result:
“4-7” “1-3,8-9” true
“4-6,10-12,16” “1,3-5,12-14” false
“” “10” true
7) is_subset (intervals_1, intervals_2)
Returns true if every integer in intervals_1 is also found in intervals_2, false otherwise.
Intervals_1: Intervals_2: Expected result:
“1-5,7-9” “1-9” true
“4-6,10-12,16” “1,3-5,12-14” false
“” “10” true
Language-specific requirements
Every language must implement the same functions. The only distinction between them is
the parameter and return value types and the function (or method) signatures.
1) Smalltalk requirements:
Create a class called IntervalOps, with the following instance methods:
expand: intervals
collapse: intervals
union: intervals_1 and: intervals_2
intersection: intervals_1 and: intervals_2
difference: intervals_1 and: intervals_2
is_disjoint: intervals_1 and: intervals_2
is_subset: intervals_1 and: intervals_2
Sample usage in the Pharo Playground can be seen below:
| io i1 i2 i3 nums |
io := IntervalOps new. “Create IntervalOps object”
i1 := ‘4-6,10-12,16’. “Intervals are Strings”
nums := #(4 5 6 7 8 9). “Expanded form is an Array”
i2 := io collapse: nums. “Collapse nums”
i3 := io union: i1 and: i2. “Union of i1 and i2”
Transcript show: i3; cr.
In the above example, i3 should be printed as ‘4-12,16’
2) Elixir/Haskell/Rust requirements:
For these three languages, you are given mix/cabal/cargo projects with source files and
test cases already created. For each language, you simply fill in the function skeletons
provided in the intervalops source file. By looking at each language’s tester, you can
see the types involved. Notice that Rust functions return heap Strings, not &str.
Testing & Evaluation
Your code will be evaluated using an automated tester written by me. Therefore, it is of
utmost importance that your code compile properly, handle input properly, and return
results in the indicated format for each language. Do not deviate from the requirements or
your code will fail the tester outright. Your code must compile and run as a baseline. Half-
finished code that doesn’t compile or is riddled with syntax errors will not be accepted.
To help you achieve the baseline of “code that works”, you are provided with mix/cabal/cargo
projects with a handful of simple test cases for Elixir/Haskell/Rust, just as you were for those
language’s labs. For Smalltalk, I will provide a simple script you can paste into your
Playground.
Beyond that, your grade for each assignment submission will be based solely on the fraction
of the tests for which your program returns the correct result. There are no marks for code
style, documentation, or anything of that sort. The simple tests are to help you get started,
but when I evaluate your final submission, I will be using a more sophisticated tester with
more tests and larger intervals. You are highly encouraged to add your own tests that stress
your code beyond those that are provided.
Submission
Projects must be submitted individually.
Smalltalk submission: To submit your Smalltalk assignment, you will submit the entire Pharo
image directory as an archive (zip/rar/7z/whatever). To find your Pharo image directory,
select the image in the launcher that contains your assignment, and look at the bottom of the
launcher screen to see the “Location” directory. Zip up everything in this folder – not just the
Elixir/Haskell/Rust submissions: Submit your intervalops.ex, intervalops.hs, or intervalops.rs
file on D2L. You do not need to submit the entire mix/cabal/cargo project.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com