Computational and Algorithmic Thinking Book 2 - 2011-2015

5,788 547 2MB

English Pages 190 Year 2016

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

Computational and Algorithmic Thinking Book 2 - 2011-2015

Citation preview

COMPUTATIONAL AND ALGORITHMIC THINKING 2011—2015 BOOK 2

DAVID I CLARK

M

A

T

COMPUTATIONAL AND ALGORITHMIC THINKING 2011—2015 BOOK 2

DAVID I CLARK

Published by

Australian Mathematics Trust 170 Haydon Drive Bruce ACT 2617 AUSTRALIA

Copyright ©2016 AMT Publishing PDF edition 2018

Telephone: +61 2 6201 5136 www.amt.edu.au AMTT Limited ACN 083 950 341 National Library of Australia Card Number and ISSN Australian Mathematics Trust Informatics Series ISSN 1838-8086 Computational and Algorithmic Thinking 2011-2015 Book2 ISBN 978-1-876420-76-5

Contents

Introduction Computational and Algorithmic Thinking Algorithmic Thinking and the Australian Curriculum Acknowledgments

v v vi vi

Questions

1

Applying Rules

3

Logic

9

Analysis Searching Sorting Patterns Number of Routes How Many Ways? Analyse the Problem

19 19 19 21 23 26 31

Algorithms Breadth-first Search Shortest Path Maximum Flow Single Pass Algorithms Dynamic Programming Two Person Games Greedy Algorithm Lists Working Backwards Chains Ad Hoc Algorithms

35 35 48 51 51 54 57 62 64 66 67 68 iii

Solutions

81

Applying Rules

83

Logic

87

Analysis Searching Sorting Patterns Number of Routes How Many Ways? Analyse the Problem

93 93 94 96 98 101 105

Algorithms Breadth-first Search Shortest Path Maximum Flow Single Pass Algorithms Dynamic Programming Two Person Games Greedy Algorithm Lists Working Backwards Chains Ad Hoc Algorithms

109 109 121 125 126 128 132 139 144 146 148 150

Development of Algorithms

161

Statistics

173

High Distinction Students 2011 Competition 2012 Competition 2013 Competition 2014 Competition 2015 Competition

175 175 176 177 179 181

iv

Introduction

Computational and Algorithmic Thinking The Computational and Algorithmic Thinking (CAT) competition, formerly known as the Australian Informatics Competition (AIC), is a pre-programming competition taken annually by more than 7000 school students from Australia, New Zealand and a number of other AsiaPacific countries. It is run by the Australian Informatics Olympiad Committee (AIOC) and is intended to serve a number of purposes. Firstly, it introduces students and their teachers to algorithmic thinking, now a required component of the Australian Curriculum, through engaging problems without the need for programming skills. Secondly, it identifies students with the capacity to program and points them towards resources through which they can pursue this, and to further competitions which they can enter with a view to developing their programming skills. Finally, it is the first in a series of events that identify students who will represent Australia at the annual International Olympiad in Informatics (IOI). (The term informatics is used in Europe as a synonym for computer science.) The CAT has traditionally been a pen and paper competition, but in 2014 a decision was made to introduce an online version of the competition from 2015. In addition, a further division of the competition was introduced for Upper Primary students (Years 5 and 6). The questions in the CAT are designed to be quick to solve and highly approachable, and range in difficulty from very easy to challenging. The contest employs a mixture of multiple-choice and integer answers, and incorporates unique ‘three-stage tasks’ that encourage students to develop informal algorithms and apply them to test data of increasing size. The multiple-choice questions can be classified into four broad categories: ˆ applying the rules questions, that ask students to apply a well-defined set of rules to given data ˆ logic questions, that use non-algorithmic puzzles to encourage rigorous reasoning and case analysis ˆ analysis questions, where students are asked to understand the behaviour of an algorithm that solves a given problem ˆ algorithm questions, that encourage students to develop an informal algorithm to solve a given puzzle.

Explanations of these categories and their relevance are given in the ‘Solutions’ section of this book. v

The integer answer questions are typically algorithmic. Students must devise and follow some repeated systematic procedure. For each question the students are given three sets of data of increasing size. These questions are explicitly designed to entice students into formulating algorithms. The first data set is often small enough to be solved by ad hoc techniques. By the second, students should have a feel for the problem and be developing systematic procedures for solving the problem. These procedures can then be applied to the third data set. Algorithmic and analysis questions are often variations on well-known classes of problems such as shortest path problems (algorithm questions) and searching algorithms (analysis questions), and some students may have already encountered them. Other questions are not standard and students have to devise algorithms from the context of the problem. The ‘Questions’ section of the book presents the questions, organised by category and problem type. The ‘Solutions’ section gives the solutions and answers. Each category is given a general introduction, describing its relevance to information technology in general and programming in particular. Each problem type also has an introduction, including the practical applications of the problem type and an outline of the method of solution.

Algorithmic Thinking and the Australian Curriculum The Australian Curriculum has been developed over the last few years and is being adopted by all states and territories with implementation F – 10 scheduled to be complete by 2018. In the Technologies learning area of the Curriculum, there are two distinct but related subjects, one of which is Digital Technologies. For many teachers, the content of this subject will present quite a challenge, as it requires them to teach algorithmic thinking from the Foundation year and to introduce coding from as early as Year 3. Previously, this has been the preserve of a small number of courses in the senior years of the curriculum, but there is a worldwide demand for greater coding skills as a part of core education; Australia is not alone in promoting this type of thinking as a part of the compulsory curriculum. Victoria has taken a further initiative and included algorithmic thinking as a part of the mathematics curriculum. Other states are also looking at how this implementation will work in practice and who can best deliver the algorithmic content. There is a rapidly growing variety of resources to teach various different programming languages, but there is little point in learning a programming language without a good understanding of the algorithmic thinking which sits behind any purposeful computer program. In addition to providing many questions which promote this type of thinking, this book contains a background chapter on what an algorithm is and explores how questions can be analysed from an algorithmic perspective. We would prefer that teachers did not think of algorithmic thinking as yet another thing which they have to teach, but rather as a pedagogical approach to problem solving in general, a skill which will be transferable across many disciplines.

Acknowledgments The AIOC is a department of the Australian Mathematics Trust (AMT), which provides both financial and administrative support to the informatics program. Indeed, the formation of the AIOC in 1999 was an initiative of Professor Peter Taylor, then Executive Director of the AMT. Without the support of the AMT, the AIOC could not survive. The Chair of the CAT problems committee since 2007 has been David Clark, who is also the author of this book. For David, this has been a labour of love. His relentless and vi

continuing enthusiasm is amazing. The problems in the CAT have been devised by past and present members of the CAT problems committee: Ben Burton, Bernard Blackham, David Clark, David Kennedy, Andrew Gray, Katherine Kavanagh, David Ananian-Cooper, Dmitry Kamenetsky, Robert Newey, Christopher Chen, Judith Heglers and Mike Clapper. Their ability to construct new and interesting problems continues to astonish me. Thanks are also due to Margot Phillipps, Terry McClelland, Jan Honnens and Katherine Kavanagh: teachers who have provided second round moderation of the competition. Their comments and suggestions have helped to ensure that the problems are understandable by the students and accessible to them. Special thanks are due to Bernadette Webster for careful proofreading of this book, and of all of the CAT problems before they go to print, and to Heather Sommariva for the cover design. This book was typeset in TEX, the mathematical typesetting system designed by Donald Knuth. Many contributors have given freely of their time and expertise to extend the capabilities of TEX. The TikZ/PGF package written by Till Tantau was used in all of the diagrams in this book. Finally, special thanks are due to the late Ian Lisle for expert advice on all things TEX. Mike Clapper Executive Director Australian Mathematics Trust September 2016

vii

QUESTIONS

Applying Rules

1. Zabs

2011 J.1

On a distant planet, the dominant carnivore, the zab, is nearing extinction. The number of zabs born in any year is one more than the (positive) difference between the number born in the previous year and the number born in the year before that. Examples: If 7 zabs were born last year and 5 the year before, 3 would be born this year. If 7 zabs were born last year and 10 the year before, 4 would be born this year. 2 zabs were born in the year 2000 and 9 zabs were born in 2001. What is the first year after 2000 when just 1 zab will be born? (A) 2009

(B) 2011

(C) 2013

(D) 2015

(E) 2017

2. Word Search

2012 I.1

A word search uses the following special symbols: ? represents a single letter * represents any number of letters, including no letters. In order for a search term to match a word, it must represent the entire word from start to finish. For example, b * t matches bat but not bath. How many of the following words does b??st*ing match? blasting blustering boasting boosting bootstrapping bowstrings bristling busting (A) 2

(B) 4

(C) 5

(D) 6

3

(E) 7

4

applying rules

3. Uranium Storage

2014 J.5

For safety reasons, highly reactive uranium bars need to be stored in such a way that they are always as far away from others as possible, but once placed in storage they cannot be moved. An empty storage facility has 89 storage rooms all in a row. Unfortunately no-one has any idea how many bars will need to be stored. The first bar to arrive is put in room 1 and the second, in line with recommendations, is put in room 89. In which room could the 6th bar to arrive be placed? (A) 11

(B) 21

(C) 33

(D) 56

(E) 77

4. The Game of Life

2011 S.1

In Conway’s game of life, some cells of a grid are dead and some are alive. Two cells neighbour each other if they are adjacent horizontally, vertically or diagonally. At the end of each day – a dead cell becomes live if it had exactly 3 live neighbours during the day – a live cell becomes dead unless it had exactly 2 or 3 live neighbours during the day. In the following grid, a

indicates a live cell.

How many live cells will there be the next day?

(A) 5

(B) 6

(C) 8

(D) 9

(E) 10

5 5. Odysseus

2011 I.2

The intrepid adventurer Odysseus, on his way home from the sacking of Troy, has been diverted by rumours of treasure deep in the Cretan labyrinth. Ariadne, Minos’ daughter, has told Odysseus that – – – –

the labyrinth consists of square and circular chambers circular chambers lead to 1 or 2 square chambers square chambers lead to 1, 2 or 3 square or circular chambers the treasure is in a circular chamber.

Ariadne’s advisor, Machiavelli, who is not always reliable, has devised an algorithm to lead Odysseus to the treasure. 1. 2. 3. 4.

Never return directly to the chamber you have just left. If you can, enter a circular chamber. Enter a square chamber. Repeat steps 2 and 3 until you have found the treasure.

Odysseus starts at the circular chamber labelled S. D

T S

M

What will happen to Odysseus? (A) He will find the treasure in chamber T after visiting 3 square chambers. (B) He will find the treasure in chamber T after visiting 16 square chambers. (C) He will be eaten by the dragon in chamber D. (D) He will spend the rest of his life trapped by the wiles of the evil enchantress Morgan le Fey in chamber M. (E) He will die of exhaustion.

6

applying rules

6. Swapsies

2015 UP.2

Six girls, Anh, Bev, Chris, Dat, Emma and Fang are practising a new dance. They line up in order with Anh first: A B C D E F (using their initials). Then 1. A swaps with D. 2. Everyone reverses their order. (1st swaps with last, 2nd with 2nd last, etc.) 3. E swaps with the girl immediately behind her. 4. A swaps with D. 5. Everyone reverses their order. 6. E swaps with the girl in front of her. What is the new order of the dancers? (A) A B C D E F

(B) A B C E D F

(D) A B E D C F

(C) A B E C D F

(E) A E B C D F

7. Disco Lights (Junior)

2015 J.4

A DJ has a circle of lights that flash either blue or white. Each light is thus between exactly two other lights. He wants to write a program to give a dashing sequence, changing every second, and tries the following rule: At each change, a light turns (or remains) blue if it is between a white and a blue light, and turns (or remains) white if it is between two white or two blue lights. If his starting pattern is W B

W

B W

how many seconds will it take until the next time the lights display the starting pattern? (A) 2

(B) 3

(C) 4

(D) 5

(E) 6

7 8. Disco Lights (Intermediate)

2015 I.3

A DJ has a circle of lights that flash either blue or white. Each light is thus between exactly two other lights. He wants to write a program to give a dashing sequence, changing every second, and tries the following rule: At each change, a light turns (or remains) blue if it is between a white and a blue light, and turns (or remains) white if it is between two white or two blue lights. However, he has a fault in his electronics and if just one light is white his lights will shortcircuit. How many seconds will it take until just one light is white if his starting pattern is W

B

W

B

B

(A) 2

(B) 3

B

(C) 6

(D) 7

(E) It never happens

9. Disco Lights (Senior)

2015 S.1

A DJ has a circle of lights that flash either blue or white. Each light is thus between exactly two other lights. He wants to write a program to give a dashing sequence, changing every second, and tries the following rule: At each change, a light turns (or remains) blue if it is between a white and a blue light, and turns (or remains) white if it is between two white or two blue lights. Disappointingly, when he runs the program, the lights all quickly turn to white and stay white, no matter what his starting position. If his starting pattern is B B

W

B

W

W

B W

how many seconds will it take until all lights are white? (A) 2

(B) 3

(C) 4

(D) 5

(E) 6

8

applying rules

Logic

1. Least exactly 4 In a recent test of – 95 answered – 75 answered – 97 answered – 95 answered – 96 answered

2011 S.6

100 students, question 1 correctly question 2 correctly question 3 correctly question 4 correctly question 5 correctly.

What is the smallest number of students who could have answered exactly 4 of the 5 questions correctly? (A) 3

(B) 4

(C) 5

(D) 8

(E) 17

2. Wandering Robot

2011 J.4

The wandering robot is the latest innovation in military reconnaissance. Rather than go directly to its target, which would make it predictable and therefore vulnerable, it makes random moves in the general direction. The disadvantage is that it takes longer to reach its target. N

W

E

A move is either to the north (N), east (E), south (S) or west (W). S

One robot reached its target in the 22 moves E E N E N N W N E N E S E E E E E S S S W N. If it had been direct, how many moves would it have taken? (A) 8

(B) 10

(C) 12

(D) 13

9

(E) 14

10

logic

3. Paper Folding

2011 I.4

A piece of paper can be folded vertically or horizontally, and forward or backward. Vertical folds are from the left (the left goes to the right), and horizontal folds are from the bottom (the bottom goes to the top). vertical, forward

vertical, backward

horizontal, forward

horizontal, backward

After folding and unfolding the paper, the creases are depicted as shown below.

vertical, forward

vertical, backward

horizontal, forward

horizontal, backward

The piece of paper below has been folded four times and then unfolded.

The last two folds were (A) vertical forward, horizontal forward (B) vertical backward, horizontal forward (C) vertical backward, horizontal backward (D) horizontal forward, vertical backward (E) horizontal forward, horizontal backward

11 4–6. Ant

2011 S.13–15 Directions the ant faces 3

2

u n

1

w

e

s d

An ant is on the front face of a cube, facing up. It is trained to move around the cube by obeying the following instructions: F: move forward one side L: turn left, and move forward one side R: turn right, and move forward one side B: turn 180°and move forward one side. For example, if the ant is on side 1 facing up (1u) and receives the instruction R, it will move to side 2 facing north (2n). Then after the instruction L it would move to side 3 facing west (3w). For each set of instructions below, what is the final side the ant is on, and which direction is it facing? 4.

BB LLL LRLRLR FBFB

5.

RLRLRLRRRBFBFBBFB

6.

LRLBBRLRFBLLBBLFBBRRRBLL

Your answer will be a two-digit number. The first digit is the side. (Sides 4, 5 and 6 are opposite sides 1, 2 and 3 respectively.) The second digit will be the direction. Replace • up and down with 1 and 2 (for sides 1, 2, 4 and 5) • north and south with 3 and 4 (for sides 2, 3, 5 and 6) • west and east with 5 and 6 (for sides 1, 3, 4 and 6).

12

logic

7. Card Cutting

2012 S.3

Five people are playing a game of cards. There are 52 cards in the deck. Each person cut the pack. A ‘cut’ consists of taking the top N cards and putting them on the bottom, without otherwise changing their order. First Andrew cut 28 cards, then Kumar cut 31 cards, then Daniel cut 2 cards, then Mahendra cut some cards, then Graeme cut 21 cards. The final cut restored the pack to its original order. How many cards did Mahendra cut? (A) Fewer than 10

(B) Between 11 and 20

(D) Between 31 and 40

(C) Between 21 and 30

(E) More than 40

8. Fireworks

2012 J.1

Vera, Steve, Tim and Xiu are watching the new year fireworks from their respective homes. At midnight, a sequence of starburst fireworks is set off, one after the other. Each starburst is a single colour, red (R), blue (B), yellow (Y) or green (G). Due to trees and buildings in the way, no-one sees all of the fireworks. However, they all record the colours of the fireworks they do see, in the order that they see them. Later, they compare notes and try to work out what would have been seen by someone at the event. Vera saw Steve saw Tim saw Xiu saw

B R R B

B G B B

Y Y B G

G R R Y

Y Y Y G Y Y

Which of the following sequences is consistent with what they saw? (A) R B B G Y R G Y Y (B) R B B G Y R B Y Y (C) B G B R Y R G Y Y (D) B R B G Y R G Y Y (E) R B G B Y R G Y Y

13 9. Passwords

2012 I.3

Your rich uncle, who is something of a Luddite, is worried about your Facebook security. He has promised you a new mountain bike, provided you change your password each day for two years. You have negotiated him down to 720 days, but that is still a lot of passwords. Your current password is B I L T O X (the name of your sister’s cat). You decide that you will work through all the arrangements of the letters in B I L T O X in alphabetical order, B I L O T X, B I L O X T, . . . , X T O L I B. Which password will follow O X T I L B? (A) O X T I B L

(B) O X T L I B

(D) O X T B I L

(C) O X T L B I

(E) O X T B L I

10. Rail Fence Cipher

2012 S.2

The rail fence cipher first appeared in the US civil war. The message to be encrypted is written in a wavelike pattern, down, up, down, up, . . . on a fixed number of lines or rails. The cipher text is then read horizontally, rail by rail. For example, with three rails, the message K O O K A B U R R A S would be written down as K

A O

K

R B

O

R U

A S

and the encrypted message would be K A R O K B R A O U S. A message was encrypted using the rail fence cipher with three rails, giving O E T R Y T R A C E S S C H. What was the 7th letter of the message? (A) Y

(B) T

(C) R

(D) A

(E) C

11. Christmas Lights

2013 J.3

John has a string of coloured Christmas lights he’d like to hang up. Each light on the string is either red(R), blue(B) or green(G). However John has a very specific aesthetic taste for Christmas lights, and would like to remove some of the lights from the string so that the remaining sequence of lights is comprised of exactly two colours and alternates between them. For example, in the following initial sequence of lights: RBGBGRGBRGRBGBGBRGBRBGR John could remove all but the lights shown in bold below RBGBGRGBRGRBGBGBRGBRBGR to get a sequence of 6 alternating blue and red lights. BRBRBR What is the longest such row that could be obtained from the initial sequence of lights? (A) 11

(B) 12

(C) 13

(D) 14

(E) 15

14

logic

12. Messages From Space

2013 I.1

Messages sent to Earth from a spacecraft consist of the digits 1, . . . , 9. Some of the digits may be lost in transmission. To combat this, extra (redundant) information is sent so that the message can be reconstructed. In one scheme, d − 1 zeros are inserted after each digit d. For instance, the message 4 2 3 1 2 would be sent as 4 0 0 0 2 0 3 0 0 1 2 0. A message sent from the spacecraft was received as 0 0 4 0 3 0 0 1 0 2 4. What is the fewest number of digits that could have been lost? (Include zeros.) (A) 5

(B) 6

(C) 7

(D) 8

(E) 9

13. Semi-Sudoku

2013 J.1

You are teaching your young niece to play Sudoku. As a first step you tell her to fill in the following grid so that each row and each column contains the numbers 1, 2, 3, 4, 5 and 6. 6

1 

2

4

5

4

5

6



3

6

4

6

3

2

1

2

5

1

3

4

5

4

6

1

3

2

What is the sum of the two cells containing a ? (A) 5

(B) 6

(C) 7

(D) 8

(E) 9

14. Only Turn Right

2013 I.3

How many of the following diagrams can you draw without lifting your pen and without making any left turns? (You can start wherever you like, start drawing in any direction, and draw over lines more than once.)

(A) 1

(B) 2

(C) 3

(D) 4

(E) 5

15 15. Migrating Platypus

2014 J.6

The endangered migrating platypus of SW Tasmania nest in burrows in the upper reaches of the Ornithorhynchus River. After the platypups hatch, they swim downstream to their feeding grounds. This requires them to swim over the Anatinus falls.

3m

3m

3m

3m

3m

3m

rocks

rocks

rocks

river

The Anatinus Falls consists of a series of drops of 3 or 6 metres onto horizontal ledges. The platypups can survive a drop of 3 metres, but not 6 metres. And they do not survive dropping onto rocks. As a conservation measure, barriers are to be constructed at one or both ends of some of the ledges. What is the fewest number of barriers that would ensure the survival of all of the platypups? (A) 2

(B) 3

(C) 4

(D) 5

(E) 6

16

logic

16. Rectangles

2014 I.5

A grid has been subdivided into non-overlapping rectangles. One cell in each rectangle has been labelled with the area of the rectangle. Your task is to determine the rectangles from the labels. For instance, if you were given 4

you would deduce 4

6

6

2

2

4

4

Here is the grid. 6 8 4 5

2

3

×

3

2 8

4 4

What is the area of the rectangle containing the ×? (A) 2

(B) 3

(C) 4

(D) 6

(E) 8

17. Card Cutting 2

2015 S.2

Anna, Brett, Chris, David and Emma are playing a card game with a pack of 15 cards, each of which has one of the letters A, B, . . . , O. The cards are in order A B C D E F G H I J K L M N O with A on top. Anna takes some cards from the top. Then Brett takes some cards from the top of the remaining cards. Then Chris and David do likewise. Finally Emma takes the rest. Without changing the order of their cards, each one puts their cards back to form a new deck, giving H I M N O A B C J K L D E F G with H on top. When did David return his cards? (A) first

(B) second

(C) third

(D) fourth

(E) fifth

17 18. Wonder Fabric

2011 J.3

The 30 designers are all impressed with the new wonder fabric, and each wants to take back a sample for testing. There is one large piece of fabric that has to be cut into 30 samples. The machine takes several minutes to make each cut, and the designers are waiting, so you want to make as few cuts as possible. The fabric cannot be folded, but the machine can cut a stack of up to 5 pieces at a time. What is the smallest number of cuts required to cut the fabric into 30 pieces? (The pieces don’t have to be all the same size.) (A) 6

(B) 7

(C) 8

(D) 9

(E) 10

19. Great-uncle’s Will

2011 I.6, S.5

Your eccentric great-uncle has left you a bequest in his will. Sort of. He somehow got his hands on this weird little machine with a display and five buttons. The display shows four digits. The machine operates as follows. ˆ When the A button is pressed, the first digit decreases by 1. If it is on 0, it changes to 9. The B, C and D buttons do the same thing for the second, third and fourth digits. ˆ When the E button is pressed, every digit increases by 1. If any digit is on 9, it changes to 0.

The provision in the will is that $500 is to be shared between you and your undeserving younger sister. You have to press buttons to change the display from 4 4 4 4 to 1 5 6 7. (These numbers seem very strange. Your great-uncle was decidedly odd.) The will states that you start off with the $500, and every time you press the A, B, C or D button she gets $10, and every time you press the E button she gets $20. And she doesn’t have to do anything! What is the smallest amount that you can give her? (A) $150

(B) $190

(C) $230

(D) $270

(E) $290

20. Magic Carpet

2012 S.4

Anna, Beth, Coral, Dianne, Emma and Frances are going camping on an offshore island. They are using their magic carpet to get to the island. The magic carpet can only take 2 people at a time, so there will need to be 9 trips, 5 across carrying 2, and 4 returning carrying 1. Flying on a magic carpet can cause air sickness, so the speed of the carpet is determined by the rate at which the more susceptible passenger can travel. The times that Anna, Beth, Coral, Dianne, Emma and Frances can travel one way without queasiness are 1, 2, 7, 9, 11 and 12 minutes respectively. What is the least time, in minutes, required to fly all members to the island? (A) 33

(B) 37

(C) 41

(D) 45

(E) 49

18

logic

Analysis

Searching 1. Robot Guessers

2012 J.3

Alan, Beth, Con, Dan and Eve have each programmed their pet robots to play a guessing game. The robots have to find a number between 10 and 99, by being told whether its guesses were too high, too low or correct. Each of the robots found the number 17 in 8 guesses: Alan’s robot Beth’s robot Con’s robot Dan’s robot Eve’s robot

10 90 10 50 90

11 70 99 20 10

12 50 50 10 50

13 30 30 25 20

14 10 20 15 11

15 20 15 19 13

16 19 16 18 16

17 17 17 17 17

Clearly their strategy was not always very good. But only one of the robots made a logic error. Whose robot was it? (A) Alan’s

(B) Beth’s

(C) Con’s

(D) Dan’s

(E) Eve’s

Sorting 2. Swap Three

2014 I.4

You have a list of cards, each showing a single letter. You wish to sort them into alphabetical order (A B C. . . ). A move consists of reversing the order of three consecutive cards. For example, B D C A → C D B A or B A C D. Which of the following lists can be sorted into alphabetical order by a series of such moves? (A) F B C D E A

(B) C F A B E G D

(D) C F G A E D H B

(C) C F A B G D E (E) H B C F B D E G A

19

20

analysis

3–8. Selection Sort

2011 J.10–12, I.10–12

The Selection Sort algorithm is a simple, though usually inefficient, method of sorting a list. The algorithm works as follows: 1. Find the maximum value in the list. 2. Swap it with the value in the last position. 3. Repeat the steps above with the remainder of the list. Each of the following two examples shows an initial list and three passes of the Selection Sort algorithm. 1. B D A C → B C A D → B A C D → A B C D 2. B A D C → B A C D → B A C D → A B C D Note that in the first example 3 swaps were required. But in the second example only 2 swaps were required as the C was already in position at the second pass. For each of the following lists, how many swaps are necessary when the list is sorted using Selection Sort? 3.

6

2

1

5

4

3

4.

4 0 1 2 3 9 5 6 7 8 14 10 11 12 13 19 15 16 17 18 24 20 21 22 23

5.

4 3 2 1 0 9 8 7 6 5 14 13 12 11 10 19 18 17 16 15 24 23 22 21 20 29 28 27 26 25 ... 94 93 92 91 90 99 98 97 96 95

6.

7

3

2

6

1

4

5

7.

9

8

7

6

5

4

3

2

1

0

19 18 17 16 15 14 13 12 11 10 29 28 27 26 25 24 23 22 21 20 ... 999 . . . 990 8.

2

4

1

0

3

12 14 11 10 13 ... 92 94 91 90 93

7

9

6

5

8

17 19 16 15 18 97 99 96 95 98

Note: The first three lists were in the Junior paper, while the second three were in the Intermediate paper.

patterns

21

9–11. The iSorting Machine

2012 I.10–12

The iSorting machine sorts a list of numbers in the following way. It compares the first two numbers, and writes the smaller to a new list, removing it from the original list. If the numbers are the same, it writes one of them to the new list, again removing it from the original list. It repeats this procedure until there is only one number left, which it writes to the new list. This constitutes one pass of the iSorting machine. For example, if the original list was 3 3 1 then one pass of the iSorting machine would give 3 1 3. If the new list is not in order, the machine iSorts it, continuing until the list is sorted. The example above would be sorted to 1 3 3 by a second pass of the iSorting machine. For each of the following lists, how many passes of the iSorting machine would be required to sort the list? 9.

86429753

10.

43215432

11.

42133413

Patterns 12. Triangles (Junior)

2014 J.1

The Sierpinski triangle is a fractal that can be generated as shown.

The first four Sierpinski triangles are shown. How many downward-pointing (white) triangles are there in the 5th Sierpinski triangle? (A) fewer than 30 (D) 40 – 44

(B) 30 – 34

(C) 35 – 39

(E) more than 44

22

analysis

13. Triangles (Intermediate)

2014 I.1

The Sierpinski triangle is a fractal that can be generated as shown.

The first five Sierpinski triangles are shown. How many downward-pointing (white) triangles are there in the 6th Sierpinski triangle? (A) fewer than 100

(B) 100 – 149

(D) 200 – 249

(C) 150 – 199

(E) more than 249

14. Great-aunt’s Bathroom

2012 S.6

You are tiling your great aunt’s bathroom. You much prefer red to orange to yellow to green to blue to indigo tiles. However, she has bought a bunch of tiles on eBay, and as a result you have to use: at least as many indigo tiles as (blue + green + yellow + orange + red) tiles, at least as many blue tiles as (green + yellow + orange + red) tiles, at least as many green tiles as (yellow + orange + red) tiles, at least as many yellow tiles as (orange + red) tiles, at least as many orange tiles as red tiles. The bathroom will require 100 tiles. How many green tiles will you use? (A) 12

(B) 13

(C) 14

(D) 15

(E) 16

15. Chromatic Glow-worms

2012 I.2

The recently discovered chromatic glow-worms are named for their colour changes. Each night they glow with a different colour, cycling from R(red) → B(blue) → G(green) → O(orange) → R(red) → · · · In a recent trip to the rainforest, Anna has discovered a row of 5 chromatic glow-worms hanging from their threads. They are coloured R B B G B. When she returns in 3 weeks (21 days) time, the 5 chromatic glow-worms will be coloured (A) B G G O G

(B) B G G R G

(D) G O O B O

(C) G O O R O

(E) O R R B R

number of routes

23

16. Light Show

2011 S.3

The light show is produced by a row of coloured searchlights. Every 10 seconds one of the searchlights, the ‘active’ searchlight, is switched on if it is off, and off if it is on. Then the next searchlight in line becomes the active searchlight. For instance, if the row consisted of a red, a green, and a blue searchlight, with the red and blue searchlights on and the green one off, and the red one active, then after 10 seconds the red one would be switched off and after another 10 seconds the green one would be switched on, and so on. The sequence is illustrated below (upper case indicates on, lower case indicates off). RgB → rgB → rGB → rGb → RGb → ... A light show had a row of 10 searchlights, coloured white, red, orange, yellow, chartreuse, green, aqua, blue, indigo, violet. At the start of the show the white searchlight was active and the switches were WroYCGabiv The show lasted for 6,265 seconds. How many searchlights were on at the end of the show? (A) 2

(B) 3

(C) 4

(D) 5

(E) 6

Number of Routes 17. Arc Routes

2013 I.5

A

B

In the diagram above, there are five left-to-right routes from A to B:

A

B

A

B

A

B

A

B

A

B

How many left-to-right routes are there from A to B in the diagram below?

A

B (A) 100 – 299 (D) 700 – 899

(B) 300 – 499

(C) 500 – 699 (E) 900 – 1099

24

analysis

18. Fun Run

2012 S.5

The annual fun run crosses all 6 bridges across the town’s river. Start, Finish

At this year’s fun run, the organisers allowed the competitors to choose their own route, provided they crossed all 6 bridges. It seemed a good idea at the time. Chaos resulted, and the organisers are hoping to settle out of court. Each competitor crossed every bridge once, but there were still several routes to choose from. How many routes were there? (A) 20

(B) 24

(C) 26

(D) 28

(E) 32

19. Hexagon Paths

2012 J.5

On your morning run you pass through a park where the paths are laid out in hexagons.

You always run left to right. How many possible routes are there through the park? (A) 8

(B) 12

(C) 16

(D) 20

(E) 24

number of routes 20–24. Routes

25 2015 J.10–12, I.10–12, S.7–9

Judith’s daily run takes her through a garden. There are several paths through the garden, going from top left to bottom right. She always runs the shortest distance, but likes variety. For each of the gardens below, how many different routes could Judith take? 20.

21.

22.

26

analysis

23.

24.

Note: The first, second and third gardens were used in the Junior paper, the first, third and fourth in the Intermediate paper, and the second, third and fifth in the Senior paper.

How Many Ways? 25. Up and Down

2013 S.2

Given the list of numbers 1 3 4 2, you can extract three ‘up-down’ lists 1 3 2, 1 4 2, and 3 4 2, where the second digit is greater than the first and the third is smaller than the second. How many ‘up-down’ lists can you make from 1 3 2 5 9 7 6 8 4? (A) 30

(B) 32

(C) 34

(D) 36

(E) 38

how many ways?

27

26–28. Gulliver’s Dilemma

2011 I.13–15

On the island of Lilliput, Gulliver has organised an Eggmoot to resolve the dispute between the Bigendians and the Smallendians. The seating at the head table at the opening feast has proven difficult. Bigendians and Smallendians will not sit next to one another, although there are no difficulties with the other nationality, the Poachers. A further complication is that several of the eminent Bigendians, Smallendians and Poachers have traditional places at the table. Gulliver is wondering exactly how many possibilities there are for the seating arrangement at the head table. For example, if the head table seated 6, and the reserved places were as shown below, B S P there would be 6 possible seating arrangements: B B P S P S B B P S P B B B P S P P P B P S P S P B P S P B P B P S P P For each of the following head tables, how many seating arrangements are possible without permitting Bigendians to sit next to Smallendians? 26. 27.

S P

28.

B B

S

S

P

S B

P B

P

P

P S

29. Maths Test

2012 J.4

Kim says to David, ‘My mark in the maths test is exactly halfway between yours and Lee’s’. Intrigued, David decides to check out whether he could say the same. His mark was 70 and his classmates’ marks were: 52 58 58 60 62 62 62 66 66 66 68 68 72 76 78 80 82 82 84 86 To how many pairs of his classmates could David say ‘My mark was halfway between your two marks’ ? (A) 6

(B) 7

(C) 8

(D) 9

(E) 10

28

analysis

30. Shoelaces

2014 S.6

The Shoelace Makers’ Guild has determined the rules for tying shoelaces. ˆ Start at the bottom left. ˆ Thread holes criss-cross fashion, left, right, left, right, . . . ˆ Progress upwards towards the top row, threading a hole next to or somewhere above the current one, but never below. ˆ On the return journey, only travel across or downwards. ˆ The lace must go through each hole exactly once. ˆ The lace must come out of the bottom-right hole at the finish. There are exactly three ways of tying the laces in a shoe with three rows of holes.

How many ways are there of tying laces in a shoe with four rows of holes? (A) 4

(B) 6

(C) 7

(D) 8

(E) 9

31. Hop, Skip and Jump

2015 S.3

In the Hop, Skip and Jump event Fred’s total distance was 15 metres. It was noted that each of his hop, skip and jump distances was a whole number of metres. Finally his jump was longer than his skip, and his skip was longer than his hop. How many possible combinations of distance are there that could achieve this result? (A) 5

(B) 9

(C) 10

(D) 11

(E) 12

how many ways?

29

32–34. Pyramid

2015 UP.10–12, J.2

Pyramid is a mathematical word game. You start collecting letters at the top of the pyramid, and go down one level at each step. You can only take a letter that is on a lower diagonal from the letter you come from. You want to find out how many ways you could create a target word. For instance, if the pyramid was R O O

O O

X

you could make ROO in three ways (left, left; left, right; right, left). For each of the pyramids below, in how many ways could you make the target word? 32.

KOALA

K O

O

A

A

L

L

A

33.

A L

A

A

QUOLL

A

U

O

O

L

O

X

L

L

L

X

M B

O M

B X

T

L

W O

A

L

L

WOMBAT

T

A

Q U

34.

L

M X

A T

B A

T

A T

T

Note: All three pyramids were used in the Upper Primary paper. The third was used in the Junior paper.

30

analysis

35–37. Yawling Yachties

2011 S.7–9

The home lake of the Yawling Yachties Sailing Club has breezes that blow from the south in the mornings and from the north in the afternoons. There is also a steady west to east current. On the opening day of the sailing season, the club has a tradition that members will breakfast on one island, sail to another in the morning, have a leisurely lunch, and sail to a third island in the afternoon. They always sail downwind, and never against the current, so that in the lake below •



N W



E S



there are three possible trips. •



















• •

For each of the lakes below, how many possible trips could a Yawling Yachtie make?

35.















36. •











• •



analyse the problem

31

37. •



• •













Analyse the Problem 38. Bird Calls Volunteer ornithologist Anna Clark has returned from a field trip to the remote Simpson desert with a recording of calls of the endangered whistling emu. At dawn, each bird calls once. The call is one of

2011 J.2

ˆ a single low note (L) ˆ a high note followed by a low note (H L) ˆ a low note followed by a high note (L H).

Anna has analysed the recording and found it to consist of the following notes: L H L L H H L L H L H L L H H L L L H H L H L L L H L How many birds were there? (A) 11

(B) 16

(C) 18

(D) 21

(E) 27

39. Robot Relay

2015 UP.6

You have entered a team of five robots in the Robot Games Relay race. Each robot takes two glasses from a line of 11 glasses but only if the two glasses are side by side. Each glass is partly filled with oil, as indicated by the numbers in the diagram below. The aim of the relay is to take as much oil as possible. What is the least amount of oil that your team can leave?

5

(A) 2

8

6

(B) 3

2

8

3

(C) 4

7

7

(D) 5

6

4

(E) 6

5

32

analysis

40. Digital Bees

2012 I.5

In a computer simulation, bees are represented internally by strings of 0s and/or 1s. In order to get variation in a swarm, the strings are generated by the following algorithm. Start with the string “A” While there is an A in the string randomly replace the A with B 0 or A 1 or 1 Endwhile While there is a B in the string randomly replace the B with 1 B or 1 0 Endwhile Which of the following strings will not represent a bee? (A) 1 0 0

(B) 1 1 1 1 1

(C) 1 1 1 1 0 0

(D) 1 1 1 0 0 1 1

(E) 1 0 1

41. Grid Swaps

2015 I.5

A grid can be transformed by swapping rows or columns. For example, 1

2

3

4

5

6

7

8

swap rows 1&3



9

7

8

9

4

5

6

swap columns

3



1

2

1&2

8

7

9

5

4

6

2

1

3

The grid 2

2

1

1

1

2

1

2

2

1

2

1

1

2

2

2

has been transformed into one of the grids below by 0 or more column swaps and 0 or more row swaps. A

B

C

D

E

2

1

1

2

2

1

1

1

2

1

2

1

2

1

2

2

1

2

2

2

1

2

1

2

2

2

1

2

1

2

1

2

1

2

2

1

2

2

2

1

1

2

2

1

1

2

2

1

1

2

2

1

2

1

2

1

2

2

1

1

2

1

2

1

1

2

2

2

1

2

2

2

1

2

1

2

2

1

1

2

Which one is it? (A) A

(B) B

(C) C

(D) D

(E) E

analyse the problem

33

42–44. Domino Loops

2014 I.13–15, S.13–15

Dominoes are rectangular tiles with a digit written on each end. You are playing a game using domino tiles. In it you try to make a loop of three or more dominoes connected end-to-end, with the digits matching wherever the dominoes touch. The diagrams below show domino loops of 3 and 4 dominoes. Note that dominoes can be turned upside down, as in making the second loop below. 4

6

1

1

4

6

4

4

2

2

2

6

2

6

At each turn you draw a new domino from the pile. The game ends when you are able to make a single domino loop out of all the dominoes drawn so far. For instance, if the domino pile was [1:4] [2:6] [2:4] [1:6] [3:0] and you drew dominoes from left to right, then you could finish the game after 4 turns, to give the second loop in the diagram above. For each of the following domino piles, how many turns does it take you to finish the game, drawing dominoes from the left (top row first)? 42. 1 2

2 5

5

0

5

1

0

3

2

2

3

6

5

6

1

2

2

0

0

0

6

1

2

4

6

6

3

2

3

1

0

4

1

4

5

6

2

0

6

4

1

2

1

1

5

1

3

0

3

6

5

0

2

2

0

6

5

4

6

2

2

4

4

4

2

6

3

1

3

5

1

5

4

6

1

6

6

6

1

0

3

4

6

3

3

3

4

0

5

0

2

2

0

6

0

0

5

5

43.

44.

34

analysis

Algorithms

Breadth-first Search 1. Secret

2015 UP.1, J.1

Wilma has a secret. ˆ On day 1: Wilma tells the secret to all her friends. ˆ On the following days: all people who heard the secret on the day before will tell the secret to any of their friends who do not know it.

Wilma’s network of friends is shown below. The dots are people and a line means that two people are friends.

W

How many days does it take before everyone knows the secret? (Include day 1.) (A) 2

(B) 3

(C) 4

(D) 5

35

(E) 6

36

algorithms

2. Sugar Gliders

2011 I.3

The call of baby sugar gliders was heard in the bush three days ago. There are three babies, each in its own nesting tree. On the first night a baby sugar glider will glide from its nesting tree to an adjacent tree. Each subsequent night it will either stay put or glide to another tree. It will not return to the nesting tree. In the diagram below, the three nesting trees are shaded.

A sugar glider will only glide to a tree that is horizontally or vertically adjacent to it—the diagonal trees are too far away. How many trees could contain one or more sugar gliders after three nights?

(A) 36

(B) 38

(C) 40

(D) 42

(E) 44

3. Kangaroo Rat

Kangaroo rats are good jumpers, but they do not like being in water. They can jump over any stretch of water on their way to the next mound. However they will only jump left, right, up, or down. They will not jump diagonally. And they will not jump over a mound. The diagram to the right shows the possible jumps from the mound M. (Water is grey, mounds are white.)

2015 UP.5

  

 

M





A kangaroo rat is at the mound marked M. It spots a nice clump of sedge on a nearby mound. What is the fewest number of jumps it can take to get to the sedge?

breadth-first search

37

M

(A) 6

(B) 7

(C) 8

(D) 9

(E) 10

4. Bug in the Wind

2015 J.5

When the wind blows for a day, a bug either stays still or moves one unit of distance in the direction of the wind. For example, if the bug was at A and the wind was blowing from the south, the bug could end up at any of the positions marked S, or stay at A. And if it was at B and the wind was blowing from the west, it could end up at either of the positions marked W or stay at B.

S S

N

S A

W

E

W

S

B W

In the diagram below, the bug starts in the position labelled A. In how many possible positions could it be after the wind blows for two days from the east then two days from the north?

A

N W

E

S

(A) 18

(B) 19

(C) 20

(D) 21

(E) 22

38

algorithms

5. Hex Frog (Intermediate)

2013 I.6

A frog is sitting on a lily pad in a large pond. The frog may jump from one lily pad to another. However, the frog may only jump straight up or down, or diagonally at 60◦ from the vertical. It can jump over large spans of water, but it may not jump over another lily pad or land in the water. (White squares represent lily pads and grey squares represent water.)

   

F 



F

In the diagram above, the frog is on the lily pad marked F. The number of pads that are more than 3 jumps away from the frog is (A) 0

(B) 1

(C) 2

(D) 3

(E) 4

6. Hex Frog (Senior)

2013 S.6

A frog is sitting on a lily pad in a large pond. The frog may jump from one lily pad to another. However, the frog may only jump straight up or down, or diagonally at 60◦ from the vertical. It can jump over large spans of water, but it may not jump over another lily pad or land in the water. (White squares represent lily pads and grey squares represent water.)

   

F 



F

In the diagram above, the frog is on the lily pad marked F. The number of pads that are more than 3 jumps away from the frog is (A) 2

(B) 3

(C) 4

(D) 5

(E) 6

breadth-first search

39

7. Governor’s Island

2013 J.5

The new Government House is being built on Governor’s Island. Four possible locations have been identified for jetties on the mainland. In the map below, the island is black, the rocks are grey and the possible locations for jetties are marked with an ×. The governor’s boat takes one minute per cell and can only travel horizontally or vertically, and must not go through a cell where there is a rock. The time is counted from an × to one of the cells marked G, immediately to the left of the island. Count the cell marked G but not the cell marked ×. For instance, if there were no rocks the time taken from the top-left (×) location would be 12 minutes, and the time taken from the bottom-right (×) location would be 13 minutes.

×

G G

×

×

× The governor insists that his boat trips must be less than 15 minutes. How many of the locations are less than 15 minutes from the island? (A) 0

(B) 1

(C) 2

(D) 3

(E) 4

40

algorithms

8. Wombat Moot

2012 I.6

Four wombats are going to a wombat moot. W

W



W

W

All wombats (W in the diagram) move at the same pace and start at the same time. They only go along wombat tracks (solid wavy lines) and each takes the shortest path to the moot ( • above). Which of the following is true? (A) All will arrive at the same time. (B) Exactly three will arrive at the same time. (C) Exactly two will arrive at the same time. (D) One pair will arrrive equal first, and the other two equal last. (E) No two will arrive at the same time.

breadth-first search

41

9. Gems

2014 I.3

The number of gems to be found in a particular area is documented on the map below. 8

5

3

1

2

3

6

3

2

6

2

4

C

5

1

3

4

2

2

5

1

2

5

5

4

You are at the camp at C, and can only move horizontally or vertically away from the camp. What is the maximum number of gems that you could find in three moves? (A) 11

(B) 12

(C) 13

(D) 14

(E) 15

10–12. Polly Nomial

2012 J.7–9

Miss Polly Nomial walks into a maze of hexagonal cells. Each cell has a unique number. She starts from the leftmost cell. From any cell, she can move to either the adjacent cell with the largest number, or the adjacent cell with the second largest number. (Two adjacent cells must share an edge.) No other moves are permitted. In the following mazes, how many cells can Polly reach? (Include the one where she begins.) 11.

10.

6

1 4 6

5

5 2

8

12

9

4

3

1 3

11 12

14 6

7 9

4 10

5 15

16 8

9 3

8

12.

2

10 5

1

7

13

11 2

42

algorithms

13. Prospecting

2011 J.6

A miscalculation whilst prospecting in the Great Sandy Desert has left you far from your base camp and short of water. You need 1 litre of water per kilometre, and you only have 3 litres of water with you. Moreover, water is in short supply at your base camp, and you would like to arrive with as much water as possible. The map below is 8 km × 8 km. The numbers show the location and capacities of the water holes, and the dotted lines show the trails made by the desert penguins. 4

You

9

3

2

2

3

4

1

1

3

2

1

2

1

2

1

4

1

7

4

3

Camp

4

It is too sandy to leave the penguin trails, and you do not have the energy to walk more than 16 km. What is the greatest volume of water that you can bring back to camp? (A) 2 litres

(B) 3 litres

(C) 4 litres

(D) 5 litres

(E) 6 litres

breadth-first search

43

14–16. Treasure Hunt

2014 J.7–9

There are treasure chests at various points on a grid. Each treasure chest contains coins of a fixed value in roubles, denoted by the number on the chest in the diagrams below. Contestants start at S and can only move right or down, finishing at F . They may only take one coin from a chest. What is the greatest value in roubles of coins they can collect? 14. S 10 11 15 8 12 9 10 10 13

F

15. S

5 9 4 8 5

5 7

6

4 6 2 7

4 3

8

6 4

F

16. S

4

9 3

4 3

3 2

4

3

4

4

2 6

3

9

2 3

4

1 3

1

F

44

algorithms

17–19. Chiropteran Scatology

2011 I.7–9, S.10–12

As a chiropterist with an interest in scatology, your delight is to examine bats’ droppings to determine their diet, health and feeding range. You have obtained a permit to visit the bat cavern in Grand Fenwick. The cavern is flooded and you will have to canoe through it. On a previous visit you mapped the cavern and identified the location and value of the islands from which you will obtain samples. Your permit only allows you one more visit, and you want to get full value from it. You cannot paddle more than 45 degrees from the current, which goes left to right, so you cannot take samples from all of the islands. What is the maximum value of samples that you can obtain from each of the cavern maps following? 17. current

4 5

5

5 4

3 4 4 3

4

3

3

3 3 4 4

5

3

18. 4

4

4

5 5

3 3

4 4

3

3

5

4 5 5 3

3 4 5

4 3

5

5 5

19. 4 3

4

3

3

4

5

5

5

3 5

4

3

4

3

3

4 3

4

4 3

4

5

4

breadth-first search

45

20–22. Path through the Bush

2015 UP.7–9

Your path through the bush skirts round some hills. The maps below show how long it would take you to walk around each hill. For each map, what is the shortest time you could take from Start to Finish? 20. 6

9

6 4

7

4

Start

Finish 2 7

9

3

8

8

21. 7 7

5

2

2

3

4 5

Start

Finish

1 7

5

9

22. 7 7 4

5

2

1

Start

Finish 2

2 4

4

5 8

46

algorithms

23. Don’t like climbing

2013 S.3

You wish to walk from the top-left cell to the bottom-right cell. You don’t want to walk any further than you need to, so you will only walk right or down. But you don’t like climbing so want to climb as little as possible. The number in a cell gives its height in metres. For instance, going from a cell at height 3 to one of height 5 means you climb 2 metres. Note that going downhill, such as from 5 to 3, counts as 0. What is the least amount of climbing that you must do to walk from the top-left (shaded) cell to the bottom-right (shaded) cell?

(A) 5

0

4

2

4

1

3

2

4

2

4

1

3

2

3

2

3

1

2

0

3

(B) 6

(C) 7

(D) 8

(E) 9

24. Ariadne’s Maze

2015 J.3

Theseus is deep in the Cretan Labyrinth and has to pass through Ariadne’s Maze. The enchantment on the maze requires Theseus to pick up the piece of obsidian in the first chamber. Then in each subsequent chamber he must swap it with the next obsidian if that one is heavier. 1

9

21

7

15

17

19

10

20

8

3

18

23

22

5

14

25

4

13

2

24

6

16

12

11

The number in each chamber represents the weight of the obsidian in it. Theseus wants to walk as little as possible in the maze, so will only walk to the right or down on the map. He also wants to carry as little weight as possible when he leaves the maze. What is the least weight he can leave with if he only walks right or down? (A) 16

(B) 17

(C) 18

(D) 19

(E) 20

Note: This question has a breadth-first search and an ad hoc solution. It appears in both sections.

breadth-first search

47

25–27. Rapids

2014 I.7–9

You are at A and want to kayak down parts of one or more rivers. Each river runs left to right and has six rapids, denoted by thick black irregular segments of the line. Each rapid has a thrill factor, denoted by the number above the rapid. From each river to the next are seven paths, denoted by dotted lines. A

4

2

5

3

1

6

5

2

3

4

2

5

6

1

4

2

3

5

4

3

4

3

3

3

B

C

D

You can only use a path to carry your kayak from one river to another, and once you have done so you cannot go back. This means that you will kayak down exactly six rapids. You want to maximise the sum of your thrill factors. For each of the endpoints below, what is the maximum sum of your thrill factors if you start at A? 25.

B

26.

C

27.

D

48

algorithms

Shortest Path 28–30. Brown Treecreeper

2013 J.13–15

The brown treecreepers are nesting and you are monitoring their progress. There are several paths through the bush from the reserve entry to their tree hollow. In the maps below, the numbers give the times, in minutes, of each leg. For each map, what is the shortest possible travel time from the entry (E) to the nesting hollow (H)? 28. 3

E

2

2

2

2

1

3

1

1

2

H

3

29. 5

E

2

3 4

2

2

1

2

2

4

2

1

2

2

H

3

30. 2

E

2

1 1

5

3

1

3

4

1

2

2

H

2

31–33. Gullies

2011 J.13–15

You are several kilometres downstream from your car. There is a good track on both sides of the river, but there are several gullies that will slow you down. You would like to minimise the amount of time you spend crossing the river and gullies. In the map below, the time it takes to cross each gully is shown, and it takes you 2 minutes to cross the river. You can reduce the amount of time you spend crossing the river and gullies to 5 minutes by crossing the river twice as shown. 1

2

You

3

Car

2

shortest path

49

For each of the following maps, what is the shortest amount of time that you could take crossing the river and gullies?

31.

River crossing takes 2 minutes. 1

3

2

3

1 2

You Car

2

32. 2

3

3

1

2

2

River crossing takes 1 minute. 2

1

1

2

3

1 2

1

You

Car

1

33. 3

1

2

2

2

1

2

River crossing takes 2 minutes. 1

3

3

2

2

4

4 3

You Car 3 4

2

4 2

2

2

3

50

algorithms

34. Stepping Stones

2012 J.2

On your way home you have to cross a river using stepping stones. You can step 1 or 2 metres, and consider it a point of honour to step on as few stones as possible. But you only step forward or sideways. Your elder brother has told you that you are likely to slip if you step diagonally. You don’t believe him, of course, but you would rather not risk it.

What is the fewest number of stones you will have to step upon? (The dotted lines are 1 metre apart.) (A) 6

(B) 7

(C) 8

(D) 9

(E) 10

35. Tollroads

2015 S.5

You want to drive from A to B. There are tolls on the horizontal roads, but the vertical ones have no toll. The numbers on the vertical roads show the number of roundabouts on these roads. There are no roundabouts on the horizontal roads. $2

A 3

$4

2

$2

1

1

$2

4

$3

$4

4

$3

2

$3

$1

$3

1

$2

1

$3

2

$3

2

$1

$3

3

$2

1

$4

$1

2

$1

2

$3

B

1

$2

What is the fewest number of roundabouts you must go through if you want to pay as little as possible in tolls? (A) 7

(B) 8

(C) 9

(D) 10

(E) 11

maximum flow

51

Maximum Flow 36. Maximum Flow

2014 S.3

This diagram shows a network of pipes, with the numbers representing the maximum flow through each pipe. −→ 7

3 −→ 9

7

−→ 6

2 −→ 18

19 4 −→

−→ 4 8

7

−→ 3

7 −→ 32

−→ 3

3 −→ 7

7

−→ 3

5 −→ 11

16

−→ 5

4 −→ 6

11 6 −→

−→ 2

What is the maximum flow from left to right through the network? (A) 25

(B) 27

(C) 29

(D) 32

(E) 35

Single Pass Algorithms 37. Maximum Sum

2015 S.4

A subsequence is a set of one or more adjacent elements from a list. For example, 1 5 3 is a subsequence of 4 1 5 3 6 8. The subsequence 1 5 3 has a sum of 9. What is the maximum sum of any subsequence from the following list? -6 1 6 0 -3 -3 5 7 -9 3 -9 4 7 -5 1 6 -2 1 -5 7 (A) 11

(B) 12

(C) 13

(D) 14

(E) 15

52

algorithms

38. Camel Buying

2015 I.2

You are going on a camel-buying journey, visiting several studs. In order to increase the camels’ genetic diversity, the Camel Breeders’ Guild requires that at each camel stud they visit, buyers have to surrender half of their camels (rounded down) before they are allowed to buy from the stud. If you start with two camels, and the number of camels you can buy at each stud is 8 6 4 3 9 2 5 8 6 what is the most camels you can end up with if you visit or bypass the studs in that order? (Note that you do not have to visit each stud.) (A) 14

(B) 15

(C) 16

(D) 17

(E) 18

39–41. Longest Increasing Subsequence

2013 J.7–9

Cards with the numbers 4 1 2 6 3 5 are placed on a table. A game is played where the goal is to take as many cards as possible. You may take any card you like to start with, but the next card you take must be to its right and have a greater number on it. And any subsequent cards that you take must be to the right of and have a greater number than the previous card you took. For example, for the cards 4 1 2 6 3 5 it is possible to take a maximum of four cards, 1 2 3 5. From the following sets of cards, what is the maximum number of cards that can be taken in this manner? 39.

4 3 1 2 5 6 4 7 5 8

40.

1 4 7 5 10 6 9 12 16 14 15 14

41.

3 1 4 2 3 4 5 3 6 4 5 7 9 7 10 8 9 11

42. Largest Increasing Sequence Sum

2014 S.5

A strictly increasing sequence of numbers is one where each number is greater than the previous number. For example, 2 5 10 11 is a strictly increasing sequence. Find the largest total that can be formed by taking a strictly increasing sequence from left to right from 7 11 3 6 8 10 2 14 12 5 9 13 (A) 32

(B) 39

(C) 41

(D) 52

(E) 56

single pass algorithms

53

43. Missing Planks

2014 J.3

The footbridge to the side is missing two planks. To cross the river, you can step onto the next plank, or over one plank, or over a gap. For this footbridge, the fewest number of planks you can step on is five. (For example, the 2nd , 3rd , 5th , 6th and 7th from the left.) For the footbridge below, what is the fewest number of planks that you could step on?

(A) 15

(B) 16

(C) 17

(D) 18

44–46. Petrol Stores

(E) 19 2013 S.10–12

You wish to cross an unmarked desert in a particularly ungreen fuel-guzzling vehicle that only travels 1 kilometre per litre of fuel. Further, the vehicle’s fuel tank only holds 20 litres, so you will need to store fuel along your route. The cost of storing fuel is: ˆ $1 per litre of fuel for stores within 10 km of either end ˆ $2 per litre of fuel for stores between 11 and 20 km of either end ˆ $3 per litre of fuel for stores between 21 and 30 km of either end ˆ $4 per litre of fuel for stores more than 30 km from either end.

In the examples below, what is the lowest cost of storing petrol for your journey? The first line is the distance you have to travel, and the second is the potential locations of petrol stores. In each case you start with a full tank. 44.

40 3 7 15 20 26 31 35

45.

50 2 8 11 26 28 33 38 42 46

46.

70 2 9 21 28 33 44 55 56 62 64

54

algorithms

Dynamic Programming 47–49. Hopping

2013 J.10–12, I.7–9

You are playing a game where you have to hop along a line of squares from left to right. You can hop to the adjacent square, or hop over it to the next one. Each square has a number in it. If you hop onto a square from the adjacent square, you get that number of points. If you hop over a square, you get double the points of the square you land on, but miss out on the points in the square you hop over. Consider the squares below. S

4

2

3

Starting from S to the left of the squares, you could get 9 points by hopping onto all squares, 7 by hopping over the first square, and 10 by hopping over the second square. Each list below represents numbers in a row of squares. For each list, what is the most points you could get following the rules above? 47.

4 5 6 7 4 5

48.

2 1 4 5 1 2 5 6 3 2

49.

2 3 5 3 4 6 4 5 8 5 6 9

50–52. Nerdy Nephew

2015 I.7–9

You have to babysit your young nerdy nephew. To keep him amused and out of your hair you devise the following problem for him. ‘Starting on the left, you progress through a list of numbers. You want to accumulate the largest sum. As you arrive at a number, you have two choices: either add that number and skip the next two numbers, or move on to the next number. For instance, with the list 2 4 1 3 you would choose the 2 and the 3, giving 5, but with the list 2 6 1 3 you would simply choose the 6.’ Find the largest sum he could accumulate from each of the following lists: 50.

4 5 8 7 5 4 3 4 6 5

51.

5 9 3 7 1 8 6 8 6 2 9 7 8

52.

4 5 2 5 6 7 5 4 8 7 8 4 2 1 2

dynamic programming 53–55. Camels

55 2013 S.7–9

You are mounting an expedition to collect Hojari frankincense. You have determined that it is available at a line of oases spaced one league apart between two desert towns. A condition of the hire of camels is that apart from the first and last day, they must travel at least two leagues per day. If you stop at an oasis the camels refuse to go any further that day, so you will have to miss some oases. You have texted ahead and know how much frankincense is available at each oasis. All you need to do now is to work out the maximum amount of frankincense you can purchase on the expedition. For instance, for a line of four oases with the following amounts of frankincense available (in kiloshekels) : ˆ 4 3 4 3 you would choose the first and third oases ˆ 2 4 5 4 you would choose the second and fourth oases ˆ 5 4 2 3 you would choose the first and fourth oases.

In each case you would buy 8 kiloshekels. From each line of oases with availabilities of frankincense, determine the maximum total amount you could buy without stopping at adjacent oases. 53.

2 5 2 4 7 4 5 5

54.

1 2 4 3 2 1 2 3 1 2 1

55.

3 1 4 1 5 9 2 6 5 3 5 8 9 8

56–58. Elfstones

2015 S.10–12

You have discovered the hiding place of the fabled elfstones. They are buried in equally spaced caches, with several elfstones in each cache. You are at the leftmost cache and want to get as many elfstones as possible. However, the built-in defence means that if you take a cache of n elfstones, the next safe cache to the right will be n caches away. For instance, if the caches were 2 1 2 4, and you took the leftmost 2, you could also take the other 2 or the 4, but not the 1 next to it. (In this case you would take the leftmost 2 and the 4 for the best result.) For each set of elfstone caches below, what is the largest number of elfstones that you could safely take? 56.

2 3 6 5 3 5 1 4

57.

1 2 8 7 3 5 1 1 1 4

58.

2 5 2 3 8 2 7 3 1 1 2 7 3 1

56

algorithms

59–61. Electric Car

2012 I.13–15, S.10–12

You intend driving from home to the beach in your new all-electric car. Your battery is only partly charged with 20 kWh, and there is no recharge station at the beach, so you want to arrive with as much charge in your battery as possible. Some of the roads on the way are equipped with remote induction technology that charges the battery while you drive. You don’t mind driving extra distance provided it increases your battery charge, but the induction roads are one way, and you are not permitted to circle round and keep recharging the battery. For example, on the roads below, the numbers indicate how many kWh you use on the normal roads, or the amount of charge you will get on the induction roads. Arrows indicate the direction you can travel. Your best route is to take the first road down, go back up the middle road, and then down the last road. This leaves you with 20 − 1 + 9 − 1 − 2 − 4 − 1 − 2 + 6 − 1 = 23 kWh. 2

1

1

2

ˆ

ˆ 9

ˆ

1

8

4

1

ˆ

Home

6

2

6

1

3

1 Beach

For each of the roads below, what is the greatest number of kWh you could have in your battery on arriving at the beach? In each case, your battery starts with 20 kWh. 59. 1

2

3

ˆ

ˆ

ˆ 10

1

8

ˆ

2

5

3

4

4

5

2

5

ˆ

1

ˆ

Home

6

1

9

1

2

1 Beach

60. 1

ˆ

ˆ

ˆ

12

2

4

8

3

3

ˆ

10

2

2

2

4

1

9

4

2

5

ˆ

1

6

2

4

ˆ

3

3

1

ˆ

Home 1

7

3

8

2

1 Beach

two person games

57

61. 2

1

1

3

ˆ

ˆ 9

6

4

1

1

4

ˆ

1

4

1

2

2

ˆ

Home

7

2

3

1

2

1

4

1

1 Beach

Two Person Games 62. Move 1 or 2

2013 S.4

A game between two people is based on a line of numbers. Each number is either 1 or 2. Players take turns moving a token along the line. If the token is on a 1, it must be moved one place to the left. If it is on a 2, it can be moved either one or two places to the left. The aim of the game is to make your opponent make the last move, which will take the token off the line of numbers. You are to start the game below. P Q R S 1 2 2 2 1 2 2 2 1 2 1 1 1 2 1 2 1 1 2 2 Which of the starting positions P Q R S would guarantee you a win? (A) P and Q

(B) P and R

(C) Q and R

(D) Q and S

63. Bucket Game (Intermediate)

(E) R and S 2015 I.6

Alice and Bob are playing a game. There are 7 white counters and 3 black counters in a bucket. Alice and Bob take it in turns to remove counters. Each turn, a player may remove between 1 and 3 white counters from the bucket or, alternatively, remove 1 or 2 black counters. The player who takes the last counter(s) out of the bucket wins. Alice moves first. How many counters should she take to guarantee that she can win? (A) 1 white

(B) 2 white

(C) 3 white

(D) 1 black

(E) 2 black

58

algorithms

64. Bucket Game (Senior)

2015 S.6

Alice and Bob are playing a game. There are 7 white counters and 5 black counters in a bucket. Alice and Bob take it in turns to remove counters. Each turn, a player may remove between 1 and 3 white counters from the bucket or, alternatively, remove 1 or 2 black counters. The player who takes the last counter(s) out of the bucket wins. Alice moves first. How many counters should she take to guarantee that she can win? (A) 1 white

(B) 2 white

(C) 3 white

65. Map Game

(D) 1 black

(E) 2 black 2011 S.4

You and a friend are playing a rather unusual game with a model car and a road map. You take it in turns to move the car along one section of a road on the map. (All roads on the map are one-way, left to right.) You win if you force your friend to move the car to the garage. X

Y

Start

Z

For the map above, it is your turn to go first. You can be sure of winning if your first move is to (A) any of X, Y , or Z (B) X or Y , but not Z (C) X or Z, but not Y (D) Y or Z, but not X (E) Y , but not X or Z

Garage

two person games

59

66–68. Board Game

2014 S.10–12

Anna and Brett are playing a game with a single counter that is moved along a board with numbers in a row. Anna starts by placing the counter on one of the two leftmost numbers. Then the players take turns, moving the counter one or two places to the right. Placing the counter on a number earns the player that number of points. The winning margin is (the winner’s score) − (the loser’s score). The aim of the game is to get as large a winning margin as possible. If both players play as well as possible, what is Anna’s winning margin? 66. 5

3

5

4

4

3

2

4

5

5

4

5

4

3

2

2

1

2

4

7

3

5

4

67.

68. 3

60

algorithms

69–71. Hex Game

2015 S.13–15

Anna and Brett are playing a game on a board with numbers in hexagonal cells. The players take turns, moving the token one place up, down, right-up or right-down, but the token cannot be placed onto any cell twice. The game finishes when the token is placed on the rightmost (shaded) cell. When Anna places the token onto a cell, her score is increased by that number of points. When Brett places the token onto a cell, Anna’s score is decreased by that number of points. Anna wants her final score to be as large as possible, whilst Brett wants Anna’s score to be as small as possible. Anna goes first and places the token on the leftmost (shaded) cell. For each of the boards below, what is Anna’s final score if both she and Brett play as well as possible? 69. 3 4

5 5

3

3

7

2

3

70.

5

3 5

3 4

6

5 5

3

3 7

71. 1 5

4 1

1

3 4

6

5 5

3

3 7

two person games

61

72–74. Board Game N x N

2015 I.13–15

Wilma and James are playing a game that involves moving a token on a board with numbers on a grid. The players take turns, moving the token one place right or down. The game finishes when the token is placed on the bottom-right square. When Wilma places the token onto a square, her score is increased by that number of points. When James places the token onto a square, Wilma’s score is decreased by that number of points. Wilma wants her final score to be as large as possible, whilst James wants it to be as small as possible. Wilma, who will only place the token on a white square, goes first and places the token on the top-left square. For each of the boards below, what is Wilma’s final score if both she and James play as well as possible? 72. 9

6

5

4

7

4

4

3

5

4

9

7

9

9

6

5

8

6

3

7

7

2

7

5

8

3

3

3

2

1

2

3

4

6

4

6

8

3

73.

74.

62

algorithms

Greedy Algorithm 75. Maximum Sum of Adjacent Products

2013 I.2

The sum of adjacent products of the list 4 2 3 1 is (4 × 2) + (2 × 3) + (3 × 1) = 8 + 6 + 3 = 17. However, you can reorder the list to give a larger sum of adjacent products. What is the largest sum of adjacent products for a list containing each of the numbers 1, . . . , 7 exactly once? (A) 111

(B) 115

(C) 119

(D) 123

76. Aesthetic Skyline

(E) 127 2014 I.6, S.4

The council’s planning committee has decided that the buildings in a new development should be arranged to provide an aesthetic skyline. This means that adjacent buildings should differ in height as much as possible. For example, consider the two arrangements of five buildings with heights of 8, 4, 3, 2 and 1 floors below:

The arrangement on the left has a total height difference of 4 + 3 + 1 + 1 = 9 floors, whilst that on the right has a total height difference of 4 + 7 + 2 + 1 = 14 floors. (But better arrangements can be found.) A new development consisting of eight buildings with heights of 2, 3, 5, 2, 9, 6, 5 and 1 floors is planned.

What is the maximum total height difference for these eight buildings? (A) 28

(B) 29

(C) 30

(D) 31

(E) 32

greedy algorithm

63

77. The New Truck (Junior)

2013 J.4

A mining community consists of 7 towns that are already connected by an extensive road system. However a new truck has been ordered that requires some of the existing roads to be widened. A survey has revealed the cost of widening each section of road and the results are given on the diagram below. The costs are given in the local currency of rads. The council is not concerned whether the truck travels by the shortest route. It only requires that there is a way the truck will be able to travel from any one town to any other town in the community. 12 14 16

11 13

10 11 13

16

14

15

15

What is the smallest total cost in rads that the council would have to pay? (A) 70

(B) 71

(C) 72

(D) 73

(E) 74

78. The New Truck (Intermediate, Senior)

2013 I.4, S.5

A mining community consists of 9 towns that are already connected by an extensive road system. However a new truck has been ordered that requires some of the existing roads to be widened. A survey has revealed the cost of widening each section of road and the results are given on the diagram below. The costs are given in the local currency of rads. The council is not concerned whether the truck travels by the shortest route. It only requires that there is a way the truck will be able to travel from any one town to any other town in the community. 16 10 12

15

11 15 14

13

13

17

13

14

16 17

What is the smallest total cost in rads that the council would have to pay? (A) 100

(B) 102

(C) 104

(D) 106

(E) 108

64

algorithms

Lists 79. Four Dispensers

2015 J.6

There are four digit-dispenser chutes below. When you choose a digit from the bottom of one of the chutes, the remaining digits in that chute drop to the bottom. The first digit you choose forms the first digit of a new number. You then choose a second digit from the bottom of one of the chutes, providing the second digit of the new number. This process is repeated until all the chutes are empty. Your aim is to choose the digits so that you get the largest possible 12-digit number. 9

7

6

7

7

9

8

4

3

4

6

5

What will be the last three digits of the number you obtain? (A) 686

(B) 679

80–82. Robot Librarian

(C) 796

(D) 477

(E) 379 2014 I.10–12, S.7–9

The school has acquired a robot to help the librarian. It can sort books on shelves, but only by taking a book out and placing it at either end of the shelf. For instance, if the books A B C were on a shelf in the order B A C they could be sorted by moving the A to the front. If they were in the order C B A they could be sorted by moving the C to the end and then the A to the front, (or the A to the front and then the C to the end). Each of the following lists represents a shelf of books. For each shelf what is the smallest number of books the robot must move to sort the books into alphabetical order? 80.

FCABDE

81.

DECAFBGH

82.

DFAECIGBJH

lists

65

83–85. Card Shuffle

2013 S.13–15

You have two tables, labelled A and B. To begin with, there is a line of cards on table A. Each card displays a single digit: a 1, a 2 or a 3. Together the line of cards forms a number. Table B is empty. You wish to move the cards to table B so that they make as large a number as possible. You are allowed the following moves. ˆ Move W: Take the leftmost card from table A and place it at the leftmost end of the cards on table B. ˆ Move X: Take the leftmost card from table A and place it at the rightmost end of the cards on table B. ˆ Move Y: Take the rightmost card from table A and place it at the leftmost end of the cards on table B. ˆ Move Z: Take the rightmost card from table A and place it at the rightmost end of the cards on table B.

For example, suppose that table A begins with five cards that form the number 1 3 2 1 3. The following diagram illustrates the moves YXWXX, giving a final number 3 3 1 2 1 on table B.

A B

13213

Y

−→

A B

1321 3

X

−→

A B

321 31

W

−→

A B

21 331

X

−→

A B

1 3312

X

−→

A B

33121

In each of the following questions, you are given the starting number on table A and you must work out the largest number that can be formed on table B using the moves above. In each case, your answer should be the final three digits of this largest number. In the example above, your answer would be 1 2 1. 83.

3 2 1 2 3 1 1 2

84.

1 2 3 1 1 3 2 3 1 2

85.

2 3 1 2 1 3 1 1 3 2

86. Number Game

2012 S.1

You have a single row of cards. On each card is a digit, so the row of cards forms a number. To make a second row of cards, you take one card at a time from the front of the first row and put it either at the front or the end of the second row. Your aim is to make the number in the second row as large as possible. For example, if your row of cards was 1 3 2 the largest number you could produce would be 3 1 2. Which of the following would produce the largest number? (A) 5 2 1 8 4 6 3 7

(B) 6 7 3 8 4 1 2 5

(D) 1 3 2 5 4 8 6 7

(C) 1 4 2 3 7 6 5 8

(E) 7 8 1 2 6 3 5 4

66

algorithms

Working Backwards 87. Tardis

2014 J.4, I.2

Your tardis (time machine) is playing up. It will only A: take you forward one century, B: double the number of centuries you have already travelled from the present. For example, to get to the 6th century in the future you would need 4 jumps, AAAB or ABAB. What is the smallest number of jumps needed to get to the 762nd century in the future? (A) 12

(B) 16

(C) 20

(D) 21

88–90. Twos

(E) 22 2015 UP.13–15, J.13–15

Alex’s favourite number is two. He plays a number game on his special T wos calculator. The calculator has only two operation buttons: +2 which adds 2 to the number shown ×2 which doubles the number shown. Twos calculator ×2

+2 2

He can press the buttons as many times as he likes, making the answer bigger each time. He always tries to press as few buttons as possible to get to his preferred number. Starting at 2, he could get to 8 by pressing ×2 + 2 + 2, but this would take more button presses than ×2 ×2. If the calculator starts at 2, find the fewest number of button presses to get to 88.

10

89.

100

90.

1000

chains

67

91. Slow Aphids

2011 J.5

Aphids reproduce by cloning. They breed very, very fast and are the bane of gardeners. The Genetically Modified Aphid Company has produced a strain they call ‘Slow Aphids’. Slow Aphids can clone themselves at most once per day. Moreover, on any one day either all of the Slow Aphids clone, or only one Slow Aphid clones. What is the shortest time in which a single Slow Aphid on a plant could reproduce to exactly 99 Slow Aphids on the plant? (A) 9 days

(B) 11 days

(C) 12 days

(D) 14 days

(E) 15 days

Chains 92–94. Car Parking

2012 S.7–9

When hire cars are returned, they are put into the first parking bay available. Then the cars are labelled A B C . . . in order of daily rental. Part of your job is to move them so that car A is in bay a, car B is in bay b, and so on. There is a spare bay to use while doing this. So if, for example, car B was in bay a, and car A in bay b, you would require 3 moves to swap them. spare bay

3

B bay a

1

2

A bay b

For each of the following order of cars in the bays, what is the smallest number of moves required to get them into the order A B C . . . ? 92.

BADECGF

93.

CEFAJDGKBIH

94.

BDHFLICEJKAG

68

algorithms

95–97. Christmas Presents

2013 I.10–12

Several families gathered for Christmas. Each of the children received a present, and there was promptly a flurry of swapping. Sometimes a child swapped more than once. For each of the following, what is the smallest number of swaps that could have taken place? 95.

96.

97.

child present before swapping present after swapping

A B C D E F G H I J K L a b c d e f g h i j k l c d b e a j h l k g f i

child present before swapping present after swapping

A B C D E F G H I J K L M a b c d e f g h i j k l m d c b i f g h e l m j a k

child present before swapping present after swapping

A B C D E F G H I J K L M N O a b c d e f g h i j k l m n o b k d j c l e m f n g o a i h

Ad Hoc Algorithms 98. Alpine Kelp

2011 I.1

Alpine kelp seeds are planted in late winter and the ground must be protected from frosts by thick mats. As the plants grow, the mats break down and nurture the soil. When the plants are two metres high, they are harvested, pulped and the fibres woven into mats. These mats are then used to protect next season’s alpine kelp crop. You intend to make your fortune growing alpine kelp, and have bought a 8 m × 8 m field. You have divided the field into sixty-four plots, each 1 m square. You have had each plot tested for its suitability to grow alpine kelp. The shaded squares in the diagram below indicate plots that are suitable for growing alpine kelp.

You ordered two 8 m × 4 m mats, but, alas, only one has arrived. What is the largest number of shaded plots that can be covered by the mat? (A) 20

(B) 21

(C) 22

(D) 23

(E) 24

ad hoc algorithms

69

99. Golf (Junior)

2013 J.6

Rory and Luke are entering as a team in a golf match. Their match score is calculated as follows. For each hole they must choose to include either Rory’s score or Luke’s score. Overall, an equal number of scores must be chosen from each player. For example, if there are 10 holes in a game, 5 of Rory’s scores and 5 of Luke’s scores must be included. The aim is to make the combined score as small as possible. For instance, suppose there were four holes and the scorecard was as follows: Hole Rory Luke

1 4 2

2 1 3

3 4 4

4 5 2

The smallest match score, 9, would be achieved by taking Rory’s score for holes 2 and 3, and Luke’s score for holes 1 and 4. What is the smallest possible match score for the scorecard below? Hole Rory Luke

1 5 3

2 4 3

(A) 21

3 5 4

4 3 3

5 2 4

6 3 2

7 3 2

(B) 22

8 4 2 (C) 23

(D) 24

(E) 25

100–102. Golf (Intermediate)

2013 I.13–15

Yani and Na Yeon are entering as a team in a golf match. Their match score is calculated as follows. For each hole they must choose to include either Yani’s score or Na Yeon’s score. Overall, an equal number of scores must be chosen from each player. For example, if there are 10 holes in a game, 5 of Yani’s scores and 5 of Na Yeon’s scores must be included. The aim is to make the combined score as small as possible. For instance, suppose there were four holes and the scorecard was as follows: Hole Yani Na Yeon

1 4 2

2 1 3

3 4 4

4 5 2

The smallest match score, 9, would be achieved by taking Yani’s score for holes 2 and 3, and Na Yeon’s score for holes 1 and 4. For each of the scorecards below, what is the smallest possible match score? 100.

Hole Yani Na Yeon

101.

Hole Yani Na Yeon

1 4 3

2 1 2

3 3 2

4 2 3

5 3 4

6 2 1

7 4 5

8 5 6

1 2 4

2 1 2

3 2 3

4 2 5

5 5 4

6 6 5

7 1 4

8 2 2

9 2 6

10 2 5

11 3 2

12 1 4

70

algorithms

102.

1 3 1

Hole Yani Na Yeon

2 5 2

3 4 1

4 3 1

5 5 5

6 5 1

7 6 2

8 4 7

9 7 3

10 3 3

11 5 2

12 7 4

13 2 1

14 1 3

15 2 3

16 4 3

103. MistressChef

2011 I.5, S.2

The latest reality TV show is a pairs cooking contest. To give it added spice, each week two wives contest against their husbands. The sponsors have also decided that contesting pairs should be evenly matched. As viewers cannot actually taste the food, this is based on their ‘star rating’. The star rating of a pair is the sum of the star ratings of the two members of the pair. For instance, if Kathryn (star rating 8) is married to Lawrence (5), Jackie (8) to Snags (6), and Anna (6) to Brett (9), then Kathryn and Anna (8 + 6 = 14) would be evenly matched against Lawrence and Brett (5 + 9 = 14). But Kathryn and Jackie (8 + 8 = 16) would not be evenly matched against Lawrence and Snags (5 + 6 = 11). The table below gives the star ratings for the applicants for the first series. The first row gives the star ratings of the wives, and the second row the star ratings of their husbands. The rating for a husband is immediately below that of his wife. 5 9

6 1

1 4

3 9

2 7

2 3

3 2

7 7

8 4

7 10

8 2

1 8

5 8

1 6

6 8

1 1

4 3

8 6

3 5

4 2

Contesting pairs must be evenly matched, and no-one can appear more than once. For how many weeks could the series run? (A) 6

(B) 7

(C) 8

(D) 9

(E) 10

104. Lookouts

2014 J.2

You are walking along a path near a clifftop and want to take photos from four of the seven lookouts on the way. 9 11 11

3

14

10

17 12 2

4

5

6

9

4

The numbers at the lookouts represent the time it will take in minutes for you to walk to the lookout and back on the tracks (dotted lines). The numbers on the path (dashed line) represent the time it takes to walk along the path without visiting the lookout. It would take you 100 minutes to walk along the path without visiting any lookouts. What is the shortest time, in minutes, that you could take if you visit four lookouts? (A) 125

(B) 126

(C) 127

(D) 128

(E) 129

ad hoc algorithms

71

105–107. Aircraft Baggage

2011 J.7–9

When loading an aircraft, bags in excess of 20 kilograms (kg) are directed to a single conveyor which branches to dual weighing scales. When a bag leaves one of the scales, it is replaced by the next bag on the belt.

bags

bags

Aircraft baggage is best loaded with the heaviest items to the rear of the plane. However, the bags are loaded directly from the conveyor belt, and cannot be rearranged whilst loading. For example, if three bags were placed on the conveyor belt, the first 2 kg in excess, the second 1 kg in excess and the third 3 kg in excess, then leaving the scales in the order 2 kg in excess, 3 kg in excess, 1 kg in excess is the best that can be done. In each of the questions below, the numbers represent the excess weights of the bags as they arrive at the weighing scales (leftmost number first, rightmost number last). Your answer will be a 3-digit number, giving the excess weights of 3 specified bags as they leave the scales. For instance, in the first question, if you believe that the 3rd , 4th and 5th bags to leave the scales had excess weights of 5, 3 and 6 kg, your answer would be 536. 105.

Excess weights of bags arriving at the scales: 4 5 6 3 5 4 2 3 1 Excess weights of the 3rd , 4th and 5th bags to leave the scales.

106.

Excess weights of bags arriving at the scales: 6 8 7 9 5 7 4 6 3 4 6 Excess weights of the 4th , 8th and 9th bags to leave the scales.

107.

Excess weights of bags arriving at the scales: 7 9 8 6 7 6 5 6 9 5 4 Excess weights of the 3rd , 7th and 9th bags to leave the scales.

72

algorithms

108. Sapphires

2014 S.2

You have inherited several emeralds, and your cousin has inherited several sapphires. You much prefer sapphires. Your cousin will swap sapphires for emeralds provided: ˆ Each swap is one sapphire for one emerald. ˆ The weight of the emerald (in carats) is at least the weight of the sapphire.

You agree to these conditions. Your first aim in swapping is to maximise the total weight of the sapphires you collect. Your second aim is to maximise the total weight of the emeralds that you retain. For example, if you had an 8-carat emerald, you would swap it for a 6-carat sapphire rather than a 5-carat sapphire. And you would swap a 6-carat emerald rather than a 7-carat emerald for a 4-carat sapphire. You have inherited 8 emeralds weighing 16, 12, 11, 10, 9, 5, 4 and 2 carats, and your cousin has inherited 7 sapphires weighing 15, 14, 13, 10, 10, 4 and 1 carats. How many carats will you lose in your swaps? (A) 3

(B) 4

(C) 5

(D) 6

(E) 7

109. Maze Shortcut

2013 S.1

The way through the maze below passes through all 49 cells.

↓ 1

2

9

10

11

12

13

4

3

8

23

22

15

14

5

6

7

24

21

16

17

28

27

26

25

20

19

18

29

34

35

40

41

46

47

30

33

36

39

42

45

48

31

32

37

38

43

44

49

↓ How long is the shortest path made possible by removing one wall of one cell? (A) 15

(B) 17

(C) 19

(D) 21

(E) 23

ad hoc algorithms

73

110. Trapdoors

2014 S.1

In the board game ‘Trapdoors’, the players start at the top left and finish at the bottom left. Players move from 1 to 6 squares by rolling a dice. If they land on a trapdoor, they drop one, two or three rows. For example, rolling a 2 from S means the player would drop to the second row, and rolling a 2 from the square marked × means she would drop to the third row. Players move from left to right on the odd (shaded) rows and from right to left on the even (white) rows. At the end of a row they move down to the next row, so that rolling a 5 from the square marked × would also mean the player would drop to the third row. →

×

S

← → ← → ← → ← → ←

F

On the board above, what is the fewest number of rolls of the dice required to get from S to F? (A) 6

(B) 7

(C) 8

(D) 9

(E) 10

111. No more than 10

2015 I.4

You are given a list of numbers and have to split it into one or more new lists according to the following rules: 1. One by one, take a number from the left end of the input list and put it at the right end of one of the new lists, or start a new list. 2. In the new lists, no two consecutive numbers can have a sum of more than 10. 3. Make as few lists as possible. For example, the list 5 6 5 3 could be split into two lists 5 5 and 6 3. What is the smallest number of lists that 5 6 5 3 6 5 4 5 2 8 5 could be split into using these rules? (A) 2

(B) 3

(C) 4

(D) 5

(E) 6

74

algorithms

112. Four-digit Display

2015 UP.4, I.1

A four-digit display can be altered as follows: ˆ one digit can be increased by 1, with 9 going to 0, at a cost of $2 ˆ one digit can be decreased by 1, with 0 going to 9, at a cost of $1.

For example, it would cost $1 + $2 = $3 to change 8800 to 8710. Four-digit Display 8

8

0

0

+

+

+

+









What is the smallest cost to change 8800 to 1234? (A) $24

(B) $25

(C) $26

(D) $27

(E) $28

113. Music Rooms

2015 UP.3

The School of Music has several rooms available for practice, from 1:00 pm to 9:00 pm. The following bookings have been made. Anya: Bess: Choi: Dot: Eve: Flora: Grace: Heidi: Ian: James:

5:00 6:00 1:00 8:00 2:00 1:30 2:00 5:30 7:30 5:30

– – – – – – – – – –

6:30 9:00 4:30 9:00 4:00 3:30 5:00 8:00 9:00 7:30

What is the fewest number of rooms needed? (A) 3

(B) 4

(C) 5

(D) 6

(E) 7

ad hoc algorithms

75

114. Collapsing Bridges

2012 J.6

A marshy area has several routes through it, with bridges over the wetter areas. However, the bridges have not been maintained, and a convoy of trucks is about to cross. Engineers have assessed each bridge to determine how many trucks can pass over it before it becomes too unsafe. 3 ≡

1 ≡

≡ 4



5 ≡

5

≡ 3

3 ≡

2 ≡

≡ 4

≡ 6 ≡ 2

How many trucks can safely make their way through the marsh? (A) 6

(B) 8

115–117. Game Show

(C) 10

(D) 13

(E) 16 2014 J.10–12

In a game show, contestants are given a number. They can increase or decrease a digit in the number by the click of a button. They are required to make all of the digits equal in as few clicks as possible. For instance, if they were given the number 114, the best they could do is three clicks (by decreasing the ones digit three times, giving 111). For each of the following numbers, what is the fewest number of clicks required to make all digits equal? 115.

2393

116.

99478

117.

5559993321

76

algorithms

118–120. Recent URLs

2012 J.10–12, I.4

Katy has been researching gemstones on the web. She notices that whenever she clicks on a link, it moves up one place on the list of recent URLs. For each of the following sessions, what is the fewest number of clicks required to change the before list to the after list? 118. before Agate Beryl Carnelian Diamond Emerald Fluorite Garnet

after Garnet Fluorite Emerald Diamond Carnelian Beryl Agate

120. before Agate Beryl Carnelian Diamond Emerald Fluorite Garnet

after Emerald Diamond Beryl Garnet Agate Fluorite Carnelian

119. before Agate Beryl Carnelian Diamond Emerald Fluorite Garnet

after Garnet Beryl Carnelian Diamond Emerald Fluorite Agate

Note: All three sessions were used in the Junior paper. The third one was used in the Intermediate paper. 121. Removing Digits

2013 J.2

The latest reality TV show has a mathematical twist. Contestants are given a number and told to remove pairs of adjacent digits until there is one digit left. At each step the number remaining must be as large as possible. For example, if the number was 5 4 1 3 2 they would remove the 1 3 leaving 5 4 2, and then remove the 4 2 leaving 5. Which digit would be left if they were given 4 9 2 3 6 8 1 7 5? (A) 5

(B) 6

(C) 7

(D) 8

(E) 9

ad hoc algorithms

77

122–124. Village Meeting

2012 J.13–15, I.7–9

In the village of St Mary’s Mead, the cottages are strung out one furlong apart. A village meeting is to be held at one of the cottages. They decide to meet at the cottage that minimises the total distance walked by the villagers. For instance, if 3 villagers each had to walk 2 furlongs, and 5 had to walk 1 furlong, the total distance walked would be 11 furlongs. What is the smallest total number of furlongs the villagers will have to walk in each of the following villages? The lists give the number of people living in each cottage, from left to right. 122.

2 3 1 1 1 1 2

123.

4 2 1 3 3 4 1 3

124.

2 3 4 1 2 3 4 4 2

125. Ariadne’s Maze

2015 J.3

Theseus is deep in the Cretan Labyrinth and has to pass through Ariadne’s Maze. The enchantment on the maze requires Theseus to pick up the piece of obsidian in the first chamber. Then in each subsequent chamber he must swap it with the next obsidian if that one is heavier. 1

9

21

7

15

17

19

10

20

8

3

18

23

22

5

14

25

4

13

2

24

6

16

12

11

The number in each chamber represents the weight of the obsidian in it. Theseus wants to walk as little as possible in the maze, so will only walk to the right or down on the map. He also wants to carry as little weight as possible when he leaves the maze. What is the least weight he can leave with if he only walks right or down? (A) 16

(B) 17

(C) 18

(D) 19

(E) 20

Note: This question has a breadth-first search and an ad hoc solution. It appears in both sections.

78

algorithms

126–128. Carmen

2012 S.13–15

During a performance of the opera Carmen, a chorus line of gypsies (G), bullfighters (B) and soldiers (S) has to be re-ordered so that all of the gypsies are at the left end of the line, the bullfighters are in the middle, and the soldiers are on the right. The director’s instructions are that only one performer can move at a time, either left or right. For instance, if the order was B S B S G, then the line could be reordered to G B B S S by the G moving to the left of the line, and then the first S moving to second from the right. In this case, only two singers had to move to re-order the queue. In each of the following chorus lines, what is the fewest number of people who have to move to re-order the line to G . . . B . . . S? 126.

BGSBBSGG

127.

BGSGBSGSSGB

128.

BGSGBSGSSGBBGSGBSGSSG

129–131. Choreography

2014 J.13–15

The choreographer of a new musical has a line of dancers dressed in red (R), green (G), or (sometimes) blue (B). She wants to put them in order R. . . G. . . B. For example, a line of dancers R G B B G B R should be arranged into the order R R G G B B B. Her choreography requires that a pair of dancers dance out, round each other and then back to the other’s spot. For each of the lines below, what is the smallest number of such swaps needed to get the dancers in order? 129.

R G R R G G G R G R G R

130.

B R G B R G R B B R G G R B R

131.

B R G B R R B B R G B G G B G

ad hoc algorithms

79

132–134. Bomb Bots

2015 J.7–9

Bomb Bots are robots that are programmed to walk across fields, avoiding land mines. They follow set paths, shown below by the grid lines. On these grids lines they can move left, right, up or down only. They are programmed to move at most two steps in any direction before changing direction. For instance, they could move up, right, right, but not up, up, up. In addition, they cannot travel over swampy ground. Each of the fields below is of size 4 steps up/down and 16 steps left/right. For each, what is the least number of steps a Bomb Bot will take to get from A to B ? 132. A swamp swamp swamp

B 133. A swamp swamp B 134. A swamp swamp swamp

swamp B

80

algorithms

SOLUTIONS

Applying Rules

The questions in this section are often straightforward questions appearing early in the paper. But they still represent an important part of information technology (IT). An essential part of gathering requirements for a project is understanding the customer’s business rules. Many projects have failed simply because the customers have not been able to communicate them to the developers. This problem is addressed in Agile methodologies such as Extreme Programming by using tests to enhance communication. A developer could ask a customer a question such as ‘So if a DVD is returned 8 days late the fine is $5?’ This has proved a very effective way of making sure that customers and developers understand one another. 1. Zabs Applying the rule, we have 2, 9 → 8 → 2 → 7 → 6 → 2 → 5 → 4 → 2 → 3 → 2 → 2 → 1 12 more years were required. Hence (C). 2. Word Search The search term b??st*ing matches 5 of the words.        

blasting blustering boasting boosting bootstrapping bowstrings bristling busting

Hence (C).

83

84

applying rules

3. Uranium Storage The third bar is stored in room 45, and the fourth and fifth bars are stored into rooms 23 and 67. The sixth bar could then be stored in room 12, 34, 56 or 78. Hence (D). 4. The Game of Life Applying the rules we have



There are 8 live cells (3 survivors and 5 new). Hence (C). 5. Odysseus By following the instructions, Odysseus gets into a repeating loop as shown below: D

T S

M

Odysseus will die of exhaustion. Hence (E).

85 6. Swapsies The order after each move is ABCDEF 1. D B C A E F 2. F E A C B D 3. F A E C B D 4. F D E C B A 5. A B C E D F 6. A B E C D F Hence (C). 7. Disco Lights (Junior) Applying the rules, we have W

B

B

B

B W

−→

B

W

W W

B

B

−→

W W

W

B

−→

W B

B

W

After three iterations the pattern is the same as the starting pattern. Hence (B). Note that it is not necessary to draw the diagram every time. We can simply write the colours in a line. In the lines below, the letters in lower case are the opposite ends of the line repeated for ease of applying the rules. → → →

w b b

W W W W

W B B W

B B W B

B B W B

W B B W

w w w

86

applying rules

8. Disco Lights (Intermediate) Applying the rules, we have W

B

B

W

−→

B

B

B

B

W

W

B

B

−→

B

W

B

W

B

B

After two iterations the lights are back to the starting pattern. So they just cycle around the two patterns above. They never get to a pattern when one light is white. Hence (E). Note that it is not necessary to draw the diagram every time. We can simply write the colours in a line. In the lines below, the letters in lower case are the opposite ends of the line repeated for ease of applying the rules. b w

→ →

B W B

B B B

W B W

W B W

B B B

B W B

b w

9. Disco Lights (Senior) Applying the rules, we have B

B

B

W

B

W

W

W



B

B B

B

W

B

B

W



W

W W

B

W

B

W

B

W B



W

W

W

W

W W

After three iterations all lights are white. Hence (B). Note that it is not necessary to draw the diagram every time. We can simply write the colours in a line. In the lines below, the letters in lower case are the opposite ends of the line repeated for ease of applying the rules. → → →

b w w

W B B W

W B W W

B B B W

B W W W

B B B W

W B W W

W B B W

B W W W

w b b

Logic

The ability to think logically is an essential requirement in IT. It is necessary in all CAT questions. In many questions, logical thinking leads to an algorithm (i.e. you apply the logic in a systematic, repeated fashion). In others, it is used in analysing an algorithm. Although the questions in this section can be treated purely as logic problems, in several of them the logic could lead to an algorithm which could be used to solve the problem if the data was changed. For example, the approach taken in Rail Fence Cipher could be developed into an algorithm to decrypt an encrypted message of any length. Similarly, the approaches taken in several of the other problems could be used in developing algorithms which could be used for any data. This is explored further in the chapter ‘Development of Algorithms’. 1. Least exactly 4 A maximum of 75 could have answered all questions correctly. Of the remaining 25, the 5 who got question 1 wrong, the 3 who got question 3 wrong, the 5 who got question 4 wrong and the 4 who got question 5 wrong could have been uniquely different giving 17 who got exactly 3 questions correct. This leaves 8 who got exactly 4 questions correct. Hence (D). 2. Wandering Robot The robot makes 10 moves to the east, and 2 to the west. This is equivalent to 8 moves east. And it makes 6 moves to the north and 4 to the south. This is equivalent to 2 moves to the north. Going direct would have taken 10 moves. Hence (B). 3. Paper Folding The first fold must go all the way across or down the paper, so the first fold was horizontal forward. Because the horizontal folds are from the bottom, the top half of the paper is unaffected. So we now have to consider

The next fold is vertical backward, and as vertical folds are from the left, the right-hand side of the paper is unaffected. So we have to consider 87

88

logic

The next fold is vertical forward, leaving

and the final fold is horizontal forward. The last two folds were vertical forward and horizontal forward. Hence (A). 4–6. Ant It is easier to follow the ant’s path if the cube is ‘flattened’ as show below.

4

6

5

3

2

1

4. Each of B B, L L L, L R L R L R, and F B F B returns the ant to the starting side and direction. So the ant ends up where it started, on side 1 facing up. Hence 11. 5. Each of R L R L R L, R R R, B F B F, and B B returns the ant to its starting position, leaving F B. From 1u, F leads to 3n and then B leads to 1d. Hence 12. 6. Removing embedded moves that have no effect, we have LRLBBRLRFBLLBBLFBBRRRBLL → LRLRLRFBLLLFRRRBLL → FBFBLL → LL From 1u, L leads to 5n and then L leads to 6e. Hence 66.

89 7. Card Cutting The pack is restored to its original order after 52 cards have been cut. Andrew, Kumar, Daniel and Graeme have cut 82 cards between them. The next multiple of 52 is 104, requiring Mahendra to cut 22 cards. Hence (C). 8. Fireworks The correct answer is (A). (This is enough to answer the question.) Vera Steve Tim Xiu

R B B R R B B

B G Y R G Y Y B Y G Y Y G Y R Y B R G B G Y Y Y

Each of the others fails for one of the viewers.

Vera

R B B G Y R B Y Y B B Y

G Y Y

Steve

B G B R Y R G Y Y R G Y

R Y

Tim

B R B G Y R G Y Y R B

B R G

Xiu

R B G B Y R G Y Y B B G Y Y

Y

9. Passwords It is easier to replace the letters with digits, B = 1, I = 2, L = 3, O = 4, T = 5, X = 6. Then O X T I L B is 4 6 5 2 3 1, which is followed by 4 6 5 3 1 2, that is, O X T L B I. Hence (C). 10. Rail Fence Cipher With 14 letters, there are 4 on the first rail, 7 on the second and 3 on the third: O E T R Y T R A C E S S C H. So the fence can be reconstructed to O

E Y

T S

T R

A C

R C

E H

and the unencrypted message is O Y S T E R C A T C H E R. The 7th letter is C. Hence (E).

90

logic

11. Christmas Lights The three possible sequences are: R B G B G R G B R G R B G B G B R G B R B G R R B R B R B R B R B R R G R G R G R G R G R G R B G B G B G B G B G B G B G

RB RG BG

The longest of these is the B G sequence, of length 14. Hence (D). 12. Messages From Space If there are too few zeros after a (non-zero) digit, we have to add zeros. 00403001024 → 00400030010204000 If the non-zero digit before a string of zeros is too small (or absent), we have to add a nonzero digit. 00400030010204000 → 3004000300120204000 8 digits were added (6 zero and 2 non-zero). Hence (D). 13. Semi-Sudoku First complete the rows and columns that contain a single empty cell. Next fill in the cells where both row and column have to be taken into account. 6

1 2 4 5 4 5 6  3 6 4 6 3 2 1 2 5 1 3 4 5 4 2 6 1 3 

−→

6 1 3 4 2 5

3 1 2  4  5 6 5 3 5 6 1 4 2 6

4 5 6 2 3 1

5 6 2 1 4 3

−→

6 1 3 4 2 5

3 2 1 6 5 4

1 3 4 5 6 2

2 4 5 3 1 6

4 5 6 2 3 1

5 6 2 1 4 3

The sum of the two cells containing a  is 2 + 4 = 6. Hence (B). 14. Only Turn Right Four of diagrams can be drawn without lifting your pen and without making any left turns. The middle one cannot as drawing the top-right square first would require left turns for the bottom-left square (shown), and drawing the bottom-left square first would require left turns for the top-right square. Hence (D).

91 15. Migrating Platypus Five barriers are required to ensure the survival of the platypups. There are several possible places where they could be built. One is indicated by the ×s on the diagram below. Hence (D).

× × × ×

×

rocks

rocks

rocks

river

16. Rectangles The rightmost 8 can only be part of the 4 × 2 rectangle with the 8 in the top-right corner. Then the lower 4 must be part of the 4 × 1 rectangle immediately below it. Continuing on, we get the rectangles below. The shading from lightest to darkest indicates one order in which the rectangles can be deduced (there are some ties). 6 8 4 5

2

3

×

3

2 8

4 4

The × is in the 3 × 1 rectangle of area 3. Hence (B).

92

logic

17. Card Cutting 2 Each player returns his cards in the order he removed them. In H I M N O A B C J K L D E F G we see 5 sequences of cards in order H I M N O A B C J K L D E F G. So Anna took A B C, Brett took D E F G, Chris took H I, David took J K L and Emma took M N O. David was the second player to return his cards. Hence (B). 18. Wonder Fabric There will be 2 pieces after the 1st cut, 4 after the 2nd , and 8 after the 3rd . Each subsequent cut can add 5 more, giving 13 after the 4th , 18 after the 5th , 23 after the 6th and 28 after the 7th . One more cut is required for the final two pieces, so 8 cuts is enough to cut the fabric into 30 sample pieces. Hence (C). 19. Great-uncle’s Will We take advantage of the fact that it does not matter in which order the buttons are pressed. We first press the E button until one of the digits is at its target, then press A, B, C and D buttons until the target display is reached. We have to do this for each of the digits. The display after pressing the E, A, B, C and D buttons is: 4444 → 1111 → 1511 → 1561 → 1567 requiring 7 × E, 0 × A, 6 × B, 5 × C, and 4 × D presses, for a cost of $290; 4444 → 5555 → 1555 → 1565 → 1567 requiring 1 × E, 4 × A, 0 × B, 9 × C, and 8 × D presses, for a cost of $230; 4444 → 6666 → 1666 → 1566 → 1567 requiring 2 × E, 5 × A, 1 × B, 0 × C, and 9 × D presses, for a cost of $190; 4444 → 7777 → 1777 → 1577 → 1567 requiring 3 × E, 6 × A, 2 × B, 1 × C, and 0 × D presses, for a cost of $150; 4444 → 1444 → 1544 → 1564 → 1567 requiring 0 × E, 3 × A, 9 × B, 8 × C, and 7 × D presses, for a cost of $270.

The best you can do is $150. Hence (A). 20. Magic Carpet

Francis has to go across, and whoever goes with him the time will be 12 minutes. The best person to go with him is Emma, else there will need to be a trip taking 11 minutes. Neither should come back, so the best arrangement is for Anna and Beth to fly across first, and Anna (or Beth) flies back. Then Emma and Frances fly across and Beth (or Anna) flies back. This takes 2 + 1 + 12 + 2 = 17 minutes. Then the same strategy is used to fly Coral and Dianne across, taking 2 + 1 + 9 + 2 = 14 minutes. Finally Anna and Beth fly across (for the third time), taking 2 minutes. So the total time is 17 + 14 + 2 = 33 minutes. Hence (A).

Analysis

Analysis is a discipline within computer science that allows developers to decide between two algorithms, and to get a handle on how an algorithm will perform as the amount of data increases. This is important, despite the speed of modern computers. An inefficient algorithm could take literally thousands of years with quite small amounts of data on very fast computers. (‘Try all routes’ in the Travelling Salesperson problem is one such example.) And an algorithm that is adequate for relatively small amounts of data may be far too slow when the amount of data increases. (Each Google query involves searching terabytes of data, but still gives results in a few seconds.) Analysis of the running time of an algorithm is done by counting ‘operations’, without being concerned with how long the operation takes. A typical operation is ‘compare two numbers’, used in searching and sorting algorithms. Another objective in analysis is to explore how the complexity of the problem increases as the problem size increases. An inefficient but simple algorithm may be preferred to an efficient but complex one if the complexity of the problem does not increase much as the size of the data increases.

Searching The most important searching algorithm is binary search. A binary search is similar to looking for a name in a telephone book. The first operation compares the middle element in the list with the target. This halves the portion of the list that the target could be in. Then the middle element of the half is compared with the target. This process is repeated until the target is found. So a list with 2 elements will require 1 comparison, 4 elements will require 2 comparisons, 8 elements will require 3 comparisons, and so on. If the amount of data is doubled, the number of comparisons required only increases by 1. A list with 1000 numbers will take 10 comparisons, a list of 2000 elements will take 11 comparisons, and a list of 1 000 000 elements will take only 20 comparisons.

93

94

analysis

1. Robot Guessers If the logic is correct, a ‘too high’ response will give a new high limit, a ‘too low’ response will give a new low limit, and each guess will be between the upper and lower limits of guesses so far. We do not know the responses, but if the logic is correct, we can deduce whether a guess was too high or too low from the next guess. If the logic in Dan’s robot is correct, its second and third guesses should imply that the target is less than 20. But its fourth guess is 25. So Dan’s robot has made a logic error. Hence (D).

Sorting Sorting has been an important part of computing since its inception. Items are sorted so that efficient searches can be performed, either by humans (telephone books) or computers (words in a spell checker). There are many sorting algorithms. The efficient ones such as Quicksort have the property that the number of comparisons does not grow much faster than the increase in the number of items being sorted. For instance, if the amount of data was increased from 10 000 items to 1 000 000 items (a factor of 1000), the number of comparisons would increase by a factor of 2000. In contrast, inefficient algorithms such as BubbleSort would require 1 000 000 times as many comparisons. 2. Swap Three Consider the first list, F B C D E A. The A is in the 6th position. Reversing the last three letters would put it in the 4th position, and then reversing the 2nd , 3rd and 4th letters would put it in the 2nd position. But it would always end up in an even numbered position, and never an odd numbered position, including the first. So it is not possible to sort this list into alphabetical order. We can extend this idea by putting each letter’s position in the alphabet under it. A list can only be sorted into alphabetical order if these numbers are odd – even – odd . . . FBCDEA 623451

CFABEGD 3612574

CFABGDE 3612745

CFGAEDHB 36715482

HBCFBDEGA 823624571

Only the third list, C F A B G D E, has the odd – even pattern. Hence (C).

sorting

95

3–8. Selection Sort 3. 621543 → 321546 → 321456 → 123456 Hence 3. 4. This list separates into 5 groups of 5 numbers, which are sorted separately. Each group of 5 requires 4 swaps, as in 4 0 1 2 3 → 3 0 1 2 4 → 2 0 1 3 4 → 1 0 2 3 4 → 0 1 2 3 4 Hence 4 × 5 = 20. 5. This list separates into 20 groups of 5 numbers, which are sorted separately. Each group of 5 requires 2 swaps, as in 43210 → 03214 → 01234 Hence 2 × 20 = 40. 6. 7326145 → 5326147 → 5324167 → 1324567 → 1234567 Hence 4. 7. This list separates into 100 groups of 10 numbers, which are sorted separately. Each group of 10 requires 5 swaps, as in 9876543210 → 0876543219 → 0176543289 → ... Hence 5 × 100 = 500. 8. This list separates into 20 groups of 5 numbers, which are sorted separately. Each group of 5 requires 4 swaps, as in 24103 → 23104 → 20134 → 10234 → 01234 Hence 4 × 20 = 80. 9–11. The iSorting Machine This problem can be solved by tracing, but a better method is to observe that although numbers can move several places to the right in one pass, they can only move one place to the left. So the number of passes will be the greatest number of positions that a number has to move to the left. The tables below only show the numbers that have to be moved to the left. For instance, in the first table, the 2 has to be moved 3 positions—from the fourth to the first.

96

analysis

9. Position in list Sorted list Original list Positions to be moved

1 2 3 4 5 6 7 8 2 3 4 5 6 7 8 9 8 6 4 2 9 7 5 3 3 3 6

Hence 6 passes. 10. Position in list Sorted list Original list Positions to be moved

1 2 3 4 5 6 7 8 1 2 2 3 3 4 4 5 4 3 2 1 5 4 3 2 1 3 2 5

Hence 5 passes. 11. Position in list Sorted list Original list Positions to be moved

1 2 3 4 5 6 7 8 1 1 2 3 3 3 4 4 4 2 1 3 3 4 1 3 2 5 2

Hence 5 passes.

Patterns These questions are typical of one aspect of analysis. The analyst is trying to find out what happens to the complexity of the problem as the data increases. If a pattern can be found and a formula derived from it, this can influence the algorithm chosen to solve the problem. For instance, the number of routes through a network is N! (factorial N). So an algorithm that required trying all routes would not be appropriate even for quite small networks. Repeating patterns such as in Chromatic Glow-worms or Light Show below, can result in very simple algorithms. 12. Triangles (Junior) The 1st Sierpinski triangle has 0 white triangles. The 2nd Sierpinski triangle has 1 white triangle. The 3rd Sierpinski triangle has 4 white triangles. The 4th Sierpinski triangle has 13 white triangles. The pattern is wn+1 = 3 × wn + 1, so there are 3 × 13 + 1 = 40 white triangles in the 5th Sierpinski triangle. Hence (D).

patterns

97

13. Triangles (Intermediate) The 1st Sierpinski triangle has 0 white triangles. The 2nd Sierpinski triangle has 1 white triangle. The 3rd Sierpinski triangle has 4 white triangles. The 4th Sierpinski triangle has 13 white triangles. The pattern is wn+1 = 3 × wn + 1, so there are 3 × 13 + 1 = 40 white triangles in the 5th Sierpinski triangle, and 3 × 40 + 1 = 121 white triangles in the 6th Sierpinski triangle. Hence (B). 14. Great-aunt’s Bathroom Solution 1 If you had to use 32 tiles, you would use 1 red, 1 orange, 2 yellow, 4 green, 8 blue and 16 indigo tiles. So you had to use 96 tiles, you would use 3 red, 3 orange, 6 yellow, 12 green, 24 blue and 48 indigo tiles. This leaves 4 tiles, and the best you can do is 3 red, 3 orange, 6 yellow, 13 green, 25 blue and 50 indigo tiles. Hence (B). Solution 2 Great aunt requires that at least half of your tiles be indigo. You want to use as few indigo as possible, so you use exactly 50 indigo tiles, leaving 50. Great aunt requires that at least half of these be blue. You want as few as possible of these be blue, so you use 25 blue tiles, leaving 25. Great aunt requires that at least half of these be green, while you want as few as possible to be green, so you use 13 green tiles. Hence (B). 15. Chromatic Glow-worms The glow-worms cycle through their pattern every 4 days, so after 20 days they are back to their original colours. Hence the changes for the 21st day are R → B, B → G, G → O, and R B B G B changes to B G G O G. Hence (A). 16. Light Show The settings on a bank of N searchlamps will be back to the starting settings after every 2 × N × 10 seconds. So for a bank of 10 searchlamps, the settings will be back to the starting settings after 200, 400, ..., 6200 seconds. In the remaining 65 seconds, 6 searchlamps will be switched, giving w R O y c g a b i v Two searchlamps are on. Hence (A).

98

analysis

Number of Routes Many problems in computer science involve finding routes through networks. Finding the shortest path between two nodes in a network, and finding the minimum spanning tree are two examples. (There are several shortest path questions in the sections ‘Breadth-first Search’ and ‘Shortest Path’. The New Truck questions in the ‘Greedy Algorithm’ section are minimum spanning tree problems.) Suppose we want to count the number of routes through a network such as:

 C

B  D

E 



A 

G 

 F

There is one route through edge B and one through edge D, so there are two through edge E. There is also one route through edge F, hence three through edge G. The three routes are



 







and

 











In general, when a route splits, each edge leading from the split is part of the same number of routes as the route that split. And when two edges join, each edge leaving the junction is part of R routes, where R is the sum of the number of routes leading to the junction.

 1

1  1

2 



1 

3 

 1

17. Arc Routes When one path leads into a junction, each path leading from the junction is part of the same number of routes as the path leading into the junction. When two paths lead into a junction, each path leading from the junction is part of R routes, where R is the sum of the number of routes leading to the junction. For the horizontal paths, the number of routes increases according to the Fibonacci series: 1, 1, 2, 3, 5, 8, . . . 1 A

1

1

2 1

2 1

5 3

5 3

8

13 8

There are 610 routes from A to B. Hence (C).

21

34

55

89

144

233

377

610

B

number of routes

99

18. Fun Run Once a runner has reached the bottom of the sixth bridge (* below), the route back is fixed. Any bridge not crossed on the way out must be crossed on the way back. So the number of routes is the number of routes to the bottom of the sixth bridge. Solution 1 The numbers below show how many routes pass through that point on the way out. For example, the top ‘2’ can be reached by not crossing any bridges, or by crossing both of the first two bridges. Start, Finish

16

8

4

2

1

8

4

2

1

16

*

The point * can be reached via 32 routes, 16 from the left (after having crossed one, three or five bridges), and 16 by crossing the sixth bridge (after having already crossed no, two or four bridges). Hence (E). Solution 2    There are 61 = 6 routes that reach * after crossing one bridge, 63 = 20 routes that reach  6 * after crossing three bridges, 5 = 6 routes that reach * after crossing five bridges, for a total of 6 + 20 + 6 = 32 routes. Hence (E). 19. Hexagon Paths When a route splits, each path leading from the split is part of the same number of routes as the route that split. And when two paths join, each path leaving the junction is part of R routes, where R is the sum of the number of routes leading to the junction. Applying this to the hexagon paths, we have: 1 1 1 1

4 3

2 1

6 3

1

20 10

4 1

There are 20 routes. Hence (D).

10

100

analysis

20–24. Routes When a route splits, each path leading from the split is part of the same number of routes as the path going into the split. And when two paths join, each path leaving the junction is the sum of the number of routes leading to the junction. The number on each path junction represents the number of different routes that meet at the junction. 20. 1

1

1

1

1

1

2

3

1

2

4

6

There are 6 possible routes.

21. 1

1

1

1

1

1

2

1

1

2

3

2

5

7

There are 7 possible routes.

22. 1

1

1

1

1

1

2

3

4

5

1

1

4

4

9

1

2

6

10

19

7

17

36

1

There are 36 possible routes.

how many ways?

101

23. 1

1

1

1

1

1

2

3

4

5

1

1

4

4

9

1

2

6

10

19

7

17

36

37

37

74

1

1

1

There are 74 routes.

24. 1

1

1

2

1

1

2

3

3

3

1

1

4

5

6

There are 11 possible routes.

11

How Many Ways? The following problems are similar in some respects to ‘Number of Routes’ problems, although the context is different. The underlying idea, though, is again to get a handle on the complexity of a problem and how it grows as the amount of data increases. 25. Up and Down For each digit, we calculate the number of lists in which it is the middle digit. This is the product of the number of smaller digits before it and the number of smaller digits after it. # of smaller digits before # of smaller digits after up-down lists

1 0 0

3 1 1 1

2 1 0 0

5 3 1 3

9 4 4 16

7 4 2 8

6 4 1 4

8 6 1 6

4 3 0

There are 0 + 1 + 0 + 3 + 16 + 8 + 4 + 6 + 0 = 38 lists. Hence (E).

102

analysis

26–28. Gulliver’s Dilemma In the example, the 1st place could be taken by a B or a P. So there are 2 possibilities for the first two places, B B and P B. The 3rd place must be a P, so there are still two possibilities for the first 3 places. Places 4 and 5 are fixed. The final place could be B, S or P, each of which have 2 possibilities for the first 5 places, making 6 in total. This can be managed by using a table as shown below. An × means that a person of that nationality cannot sit there, and a − means that the place is already taken by someone of another nationality. B S P

1 × 1

B 2 − −

× × 2

S 2 − −

P 2 − −

2 2 2

The sum of the last column gives the total number of possibilities. 26. B S P

× 1 1

S − 2 −

× × 2

B 2 − −

× × 2

S − 2 −

× 2 2

P − − 4

4 4 4

P − − 12

There are 12 possible seating arrangements. 27. B S P

P − − 1

1 × 1

B 2 − −

2 × 2

× 2 4

S − 6 −

× 6 6

6 × 12

B 18 − −

18 × 18

P − − 36

There are 36 possible seating arrangements. (Note that the only possibilities for the 4th and 5th places are B P, P P and P S.) 28. B S P

× 1 1

S − 2 −

× × 2

B 2 − −

2 × 2

4 2 4

P − − 10

10 10 10

P − − 30

There are 60 possible seating arrangements.

S − 30 −

× 30 30

how many ways?

103

29. Maths Test Rather than calculate all possible pairs, it is simpler to make a table of the number of marks relative to David’s mark. difference number < number >

18 1 0

16 0 1

14 0 1

12 2 2

10 1 1

8 3 1

6 0 1

4 3 0

2 2 1

Then for each difference, we take the product of the number < and the number >. difference number < number > pairs

18 1 0 0

16 0 1 0

14 0 1 0

12 2 2 4

10 1 1 1

8 3 1 3

6 0 1 0

4 3 0 0

2 2 1 2

Finally we sum these products, getting 4 + 1 + 3 + 2 = 10 pairs. Hence (E). 30. Shoelaces Threading the lace upwards, there is no choice about the bottom row (must be threaded first on the left only) or the top row (must be threaded in both holes), but the ones in between each offer three choices: ˆ Skip the row. ˆ Thread one hole in the row. ˆ Thread two holes in the row. The ‘return journey’ of the lace offers no choices either; there will be only one way of lacing all the remaining holes. Therefore for n rows of holes there are 3n−2 ways of lacing the shoe. For four holes, that means 9 ways. Hence (E). 31. Hop, Skip and Jump The possibilities for the hop, skip and jump distances are  1 + 2 + 12    1 + 3 + 11   1 + 4 + 10 5 combinations   1 + 5 + 9     1+6+8  2 + 3 + 10   2 + 4 + 9 4 combinations 2 + 5 + 8    2+6+7  3 + 4 + 8  3 + 5 + 7 3 combinations   4+5+6 There are 5 + 4 + 3 = 12 combinations. Hence (E).

104

analysis

32–34. Pyramid The numbers in the pyramid to the right represent the number of (partial) words that the corresponding letter could finish. For instance, the middle A could be the last letter of KOA in two ways (left, right; right, left). 32.

K O A L A

1 O

A L

1 A

1

L

A

A

1

L

2

1

A

3

1

A

1 3

4

6

1 4

1

KOALA could be made 1 + 4 + 6 + 4 + 1 = 16 ways.

33.

Q U O L L

1 U

O X

L

1 1

O L

L

1 2

1

L X

L

-

1

3

1

3

QUOLL could be made 1 + 1 + 3 + 1 = 6 ways.

34.

W O M B

B

A

X

T

O M

M X

A

T

T

B A

A

T

T

T

1 1 1 1 1 1

3 -

1

1 2

1 -

3 3

1 1

4

1 2

1

1

WOMBAT could be made 1 + 1 + 3 + 4 + 2 + 1 = 12 ways. This corresponds to option (B) in the Junior paper.

1 -

1

analyse the problem

105

35–37. Yawling Yachties For each island, we calculate the number of trips in which the island will be the lunch spot. This is the product of the number of islands to its west and south (left and below) and the number of islands to its east and south (right and below). Numbering islands from the left, we have 35. island # W and S # E and S trips

1 0 2 0

2 1 4 4

3 0 0 0

4 2 2 4

5 4 2 8

6 2 1 2

7 1 0 0

There are 4 + 4 + 8 + 2 = 18 possible trips. 36. island # W and S # E and S trips

1 0 4 0

2 1 5 5

3 0 1 0

4 3 5 15

5 0 0 0

6 4 3 12

7 1 0 0

8 4 1 4

9 3 0 0

There are 5 + 15 + 12 + 4 = 36 possible trips. 37. island # W and S # E and S trips

1 0 5 0

2 0 2 0

3 1 3 3

4 3 4 12

5 0 1 0

6 5 4 20

7 5 3 15

8 4 2 8

9 0 0 0

10 3 0 0

There are 3 + 15 + 20 + 15 + 8 = 58 possible trips.

Analyse the Problem In the problems below, a careful examination of the problem can lead to a substantial simplification of it, and in some cases lead to a simpler algorithm. 38. Bird Calls Each call has exactly one low note, so the number of calls equals the number of low notes. There are 16 low notes. Hence (B). 39. Robot Relay If all five robots are to take a pair of adjacent glasses, then an odd-placed glass must remain. So the least oil that can be left is the odd-placed glass with the least oil in it. This is the first or last, containing 5 fluid units of oil. Hence (D). 40. Digital Bees The first loop terminates with a string of 1s or a string containing B 0. If the latter, the second loop terminates with a string containing B 0 0. Option (E) only has a single 0, so cannot be generated by the algorithm. Hence (E).

106

analysis

41. Grid Swaps When rows or columns are swapped, the new grid has the same number of 1s and 2s as the original grid. Moreover the number of rows with one (two, three) 1s does not change. And the same applies for columns. The grid

2

2

1

1

1

2

1

2

2

1

2

1

1

2

2

2

has seven 1s; rows with two, two, two and one 1s; and columns with two, one, two, and two 1s. We will write these properties as {7; (2, 2, 2, 1); (2, 1, 2, 2)}. Any grid with these properties can be generated from the original grid. Note that the order of the row and column properties does not matter. That is just the result of swapping. A

The A grid has properties {8; (2, 2, 2, 2); (2, 2, 2, 2)}. There are too many 1s in the grid, so this grid could not be generated from the original one.

2

1

1

2

1

2

1

2

1

2

2

1

2

1

2

1

2

1

1

1

2

2

1

2

1

2

2

1

1

2

2

2

B

The B grid has properties {7; (3, 1, 2, 1); (2, 1, 2, 2)}. There is no row with three 1s in the original grid, so this grid could not be generated from it.

C

The C grid has properties {7; (2, 2, 2, 1); (3, 1, 1, 2)}. There is no column with three 1s in the original grid, so this grid could not be generated from it.

2

1

2

1

1

2

1

2

1

2

2

1

1

2

2

2

D

The D grid has properties {7; (1, 2, 2, 2); (2, 2, 1, 2)}. The properties of this grid are the same as for the original grid, so this grid could be generated from it.

2

1

2

2

1

2

2

1

2

1

2

1

1

2

1

2

1

2

2

2

2

2

2

1

2

2

1

1

2

1

1

2

E

The E grid has properties {6; (1, 1, 2, 2); (1, 1, 2, 2)}. There are not enough 1s in the grid, so this grid could not be generated from the original one.

Hence (D).

analyse the problem

107

42–44. Domino Loops One or more domino loops can be constructed whenever there is an even number of each digit. This (first) happens after 8 dominoes in the first data set, 12 dominoes in the second data set and 7 dominoes in the third data set. In the first two data sets, a single loop can be constructed. However, in the third data set two domino loops are required, and a further 7 dominoes must be drawn to construct a single domino loop. 42. 1

2

2

2

0

0

3

3

5

1

5

2

5

6

5

6

A single domino loop can be made with the first 8 dominoes. 43. 1

1

1

2

2

1

5

5

6

6

6

6

0

2

0

4

4

1

2

3

4

3

1

4

A single domino loop can be made with the first 12 dominoes. 44.

4

3

6

5 5

2

3

4

4

4

1

1

The first 7 dominoes can be used to form two domino loops, but not one.

2

6

A further 7 dominoes are required to form one loop.

3

3

4

4

3

4

2

5

1

3

3

0

6

0

4

6

1

2

6

1 6 6

4 4

5

1

3

6

A single domino loop can be made with the first 14 dominoes.

108

analysis

Algorithms

An algorithm is a set of instructions for solving a problem. In that respect it is similar to a recipe, knitting pattern or building plan. The main contexts for algorithms are mathematics and computer science. The rules for adding or subtracting two numbers, or adding two fractions, are examples of algorithms that will be familiar to most students, although the word algorithm may not be. Algorithm is a corruption of ‘Al-Khwarizmi’, the name of the Persian mathematician who composed the oldest works on arithmetic and algebra. The title of his classical work, written in 820AD, is Al-Jabr wa-al-Muquabrala (The Science of Equations) which has given rise to ‘algebra’. Many of the questions in this section are variations on problems such as Shortest Path, Maximum Flow, Game Theory and Dynamic Programming. The algorithms that solve these problems are well known, though students will often discover them for themselves. For other problems, an algorithm has to be devised from the rules inherent in the question.

Breadth-first Search The problem of finding the shortest path between two nodes in a network has a surprising variety of applications. Applications are as diverse as finding the shortest route on a map to distinguishing between homophones in speech recognition. Problems in equipment replacement and capital allocation are among many that can be expressed as a shortest path problem. When the search arcs or links have the same weight, a simple breadth-first search can be used. The starting node is labelled 0. All nodes linked to the starting node are labelled 1. All unlabelled nodes linked to a label 1 node are labelled 2. This process is repeated until the destination node is labelled. Its label gives its distance from the starting node. A breadth-first search can also be used to find the shortest (or longest) path through a grid where movement is constrained to one horizontal direction (eg right) or one vertical direction (eg down). The following problems are variations on shortest path problems that can be solved using a breadth-first search.

109

110

algorithms

1. Secret The numbers below show the day when the secret is known to the friend. 1 1 3 4 2 W 3 2 1 4 3 2

The secret is known to all the friends after 4 days. Hence (C). 2. Sugar Gliders The locations of the trees that the sugar gliders can reach in 1, 2 or 3 glides are shown in the diagram below. 2

1

2

3

3

1 2

1

3

2

3

3

3

2

2

1

3

3

2

3

3

2

1

2

2

1 1

2

2

3

1 1

2

2

3

2

Between them, the sugar gliders could reach 36 trees in three glides. Hence (A).

breadth-first search

111

3. Kangaroo Rat The numbers on the mounds below show how many jumps it would take the kangaroo rat to reach each mound. Note that as the grid is symmetrical, we only needed to label the mounds in the top-right corner. 4

5

5

3 4

2

3

2

3

4

4

5

6

6

5

7

6

7

1

7

6

6

5 6

7

6

6

7

6

7

5

6

6

4

5 4

3

2

4

5

2

7

7

1

5

4 5

1

M

3

6

7

7

5 3

7

7

2

4

1

4

2

3

4

3 5

4

It takes 7 jumps to reach the sedge. Hence (B). 4. Bug in the Wind The numbers in the cells below represent the number of days the bug could take to get to the cell. So that after one day it could be in either of the cells with a 1, or the cell with A. And after two days it could be in any of the three cells with a 2, or any of the three cells it could have been in after one day.

2 3 4

1 2

3 4

A 1

2 3

4

3 3

3 3

4

N

4 4

W

E

4 4

4

The bug could be in any one of 1 + 2 + 3 + 7 + 9 = 22 cells. Hence (E).

S

112

algorithms

5. Hex Frog (Intermediate) The number of jumps to reach each lily pad is shown below. 3 2

2

3 2

2

3

2

2

2

3

1

1

1

2

F

2

3

2

3 2

1 There are no pads more than three jumps away. Hence (A). 6. Hex Frog (Senior) The number of jumps to reach each lily pad is shown below. 2 3 1

3

3

2

2

2 1

2

2

3 3

2

1 F

3 4

4 2

1

4 3

1

3 2

There are three pads that are more than three jumps away. Hence (B).

breadth-first search

113

7. Governor’s Island The shortest route from each location is shown below. (There are alternative shortest routes, some of which are shown.)

× 1

2 3

4

5

6 7

× 1

2

3

15 8

9 10 11 12 13 14

7

10

13

6

9

12

5

8

11

7

10

6

9

5

8

4

5

6

2 1

×

2

3

4

4 3

7 6

2 1

5 2

× Each location is exactly 15 minutes from the island. Hence (A).

3

4

114

algorithms

8. Wombat Moot It is easier to determine the distances from the moot. The numbers below are the distances to junction points on the wombat tracks. Where there is ambiguity, the arrows indicate the shortest paths. 23

22 13 20

19

14 18 6 5 3

15

2 2 8

22

21

11

15

20 22

Three of the wombats have the same distance to travel. Hence (B). 9. Gems The greatest number of gems that can be found in each cell is the second number. 8/12

5/11

3/13

1/4

2/9

3/13←6/10

3/3

2/7

6/13



2/6

4/4 ←

C

5/5

1/6

3/11

4/8

2/2

2/7

5/12

1/9

2/4

5/12

5/11

4/8

The greatest number of gems that can be found in three moves is 13. One of the ways in which this can be done is shown by the arrows. Hence (C).

breadth-first search

115

10–12. Polly Nomial The cells that Polly can reach are shaded. Arrows on the first maze indicate the cells that can be reached from a shaded cell. 11.

10.

6

1 4 6

5

5 2

8

12

9

11 2

4

3

10 5

1

7

9 3

8

7 cells

8 cells

12. 1 3 13 2

11 12

14 6

7 9

16

4

8

10

5 15

7 cells 13. Prospecting The diagram below shows the amount of water you would have at each waterhole, taking account of how much you started with, how much you used, and how much was there. Water holes that cannot be reached without running out of water are marked with an ×. Your best route is shown by the solid lines. You 3

×

4 3

3

4

4 ×

2

3

3

3 3

×

4

4

3

4

× ×

5

×

6

3 Camp

If you take your best route, you will have 3 litres of water when you reach camp. Hence (B).

116

algorithms

14–16. Treasure Hunt We determine the greatest value of coins that could have been collected on the way to each intersection. This will be the greater of the total collected by coming from the left and that by coming from above. In a computer program, these amounts would have to be calculated for each intersection. However the grids are sparse, and the amounts for some intersections only need be calculated. These are shown in circles below. The route that gives the greatest total value of coins is shown by the wavy lines. 14.

15.

S

S

5 9

10 4

11 21

14 8

15 5

8 23

13

5 19

7

12 6

9 24

12

4 17

6

10

12

10 22

2 14

7 13 23

4

13

24

F

3 16

8

The best path allows coins totalling 24 roubles to be collected.

6 4 17

23

The best path allows coins totalling 23 roubles to be collected. (There is an alternate route.) 16. S

4

9 3 7

13

4

3

3 10 2

3

4

4

4

8

14

17

2 6

3

12

12

9

2 3 15

4 19

19

1 10

3 18

The best path allows coins totalling 20 roubles to be collected.

1 20

F

F

breadth-first search

117

17–19. Chiropteran Scatology The diagrams below show the best route to each island, with the cumulative values of the droppings selected. The best overall route through the cave is shown by the solid lines with the double arrows. (Note that sometimes the best route may not be unique.) 17. 9 5

18

23 27

8 13 22 3

9

25

28

16 19 4 8

13

16

Hence 28. 18. 11

4

15

27 20

15 7

22 18

12 3

32

7 25 30 8

20 17 30

13 21 5

26 18

Hence 32. 19. 10 14 3

6

17

21

31

12 26 4

Hence 49.

7

11 14 17

44 48 34 39 42 45

21 30 35

49

118

algorithms

20–22. Path through the Bush The path in bold takes the shortest time. 20. 6

9

6

17

23

4 7

7

4

13

26

2 7

9

8

3

15

23

8

The shortest time is 7 + 6 + 2 + 8 + 3 = 26.

21. 7 7

2

5

2

18

9

3 7

5

12

1 7

2

4

5

20

13

9

The shortest time is 2 + 5 + 5 + 1 + 5 + 2 = 20.

22. 7 7 2

4

9

5

2

1

10 16

5

2

2 7

4

4

5 8

The shortest time is 2 + 7 + 1 + 4 + 2 = 16.

14

breadth-first search

119

23. Don’t like climbing This is a shortest path problem for which we can use a breadth-first search. We consider the cells that are one away from the start, two away and so on. In the diagram below, the first number in a cell is the height of the cell. The second number (in bold) is the least climbing to reach that cell. 0 0

4

2

4

0 0→4 4

1

2

4

0 0→4 4→2 4

1

↓ 3

1

3

2

3

1

4

2

2

2

3

0

3 3

4

2



3

4

0 0→4 4→2 4→4 6

1



1

2

3

3

1

4

2

2

3

2

0

3 3→2 3

4



2

3

4

2

3

2

3

2

↓ 3

1

2

3 3→2 3→4 5

4

↓ 1 3

1



0







1 3

3 4

1

4

2

3

2

2

0

3

↓ 3 5

3

2

→ 0 0→4 4→2 4→4 6→1 6

0 0→4 4→2 4→4 6→1 6

↓ 3 3→2 3→4 5→2 5 ↓ 1 3

0 0→4 4→2 4→4 6→1 6

↓ ↓ 3 4→2 4





3 5

1 4

2

3 3→2 3→4 5→2 5→4 7

4

3

2

0

3



0 0→4 4→2 4→4 6→1 6







1 3

3 4→2 4→3 5







3 5

1 4

2 4

0



3 3→2 3→4 5→2 5→4 7



2

3

↓ 1 3

↓ 3 4→2 4→3 5→2 5





3 5

1 4

↓ 2 4→0 4

3

3 3→2 3→4 5→2 5→4 7



↓ 1 3

↓ 3 4→2 4→3 5→2 5





3 5

1 4

↓ 2 4→0 4

↓ 3 6

The least amount of climbing is 6. Hence (B). 24. Ariadne’s Maze The numbers in circles represent the smallest weight that Theseus would have to carry when leaving the chamber. 1 1

9 9

17 17

19 19

17 3

22

23

20 5

22 13

23 16

20 8

22

4

24 6

20

23

25

21 15

20

23

25

24 24

19

18

17

21 7

10

18

14

21 21

20 2

22 12

20 11

The least weight Theseus can leave with is 20. One route is shown by the arrows. Hence (E). Note: There is an alternate solution to this question in the ‘Ad Hoc’ section.

120

algorithms

25–27. Rapids This is a breadth-first search problem. We find the greatest total thrill factor at the point at the beginning and end of each path. For the end of a path, this will be the greater of the thrill factors at the beginning of the path, and the thrill factors after coming down an earlier path and shooting the rapid immediately upstream. We can take advantage of the thrill factors calculated for the second river in calculating the thrill factors in the third river, and those in the third river for the fourth. The highest possible thrill factors are shown in circles on the diagram below. A

0

0

0

0

4

5

6

4

4

5

6

6

2

2

1

3

6

7

7

9

5

3

4

4

11

11

11

13

25. The highest total thrill factor ending at B is 22. 26. The highest total thrill factor ending at C is 23. 27. The highest total thrill factor ending at D is 23.

3

4

2

3

14

15

15

16

1

2

3

3

15

17

18

19

6

5

5

3

21

22

B

23

C

23

D

shortest path

121

Shortest Path In more general shortest path problems, the links do not have the same weight. Consider finding the shortest path from A to D in B

1

C

1

1 4

A

D

Clearly, the shortest path is A – B – C – D, but a breadth-first search would give A – D. The standard algorithm for finding the shortest path between two nodes in a network where the nodes do not have equal weight is due to Dijkstra. Each node is systematically labelled with its shortest distance from the start. So the starting node is labelled with 0. Then each step consists of finding the unlabelled node that is closest to the start (or nodes—there may be ties). This must connect to one of the labelled nodes, whose distance is known. So in the example we have the following steps: 1 0

1 0

2

1 0

2 3

122

algorithms

28–30. Brown Treecreeper For the first map it will be convenient to label the path junctions a, b, . . . , g. Then the algorithm is to find the closest junction to a, the second closest, and so on. 28. 3

E

2

2

2

a

2

1

c

b

1

3

1

e

d

g

f

2

H

3

The closest junction to a is b, taking 2 minutes. Then to find the second closest, we need to consider b → c, a → c and b → d. The second closest is c which is 3 minutes from a. Continuing on we get 3

E

0 a

2

2

2

3 c

2

b

5

2

5 e

1

d

3

6

1

7 g

1

f

2

H

3

The shortest time required to reach the nesting hollow is 7 minutes. 29. 5

E

0

2

3

2

5

4

2

6

2

7

1

4

2

8

2

9

2

2

1

10

2

2

8

11

3

The shortest time required to reach the nesting hollow is 11 minutes. 30. 2

E

0

2

2

1

1

2

3

3

4

5

1

3

2

4

6

1

7

2

The shortest time required to reach the nesting hollow is 8 minutes.

H

H

shortest path

123

31–33. Gullies The numbers on the simplified maps show how long it would take to get to the closest gully, the second closest, and so on. The arrows show the shortest routes. (There are alternatives.) Note that in the second and third maps there are adjacent gullies without a gully between them on the opposite side. In this case the two gullies can be replaced in the map by one that takes the same time as the two it replaces. 31. River crossing takes 2 minutes. 1 You

3

0

2

1

3

4

2

6

3 2

1 8

5 2

2 9

6 1

11

9 3

Car 13

11 2

3

The smallest amount of time you can spend in crossings is 13 minutes.

32. River crossing takes 1 minute. 2

3

0

2

2

1

3

3

5

1

6

3

8

9

11 Car

You 1

2 1

4 2

6 3

7 1

9 2

10 2

The smallest amount of time you can spend in crossings is 11 minutes.

33. River crossing takes 2 minutes. 3 You

4

0

3

3 2

7 5

4

2 9 7

2

4 11 10

3

3 15 13

4

2 17 15

2

4 19 18

3

The smallest amount of time you can spend in crossings is 21 minutes.

23 21

4

Car

124

algorithms

34. Stepping Stones The label on each stone below represents the fewest number of stones stepped on to reach it. The lines show the ways of reaching the stones. 8 8 7

7

7

6

6

6 7

4

6

5

5

4

3

6 5

2

2

1

1

5

4 4

4

3

3

3

2

2 1 1

The far bank can be reached from the top stone with label 7. Hence (B). 35. Tollroads After removing the more expensive tollroads, the problem becomes finding the path from A to B with fewest roundabouts. (None of the horizontal legs have any roundabouts.) The circled numbers show the fewest number of roundabouts at the end of each vertical leg. 0

A 3

0

6

2 3

4 2

2 2

1 2

1 4

6

6 2

5

8 3

5

7

B

2 5

5

2 3

3

The path with the fewest roundabouts has 2 + 1 + 2 + 2 = 7 roundabouts. Hence (A).

maximum flow

125

Maximum Flow The maximum flow problem answers questions such as ‘A network of connected pipes is given. The pipes have different flow capacities. What is the maximum rate that water can flow through the network from a starting point to an ending point?’ The pipes may be water pipes, or bridges with limited carrying capacities, or internet connections, or electrical cables, and so on. 36. Maximum Flow The maximum flow through each pipe on the left is the smaller of the capacity of the pipe and the sum of the maximum flows coming into it. These are shown in circles above the pipe. The maximum flow through the pipes on the right is the smaller of the capacity of the pipe and the sum of the maximum flows exiting it. These are shown by circles below the pipe. Finally the maximum flow through the network is the smaller of the two flows at the central pipe. −→ 7

3 −→

9 9

−→ 6

7 16

5

18 −→ 4

2 −→

19

7

4 −→

12

8

7

−→ 3

27

7

7 −→

32 −→ 3

6

3 −→

28

7 −→ 3

7 11 11

−→ 5

6

7

5 −→

16 4 −→

16

6 −→ 2

The maximum flow through the network is 27. Hence (B).

11 10

6 −→

126

algorithms

Single Pass Algorithms Solving the problems in this section only requires a single pass through the data. Single pass algorithms tend to be simple and efficient. In some, such as Camel Buying, the algorithm derives directly from the data. In others, the algorithm is less apparent. For Maximum Sum and Missing Planks the algorithm could be left to right or right to left. In Petrol Stores the algorithm works in from both ends. 37. Maximum Sum Write down the running sum. As soon as you hit a negative running sum, start back from 0 (indicated by underline). Keep track of the maximum: -6 -6

1 1

6 7

0 7

-3 4

-3 1

5 6

7 13

-9 4

3 7

-9 -2

4 4

7 11

-5 6

1 7

6 13

-2 11

1 12

-5 7

7 14

The best is 14 (from 4 + 7 - 5 + 1 + 6 - 2 + 1 - 5 + 7). Hence (D). 38. Camel Buying At each stud we determine whether it is better to enter and buy or to bypass the stud. bypass buy

8 2 9

6 9 11

4 11 10

3 11 9

9 11 15

2 15 10

5 15 13

8 15 16

6 16 14

The most you can end up with is 16 camels, buying at the first, second, fifth and eighth studs. Hence (C). 39–41. Longest Increasing Subsequence We move from left to right labelling each number with its position in the longest subsequence that contains it. This will be one more than the label of a preceding smaller number. The length of the longest increasing subsequence will then be the largest label. So in the example we have 4 1 2 6 3 5 1 1 2 3 3 4 and the longest subsequence has length 4 (1 2 3 5). 39. 4 3 1 2 5 6 4 7 5 8 1 1 1 2 3 4 3 5 4 6 The longest increasing subsequence has length 6. There is one such subsequence, 1 2 5 6 7 8. 40. 1 4 7 5 10 6 9 12 16 14 15 14 1 2 3 3 4 4 5 6 7 7 8 7 The longest increasing subsequence has length 8. There is one such subsequence, 1 4 5 6 9 12 14 15.

single pass algorithms

127

41. 3 1 4 2 3 4 5 3 6 4 5 7 9 7 10 8 9 11 1 1 2 2 3 4 5 3 6 4 5 7 8 7 9 8 9 10 The longest increasing subsequence has length 10. There are two such subsequences, 1 2 3 4 5 6 7 8 9 11 and 1 2 3 4 5 6 7 9 10 11, and the first can be derived two ways. 42. Largest Increasing Sequence Sum Let t[i] be the total of the LISS ending at index i. Then t[0] = n[0], t[i] = n[i] + maxk B A=A−B Else B=B−A EndIf EndWhile HCF = A

Expressing Algorithms The above examples illustrate how algorithms are expressed. Repetitions (loops) are expressed using While . . . EndWhile. Decisions are expressed using If . . . EndIf or If . . . Else . . . EndIf. Low-level algorithms are given a name that describes what they do. And variables are introduced when needed. The above way of expressing algorithms is called pseudocode. It is used by serious programmers, often quite informally. Flowcharts are a visual alternative to pseudocode. They can be helpful for beginning students. The pseudocode and flowchart for an algorithm to calculate B mod A are given below. Recall that B mod A is the remainder after B is divided by A. For example, 37 mod 10 = 7. The algorithm subtracts A from B until B is less than A. In the example, 37 → 27 → 17 → 7. Let the two numbers be A and B While B ≥ A B=B−A EndWhile A mod B = B

Input A, B

Is B ≥ A?

yes Subtract A from B

no

Output B

Note that the flowchart does not have a direct way of expressing a loop. It uses a decision box (the diamond) instead.

165

Examples from CAT Papers 1. Wandering Robot

2011 J.4

The wandering robot is the latest innovation in military reconnaissance. Rather than go directly to its target, which would make it predictable and therefore vulnerable, it makes random moves in the general direction. The disadvantage is that it takes longer to reach its target. N

W

E

A move is either to the north (N), east (E), south (S) or west (W). S

One robot reached its target in the 22 moves E E N E N N W N E N E S E E E E E S S S W N. If it had been direct, how many moves would it have taken? (A) 8

(B) 10

(C) 12

(D) 13

(E) 14

Development of the algorithm The algorithm for this problem is very simple. Count the number of N(orth), S(outh), E(ast) and W(est) moves. Direct moves = difference between N and S + difference between E and W Count the number of N, S, E and W moves is a high-level algorithm. The detail of how to count the number of N, S, E and W moves is deferred. For programmers Even in this simple algorithm there is more than one possible implementation. Anyone solving the problem by hand would just pass through the moves once, incrementing the appropriate count at each move. And this is how it would be implemented by almost all programming languages. But if it was being implemented in a spreadsheet such as Excel, advantage could be taken of the CountIf function, in which case there would be 4 calls to the function, one for each direction. 2. Rail Fence Cipher

2012 S.2

The rail fence cipher first appeared in the US civil war. The message to be encrypted is written in a wavelike pattern, down, up, down, up, . . . on a fixed number of lines or rails. The cipher text is then read horizontally, rail by rail. For example, with three rails, the message K O O K A B U R R A S would be written down as K

A O

K

R B

O

R U

A S

and the encrypted message would be K A R O K B R A O U S. A message was encrypted using the rail fence cipher with three rails, giving O E T R Y T R A C E S S C H. What was the 7th letter of the message? (A) Y

(B) T

(C) R

(D) A

(E) C

166

development of algorithms

Development of the algorithm In using high level algorithms, we first figure out what to do, at a high level, without worrying about how to do it. For this problem, our first step is to determine the letters that go on each rail. Once we have that, we can reconstruct the message. So our high-level algorithms are Determine the letters that go onto each rail Reconstruct the message from the rails We are now able to implement each algorithm separately. Determine the letters that go onto each rail After experimenting with the cipher, we realise that there is a pattern in the ciphertext. We use this in developing the algorithm. If the number of characters was a multiple of 4 (4 × N ), a quarter of the letters would be on the top rail, half on the middle, and a quarter on the bottom. So the top rail would be first N , the middle the next 2 × N and the bottom the last N . If the number of characters was not a multiple of 4, the first extra letter would be on the top rail, the next on the middle and the next on the bottom. That is enough to implement the algorithm. Reconstruct the message from the rails Once the letters on the rails are determined, the message can be reconstructed by taking letters from the rails in the order top, middle, bottom, middle, top, . . . Note that this approach can be extended to any number of rails. Comment: How on earth anyone could consider this cipher as remotely secure is beyond me. It is not even ‘simple-in-the-heat-of-battle’. The ancient Greeks used an elegant little device called a skytale which was able to be used in the heat of battle. An excellent book on codes and ciphers is Simon Singh’s The Code Book. For programmers When implementing the algorithm Determine the letters that go onto each rail most programmers would use a series of If statements. For those with a little maths, it is slightly more elegant to observe that the number of letters in the top (middle, bottom) rails is (N + 3)div 4 ((N + 2)div 2, (N + 1)div 4). 3. Magic Carpet

2012 S.4

Anna, Beth, Coral, Dianne, Emma and Frances are going camping on an offshore island. They are using their magic carpet to get to the island. The magic carpet can only take 2 people at a time, so there will need to be 9 trips, 5 across carrying 2, and 4 returning carrying 1. Flying on a magic carpet can cause air sickness, so the speed of the carpet is determined by the rate at which the more susceptible passenger can travel. The times that Anna, Beth, Coral, Dianne, Emma and Frances can travel one way without queasiness are 1, 2, 7, 9, 11 and 12 minutes respectively. What is the least time, in minutes, required to fly all members to the island? (A) 33

(B) 37

(C) 41

(D) 45

(E) 49

167 Development of the algorithm The key insight here is that when Frances flies across, it will take 12 minutes no matter whoever flies with her. So the best person to fly with her will be the second slowest, Emma. Else there will have to be a separate trip taking 9 minutes. But after they have flown across, someone else will have to fly the carpet back. This should be the fastest flier. So Anna and Beth will fly the carpet across, Anna (or Beth) will fly it back, Emma and Frances fly across and Beth (or Anna) will fly it back. We now have the slowest two on the island and the rest on the shore. Keep doing this until there are only Anna and Beth on the shore, and they fly across. So the high-level algorithm is While there are more than 2 campers on shore Ferry the heaviest two to the island EndWhile The remaining 2 fly across The low-level algorithm Ferry the heaviest two to the island is The The The The

fastest and second fastest fly across fastest flies back slowest and second slowest remaining fly across second fastest flies back

But algorithms should work for all data. What if there is an odd number of campers? Then we will end up with 3 campers left on shore (Anna, Beth and Coral in the example). And then it would be quickest for Anna and Coral to fly across, and for Anna to return for Beth. The (final) algorithm now becomes While there are 4 or more campers on shore Ferry the heaviest two to the island EndWhile If there are 2 left They fly across Else Fastest flies slowest across and comes back for the other EndIf Comment: This algorithm only needs minor modification if the carpet can fly 3 or more at a time.

168

development of algorithms

4. Four Dispensers

2015 J.6

There are four digit-dispenser chutes below. When you choose a digit from the bottom of one of the chutes, the remaining digits in that chute drop to the bottom. The first digit you choose forms the first digit of a new number. You then choose a second digit from the bottom of one of the chutes, providing the second digit of the new number. This process is repeated until all the chutes are empty. Your aim is to choose the digits so that you get the largest possible 12-digit number. 9

7

6

7

7

9

8

4

3

4

6

5

What will be the last three digits of the number you obtain?

(A) 686

(B) 679

(C) 796

(D) 477

(E) 379

Development of the algorithm The overall algorithm is straightforward: While there are some digits left Determine the best chute Move digit from best chute to the next digit of new number EndWhile A first pass at Determine the best chute is simply Choose chute with largest bottom digit. This works until the first 4 digits have been removed, leaving 9

7

7

9

5

3

4

4

Clearly choosing the second chute is better as the next digit is a 9. Determine the best chute now becomes Choose chute with largest bottom digit If there is a tie Use the second bottom digit to choose between the tied chutes EndIf This algorithm suffices for the data in the competition question. And it can clearly be extended for cases such as:

169

9

7

6

7

9

9

3

4

4

Choose chute with largest bottom digit If there is a tie Work up until there is a difference between the tied chutes EndIf Identical chutes are not a problem. It will not matter which one is chosen. But we are still not finished. Consider 4

9

9

5

5

6

and

9

9

5

5

For the chutes on the left, choosing either chute will lead to 59594. But for the second, choosing the first chute would lead to 59596 whilst choosing the second would give 59659. However 0

6

9

9

5

5

would force the second to be chosen. So our final algorithm for Determine the best chute is Choose chute with largest bottom digit If there is a tie Work up until there is a difference between the tied chutes, treating any empty slots as if they contained 0 EndIf This final algorithm will work with any data, and can be extended to more chutes, and chutes with greater capacity. For programmers Incremental development such as this leads to the ‘Code a bit—test a bit’ approach to programming.

170

development of algorithms

5–7. Ant

2011 S.13–15 Directions the ant faces 3

2

u n

1

w

e

s d

An ant is on the front face of a cube, facing up. It is trained to move around the cube by obeying the following instructions: F: move forward one side L: turn left, and move forward one side R: turn right, and move forward one side B: turn 180°and move forward one side. For example, if the ant is on side 1 facing up (1u) and receives the instruction R, it will move to side 2 facing north (2n). Then after the instruction L it would move to side 3 facing west (3w). For each set of instructions below, what is the final side the ant is on, and which direction is it facing? 5.

BB LLL LRLRLR FBFB

6.

RLRLRLRRRBFBFBBFB

7.

LRLBBRLRFBLLBBLFBBRRRBLL

Your answer will be a two-digit number. The first digit is the side. (Sides 4, 5 and 6 are opposite sides 1, 2 and 3 respectively.) The second digit will be the direction. Replace • up and down with 1 and 2 (for sides 1, 2, 4 and 5) • north and south with 3 and 4 (for sides 2, 3, 5 and 6) • west and east with 5 and 6 (for sides 1, 3, 4 and 6). Development of the algorithm A flattened cube is useful for a few moves, but using it is error prone and is really only suitable for a limited number of moves. This is an example where a ‘by hand’ solution has limitations, and a different implementation is required. (Note that students were not expected to develop an algorithm for this question. That would be way beyond the scope of a CAT question. The aim of this question was not algorithm development, but identifying null sequences. That is, moves that end up with the ant on the same face and facing in the same direction. The gaps in the first data set help identify null sequences. After the null sequences have been removed, there are few moves left and they can be traced on a flattened depiction of the cube.) This is not an easy algorithm to develop, and we will use it to demonstrate another technique in the arsenal of a developer—that of solving a similar, but simpler problem.

171 Consider the following problem. An ant is on the circumference of a circle. It is trained to move around the circle by obeying the following instructions: F: move forward 90° B: turn 180°and move forward 90°. For example, if the ant was on the west (left) side of the circle facing in a clockwise direction (WC) and receives the instruction B, it will move to the south side of the circle, facing anticlockwise (SA). N

W

E

B

−→ S

The ant starts at position WC. After the instructions B B F F B F F, which quadrant is the ant in, and which direction is it facing? This simplified problem could, of course, be solved by hand. But there is another approach that can be extended to the side-of-a-cube problem. There are 4 quadrants to the circle, and in each quadrant the ant could be facing in one of 2 directions. So there are 4 × 2 = 8 possibilities for the ant’s position (quadrant and direction). And for each of these there are 2 possible moves. So we make a table with 8 columns and 2 rows. And in the (position, row) cell we put the position after the ant has made the move from that position. For example, from WC, F leads to NC, so in the (WC, F) cell we would put NC. We can now start to build the table. F B

WC NC SA

WA

NC

NA

EC

EA

SC

SA

The full table is not difficult to build. F B

WC NC SA

WA SA NC

NC EC WA

NA WA EC

EC SC NA

EA NA SC

SC WC EA

SA EA WC

Then the positions after each instruction can be read from the table. B

B

F

WC −→ SA −→ WC −→ NC . . . The faces of a cube problem There are 6 faces to the cube, and on each face the ant could be facing in one of 4 directions. So there are 6 × 4 = 24 possibilities for the ant’s position (face and direction). And for each of these there are 4 possible moves. So we make a table with 24 columns and 4 rows. In the (position, row) cell we put the position after the ant has made the move from that position. For example, from 1u, F leads to 3n, so in the (1u, F) cell we would put 3n.

172

development of algorithms

We can now start to build the table. F L R B

1u 3n 5n 2n 6n

1d

1e 5n 6n 3n 2n

1w

If the ant was facing down (west) it will move to the opposite face from the moves when facing up (east). F L R B

1u 3n 5n 2n 6n

1d 6n 2n 5n 3n

1e 5n 6n 3n 2n

1w 2n 3n 6n 5n

Now the 4 face can be filled in. The ant will end up on the same face as from the 1 face, but facing south rather than north. F L R B

1u 3n 5n 2n 6n

1d 6n 2n 5n 3n

1e 5n 6n 3n 2n

1w 2n 3n 6n 5n

4u 3s 5s 2s 6s

4d 6s 2s 5s 3s

4e 5s 6s 3s 2s

4w 2s 3s 6s 5s

The table can be completed in a similar manner. Once it is, it should be thoroughly tested. The null sequences, B B, L L L, R R R, L R L R L R, R L R L R L, B F B F and F B F B provide convenient test data, although more will be needed. For programmers We have just constructed a State Transition Table. These are used in automata theory and sequential logic. They are extensively used in compilers. (Compilers are programs that translate code written in a programming language such as C# into machine code.)

Statistics

The tables below give the percentage of correct responses for each question. From 2011 to 2014, there was just a Junior paper, an Intermediate paper, and a Senior paper. An Upper Primary paper was added in 2015. Year Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15

7 64 89 27 57 40 26 15 15 16 59 47 31 37 31 13

2011 8 9 61 39 90 57 23 51 55 19 35 32 23 66 15 20 14 11 15 21 56 59 43 23 28 25 34 28 30 14 12 11

10 44 59 56 27 33 72 26 11 24 69 22 29 32 17 11

11 39 36 29 38 78 23 11 20 12 26 11 30 22 23 21

12 34 41 29 39 78 28 14 19 16 24 10 33 28 27 23

Year Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15

173

7 53 31 46 24 16 57 19 11 18 20 23 15 22 16 17

8 61 34 50 30 20 65 20 16 22 30 29 20 32 26 27

2012 9 43 80 27 44 30 50 42 39 39 36 38 38 37 22 39

10 46 82 31 48 37 56 45 40 42 40 43 42 42 30 44

11 44 57 73 11 24 39 56 37 34 52 30 47 63 38 27

12 54 56 77 12 26 41 54 38 36 51 39 53 67 44 30

174

statistics

Year Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15

7 85 48 43 26 55 57 59 51 59 52 9 22 44 36 5

2013 8 9 91 48 56 29 53 37 28 43 62 21 68 29 64 65 64 17 66 32 63 26 12 22 31 20 60 62 47 42 7 37

Year Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15

5 63 59 44 30 34 55 64 45 34 15 34 14 72 7 3

6 75 61 52 42 34 65 75 53 44 19 47 18 81 8 4

10 52 38 41 50 22 33 70 20 38 30 26 23 65 50 41

11 90 39 43 32 58 38 67 56 52 16 12 12 39 33 45

12 89 39 48 28 58 40 69 56 56 16 11 15 40 36 45

2015 7 8 74 76 62 65 72 78 31 39 22 26 52 62 39 47 24 32 26 36 35 42 38 44 8 10 73 80 10 15 5 10

9 57 36 69 31 39 39 43 21 31 46 13 9 13 14 8

10 61 36 72 34 41 38 49 28 35 53 16 10 17 18 9

Year Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15

11 54 27 60 45 69 10 68 46 23 43 36 18 17 12 15

12 59 37 61 49 70 10 73 54 32 52 48 24 21 13 16

7 48 29 38 36 30 26 31 27 14 54 38 52 34 24 20

8 60 34 42 40 33 29 37 35 19 58 47 58 37 27 23

2014 9 72 46 84 54 67 34 59 47 32 58 67 34 42 32 18

10 75 47 86 56 69 38 64 53 37 62 67 40 48 38 21

11 31 62 41 46 67 22 74 82 48 32 35 23 56 45 29

12 33 62 48 44 73 24 78 87 52 33 38 28 56 48 31

High Distinction Students

Approximately 2% of students are awarded high distinctions, although this may vary a little when there are ties. The maximum score is 36.

2011 Competition NAME

SCHOOL

Goh Siau Chiak Siew Kheng Hun Shi Jing Lin Ng Wei Keane, Neville Chan Chai Feng Benjamin Lee Yu Tse Lim Yi Shen Justin Sam Zhi Hao, Ryan Tan Yu Heng Julian Chuang Fu Wen Rayner Lim Wei Liang Chua Bing Hong Lee Yong Qin Yang Gan M Glanville M Robertson Tan Siah Yong Cheong Zhi Xi, Desmond Jonathan Nee Kok Hin L Brown A Bychkov J Day L Zubcic Foo Jyong Kiat, Reuben S Arora H Chen A de Araujo C Johnston N Niranjan J Yazdani Justin Tan Tse T Chong J Garlick Y Song L Virtue Ong Jun Hao Bryan Qin Yi Lin Si Jie Q Bell

Raffles Institution Raffles Institution Raffles Institution Raffles Institution Raffles Institution Raffles Institution Raffles Institution Raffles Institution Raffles Institution Raffles Institution Raffles Institution Raffles Institution Raffles Institution Raffles Institution Canberra Grammar School Campbell High School Raffles Institution Raffles Institution Raffles Institution Penleigh & Essendon Grammar School Chatswood High School Taroona High School Penleigh & Essendon Grammar School Raffles Institution Canberra Grammar School Rossmoyne Senior High School North Sydney Boys High School Epping Boys High School All Saints Anglican Middle School Wesley College Raffles Institution James Ruse Agricultural High School Taroona High School James Ruse Agricultural High School Taroona High School Dunman High School Dunman High School Raffles Institution Scotch College

175

STATE

YEAR

SCORE

SIN SIN SIN SIN SIN SIN SIN SIN SIN SIN SIN SIN SIN SIN ACT ACT SIN SIN SIN VIC NSW TAS VIC SIN ACT WA NSW NSW QLD WA SIN NSW TAS NSW TAS SIN SIN SIN VIC

7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9

36 36 36 34 34 34 33 33 33 33 32 32 32 32 32 32 36 36 36 36 34 34 34 33 33 33 33 33 33 33 32 32 32 32 32 34 33 33 33

176

high distinction students

NAME

SCHOOL

R Klugman T Zhou Wei Ling Yue J Huang T Morgan Jansen Jarret Sta Maria Lim Jian Loong Jethro Nikki Tanu D Kuhasri J Park C Pearce Rattanin Siripornpitak J Ha R Laven B Leung N Lodge D McKee P Zhu S Farshid A Quan B Connolly B Deme S Hoang R Pennefather T Ross B Scott-Sandvik K Wu D Altman Huang Geyang Lee Wei En Joseph Teo Hua Kian Hubert D Giritharan J Ha B Lowe C Yap N Schade B Pauley X Tan N Halton B Luo

Emanuel School North Sydney Boys High School Raffles Institution Penleigh & Essendon Grammar School Macarthur Anglican School Raffles Institution Raffles Institution Dunman High School James Ruse Agricultural High School Epping Boys High School Forest View High School (Tokoroa) Raffles Institution Penleigh & Essendon Grammar School St Peter’s College North Sydney Girls High School Penleigh & Essendon Grammar School Scots College Canberra Grammar School Canberra Grammar School Chatswood High School All Saints Anglican Middle School Canberra Grammar School Sefton High School Christ Church Grammar School Marrara Christian College Monbulk College Chatswood High School Emanuel School Anglo-Chinese Junior College Raffles Institution (Junior College) Raffles Institution (Junior College) Scotch College Scotch College Baulkham Hills High School Rossmoyne Senior High School Rosny College Christ Church Grammar School All Saints’ College Indooroopilly State High School Wesley College

STATE

YEAR

SCORE

NSW NSW SIN VIC NSW SIN SIN SIN NSW NSW NZ SIN VIC NZ NSW VIC NZ ACT ACT NSW QLD ACT NSW WA NT VIC NSW NSW SIN SIN SIN VIC VIC NSW WA TAS WA WA QLD WA

9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 12 12 12 12

33 33 32 32 32 31 31 31 31 31 31 30 36 32 32 32 32 32 31 31 30 30 30 30 30 30 30 33 31 31 31 30 30 30 30 29 31 30 29 28

STATE

YEAR

SCORE

VIC VIC ACT NSW VIC NSW VIC WA VIC VIC NSW NSW SIN VIC VIC VIC NSW VIC WA NSW WA SIN SIN VIC SIN

7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8

36 32 32 30 30 29 28 27 26 26 26 26 25 25 25 25 25 36 36 36 36 34 34 34 32

2012 Competition NAME

SCHOOL

M Cheah P Gianni M Nguyen-Kim A Barman L Potter A Hunt M Vitiello O Terry A Chen J Ives R Mannes J Spiller Ng Ying Sandra G Kaw L Luo D McNabb A Zhang A Gammon D He M Johnston N Pizzino Glen Loo Wen Bin Ho Zong Han A Barber Poon Jia Qi

Penleigh & Essendon Grammar School The University High School Canberra Grammar School James Ruse Agricultural High School The University High School Chatswood High School Penleigh & Essendon Grammar School Christ Church Grammar School Penleigh & Essendon Grammar School Buckley Park College Coleambally Central School Oxford Falls Grammar School Raffles Girls’ School (Secondary) Buckley Park College The University High School Red Cliffs Secondary College North Sydney Boys High School Scotch College Christ Church Grammar School Oxford Falls Grammar School Christ Church Grammar School Dunman High School School of Science and Technology Scotch College School of Science and Technology

2013 competition

177

NAME

SCHOOL

C Marlow Matthew Wong Kai-En Feng Jiahai Ang Wen Feng H Gaudin Kim Haeyoung Lim Sheng Yang Isaac J Doak L Li K Lin N Nguyen Owen Ong Chau Siong I Cole M Kedar E Sampson J Shaw Lim Yong Xiang Justin M Glanville A Janssen Z Paternoster J Wu Foo Jyong Kiat Reuben Jonathan Nee Eugene Lee Jeremy Ngo Hee Guan L Brown K Cao B Fielding Y Song C Thomas Wu Guan Qun Ng Yi Yan L Chan B Choy J Morrison A Butcher A de Araujo S Fung D Hellig-Smith D Stergio Qin Yi Sun Yisi D Chiu A Church J Hong A Keesing S Mulholland-Patterson E Park A Ross S Swan A Gruen Matthew Soh Cher Wei J Kenny Christabella Irwanto H Dyer S Lo A Lui Y Wu P Meiring

Duncraig Senior High School St. Joseph’s Institution Raffles Institution Dunman High School Logan Park High School Raffles Girls’ School (Secondary) School of Science and Technology Armidale High School Christ Church Grammar School Hamilton Girls’ High School Penleigh & Essendon Grammar School School of Science and Technology Presbyterian Ladies’ College Rose Bay Secondary College Presbyterian Ladies’ College Canberra Grammar School School of Science and Technology Canberra Grammar School Epsom Girls Grammar School Indooroopilly State High School North Sydney Boys High School Raffles Institution Raffles Institution Raffles Institution Raffles Institution Penleigh & Essendon Grammar School Penleigh & Essendon Grammar School Wesley College James Ruse Agricultural High School Lincoln High School Raffles Institution Dunman High School Scotch College North Sydney Boys High School Guildford Grammar School All Saints Anglican Middle School North Sydney Boys High School The University High School Emanuel School Chatswood High School Dunman High School Dunman High School James Ruse Agricultural High School Tintern Schools Epsom Girls Grammar School Elim Christian College All Saints’ College Epping Boys High School Smith’s Hill High School Christ Church Grammar School Narrabundah College Raffles Institution (Junior College) Home Education Network Raffles Institution (Junior College) Indooroopilly State High School Epsom Girls Grammar School Chatswood High School Sydney Boys High School Queensland Academy for Science, Mathematics & Technology Christ Church Grammar School North Sydney Boys High School

B Rampono K Zhuo

STATE

YEAR

SCORE

WA SIN SIN SIN NZ SIN SIN NSW WA NZ VIC SIN WA NSW VIC ACT SIN ACT NZ QLD NSW SIN SIN SIN SIN VIC VIC WA NSW NZ SIN SIN VIC NSW WA QLD NSW VIC NSW NSW SIN SIN NSW VIC NZ NZ WA NSW NSW WA ACT SIN VIC SIN QLD NZ NSW NSW QLD

8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 12 12

32 31 31 31 31 30 30 30 30 30 30 29 29 29 29 29 28 28 28 28 28 36 36 36 36 36 36 36 36 36 34 34 34 34 34 33 33 33 33 33 36 36 36 36 36 36 36 36 36 36 33 31 31 30 30 30 30 33 31

WA NSW

12 12

31 31

STATE

YEAR

SCORE

WA ACT HK

7 7 7

36 36 34

HK

7

34

2013 Competition NAME

SCHOOL

W Hu P Miller Li Chak Cheung Andy

Christ Church Grammar School Campbell High School Po Leung Kuk Leung Chow Shun Kam Primary School Island School

Wong Yat

178

high distinction students

NAME

SCHOOL

A Bharadwaj A Jeganathan J Sher K Zhou Leong Sin Yuen Lynnette A Chen H Choy A Donald V Mansell D Markakis E Moon B Robinson L Siu R Vidyasagar Liaw Xiao Tao Ye Jeff York E Buckland M Cheah Arya, Rahul Wong Yuk Guo Jingxue William Ming W Brown B Peters Samuel Ng Koh Guo Feng B Dey H Gabbedy P Gianni J Hartono R Huang J Hudson A Lawrance J Longden L Potter H Price E Vane M Vitiello W Whittakers K Wright L Yeung Xu Hongting Le Tran Kien S Jobanputra K Ranjit-Rajah J Everett P Ng Glen Loo Wen Bin A Gammon W Huang B Levy J Zhu Xue Chenyang D He A Wang J Abdulnour A Barber C Hynam C Lee N Mills N Reed J Tegel Ye Yunhao V O’Neill T Pham S Saha Y Song A Bychkov

Trinity Grammar School Christ Church Grammar School Moriah College North Sydney Boys High School School of Science and Technology Chatswood High School James Ruse Agricultural High School Lyneham High School The University High School St Catherine’s School North Sydney Boys High School The Geelong College Middle School North Sydney Boys High School The University High School School of Science and Technology Island School The University High School Penleigh & Essendon Grammar School King George V School Island School Dunman High School School of Science and Technology Penleigh & Essendon Grammar School Red Cliffs Secondary College School of Science and Technology School of Science and Technology James Ruse Agricultural High School Canberra Grammar School The University High School Macarthur Anglican School The University High School Shepparton Christian College Christ Church Grammar School John Curtin College of the Arts The University High School Taroona High School Indooroopilly State High School Penleigh & Essendon Grammar School The Geelong College Middle School Christ Church Grammar School Penleigh & Essendon Grammar School Dunman High School National Junior College Willetton Senior High School Willetton Senior High School Whakatane High School Mt Waverley Secondary College Dunman High School Scotch College Sefton High School Emanuel School North Sydney Boys High School Dunman High School Christ Church Grammar School Elim Christian College Penleigh & Essendon Grammar School Scotch College Guildford Grammar School Wesley College Elim Christian College The Knox School Macarthur Anglican School Dunman High School The University High School Christ Church Grammar School Epsom Girls Grammar School James Ruse Agricultural High School Chatswood High School

STATE

YEAR

SCORE

VIC WA NSW NSW SIN NSW NSW ACT VIC VIC NSW VIC NSW VIC SIN HK VIC VIC HKC HK SIN SIN VIC VIC SIN SIN NSW ACT VIC NSW VIC VIC WA WA VIC TAS QLD VIC VIC WA VIC SIN SIN WA WA NZ VIC SIN VIC NSW NSW NSW SIN WA NZ VIC VIC WA WA NZ VIC NSW SIN VIC WA NZ NSW NSW

7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10

34 34 34 34 33 32 32 32 32 32 32 32 32 32 36 36 36 36 34 34 34 34 34 34 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 33 33 33 33 32 32 31 31 31 31 31 30 30 30 29 29 29 29 29 29 29 36 36 36 36 36 34

2014 competition

179

NAME

SCHOOL

J Luo R Udaiyappan J Wong Chan Hiu Lok Felix Chu Jincong Chow Chun Hin

North Sydney Boys High School North Sydney Boys High School Willetton Senior High School The Chinese Foundation Secondary School Dunman High School Kwai Ming Wu Memorial School of the Precious Blood Sydney Boys High School Red Cliffs Secondary College Lincoln High School Christ Church Grammar School Sydney Boys High School Mount Aspiring College Penleigh & Essendon Grammar School Penleigh & Essendon Grammar School National Junior College Wah Yan College HK North Sydney Boys High School Caringbah High School Kwai Ming Wu Memorial School of the Precious Blood Newlands College Haileybury Sydney Boys High School Christ Church Grammar School Dunman High School The University High School Haileybury Smith’s Hill High School North Sydney Boys High School Mountain Creek State High School Christ Church Grammar School Perth Modern School

L Mah J Peters C Thomas J Brough I Lai R Sanders T Wang C Wijayasinghe Zhang Xinyi Lau Chi Yung A Cornish M Dimeglio Lo Kwun Yu P Huxford C Jones J Waring B Wright Pan Song K Chin A Ong A Ross T Huang M Finn D Wang J Povah

STATE

YEAR

SCORE

NSW NSW WA HKC SIN HK

10 10 10 10 10 10

34 34 34 33 33 33

NSW VIC NZ WA NSW NZ VIC VIC SIN HKC NSW NSW HK

10 10 10 10 10 10 10 10 11 11 11 11 11

33 33 33 32 32 32 32 32 36 36 36 36 34

NZ VIC NSW WA SIN VIC VIC NSW NSW QLD WA WA

11 11 11 11 11 11 11 11 12 12 12 12

34 34 34 34 33 33 33 33 36 34 34 33

STATE

YEAR

SCORE

SIN SIN SIN IDN SIN SIN SIN SIN WA VIC WA VIC VIC SIN ACT VIC VIC SA IDN VIC WA VIC NSW VIC NSW NSW ACT SIN SIN SIN ACT

7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8

36 34 34 33 30 30 30 30 30 29 29 29 29 28 28 28 28 28 36 36 36 34 34 34 34 34 34 33 33 33 33

2014 Competition NAME

SCHOOL

Ng Yu Peng Aung Kaung Kaung Sun Longxuan Alfian Edgar Tjandra Teoh Jun Jie Luo Ling Ke Lim An Jun Zhang Ruiyang S Dias M Lyons B Tang S Zhou J Zuk Chong Zheng Tao J Bolton M Wu C Young D Yu Hans Mahadhika Susanta J Alcalde W Hu A Bharadwaj H Choy D Howe O Kong P Patel J Welling Lee Yu Hsin Zhang Yanjun Zhou Yansheng P Miller

Hwa Chong Institution Hwa Chong Institution Hwa Chong Institution Mathematics Education Clinic Hwa Chong Institution Hwa Chong Institution Hwa Chong Institution ACS (International) SIN All Saints’ College Northcote High School All Saints’ College The University High School Elwood College Hwa Chong Institution Canberra Grammar School Penleigh & Essendon Grammar School The University High School Linden Park Primary School Mathematics Education Clinic Craigieburn Secondary College Christ Church Grammar School Trinity Grammar School James Ruse Agricultural High School Penleigh & Essendon Grammar School SCEGGS Darlinghurst James Ruse Agricultural High School Canberra Grammar School Hwa Chong Institution Hwa Chong Institution Hwa Chong Institution Campbell High School

180

high distinction students

NAME

SCHOOL

J Smith G White G Wong A Wu Lee Zi Xuan J Annear B Bliss N Lunz D Oneill E Parima V Varma Y Yuan Choo Yi Kai John Zhou Erli Keith Loi Jun Xian Li Zhuoan, Joan Clarence Chew Xuan Da Shi Lecheng Guo Jingxue Sheldon Ng M Ashurst S Bohun M Cheah H Chong O Gwatkin T Hall C Hartley J Heggie T Jeon R Ji A Law V Ma J Yim Shashvat Shukla Tan Jun Hong Toh Zhen Yu Nicholas Chua Wei Ting Lee Yang Peng Sim Ming De Chen Shahang Joyce Yeo Shuhui Yew Jen Khai Le Tran Kien Nicholas Steven Husada Matthew Ryan Wong KaiEn N Abelman K Andrew Z Carn H Charak I Davies H Ferstl M Glanville E Hall D He Y He T Johnson L Jolliffe J King E Landow C Lee D Li H Li O Li R Morf L Nguyen

STATE

YEAR

SCORE

All Saints’ College The Geelong College Middle School Burnside High School St Peter’s College Senior School Hwa Chong Institution Christ Church Grammar School The University High School Moriah College The University High School John Curtin College of the Arts Canberra Grammar School Sefton High School NUS High School of Math & Science NUS High School of Math & Science NUS High School of Math & Science NUS High School of Math & Science NUS High School of Math & Science National Junior College Dunman High School Dunman High School Lyneham High School The University High School Penleigh & Essendon Grammar School Chatswood High School Lincoln High School St Peter’s College Senior School James Hargest College Mareeba State High School Concord High School Epsom Girls Grammar School James Ruse Agricultural High School Hornsby Girls’ High School Hornsby Girls’ High School NUS High School of Math & Science NUS High School of Math & Science NUS High School of Math & Science Dunman High School Dunman High School Dunman High School Dunman High School Dunman High School National Junior College National Junior College Mathematics Education Clinic St. Joseph’s Institution

WA VIC NZ SA SIN WA VIC NSW VIC WA ACT NSW SIN SIN SIN SIN SIN SIN SIN SIN ACT VIC VIC NSW NZ SA NZ QLD NSW NZ NSW NSW NSW SIN SIN SIN SIN SIN SIN SIN SIN SIN SIN IDN SIN

8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10

33 33 33 33 32 31 31 31 31 31 31 31 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36

Mount Scopus Memorial College Secondary School Sydney Boys High School Telopea Park School Kesser Torah College Wenona School Wenona School Canberra Grammar School Lyneham High School Christ Church Grammar School Queensland Academy for Science, Mathematics & Technology Hunter Christian School Churchlands Senior High School Sydney Boys High School Armidale High School Wesley College Presbyterian Ladies’ College Lyneham High School Scotch College John Monash Science School Penleigh & Essendon Grammar School

VIC

10

36

NSW ACT NSW NSW NSW ACT ACT WA QLD

10 10 10 10 10 10 10 10 10

36 36 36 36 36 36 36 36 36

NSW WA NSW NSW WA VIC ACT VIC VIC VIC

10 10 10 10 10 10 10 10 10 10

36 36 36 36 36 36 36 36 36 36

2015 competition

181

NAME

SCHOOL

A Onus N Pizzino N Reed J Shaw J Toland S Vakirtzis T Waring M Wilson J Ye D Ying J Zhu Pek Yu-Xuan Sean R Udaiyappan A de Araujo J Liu Y Song A Tsang S Xue Chen Yankang Tan Hong Jie Uriel N O’Callaghan L Wilson Wang Fan, Francis N Chen C Thomas M Stark V Zhang

Campbell High School Christ Church Grammar School The Knox School Canberra Grammar School Condell Park Christian School Sydney Boys High School Christ Church Grammar School Samuel Marsden Collegiate School Sydney Boys High School James Ruse Agricultural High School Barker College NUS High School of Math & Science North Sydney Boys High School North Sydney Boys High School North Sydney Boys High School James Ruse Agricultural High School Christ Church Grammar School North Sydney Boys High School National Junior College NUS High School of Math & Science Christ Church Grammar School Wesley College Glen Waverley NUS High School of Math & Science North Sydney Boys High School Indooroopilly State High School Chatswood High School North Sydney Boys High School

STATE

YEAR

SCORE

ACT WA VIC ACT NSW NSW WA NZ NSW NSW NSW SIN NSW NSW NSW NSW WA NSW SIN SIN WA VIC SIN NSW QLD NSW NSW

10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12

36 36 36 36 36 36 36 36 36 36 36 36 36 34 34 34 34 34 33 33 33 33 36 36 36 34 34

STATE

YEAR

SCORE

2015 Competition NAME

SCHOOL

J Lockhart Muhammad Arif Wibisono B Lam M Silins X Chen M Lee Stanve Avrilium Widjaja H Tang L Armstrong S Burg L Coiera S Kertesz M Ma C Underwood Muhammad Surya Siddiq J Weston-Davis Y Yong Jie Arthur Ke Yansheng T Hauck T Loh E Lord Tan Cheng Yat J Tyl S Gyger L Hong T Hutchinson S Li K Lim Y Miao T Poletti J Leung B Lin Zhan Li M Schwarz

Sydney Grammar Edgecliff Prep Mathematics Education Clinic

NSW IDN

5 5

34 29

Arden Anglican School (Primary Campus) Arden Anglican School (Primary Campus) Oberthur Primary School Sydney Grammar Edgecliff Prep Mathematics Education Clinic Trinity Grammar School Trinity Grammar School St Thomas Aquinas Primary School Sydney Grammar Edgecliff Prep Sydney Grammar Edgecliff Prep Sydney Grammar Prep School Rosalie Primary School Mathematics Education Clinic Radford College Hwa Chong Institution Hwa Chong Institution All Saints Anglican Middle School Hwa Chong Institution Taroona High School NUS High School of Math & Science Chatswood High School Methodist Ladies’ College Raffles Girls’ School (Secondary) Canberra Grammar School Hwa Chong Institution Hwa Chong Institution Penleigh & Essendon Grammar School Northcote High School James Ruse Agricultural High School Hwa Chong Institution Mount Scopus Memorial College Secondary School Presbyterian Ladies’ College Sydney Canberra Grammar School

NSW NSW WA NSW IDN VIC VIC NSW NSW NSW NSW WA IDN ACT SIN SIN QLD SIN TAS SIN NSW VIC SIN ACT SIN SIN VIC VIC NSW SIN VIC

5 5 5 5 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7

29 29 28 28 36 36 34 32 32 32 31 31 36 36 36 34 34 34 34 33 33 32 32 32 32 32 32 32 31 31 31

NSW ACT

8 8

36 36

A Bai B Daniell

182

high distinction students

NAME

SCHOOL

S Foo Y Loo M Lyons N Prohm A Ritossa K Shen E Shi Cheng Z Yuan L Yue Lin S Zayne G Zhu R Bakker B Davison-Petch G Gabbedy Z Loh X Low En Xiang L Luo Y Ng A Yapp Wei Rong Alfian Edgar Tjandra M Rees R Shen V Sun C Chivers Y Lim J Liu W Hu D Lim Wee Soong He Yu L Grime D Lau J Smith O Terry A Tew

Hwa Chong Institution Hwa Chong Institution Northcote High School Smith’s Hill High School St Peter’s College Senior School James Ruse Agricultural High School Hwa Chong Institution Lyneham High School NUS High School of Math & Science NUS High School of Math & Science Telopea Park School Christ Church Grammar School Christ Church Grammar School Canberra Grammar School Hwa Chong Institution NUS High School of Math & Science Hwa Chong Institution Hwa Chong Institution NUS High School of Math & Science Mathematics Education Clinic Taroona High School Paraparaumu College Perth Modern School Willetton Senior High School NUS High School of Math & Science Brighton Grammar School Christ Church Grammar School NUS High School of Math & Science National Junior College St Ives High School North Sydney Boys High School All Saints’ College Christ Church Grammar School Temple Christian College Mile End Campus Indooroopilly State High School Taroona High School Radford College NUS High School of Math & Science Lyneham High School NUS High School of Math & Science Willetton Senior High School Canberra Grammar School Radford College National Junior College Dunman High School Barker College James Ruse Agricultural High School Penleigh & Essendon Grammar School Penleigh & Essendon Grammar School Chatswood High School Lyneham High School Lincoln High School Sydney Boys High School Penleigh & Essendon Grammar School RISE Education Sydney Boys High School Sydney Boys High School Sydney Boys High School Portland Secondary College The Knox School James Ruse Agricultural High School Mathematics Education Clinic Dunman High School Calvin Christian School Mt Roskill Grammar School The Canberra College RISE Education

J Jeffree M Stack R Stocks L Song Zhu Owen R Callaway D Cheng A Lee J Phillips S Sima Ni Tianzhen Yang Hongrui D Young S Liu M Vitiello M Cheah A Hunt M Ashurst O Gwatkin D Yan L Yeung X Hongsheng T Li K Shiva J Tian Z Heppenstall N Reed D Ying Nicholas Steven Xu Hongting C Amos J Khoo B Wu B Yu

STATE

YEAR

SCORE

SIN SIN VIC NSW SA NSW SIN ACT SIN SIN ACT WA WA ACT SIN SIN SIN SIN SIN IDN TAS NZ WA WA SIN VIC WA SIN SIN NSW NSW WA WA SA

8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9

36 36 36 36 36 36 36 36 36 36 36 34 34 34 34 34 34 34 34 33 33 33 33 36 36 36 34 34 33 33 33 33 33 33

QLD TAS ACT SIN ACT SIN WA ACT ACT SIN SIN NSW NSW VIC VIC NSW ACT NZ NSW VIC CHI NSW NSW NSW VIC VIC NSW IDN SIN TAS NZ ACT CHI

9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11

32 32 32 31 30 30 30 30 30 36 36 36 34 34 33 33 32 32 32 32 31 31 31 31 36 33 33 31 31 31 31 31 31

2015 competition

183

NAME

SCHOOL

Y Song Sui Dongchen Tang Jiacheng

James Ruse Agricultural High School Dunman High School Dunman High School

STATE

YEAR

SCORE

NSW SIN SIN

12 12 12

34 33 32

David Clark worked as a teacher and computer programmer before his love of mathematics (and a young lady) induced him to resign and undertake a Master of Mathematics at the University of Waterloo in Canada. This led to a PhD at the Australian National University, two years lecturing at the University of Kentucky and 25 years at the University of Canberra (UC). Whilst at UC he was a member of the Australian Mathematics Foundation committee for 20 years. He has been a member of the Australian Informatics Competition committee for 15 years and is currently Chair of the CAT Problems Committee, having previously held the positions of AIOC Treasurer and IOI Deputy Team Leader. He is now enjoying retirement and grandparenting (with the same lady).

T h e A u s t r a l i a n M at h e mat i c s T r u s t I

n f o r mat i c s

S

e r i e s

ISBN 978 1 876420 76 5