Question

In: Computer Science

(dominoes N) which returns a list containing the (N+1)(N+2)/2 tiles in a double-N domino set, with...

(dominoes N) which returns a list containing the (N+1)(N+2)/2 tiles in a double-N domino set, with each tile represented as a dotted pair (an improper list).

(dominoes 2) ⇒ ((2 . 2) (2 . 1) (2 . 0) (1 . 1) (1 . 0) (0 . 0))

using the programming language scheme

i need the question to be answered using the programming language Scheme

Solutions

Expert Solution

Code:

(define (domineos n)
(cond ((= n 0) (cons (cons n n) '())) ;;if n = 0 returns '((0 . 0))
(else (append (helper n n) (domineos (- n 1)))))) ;;else appends two list of pairs


(define (helper n count) ;;Helper_Function Returns list of pairs. ex:(helper 2 2) returns ((2 . 2) (2 . 1) (2 . 0))

(cond ((= count 0) (cons (cons n 0) '())) ;;if count = 0 then return '((n . 0))
(else (append (cons (cons n count) '()) (helper n (- count 1)))))) ;;else append lists and continue

Snapshot of Code and Output:


Related Solutions

Write a function child_indices(parent, branch_factor) that returns a list containing the list of indices where the...
Write a function child_indices(parent, branch_factor) that returns a list containing the list of indices where the children of the node at index parent will be stored for a heap list with the given branch_factor (ie, a branch_factor-heap). Python language Notes: The function should return all possible indices and the indices should be in order from smallest to biggest. The values in the heap list start at index 1 - that is the root of the heap is at index 1...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Double Linked List. 5. Insert a new node at the end of a DoubleLinked List 6. Insert a new node after the value 5 of Double Linked List 7. Delete the node with value 6. 8. Search an existing element in a...
There are n boxes, the 1st one containing 1 glass, the 2nd box containing 2 glasses,...
There are n boxes, the 1st one containing 1 glass, the 2nd box containing 2 glasses, the 3rd box containing 3 glasses, . . . , kth box containing k glasses, . . . nth box containing n glasses. In each box every glass is broken with probability 1/2 independently of all other glasses. A contestant chooses a box uniformly at random. Given that he found no broken glasses in this box, find the probability that he choose the 1st...
Using C (not C++): setFirst - returns value with n upper bits set to 1 and...
Using C (not C++): setFirst - returns value with n upper bits set to 1 and 32-n lower bits set to 0 * You may assume 0 <= n <= 32 * Example: setFirst(4) = 0xF0000000 * Legal ops: ! ~ & ^ | + << >> (NO IF OR FOR LOOPS) * Max ops: 10 * Rating: 2
1. Given a data set with n = 10 observations, containing one independent variable, find the...
1. Given a data set with n = 10 observations, containing one independent variable, find the critical value for an F-test at α = 2.5% significance. Show your answer with four decimal places 2. Given the following portion of an output produced by a regression software package (with some values missing), find the value of MSR: ANOVA df SS MS F Significance F Regression 9 980.4187 ? ? ? Residual 75 220.7745 ? Total 84 1201.1932 Round your answer to...
1.Write a function div7(lst) which takes in a list of integers, and returns a list of...
1.Write a function div7(lst) which takes in a list of integers, and returns a list of booleans of the same length, such that for each integer in the original list, the boolean in the output list is True if that integer was divisible by 7, or False if not. Use list comprehensions in python, the function only could be at most two lines long. Here is some examples: >>> div7([14, 5, 7, 3, 29, 28, 10]) [True, False, True, False,...
Which codes add 1 to integer n? 1) n=n+1; 2) n++; 3)++n; 4) n+=1; 5) n=--n+2
Which codes add 1 to integer n? 1) n=n+1; 2) n++; 3)++n; 4) n+=1; 5) n=--n+2
Q1- Given a set S = {1, 2, . . . , n} of players, with...
Q1- Given a set S = {1, 2, . . . , n} of players, with skill levels a1, a2, . . . , an, we need to partition the set of players S into two teams S1 and S2 of equal total skill. The teams do not need to be of equal size. However, every player must be in exactly one team. In other words, S1 ∪ S2 = S                                        (1) S1 ∩   S2 = ∅                                                     (2) Σ ak=...
(2) Let Z/nZ be the set of n elements {0, 1, 2, . . . ,...
(2) Let Z/nZ be the set of n elements {0, 1, 2, . . . , n ? 1} with addition and multiplication modulo n. (a) Which element of Z/5Z is the additive identity? Which element is the multiplicative identity? For each nonzero element of Z/5Z, write out its multiplicative inverse. (b) Prove that Z/nZ is a field if and only if n is a prime number. [Hint: first work out why it’s not a field when n isn’t prime....
(1) Show that the set { 1 m + 1 n : m, n ∈ N}...
(1) Show that the set { 1 m + 1 n : m, n ∈ N} is countable. (2) Show that the set {a + b √ 2 : a, b ∈ Q} is countable. (3) Show that the intersection of two countable sets is countable. (4) Show that the set of all irrational numbers is uncountable. (5) Let C = {0, 1, 2, . . . , 9}. Show that the set C ×C × · · · is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT