CS6373 Programming Languages
For this assignment we will use Scheme. Instructions
1. Create a file called `netid_hw_xx.yz` where netid is your NYU Net ID, xx is the assignment number and yz is hs/py/pl/jl.
2. For each of the following questions below create the corresponding functions and solve them with the constraints provided.
Note
1. Test your code by importing functions to another file. Do not create main method or modules unless otherwise specified.
2. The test cases given are not exhaustive.
3. Brute force solutions are acceptable but aim to optimize within the constraints of the problem.
4. Comment your approach. Be brief and not verbose.
5. It is okay to refer documentations of languages.
6. Ensure your file compiles/executes.
7. When creating helper functions assume that similar constraints apply to helper functions as the original problem.
What to submit ?
Submit a file named as netid_hw_xx.yz where netid is your NYU Net ID, xx is the assignment number and yz is the extension of the file relevant to this assignment. For example if you are submitting homework 9 with Haskell code and your netid is st780 you need to submit a file named st780_hw_9.hs.
The submission is auto graded so please name the file as requested.
Questions
Question 1 – Given an alphanumeric string made up of digits and lower case ASCII characters only, find the sum of all the digit characters in the string.
The function signature for `sumDigits` is –
(define sumDigits …)
1. Constraints –
– Not allowed to use library functions. This means no import statement. – No loops or list comprehension. The solution must be recursive.
– Do not use length of string in any function.
2. Input to function `sumDigits`- – An alphanumeric string.
3. Output of function
– Sum of all the digits in the string.
4. Sample test case
Test case 1
calling sumDigits ab1c2d3e54 outputs 15 = 1 + 2 + 3 + 5 + 4
Question 2 – Every country has a unique 2 letter country code. The full list of 2 letter country codes can be found here- https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes. Given a string S composed of captial ASCII letters(A hrough Z), find the number of distinct country codes present in S.
(define countCodes …)
1. Constraints –
– Not allowed to use library functions. This means no import statement. – No loops or list comprehension. The solution must be recursive.
– Do not use length of string anywhere.
2. Input to function `countCodes`-
– A string of upper case alphabets.
3. Output of function
– An integer representing the count of distinct country codes in the string.
4. Sample test case
Test case 1
calling countCodes AINBCO outputs 2 because IN and CO are two country codes of India and Colombia respectively.
Question 3 – Given a string of N characters represented as A = A1……..An. Print the size of the largest substring of A such that no two characters in the substring are same (or all characters are distinct).
(define uniqueSubstring…)
1. Constraints –
– Not allowed to use library functions. This means no import statement.
2. Input to function `uniqueSubstring`-
– A string consisting of lower case ASCII letters.
3. Output of function
– Length of the largest substring containing distinct letters.
4. Sample test case
Calling uniqueSubstring abaacb outputs 3 which is the length of the substring “acb”.