Solutions to other tests:
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  

Mathematics for the Digital Age
and
Programming in Python


>>> Second Edition

Test 10

1.
(a) T   (b) F   (c) F
2.
B
3.
4.
A
5.
D
6.
(a), (b), (c)
7.
(a), (b)
8.
(a) T   (b) T   (c) T
9.
(a), (b), (c)
10.
C
11.
(a), (b), (c)
12.
A
13.
C
14.
(a), (b), (e)
15.
(a) F   (b) T   (c) F
16.
(a), (c)
17.
(a), (c), (d)
18.
(a), (c)
19.
C
20.
(b), (c)

21.
def addTwoParityBits(s): for pos in range(2): parity = 0 i = pos while i < len(s): if s[i] == '1': parity += 1 i += 2 s += str(parity % 2) return s
22.
def isbn13CheckDigit(digits): lst = [int(d) for d in digits] s = (sum(lst[0::2]) + sum([3*d for d in lst[1::2]])) s = (10 - s % 10) % 10 return str(s) digits = input('Enter the 11-digit ISBN prefix: ').strip() print() for d in range(10): d12 = str(d) print(digits + d12 + isbn13CheckDigit(digits + d12))
23.
12 * (h % 30)
24.
The second player wins.  The winning strategy is to always take the stones that are positioned symmetrically with respect to the center to the stones just taken by the first player.
25.
This game is isomorphic to NIM with the number of stones in the first pile equal to the number of empty squares to the left of the leftmost coin; the number of stones in the second pile equal to the number of empty squares to the right of the rightmost coin; the remaining piles, which correspond to the contiguous blocks of empty squares between two coins, have one stone in each.  The given example corresponds to the [3, 2, 1, 1] NIM position.  It is not a safe position, so the first player can win.
26.
def mark_positions(board): lst = list(board) n = len(board) i = n - 1 while i >= 0: if lst[i] == 'O': if '+' in lst[i+1:i+3]: lst[i] = '-' else: lst[i] = '+' i -= 1 return "".join(lst)



Copyright © 2010 by Skylight Publishing