problem 1: tournament selection - informaticsccgs … computing competition 2016 junior – mr...
TRANSCRIPT
Canadian Computing Competition 2016 Junior – Mr Honnens’s solutions using Python 3.5
Page 1 of 5
Problem 1: Tournament Selection
The big idea in this code is to place the six game outcomes in a list and then count how many wins there are! Also, note how wins == 5 or wins == 6 is equivalent to wins in [5,6].
Canadian Computing Competition 2016 Junior – Mr Honnens’s solutions using Python 3.5
Page 2 of 5
Problem 2: Magic Squares
The big idea in this code is to use list comprehensions to quickly represent both the rows and the columns as lists of integers. Also, when placing the rows after each other, each fourth element will be in the same column! Finally, note how r1 == r2 and r2 == r3 can be written as r1 == r2 == r3.
Canadian Computing Competition 2016 Junior – Mr Honnens’s solutions using Python 3.5
Page 3 of 5
Problem 3: Hidden Palindrome
The big idea in this code is to systematically find every substring of the word using two for-loops to identify the first and last index respectively. Also, note that even though a string is immutable you can reverse it using [::-1]!
Canadian Computing Competition 2016 Junior – Mr Honnens’s solutions using Python 3.5
Page 4 of 5
Problem 4: Arrival Time
The big idea in this code is to simulate the drive. Also, note that the times in 24-hour format can be easily sorted and compared.
Canadian Computing Competition 2016 Junior – Mr Honnens’s solutions using Python 3.5
Page 5 of 5
Problem 5: Tandem Bicycle
The big idea in this code is sort lists and then find the sum of the n relevant speeds. Also, note how the list comprehensions make the code neat and tidy!