Question
I NEED HELP WITH THIS ASSIGNMENT IN HASKELL! HERE IS THE TEMPLATE CSC207A3.HS: HERE IS THE CSC207A3TESTER.HS HERE IS THE CONTENT OF THE FILE CSC207A3TESTDATA.HS
I NEED HELP WITH THIS ASSIGNMENT IN HASKELL!
HERE IS THE TEMPLATE CSC207A3.HS:
HERE IS THE CSC207A3TESTER.HS
HERE IS THE CONTENT OF THE FILE CSC207A3TESTDATA.HS
module CSC207a3TestData where
tests :: [(Integer, Integer, [Integer])] tests = [( 1, 3956, [2, 4, 23, 43, 46, 86, 92, 172, 989, 1978]), ( 2, 1021, []), ( 3, 9981, [3, 9, 1109, 3327]), ( 4, 2704, [2, 4, 8, 13, 16, 26, 52, 104, 169, 208, 338, 676, 1352]), ( 5, 9457, [7, 49, 193, 1351]), ( 6, 6530, [2, 5, 10, 653, 1306, 3265]), ( 7, 6173, []), ( 8, 2454, [2, 3, 6, 409, 818, 1227]), ( 9, 5414, [2, 2707]), ( 10, 3560, [2, 4, 5, 8, 10, 20, 40, 89, 178, 356, 445, 712, 890, 1780]), ( 11, 1798, [2, 29, 31, 58, 62, 899]), ( 12, 3943, []), ( 13, 1935, [3, 5, 9, 15, 43, 45, 129, 215, 387, 645]), ( 14, 7744, [2, 4, 8, 11, 16, 22, 32, 44, 64, 88, 121, 176, 242, 352, 484, 704, 968, 1936, 3872]), ( 15, 4500, [2, 3, 4, 5, 6, 9, 10, 12, 15, 18, 20, 25, 30, 36, 45, 50, 60, 75, 90, 100, 125, 150, 180, 225, 250, 300, 375, 450, 500, 750, 900, 1125, 1500, 2250]), ( 16, 9541, [7, 29, 47, 203, 329, 1363]), ( 17, 600, [2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 25, 30, 40, 50, 60, 75, 100, 120, 150, 200, 300]), ( 18, 2830, [2, 5, 10, 283, 566, 1415]), ( 19, 2988, [2, 3, 4, 6, 9, 12, 18, 36, 83, 166, 249, 332, 498, 747, 996, 1494]), ( 20, 8499, [3, 2833]), ( 21, 5058, [2, 3, 6, 9, 18, 281, 562, 843, 1686, 2529]), ( 22, 3594, [2, 3, 6, 599, 1198, 1797]), ( 23, 8233, []), ( 24, 4257, [3, 9, 11, 33, 43, 99, 129, 387, 473, 1419]), ( 25, 8856, [2, 3, 4, 6, 8, 9, 12, 18, 24, 27, 36, 41, 54, 72, 82, 108, 123, 164, 216, 246, 328, 369, 492, 738, 984, 1107, 1476, 2214, 2952, 4428]), ( 26, 9531, [3, 9, 27, 353, 1059, 3177]), ( 27, 4948, [2, 4, 1237, 2474]), ( 28, 5790, [2, 3, 5, 6, 10, 15, 30, 193, 386, 579, 965, 1158, 1930, 2895]), ( 29, 3113, [11, 283]), ( 30, 3030, [2, 3, 5, 6, 10, 15, 30, 101, 202, 303, 505, 606, 1010, 1515]), ( 31, 2026, [2, 1013]), ( 32, 6151, []), ( 33, 7873, []), ( 34, 419, []), ( 35, 1553, []), ( 36, 5062, [2, 2531]), ( 37, 4533, [3, 1511]), ( 38, 5560, [2, 4, 5, 8, 10, 20, 40, 139, 278, 556, 695, 1112, 1390, 2780]), ( 39, 9821, [7, 23, 61, 161, 427, 1403]), ( 40, 2959, [11, 269]), ( 41, 1725, [3, 5, 15, 23, 25, 69, 75, 115, 345, 575]), ( 42, 5282, [2, 19, 38, 139, 278, 2641]), ( 43, 7126, [2, 7, 14, 509, 1018, 3563]), ( 44, 9374, [2, 43, 86, 109, 218, 4687]), ( 45, 6055, [5, 7, 35, 173, 865, 1211]), ( 46, 1263, [3, 421]), ( 47, 4991, [7, 23, 31, 161, 217, 713]), ( 48, 5783, []), ( 49, 2744, [2, 4, 7, 8, 14, 28, 49, 56, 98, 196, 343, 392, 686, 1372]), ( 50, 9229, [11, 839]), ( 51, 4322, [2, 2161]), ( 52, 3888, [2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 27, 36, 48, 54, 72, 81, 108, 144, 162, 216, 243, 324, 432, 486, 648, 972, 1296, 1944]), ( 53, 6677, [11, 607]), ( 54, 2391, [3, 797]), ( 55, 1323, [3, 7, 9, 21, 27, 49, 63, 147, 189, 441]), ( 56, 5161, [13, 397]), ( 57, 2434, [2, 1217]), ( 58, 7993, []), ( 59, 6209, [7, 887]), ( 60, 3065, [5, 613]), ( 61, 235, [5, 47]), ( 62, 6379, []), ( 63, 6356, [2, 4, 7, 14, 28, 227, 454, 908, 1589, 3178]), ( 64, 748, [2, 4, 11, 17, 22, 34, 44, 68, 187, 374]), ( 65, 7880, [2, 4, 5, 8, 10, 20, 40, 197, 394, 788, 985, 1576, 1970, 3940]), ( 66, 3744, [2, 3, 4, 6, 8, 9, 12, 13, 16, 18, 24, 26, 32, 36, 39, 48, 52, 72, 78, 96, 104, 117, 144, 156, 208, 234, 288, 312, 416, 468, 624, 936, 1248, 1872]), ( 67, 158, [2, 79]), ( 68, 5878, [2, 2939]), ( 69, 6539, [13, 503]), ( 70, 9903, [3, 3301]), ( 71, 2268, [2, 3, 4, 6, 7, 9, 12, 14, 18, 21, 27, 28, 36, 42, 54, 63, 81, 84, 108, 126, 162, 189, 252, 324, 378, 567, 756, 1134]), ( 72, 7352, [2, 4, 8, 919, 1838, 3676]), ( 73, 1595, [5, 11, 29, 55, 145, 319]), ( 74, 9969, [3, 3323]), ( 75, 2142, [2, 3, 6, 7, 9, 14, 17, 18, 21, 34, 42, 51, 63, 102, 119, 126, 153, 238, 306, 357, 714, 1071]), ( 76, 9267, [3, 3089]), ( 77, 3009, [3, 17, 51, 59, 177, 1003]), ( 78, 9838, [2, 4919]), ( 79, 4918, [2, 2459]), ( 80, 4382, [2, 7, 14, 313, 626, 2191]), ( 81, 4211, []), ( 82, 9776, [2, 4, 8, 13, 16, 26, 47, 52, 94, 104, 188, 208, 376, 611, 752, 1222, 2444, 4888]), ( 83, 5893, [71, 83]), ( 84, 5963, [67, 89]), ( 85, 6012, [2, 3, 4, 6, 9, 12, 18, 36, 167, 334, 501, 668, 1002, 1503, 2004, 3006]), ( 86, 481, [13, 37]), ( 87, 4666, [2, 2333]), ( 88, 8526, [2, 3, 6, 7, 14, 21, 29, 42, 49, 58, 87, 98, 147, 174, 203, 294, 406, 609, 1218, 1421, 2842, 4263]), ( 89, 8754, [2, 3, 6, 1459, 2918, 4377]), ( 90, 1229, []), ( 91, 126, [2, 3, 6, 7, 9, 14, 18, 21, 42, 63]), ( 92, 8359, [13, 643]), ( 93, 3800, [2, 4, 5, 8, 10, 19, 20, 25, 38, 40, 50, 76, 95, 100, 152, 190, 200, 380, 475, 760, 950, 1900]), ( 94, 6592, [2, 4, 8, 16, 32, 64, 103, 206, 412, 824, 1648, 3296]), ( 95, 8201, [59, 139]), ( 96, 7225, [5, 17, 25, 85, 289, 425, 1445]), ( 97, 4881, [3, 1627]), ( 98, 7095, [3, 5, 11, 15, 33, 43, 55, 129, 165, 215, 473, 645, 1419, 2365]), ( 99, 8641, []), (100, 8457, [3, 2819])] PLEASE HELP ME OUT WITH THIS ASSIGNMENT IN HASKELL.
THANK YOU SO MUCH
In this assignment, you are going to write a Haskell function factors to find all proper factors of a positive Integer. Given a positive Integer value n, a proper factor of n is defined to be an Integer value i between 1 to n (exclusively) such that n is divisible by i; that is, the remainder of dividing n by i is zero (0). Note that although n is divisible by both 1 and n, they are not proper factors of n The function factors has the following type signature: factors :: Integer -> [Integer] That is, it takes an Integer and returns a list of Integer. The elements in the list are all proper factors of the parameter, and they must be in ascending order. The followings are some examples: factors 8433, 281] factors 3281 [17, 193] factors 6912 > [2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 27, 32, 36, 48, 54,64, 72, 96, 108, 128, 144, 192, 216, 256, 288, 384, 432, 576, 768, 864, 1152, 1728, 2304, 3456] factors 6693 > [3, 23, 69, 97, 291, 2231] factors 2778 [2, 3, 6, 463, 926, 1389] factors 4027 [ Note that the output for the last example is an empty list since 4,027 is a prime number and it has no proper factor Download the three files CSC207a3Tester.hs", "CSC207a3TestData.hs", and "CSC207a3.hs" from Canvas and save them in the same folder. The first two files are the tester program and the testing data file, respectively. Do not modify these two files. The last file is the file you will work on. Note that you cannot rename this file and you cannot change the name of the function (otherwise the tester will not be able to pick up your implementation) However, you can change the names of the parameters if you like. Also note that the first line is required for the tester to locate your code so don't modify it. The file "CSc207a3.hs" contains a dummy implementation of the function that always returns a singleton list with the input parameter as its only element (since a value cannot be a proper factor of itself, it is always incorrect). The contents of the file "cSc207a3.hs" is listed here for your reference module CSC207a3 where factor Integer -> Integer factor n-[n] The tester program will use the test data to test your implementation. It will run a total of 100 test cases. To see the result, just load the tester into GHCi and ask it to show the value of results. If your function is implemented correctly, it should produce the following output Prelude> load "CSC207a 3Tester.hs" [1 of 31 Compiling CSC207a 3TestData CSC207a3TestData.hs, interpreted) [2 of 3] Compiling CSC207a 3 [3 of 3] Compiling CSC207a3Tester CSC207a 3Tester.hs, interpreted) Ok, modules loaded: CSC207a3Tester, CSC207a3, csc207a3Test Data. CSC207a3Tester> results (15.0, [1,2,3, 4,5, 6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20,21,22,23,24,25, 26, 27,28,29,30,31,32,33,34,35,36, 37,38,39,40,41,42,43,44,45,46,47,48,49,5 0,51,52,53,54,55,56,57,58,59,60, 61,62,63, 64, 65, 66, 67,68,69,70,71,72,73,74 , 75,76,77, 78,79, 80, 81,82, 83, 84,85,86,87,88,89,90,91,92,93,94,95, 96,97,98, 99,1001, CSC207a3.hs, interpreted The result contains a tuple of three values. The first (highlighted in green) is a floating point value representing your score (on a scale of 15 points). The second (highlighted in blue) is a list of all test cases that you passed. The third (highlighted in pink) is a list of all test cases that you failed. If you would like, you can look up the test data from the file csc207a 3TestData.hs. This file defines a single list named tests, which consists 100 tuples. Each tuple is a test, and it has three (3) values inside: The first is an integer representing the test id . The second is the value of n representing the parameter to the function .The third is a list representing the expected result of calling factors using the input parameters The following is the first few lines in the test data file: module CSC207a3TestData where tests:: (Integer, Integer, [Integer]) tests-[1, 843, [3, 281]), 2, 3281, [17, 193]) 3, 6912, [2, 3, 4, 6, 8, 9, ,1152, 1728, 2304, 34561) 4, 6693, 3, 23, 69, 97, 291, 22311) 5, 2778, [2, 3, 6, 463, 926, 13891) 6, 4027,) Notes: 1. Your program will be tested with similar but different data. The testing results will earn 2. The remaining 5 points will be awarded based on the structure, readability, and 3. Your function CANNOT use recursion and/or list comprehension. (That means you must 4. You cannot have any import statement in your program. you up to 15 points (out of 20 points total) documentation of your implementation use higher order functions.) module CSC207a3 where factors : Integer-[Integerl factorsnIn] module CSC207a3Tester where import csC207a3 import CSC207a3TestData compareList [Integer]-Integer] -Bool compare List [] [] = True compareList [False compare List- [] = False compareList (x:xs) (y:ys) xycompareList xs ys | otherwise = False testOne n expected = compa reList expected (factors n) testAll tests(i, testOne n expected) I(i, n, expected) [Integer] That is, it takes an Integer and returns a list of Integer. The elements in the list are all proper factors of the parameter, and they must be in ascending order. The followings are some examples: factors 8433, 281] factors 3281 [17, 193] factors 6912 > [2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 27, 32, 36, 48, 54,64, 72, 96, 108, 128, 144, 192, 216, 256, 288, 384, 432, 576, 768, 864, 1152, 1728, 2304, 3456] factors 6693 > [3, 23, 69, 97, 291, 2231] factors 2778 [2, 3, 6, 463, 926, 1389] factors 4027 [ Note that the output for the last example is an empty list since 4,027 is a prime number and it has no proper factor Download the three files CSC207a3Tester.hs", "CSC207a3TestData.hs", and "CSC207a3.hs" from Canvas and save them in the same folder. The first two files are the tester program and the testing data file, respectively. Do not modify these two files. The last file is the file you will work on. Note that you cannot rename this file and you cannot change the name of the function (otherwise the tester will not be able to pick up your implementation) However, you can change the names of the parameters if you like. Also note that the first line is required for the tester to locate your code so don't modify it. The file "CSc207a3.hs" contains a dummy implementation of the function that always returns a singleton list with the input parameter as its only element (since a value cannot be a proper factor of itself, it is always incorrect). The contents of the file "cSc207a3.hs" is listed here for your reference module CSC207a3 where factor Integer -> Integer factor n-[n] The tester program will use the test data to test your implementation. It will run a total of 100 test cases. To see the result, just load the tester into GHCi and ask it to show the value of results. If your function is implemented correctly, it should produce the following output Prelude> load "CSC207a 3Tester.hs" [1 of 31 Compiling CSC207a 3TestData CSC207a3TestData.hs, interpreted) [2 of 3] Compiling CSC207a 3 [3 of 3] Compiling CSC207a3Tester CSC207a 3Tester.hs, interpreted) Ok, modules loaded: CSC207a3Tester, CSC207a3, csc207a3Test Data. CSC207a3Tester> results (15.0, [1,2,3, 4,5, 6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20,21,22,23,24,25, 26, 27,28,29,30,31,32,33,34,35,36, 37,38,39,40,41,42,43,44,45,46,47,48,49,5 0,51,52,53,54,55,56,57,58,59,60, 61,62,63, 64, 65, 66, 67,68,69,70,71,72,73,74 , 75,76,77, 78,79, 80, 81,82, 83, 84,85,86,87,88,89,90,91,92,93,94,95, 96,97,98, 99,1001, CSC207a3.hs, interpreted The result contains a tuple of three values. The first (highlighted in green) is a floating point value representing your score (on a scale of 15 points). The second (highlighted in blue) is a list of all test cases that you passed. The third (highlighted in pink) is a list of all test cases that you failed. If you would like, you can look up the test data from the file csc207a 3TestData.hs. This file defines a single list named tests, which consists 100 tuples. Each tuple is a test, and it has three (3) values inside: The first is an integer representing the test id . The second is the value of n representing the parameter to the function .The third is a list representing the expected result of calling factors using the input parameters The following is the first few lines in the test data file: module CSC207a3TestData where tests:: (Integer, Integer, [Integer]) tests-[1, 843, [3, 281]), 2, 3281, [17, 193]) 3, 6912, [2, 3, 4, 6, 8, 9, ,1152, 1728, 2304, 34561) 4, 6693, 3, 23, 69, 97, 291, 22311) 5, 2778, [2, 3, 6, 463, 926, 13891) 6, 4027,) Notes: 1. Your program will be tested with similar but different data. The testing results will earn 2. The remaining 5 points will be awarded based on the structure, readability, and 3. Your function CANNOT use recursion and/or list comprehension. (That means you must 4. You cannot have any import statement in your program. you up to 15 points (out of 20 points total) documentation of your implementation use higher order functions.) module CSC207a3 where factors : Integer-[Integerl factorsnIn] module CSC207a3Tester where import csC207a3 import CSC207a3TestData compareList [Integer]-Integer] -Bool compare List [] [] = True compareList [False compare List- [] = False compareList (x:xs) (y:ys) xycompareList xs ys | otherwise = False testOne n expected = compa reList expected (factors n) testAll tests(i, testOne n expected) I(i, n, expected)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started