Activity 1
Have a go at this challenge taken from here: http://www.folj.com/puzzles/
The Camels
Four tasmanian camels traveling on a very narrow ledge encounter four tasmanian camels coming the other way.
As everyone knows, tasmanian camels never go backwards, especially when on a precarious ledge. The camels will climb over each other, but only if there is a camel sized space on the other side.
The camels didn't see each other until there was only exactly one camel's width between the two groups.
How can all camels pass, allowing both groups to go on their way, without any camel reversing?
Activity 2
Write an algorithm for the camel challenge. Can you structure the data to make it easier to write your algorithm?
Activity 3
A common method for structuring data in a programming language is called an Array.
In Python, you can create an array by using the structure below:
myArray = ["Camel A","Camel B","Camel C", "Camel D", "SPACE", "Camel 1", "Camel 2", "Camel 3", " Camel 4"]print (myArray)Copy and paste this code into Python and see what happens.
(Download Python from here: https://www.python.org/downloads/)
Activity 4
The table shows how the array has been structured. Each location in the array has a number associated with it. Camel 1 is in location [0]. In Python, and most programming languages, the first item in the array is at location [0].
Add the following line of code to your Python program:
print (myArray[0])Run the code now and see what happens.
Try and print Camel B and Camel C to see if you can get it to work.
Activity 5
If we wanted to test out our algorithm then we would need to know how to swap positions of the camels.
Try this piece of code and see what happens:
myArray[0], myArray[1] = myArray[1], myArray[0]print (myArray)You should notice that it has swapped Camel A and Camel B over.
Challenge
Try and figure out how to code the solution to the Camel Challenge in Python!
Learn more about arrays by using this worksheet:
Code for this task is here:
# defines an array called animalsanimals=["Dog","Cat","Pig","Sheep","Elephant","Aardvark"]# prints the arrayprint (animals)# sorts the array into alphabetical orderanimals.sort()# prints the arrayprint (animals)# adds an extra item to the arrayanimals.append("Cow")# re-sorts the arrayanimals.sort()print (animals)# removes an item from an arrayanimals.remove("Dog")print (animals)# we can also do all of this with integersnumbers = [4,5,6,2,4,5,7,8]numbers.sort()print (numbers)Code for this task is here:
# this defines an arraynumbers=[]# this fills that array with numbers automaticallyx=0while x<10: numbers.append(x) #whatever is stored in x will be added to the array as an item x=x+1print (numbers)x=0while x<10: numbers.remove(x) #whatever is stored in x will be removed from the array as an item x=x+2 #because we added 2 it will only remove every other itemprint (numbers)# we can do the same for string and inputplayers=[]x=0while x<5: name=input("Enter a player name: ") # this will ask for 5 player names players.append(name) # each one will be stored as a list item x=x+1print (players) # this will display all the names storedThe logic puzzle used for this learning outcome is a classic computational thinking exercise. Students may find it easier to understand if they have a physical version of it. They could even try it in the playground with 8 students and some chalk to draw out the grid.