15-110 PS8 Sample Solutions - Spring 2018 1. (a) - means negation, ^ means and, v means or: -A ^ B ^ -C ^ -D (for 4) v -A ^ B ^ -C ^ D (for 5) v -A ^ B ^ C ^ -D (for 6) v A ^ -B ^ -C ^ -D (for 8) v A ^ -B ^ -C ^ D (for 9) (b) - ( (-A ^ B ^ -C ^ D) v (-A ^ B ^ C ^ -D) ) 2. Computers execute instructions in binary. An interpreter allows us to write in a language we can read and it will translate to binary instructions for us that the computer can execute. 3. (a) Sequence: (1) 0 5 12 9 8 13 4 1 , Period = 8 (b) The last digit repeats after every 10 numbers so the next number will end with a 4. 4. (a) return randrange(1,11) (b) return randrange(5, 101, 5) OR return randrange(1, 21) * 5 (c) return 2 ** randrange(1, 7) OR return 2 ** randrange(0,6) * 2 OR return 2 ** (randrange(6) + 1) (d) cube = ["A" "K", "Q", "J", "10", "9"] return cube[randrange(0,6)] 5. (a) In the total update, the dice are re-rolled so we're not adding the values that were tested in the if statement. (b) die1 = roll() die2 = roll() if die1 != die2: total = total + die1 + die2 else total = 0 6. (a) deck[randrange(26,52)] OR deck[randint(26,51)] OR sample(deck[26:],1)[0] OR choice(deck[26:]) (b) hand[0][0]==hand[1][0]==hand[2][0]==hand[3][0] hand[1][0]==hand[2][0]==hand[3][0]==hand[4][0] Clever solution: hand[0][0]==hand[3][0] hand[1][0]==hand[4][0]