Menu

[Solved]Write Function Occurn Takes Two Lists L1 L2 Counts Many Times Atom L1 Occurs L2 Q37206508

Write the function occurN which takes two lists l1 and l2 andcounts how many times an atom in l1 occurs in l2
Write the function occurN which takes two lists 11 and 12 and counts how many times an atom in 11 occurs in 12 Examples: (occ(rember2 ice (ice cream with fruit and ice cream with fudge)) returns (ice cream with fruit and cream with fudge). (rember2Write the function occurN which takes two lists 11 and 12 and counts how many times an atom in 11 occurs in 12 Examples: (occurN ‘(fudge ice cream) ‘(ice cream with fruit for dessert)) returns 2. (occurN ‘(fudge fruit) (ice cream with fruit for dessert)) returns 1. (fudge ice cream)) returns 0. Write the function dot-product of two vectors (ie., list of mumbers) 11 and 12 that multiplies corresponding numbers in 11 and 12 and builds a new number by summing the results. The vectors are of the same length Example: (dot-product , (1 23) , (3 24)) returns 19. Write the function subset which takes two lists 11 and 12 and returns true if 11 is a subset of 12 Examples: (subset ‘(1 2) (0 3 2 1)) is true (subset (1 2)(0 3 2 4)) is false (subset (0 3 2 1)) is true rite the function insertL which takes three arguments: the atoms new and old, and a list of atoms. It builds a list with new inserted to the left of the first occurrence of old. Example: (insertL ‘fudge ‘fruit ‘(ice cream with fruit for dessert)) returns (ice cream with fudge fruit for dessert) Write the function substall which takes three arguments: the atoms new and old, and a list of atoms. It builds a list in which all occurrences of old are replaced by new Examples: (substall ‘fudge ‘fruit(ice cream with fruit and more fruit)) returns (ice cream with fudge and more fudge) Write the function rember2 which takes two arguments: an atom a and a list of atoms 1 and removes the second occurrence of a in 1 Examples: (rember2 ‘fudge (ice cream with fruit for dessert)) returns (ice cream with fruit for dessert) (rember2 ‘ice ‘(ice cream with fruit and ice cream with fudge)) returns (ice cream with fruit and cream with fudge). (rember2’ice )) returns ). Hint: Use the function rember that we wrote in class. Write the function pair which takes two lists 11 and 12 of the same length and returns a list of two-element lists containing successive pairs of an element from each Example: (pair ‘(a b c'(1 2 3)) returns ( (a 1) (b 2) c 3) . Write a function assoc that takes an atom x and a list 1 of the form created by pair (in the previous question) and returns the second element of the first list in 1 whose first element is x. Example: (assoc y ‘((x a) (y b) (z c))) returns b. Show transcribed image text Write the function occurN which takes two lists 11 and 12 and counts how many times an atom in 11 occurs in 12 Examples: (occurN ‘(fudge ice cream) ‘(ice cream with fruit for dessert)) returns 2. (occurN ‘(fudge fruit) (ice cream with fruit for dessert)) returns 1. (fudge ice cream)) returns 0. Write the function dot-product of two vectors (ie., list of mumbers) 11 and 12 that multiplies corresponding numbers in 11 and 12 and builds a new number by summing the results. The vectors are of the same length Example: (dot-product , (1 23) , (3 24)) returns 19. Write the function subset which takes two lists 11 and 12 and returns true if 11 is a subset of 12 Examples: (subset ‘(1 2) (0 3 2 1)) is true (subset (1 2)(0 3 2 4)) is false (subset (0 3 2 1)) is true rite the function insertL which takes three arguments: the atoms new and old, and a list of atoms. It builds a list with new inserted to the left of the first occurrence of old. Example: (insertL ‘fudge ‘fruit ‘(ice cream with fruit for dessert)) returns (ice cream with fudge fruit for dessert) Write the function substall which takes three arguments: the atoms new and old, and a list of atoms. It builds a list in which all occurrences of old are replaced by new Examples: (substall ‘fudge ‘fruit(ice cream with fruit and more fruit)) returns (ice cream with fudge and more fudge) Write the function rember2 which takes two arguments: an atom a and a list of atoms 1 and removes the second occurrence of a in 1 Examples: (rember2 ‘fudge (ice cream with fruit for dessert)) returns (ice cream with fruit for dessert)
(rember2 ‘ice ‘(ice cream with fruit and ice cream with fudge)) returns (ice cream with fruit and cream with fudge). (rember2’ice )) returns ). Hint: Use the function rember that we wrote in class. Write the function pair which takes two lists 11 and 12 of the same length and returns a list of two-element lists containing successive pairs of an element from each Example: (pair ‘(a b c'(1 2 3)) returns ( (a 1) (b 2) c 3) . Write a function assoc that takes an atom x and a list 1 of the form created by pair (in the previous question) and returns the second element of the first list in 1 whose first element is x. Example: (assoc y ‘((x a) (y b) (z c))) returns b.

Expert Answer


Answer to Write the function occurN which takes two lists l1 and l2 and counts how many times an atom in l1 occurs in l2… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *