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}"...
/** * 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 ListOfNVersion02PartA {    public int[] list; // Note: no "= {0, 1, 2, 3}"...
Write a Scheme function that takes a list of integers and returns all odd integers on...
Write a Scheme function that takes a list of integers and returns all odd integers on the list in the original order: (odd-numbers `(2 4 9 16 25 7)) (9 25 7) Hint: 2 (remainder 13 5) 3 Please explain every step
Write a Scheme function that takes two integers and returns the list of all integer numbers...
Write a Scheme function that takes two integers and returns the list of all integer numbers between these two integers (inclusively) in increasing order. (numbers 10 20) (10 11 12 13 14 15 16 17 18 19 20) Please explain every step.
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).
Variable trials refers to a list where each list item is another list of 3 integers...
Variable trials refers to a list where each list item is another list of 3 integers between 0 and 9. Imagine each list of 3 integers is a combination of numbers of a lock. Further suppose the variable code refers to a list of three integers that is the correct combination of the lock. Write a program which, assuming trials and code are already defined, prints out a character for each digit of each trial. Print Y if the digit...
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)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT