That Blue Square Thing

Do now tasks slidePDF icon

Knowledge organiserPDF icon

Year 9 Computing – Algorithms, puzzles and programming

A different algorithm.

Let's think of a number...

PDF iconStart here

This is all going to get a little bit puzzling. That's a good thing.

> programming instructions

There are some ways we can extend this idea a bit further as well.

PDF iconExtending the program

About the algorithm

PDF iconAbout the algorithm

A different algorithm

There's another way to find a number. And the algorithm is simpler as well.

PDF iconLinear search algorithm

We can code this as well. But, even better, we can code it so that the computer does the guessing. A bit like an AI bot might.

Here's some Scratch code to implement this:

PDF iconThe Scratch program

And here are instructions for how to do this in Python.

> linear search programming instructions

This program will work like a robot and should guess any number using a linear search.

Testing the binary search algorithm

It is possible to write a program to create a bot to use a binary search as well, although it's quite a lot more complicated!

Here's a program that I wrote to do this job. You can copy and paste the code into a new Python window. Save it and then run the program. Does it work as well as you'd expect?

Text iconProgram code for binary search – copy and paste the program into a new Python window

How many guesses does it need for a number between 1 and 20? How about 1 to 100? How about 1 to 1000? Is this what you'd expect?

Here's the theory:

PDF iconHow many guesses?

Text iconHow many guesses program – copy and paste the program into a new Python window