More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post
page
Python IDE Dashboard

Performance Modelling & Data Visualisation – Q&A

Question 1[2 marks]
road-network A small town wants to improve the traffic within the town centre at peak time. They are considering using a synchronised traffic lights system to fluidify the traffic. But before replacing all existing traffic lights and installing new ones, they would like to use some performance modelling system to evaluate the impact the new traffic lights could have on the traffic.

A graphic designer has produced the following map of the town centre. This map will be used for the main screen of the performance modelling system.

Explain why the above map is an abstraction of the town centre.
Question 2[6 marks]
Describe how the new performance modelling system could use different data visualisation techniques to represent key information about the traffic in the town centre.
Question 3[6 marks]
Evaluate the benefits and limitations for the town to use a performance modelling system in this context?
Save / Share Answers as a link
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Recursive vs. Iterative Algorithm – Q&A

Question 1[2 marks]
For this question, we are looking at an algorithm used to implement the divisibility rule for 3 which states that:

A number is divisible by 3 if the sum of all its digits is divisible by 3.

Let’s look at the following example: is 378 divisible by 3? divisibility-rule-for-3 Here is the Python code for our recursive algorithm:
def isDivisibleByThree(n):
   sum = 0
   for digit in str(n):
     sum = sum + int(digit)
   
   if sum>=10:
     return isDivisibleByThree(sum)
   else:   
     if sum==3 or sum==6 or sum==9:
       return True
     else:
       return False
       
number = int(input("Type a number"))
if isDivisibleByThree(number)==True:
  print("This number is divisible by 3.")
else: 
  print("This number is not divisible by 3.")
Explain why the above code can be described as being a recursive algorithm? State on which line of this code does the recursion occur?
Question 2[4 marks]
Trace this algorithm if the user enters the value 8479
Question 3[4 marks]
Rewrite the function isDivisibleByThree() using an iterative approach instead of a recursive approach.
Save / Share Answers as a link
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with:

File Size Calculations – Q&A

Question 1[3 marks]

text-file-estimate
How many of the above text files can we store on a 1.44MB floppy disk?

Each text file contains 6,000 characters and is encoded using ASCII: 8 bits per character.




Question 2[3 marks]

picture-file-estimate
I have 3,000 pictures on my 32GB micro SD card. How much free space is there left on this SD card?

Each picture file has a width of 1920px, a height of 1080px and a colour depth of 24 bits.




Question 3[4 marks]

sound-file-estimate
I have selected 20 sound files to burn on a CD (700MB). How many extra sound files can I add to this CD?

Each sound file has a sample rate of 44.1kHz, a bit depth of 16-bits and lasts 3 minutes and 30 seconds.





Save / Share Answers as a link

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area


Tagged with:

OOP – Inheritance – Q&A

Question 1[2 marks]
Class File:​
   private filename​
   
   //Constructor for the File class
   procedure new(strFilename):​
      filename = strFilename​

   public procedure rename(strFilename)​
      if strfilename!="":​
         filename = strFilename​

Class MP3 inherits File:​
  private title​
  private artist​
  private duration​

  //Constructor for the MP3 class
  procedure new(strFilename, strTitle, strArtist, intDuration):​
     super.new(strfilename)​
     title = strTitle       ​
     artist = strArtist​
     duration = strDuration​

  public function getDuration():​
     min = duration // 60​
     sec = duration % 60​
     return (str(min) + ":" + str(sec))

What code would you write to instantiate one new MP3 object called topTrack for the latest 3 minutes 12 seconds song “Shivers” from Ed Sheeran?




Question 2[4 marks]

What are all the methods and properties of the MP3 class?




Question 3[4 marks]

Explain, using an example from this code, what is meant by inheritance?





Save / Share Answers as a link

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area


Tagged with: , ,

OOP – Encapsulation – Q&A

Question 1[2 marks]
class Padlock:
  private key
  private locked
  
  //Constructor for the Padlock class:
  procedure new(str_key,bool_locked):
    key = str_key       
    locked = bool_locked  
    
  public function unlock(combination):
    if combination==key:
       locked = False
       return True
    else:
      return False
      
  public procedure lock():
    locked = True
    
  public function getKey():
    return key
    
  public function setKey(combination):
    if length(combination)==4:
      key = combination
      return True
    else:
      return False
What code would you write to instantiate two new padlocks: One called bikeLock that is already locked with a combination of 4321 and one called gardenShedLock that is unlocked with a combination of 1234?
Question 2[4 marks]
Explain using an example from the above code for the Padlock class, what is meant by encapsulation.
Save / Share Answers as a link
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: , ,

Maths Puzzles…

The aim of this challenge is to write a few algorithms to solve the following Maths puzzles:

In order to solve these puzzles, we will use an iterative approach using nested loops to test all possible combinations of two numbers until we find a match.

You will first look at the code used to solve the following puzzle and then tweak this code to solve the puzzles listed above.
maths-puzzle

Iterative Approach using nested loops…

Here is our code based on nested loops to test all possible pairs of numbers between 0 and 1,000.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area


Brunel’s Engineering Algorithms

brunel-topper-hatIsambard Kingdom Brunel (1806-1859) was an English civil engineer who is considered one of the greatest figures of the Industrial Revolution. Brunel achieved many engineering firsts thanks to his hard-work, his engineering knowledge, his innovative mind and his renowned problem solving skills. Some of his achievements include assisting in the building of the first tunnel under the River Thames, the design & development of the SS Great Britain, the largest ship ever built at the time: launched in 1843 the SS Great Britain was the first propeller-driven, ocean-liner ship with an iron hull. Brunel also worked on many architectural projects and viaducts when designing the Great Western Railway (GWR) linking Bristol to London. One of his major project, who was fully completed five years after his death, is the famous Clifton Suspension Bridge over the river Avon in Bristol, UK.

In this set of challenges, we are going to write four short algorithms that could have helped Brunel on his engineering projects. Obviously, computers did not exist in Brunel’s time, but the mathematical concepts used by these algorithms were for sure known and heavily used in Brunel’s engineering calculations. You can use our online Python IDE to write your algorithms/functions in Python.

Algorithm #1: Propeller Inner Angle

When Brunel worked on the design and construction of the SS Great Britain ship, most engine powered ships of the time used paddle wheels. His first design for this large iron hull ship was also based on using paddle wheels on both sides of the hull, however Brunel soon found out that using a propeller would be more effective and therefore he changed his design halfway through the construction stage! Once the decision was approved, one of Brunel’s next decisions was to choose how many blades to use for the propeller.

To assist him with the technical drawing of the propeller, Brunel used the following formula:
propeller-inner-angle-formula

Your task is to write a function called calculateAngle() that takes one parameter, the number of blades of a propeller (as a positive integer value). Your function will calculate and return the inner angle between two adjacent blades (in degrees).

You will then be able to complete the following test plan to check that your function is working as expected:

Test #   Input Value:
Number of blades
Expected Output Actual Output
#1 propeller-2-blades 2 180°
#2 propeller-3-blades 3 120°
#3

propeller-4-blades 4 90°
#4 propeller-6-blades📷 6 60°

Algorithm #2: Viaduct Arches

A viaduct is a specific type of bridge that consists of a series of arches, piers or columns supporting a long elevated railway or road. When working on the Great Western Railway (GWR) linking Bristol to London, Brunel designed several viaducts, each with a different length, height and number of arches. The Wharncliffe viaduct 📷 is a great example of his work. Built in 1837, it was the first railway viaduct to be built with hollow piers. It is 270 meters long and consists of eight arches.


Supposing that each arch has the same width, we can calculate the width of an arch as follows:
viaduct-formula

Your task is to write a function called calculateArchWidth() that takes two parameters, the length of the viaduct in meters and the number of arches (both parameters being given as positive integers). Your function will calculate and return the width of an arch.

You can test your algorithm using the following test plan:

Test #   Input Value: Expected Output Actual Output
#1 Wharncliffe Viaduct 📷 Viaduct Length: 270m
Number of Arches: 8
Arch width: 33.75m
#2 Carnon Viaduct 📷 Viaduct Length: 230m
Number of Arches: 9
Arch width: 25.55m

Algorithm #3: Railway Slope

When designing the Great Western Railway (GWR), one of the main objectives of Brunel was to design a fairly straight route as level as possible in order to promote high speed travel on the line. To do so Brunel had to estimate the percent slope (gradient) of every section of the route to avoid steep slops.

Here is the formula that Brunel used to calculate the percent slope of every section of his planned route:
railway-percent-slope-formula

Your task is to write a function called calculatePercentSlope() that takes two parameters: delta_x (Δx) and delta_h (Δh), the difference in coordinates and altitudes between the starting and ending position of a section. Your function will use these two parameters to calculate and return the percent slope of the section.
You can test your algorithm using the following test plan:

Test #   Input Value: Expected Output Actual Output
#1 Section 1 Δx = 800m
Δh = 32m
Percent Slope: 4%
#2 Section 2 Δx = 500m
Δh = 60m
Percent Slope: 12%
#3 Section 2 Δx = 750m
Δh = 45m
Percent Slope: 6%

Algorithm #4: Suspension Bridge Arc Length

One of Brunel’s most famous project is the Clifton Suspension Bridge, Bristol’s most impressive structure. He started to design this project at the age of 24. The bridge took 33 years to complete!

clifton-suspension-bridge

One of the mathematical puzzle that Brunel had to solve, was to estimate the length of the main arc of the suspension bridge. This arc consists of wrought iron chains to support the load of the main deck as well as the extra load due to the traffic across the bridge. The arc joins the two towers on each side of the river Avon. The two towers are separated by 214 meters and are rising 26m above deck level. The deck itself is 75m above the high water mark!

The following mathematical formulas can be used to calculate the arc length based on the distance between the two towers (l) and the height of each tower (from the deck level) (h)

suspension-bridge-arc-length-formula
Your task is to write a function called calculateArcLength() that takes two parameters: the length (l) and the height (from the deck level) (h) of the suspension bridge. Your function will use these two parameters to calculate and return the length or the arc of the bridge.

You can test your algorithm using the following test plan:

Test #   Input Value: Expected Output Actual Output
#1 Clifton Suspension Bridge length = 214m
height = 26m
Arc Length: 222m

To find out more about Brunel‘s work visit the SS Great Britain museum in Bristol, UK.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area


Tagged with: ,

The Climbing Stairs Puzzle

Imagine a staircase with n steps. As you are climbing up this staircase, you either climb one or two steps at a time. The aim of this computing puzzle is to find out, using an algorithm, in how many distinct ways can you climb to the top?

Confused by this puzzle? Let’s look at an example where you are climbing a small staircase of only 4 steps. Remember, for every “step” you make, you can either climb 1 or two steps at a time. Which means there are 5 different ways you can climb this staircase as shown on the pictures below:

staircase-1-1-1-1-stepsstaircase-2-1-1-stepsstaircase-1-2-1-stepsstaircase-1-1-2-stepsstaircase-2-2-steps

A Recursive Approach?

Let’s investigate this problem, “step by step”!!

We can assume that n, the total number of steps in the staircase is a positive integer.
The output of our algorithm is the total number of distinct ways we can climb this stair.

So we can easily deduct that:

  • If n=0, the output should be zero too.
  • If n=1, the output will be 1 (there is only way to climb this step).
    staircase-1step
  • If n=2, the output will be 2 (there are only two ways to climb this step).
    staircase-1-1-stepsstaircase-2-steps
  • For any n number of steps greater than 2, we notice that to reach the nth, we have to first reach either step (n-1) or step (n-2).
    staircase-n-steps

    So to count the number of ways we can reach step n, we can use the following recursive formula:

    if n>2 then countWays(n) = countWays(n-1) + countWays(n-2)
    countWays(2) = 2
    countWays(1) = 1

    where countWays(n) is a function that returns the number of ways you can reach the nth step.

Python Code

To implement an algorithm based on this formula we will use a recursive function called countWays() that takes one parameter, n, the position of the step we aim to reach. The function will return the number of possible distinct ways to reach this step when climbing up from the bottom of the stairs.

Tracing a Recursive Algorithm

You can visualise/trace this recursive algorithm using recursivevisualization.com.

tracing-recursive-function

Your Task

What about if as you are climbing up this staircase, you could climb 1, 2 or 3 steps at a time?

Adapt the above python code to implement this small change in the climbing stairs puzzle.

Fibonacci Numbers

You may have recognised that our countWays() function is based on a very similar recursive formula used to calculate the nth term of the Fibonacci sequence.
fibonacci-sequence


unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area


Tagged with:

French Cuisine – Entity Relationship Diagram (ERD)

french-cuisineFrench Cuisine is a 5-star restaurant serving a selection of carefully selected French recipes in a cosy atmosphere. Their menu is organised into 4 categories as follows: Starters, Main Meals, Deserts & Drinks.

In the dining area, there are 21 tables of different sizes (to serve from 1 to 8 customers per table). Each table has a unique number that is used by waiters & waitresses when they take and deliver an order.

Customers have to book a table in advanced by calling the restaurant. When they do so, the receptionist records the name and phone number of the customer making the booking and the number of guests the booking is for. The restaurant does not need to record the information of all the guests when a booking is made. Depending on the number of guests, the receptionist will allocate a table to the booking. Only 1 table can be booked per booking, so if a customer requires more than one table (for a large group) they will need to make several bookings.

When an order is raised the, the waiter or waitress write downs the menu item codes from the main menu and the quantity required.

Up to now, all the information recorded by both the receptionist when a booking is made and by the waiters/waitresses taking the orders at the table, is handwritten using small notebooks. However the restaurant would like to upgrade their system and intend to provide both the receptionist and the waiters & waitresses with touchscreen tablets to record table bookings and orders on a central system/database.

Your task is to design the Entity Relationship Diagram (ERD) for a relational database that will store information about:

    the different tables in the restaurant (Table number and capacity),
    the menu items that can be ordered from the menu (with a description and a price for each item as well as an indication as whether the item is suitable for vegetarians or not),
    the bookings made (storing information such as date and time of the booking, number of guests, table number),
    the contact details of the customers making the bookings,
    the orders being raised with, for each order, the table number the order is for, a list of all item codes being ordered from the menu and the quantities required.

You can use our online ERD tool to create the Entity Relationship for this 5 star restaurant:
Design Your ERD Online
kitchen-tools

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area


Tagged with: , , ,

10/02/22 Computing Challenge

As this post was published on the 10th of February 2022 (10/02/22), we would like to use a Python algorithm to solve the following arithmetic puzzle:

10-02-22-arithmetic-puzzleLet’s consider a string consisting of 10 characters “2”: string = “2222222222”

This computing challenge consists of writing an algorithm to work out the largest number we can create by inserting 2 multiplication operators (*) anywhere within this string.

For instance:

  • 2 * 2 * 22222222 = 88,888,888
  • 2 * 22 * 2222222 = 97,777,768
  • 2222 * 2222 * 22 = 108,620,248
  • 222 * 222 * 2222 = 109,509,048
  • etc.

10th February 2022

Python Code

You can use the trinket below to write and test your algorithm… We have started the code for you to test all possible positions of the first multiplication operator. Your task is to complete this code to:

  1. Add a second multiplication sign and test every possible position for this second sign,
  2. Calculate the result of each expression and output the largest value reached.


unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area