Question

In: Computer Science

give an arbitrary list of integers, how many are 3? (in scheme)

give an arbitrary list of integers, how many are 3? (in scheme)

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

;; name the function as count that takes a number(3 in our case) and a list of numbers

(define (count x L)

      ( ;;if the list is null, then return 0 number of occurrences of x

if (null? L)

        0

        (if (eq? x (car L)) ;; for each number in the list if x is equal to that number,

          (+ 1 (count x (cdr L))) ; increase the count

          (count x (cdr L))))) ;; finally return the output of total count of x occurences

Ex:

(count 3 (list 1 3 3 0 12 -5) )

==================


Related Solutions

/** * This class maintains an arbitrary length list of integers. * * In this version:...
/** * This class maintains an arbitrary length list of integers. * * In this version: * 1. The size of the list is *VARIABLE* after the object is created. * 2. The code assumes there is at least one element in the list. * * This class introduces the use of structural recursion. * * @author Raymond Lister * @version May 2016 * */ public class ListOfNVersion03PartB {    private int thisNumber; // the number stored in this node...
/** * This class maintains an arbitrary length list of integers. * * In this version:...
/** * This class maintains an arbitrary length list of integers. * * In this version: * 1. The size of the list is fixed after the object is created. * 2. The code assumes there is at least one element in the list. * * This class introduces the use of loops. * * @author Raymond Lister * @version September 2015 * */ public class ListOfNVersion02PartB {    public int[] list; // Note: no "= {0, 1, 2, 3}"...
how many integers from 0 through 999,999 contain the digit 4 exactly twice? how many integers...
how many integers from 0 through 999,999 contain the digit 4 exactly twice? how many integers from 1 through 1000000 contain the digits 6 at least once
Use Scheme Language Write a Scheme function that takes a list and returns a list identical...
Use Scheme Language Write a Scheme function that takes a list and returns a list identical to the parameter except the third element has been deleted. For example, (deleteitem '(a b c d e)) returns ‘(a b d e) ; (deleteitem '(a b (c d) e)) returns ‘(a b e).
How many integers larger than 3, 000, 000 can be formed by arranging the digits 1,...
How many integers larger than 3, 000, 000 can be formed by arranging the digits 1, 1, 2, 5, 5, 6, 9? How many can we form so that the digit is immediately followed by a larger digit?
1. (a) How many integers from 197 to 603 are divisible by 4? (b) How many...
1. (a) How many integers from 197 to 603 are divisible by 4? (b) How many integers from 97 to 995 are divisible by 6? (c) If the largest of 87 consecutive integers is 255 then what is the smallest? 2. Compute the following: (a)9! (b)P(15,8) (c)8! (d)P(3,6)
Let us choose seven arbitrary distinct positive integers, not exceeding 24. Show that there will be...
Let us choose seven arbitrary distinct positive integers, not exceeding 24. Show that there will be at least two subsets chosen from these seven numbers with equal total sums. (Keep in mind that sets, and hence subsets, have no repeated elements.) Hint: How many subsets can you form altogether? What is the largest total sum of such a subset?
Python: How would I write a function using list comprehensions to list of integers into two...
Python: How would I write a function using list comprehensions to list of integers into two halves with the evens first, followed by odds? And on top of that, the numbers should be listed in their original order.
Question 3 You should form the list of integers with your student ID. The numbers are...
Question 3 You should form the list of integers with your student ID. The numbers are generated as follows: Number Based on your student ID number, formed by its … a 1 st and 2nd digits b 2 nd and 3rd digits c 3rd and 4th digits d 4th and 5th digits e 5th and 6th digits f 6th and 7th digits g 7th and 8th digits For example, the student ID is 19563755A. Values of a to g are:...
scheme: Write a recursive Scheme function (subst x y L), which returns a list identical to...
scheme: Write a recursive Scheme function (subst x y L), which returns a list identical to L except that every occurrence of x has been replaced with y. The following example illustrates the use of this function: > (subst 'c 'k '(c o c o n u t)) (k o k o n u t) Write a recursive Scheme function (all-different? L), which determines whether all elements of list L are distinct (that is, not equal?). The following example illustrates...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT