2)
import Data.List
convertPlural :: String -> String --function declaration
convertPlural word =
if isSuffixOf "y" word
then (init word) ++ "ies"
else word ++ "s"
3)
commonElem :: [String] -> [String] -> [String]
commonElem l1 l2 = l1 >>= (\s -> if s `elem` l2 then [s]
else [])
4)
countFound :: String -> [String] -> Int
countFound s sList = (length . filter (== s)) sList
5)
import Data.Char
rmLeadSp :: String -> String
rmLeadSp s = dropWhile (not . isAlpha) s
Haskell Programming 2. Returns the plural of a word by adding "s' unless the word ends...
Please use Haskell, thank you! For this question, you will implement (under specific constraints) a recursive function in Haskell that takes a list of characters as an argument and returns a list that contains only every third element from the argument list in the same order. As a clarifying example, this function, when passed the argument list “ABCDEFGHIJKLMNO”, should return the list “ CFILO”. It should also be noted that your function must work (i.e., not terminate with an error)...
In Haskell: Write a recursive function fibonacci that computes the n-th Fibonacci number. fibonacci :: Int -> Int Write a recursive function myProduct that multiplies all the numbers in a list. myProduct :: [Integer] -> Integer Using the technique of List Comprehension write a function that would remove even numbers from a list of lists. For Example: given input: [[1,2,3,4], [6,3,45,8], [4,9,23,8]] expected output: [[1,3], [3,45],[9,23]]. Show how the library function replicate :: Int -> a-> [a] that produces a...
Problem 1. Write a Python function times_i_at_odd(L) that takes as arguments a list L and returns a list consisting of the elements of L multiplied by the index number of the element at odd positions. (Use list comprehensions) >>> times_i_at_odd([1,2,3,4,5,6,7,8,9,10]) [2, 12, 30, 56, 90] Problem 2. Write a recursive function sum_cols(grid, n) that takes a list of lists of integers grid and integer n and returns the sum of column n in grid. For example, the call sum_cols([[1,2,3,4], [10,20,30,40],...
Help me with this Python Question a. build_word_dictionary (filename) – This builds a word dictionary indexed by words from the file who’s filename is provided as an argument. It uses the words as keys and the count of occurrences as values. It returns the dictionary it constructed. It can use the ‘tokenize()’ function that is provided in the lecture slides. b. inverse_dict(dict) – This method takes a dictionary (generated by build_word_dictionary() and inverts it (as was done with students and...
Please help with all four questions regarding LISP Programming.
Thank you.
Please answer all questions with output plesase.
LISP Programming Assignment
It is a good idea to start this assignment early; Lisp programming,
while not inherently difficult, often seem somewhat foreign at
first, particularly when it comes to recursion and list
manipulation. This assignment is loosely based on material by Dr.
Henri Casanova.
Problem #1 Define a function that takes two arguments and returns
the greater of the two.
Problem...
The digital hardness of an integer is measured by examining its representation in binary (base 2). Working from the ends of the representation inward, we remove/count corresponding pairs of leading and trailing 1s until we can no longer do so. The total number of 1s (bits) removed is the original number's digital hardness value. For example, suppose that we have an integer whose binary representation is 110101010101 (the binary representation always begins with a leading 1). We remove the leading...
Write a function count_vowels(s) that takes a string as an argument and returns the number of vowels ('a', 'e', 'i' 'o', 'u') in the string. Should you use a for or while loop? (Implement this as a function, not as a class with a method.) Be sure to include unittest test cases to demonstrate that your code works properly, e.g Part 2: last_occurance(target, sequence) Write a function last_occurance(target, sequence) that takes two arguments: 1. target: A target item to find...
Question 1. What function is used to remove leading and trailing whitespace from a string variable? A. trim B. strip C. remspaces D. empty Question 2. What statement is used to force a loop to stop processing the current iteration and start the next iteration? A. continue B. break C. The for-in loop D. While True Question 3. What function is used to add a value to a list? A. end...
In this assignment, you will explore more on text analysis and an elementary version of sentiment analysis. Sentiment analysis is the process of using a computer program to identify and categorise opinions in a piece of text in order to determine the writer’s attitude towards a particular topic (e.g., news, product, service etc.). The sentiment can be expressed as positive, negative or neutral. Create a Python file called a5.py that will perform text analysis on some text files. You can...
JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...