More results...

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

Fibonacci Sequence using LMC

fibonacci-sequence

Did you know?


The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 … where the next number is found by adding up the two numbers just before it.

number-sequence-diagram-5

The first 10 numbers of the Fibonacci number sequence are:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34

The following table shows how we can calculate each Fibonacci number from this sequence:

Fibonacci Number Calculation
0
1
1 = 0 + 1
2 = 1 + 1
3 = 1 + 2
5 = 2 + 3
8 = 3 + 5
13 = 5 + 8
21 = 8 + 13
34 = 13 + 21

Little Man Computer


Your challenge is to write a program using one of the following online LMC Simulators to calculate and output the first 10 numbers of the Fibonacci sequence.

LMC Instruction Set


Note that in the following table “xx” refers to a memory address (aka mailbox) in the RAM. The online LMC simulator has 100 different mailboxes in the RAM ranging from 00 to 99.

Mnemonic Name Description Op Code
INP INPUT Retrieve user input and stores it in the accumulator. 901
OUT OUTPUT Output the value stored in the accumulator. 902
LDA LOAD Load the Accumulator with the contents of the memory address given. 5xx
STA STORE Store the value in the Accumulator in the memory address given. 3xx
ADD ADD Add the contents of the memory address to the Accumulator 1xx
SUB SUBTRACT Subtract the contents of the memory address from the Accumulator 2xx
BRP BRANCH IF POSITIVE Branch/Jump to the address given if the Accumulator is zero or positive. 8xx
BRZ BRANCH IF ZERO Branch/Jump to the address given if the Accumulator is zero. 7xx
BRA BRANCH ALWAYS Branch/Jump to the address given. 6xx
HLT HALT Stop the code 000
DAT DATA LOCATION Used to associate a label to a free memory address. An optional value can also be used to be stored at the memory address.
unlock-access

Solution...

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

Hardware Contest

In this hardware contest, you will be presented with two computers at a time (desktops or laptops). Your task is to compare the technical specifications of both computers and discuss and justify which computer seems to have the highest specifications. You should discuss your findings with your peers.

Computer #1
CPU Clock Speed
Number of Cores
CPU Cache
RAM
Graphic Card
Hard Drive
Optical Drive
NIC Card
Screen Size
Computer #2
CPU Clock Speed
Number of Cores
CPU Cache
RAM
Graphic Card
Hard Drive
Optical Drive
NIC Card
Screen Size

LMC Simulator

LMC900
LMC simulators are based on the Little Man Computer (LMC) model of a computer, created by Dr. Stuart Madnick in 1965. The LMC simulator is generally used to for educational purposes, because it models a simple Von Neumann architecture computer which has all of the basic features of a modern computer. It is programmed using assembly code.

The LMC simulator demonstrates how assembly code is processed by the CPU using the Fetch, Decode and Execute (FDE) Cycle. It shows the impact of the FDE cycles on the main registers found inside the CPU:

  • The PC (Program Counter),
  • The CIR (Current Instruction Register),
  • The MAR (Memory Address Register),
  • The MDR (Memory Data Register),
  • The Accumulator.

The LMC simulator also demonstrates how the CPU interacts with the Random Access Memory (RAM) and how both data and instructions are stored in the RAM. On our LMC simulator the RAM consists of 100 memory cells (also called mailboxes). Each cell has a unique memory location (a number between 00 and 99).

Most assembly instructions consist of an opcode and an operand.
When coding in assembly code we use mnemonics (e.g. INP, ADD, SUB, LDA, STA, etc.) for the opcode of the instruction. A lookup table (See at the end of this blog post) is used to check the corresponding opcode matching a mnemonic. With the LMC simulator, the operand is a memory location (Direct Addressing) of where the data used by the instruction can be fetched from (e.g. LDA, ADD, SUB instructions) or needs to be stored (e.g. STA instruction).

Labels can also be used instead of hard coding memory locations in the code. Labels are extremely useful when using branching instructions (BRA, BRZ, BRP), as they can be used to locate a specific instruction in the code/RAM. They can also be used to name memory cells in the RAM used to temporary store values. (Similar to the use of variables in a high level code).

LMC simulators can be used to implement simple programs to perform basic mathematical operations such as adding or subtracting numbers, comparing or sorting numbers, etc.

Launch our online LMC SimulatorOpen in new tab/window

You will find on this blog a range of LMC challenges that you can complete using our online LMC simulator:

LMC Instruction Set / Lookup Table


Note that in the following table “xx” refers to a memory address (aka mailbox) in the RAM. The online LMC simulator has 100 different mailboxes in the RAM ranging from 00 to 99.

Mnemonic Name Description Op Code
INP INPUT Retrieve user input and stores it in the accumulator. 901
OUT OUTPUT Output the value stored in the accumulator. 902
LDA LOAD Load the Accumulator with the contents of the memory address given. 5xx
STA STORE Store the value in the Accumulator in the memory address given. 3xx
ADD ADD Add the contents of the memory address to the Accumulator 1xx
SUB SUBTRACT Subtract the contents of the memory address from the Accumulator 2xx
BRP BRANCH IF POSITIVE Branch/Jump to the address given if the Accumulator is zero or positive. 8xx
BRZ BRANCH IF ZERO Branch/Jump to the address given if the Accumulator is zero. 7xx
BRA BRANCH ALWAYS Branch/Jump to the address given. 6xx
HLT HALT Stop the code 000
DAT DATA LOCATION Used to associate a label to a free memory address. An optional value can also be used to be stored at the memory address.
Tagged with: ,

The missing key

themissingkeyThe aim of this challenge is to write a computer program that will take two whole numbers (integers) as input and output the result of multiplying these two numbers together. However, to make this task more challenging, you have to assume the * key of your keyboard is broken or missing and hence you are not allowed to use the * operator in your code.

You can complete your code in the trinket below:

Hint?


View Hint #1
5 * 4 = 5 + 5 + 5 + 5
7 * 6 = 7 + 7 + 7 + 7 + 7 +7
8 * 3 = 8 + 8 +8
View Hint #2
Use a loop!
Tagged with:

School Trip Bus Quote

school-busA school teacher is organising a school trip for the whole year group. He expects between 250 and 350 students to attend this trip. To estimate the cost of the trip, the school teacher has contacted a coach company to hire several coaches for a day.

The coach company has two categories of buses:

Bus Number of seats Cost per day
school-bus-sign Large Bus 46 Seats £360
school-mini-bus-sign Small Bus 16 Seats £140

The school teacher would like a computer program that will:

  1. Ask for the number of students taking part in the trip.
  2. Ask for the number of teachers taking part in the trip.
  3. Calculate the total number of participants (by adding the number of students and the number of teachers).
  4. Find out and output the number of large coaches that will be required.
  5. Find out and output the number of small coaches that will be required.
  6. Calculate and output the total cost of hiring these coaches for a day.

Flowchart


Here is the flowchart for this algorithm:
school-trip-bus-quote-flowchart

Python Code


Your task is to use the above flowchart to complete the Python code below:

Testing


Once your code is done, complete the following tests to check that your code is working as it should:

Test # Input Values Expected Output Pass/Fail?
#1 Number of students: 250
Number of teachers: 7
Number of large buses: 5
Number of small buses: 2
Total cost: £2080
#2 Number of students: 300
Number of teachers: 10
Number of large buses: 6
Number of small buses: 3
Total cost: £2580
#3 Number of students: 350
Number of teachers: 12
Number of large buses: 7
Number of small buses: 3
Total cost: £2940
#4 Number of students: 0
Number of teachers: 0
Number of large buses: 0
Number of small buses: 0
Total cost: £0

Extension Task #1


You have noticed that it is more cost effective to hire a large bus (£360) instead of three small buses (3 * £140 = £420) even if the large bus is not full.
So your task is to adapt the above algorithm so that, when calculating the number of large buses, if the number of pupils left (remainder) is greater than 32, your program will hire one extra large bus instead of 3 small buses. It will hence output the most cost effective solution for test #2 and test #3.

The new test plan would be as follows:

Test # Input Values Expected Output Pass/Fail?
#1 Number of students: 250
Number of teachers: 7
Number of large buses: 5
Number of small buses: 2
Total cost: £2080
#2 Number of students: 300
Number of teachers: 10
Number of large buses: 7
Number of small buses: 0
Total cost: £2520
#3 Number of students: 350
Number of teachers: 12
Number of large buses: 8
Number of small buses: 0
Total cost: £2880
#4 Number of students: 0
Number of teachers: 0
Number of large buses: 0
Number of small buses: 0
Total cost: £0

Extension Task #2


To make your program more robust, you can add some validation checks on both inputs. These validation checks will ensure that the user can only input whole numbers (integers). To do so, you should check the following blog post: number only validation in Python.

Tagged with:

Real-Time Asteroid Watch

asteroidEvery day asteroids are passing close to planet Earth. Their trajectory is closely monitored by NASA as some of these could potentially pose a threat to our planet. In this python challenge we are going to use the NeoWs API to retrieve some real-time data from NASA about these near Earth asteroids.

You can read more about the NeoWs API on: https://api.nasa.gov/api.html#neows-feed

JSON Data


This API uses JSON to format the data. JSON (JavaScript Object Notation) is a popular lightweight data-interchange format. Its main benefit is that it is easy for humans to read and write and it is easy for machines to parse and generate as you can see in the code provided below. You can read more about JSON on https://www.json.org/

You can see what the JSON data returned by the API looks like:
https://api.nasa.gov/neo/rest/v1/feed?start_date=2015-09-07&end_date=2015-09-08&api_key=DEMO_KEY

Python Code


Check our code to see how we make a call to the API and how we retrieve and extract the requested JSON data.

Your Task


Update this code to show all the near Earth asteroids approaching Earth in the next 7 days.
The JSON data also contains links to web pages for each asteroid (e.g. https://ssd.jpl.nasa.gov/sbdb.cgi?sstr=3745034). Update the Python code to also display the relevant web addresses.

Tagged with:

Maritime Signal Flags Translator

nautical-flagsInternational maritime signal flags are various flags used to communicate with ships. The purpose of the International Code of Signals is to provide ways and means of communication in situations related essentially to safety of navigation. The code uses a set of 26 flags for each letter of the alphabet plus additional flags for the 0 to 9 digits. Combinations of these alphanumeric characters are assigned as codes for various standardised messages. For instance, the master of a ship may wish to communicate with another ship, where his own radio may not be working.

The aim of this challenge was to design a web-based app to convert any message using the relevant flags.

You can use our online translator below and investigate the HTML, CSS and JavaScript code used to implement this translator.

See the Pen
Maritime Signal Flags Translator
by 101 Computing (@101Computing)
on CodePen.

Tagged with: ,

Flip Cards in HTML, CSS & Javascript

flip-cardCheck the following code used to create an interactive flip card that can be added to any existing web page.

Your Task

  • Change the HTML code to create a collection of flip cards using Computer Science terminology. (e.g. Programming Terminology)
  • Change the CSS code to change the look and feel of your flip card (front and back).

See the Pen
Flip Card
by 101 Computing (@101Computing)
on CodePen.

Tagged with:

Space Invaders in Scratch

This step by step tutorial will demonstrate how to re-create “Space Invaders” using Scratch.

space-invaders-scratch

Step 1Step 2Step 3Step 4Step 5Step 6Step 7Extension

Setting up the stage


Start a new project in Scratch and change the stage backdrop to the backdrop called “Stars”.
scratch-add-backdrop
space-invaders-stars-backdrop

The Spaceship/Rocket Sprite


Next, we will delete the Cat sprite and create a new Rocket sprite:
scratch-remove-sprite-cat
space-invader-rocketship
We will also resize our Rocketship sprite to 35% of its original size:
space-invader-resize-rocketship

The rocketship sprite has 5 costumes but costume 5 is bigger than the other 4 costumes, so we will delete costume 5:
space-invader-remove-costume

Let’s start coding


Using the Rocketship sprite, let’s add some code.

First we will make sure the “Stars” backdrop is always displayed when the game starts:
scratch-switch-to-stars-backdrop

Now let’s animate the Rocketship sprite:
scratch-animate-rocket

Controlling the Rocket ship using the left and right arrow keys


The rocket ship is positioned at the bottom of the screen. The user should be able to slide the rocket ship horizontally to the left or the right using the arrow keys.
scratch-left-right-rocket

The Invader Sprite


Let’s add a new sprite using the “Gobo” sprite from the scratch library:
scratch-gobo-sprite
We will then resize our invader sprite to 40% of its original size:
scratch-resize-invader

Let’s add some code to our invader sprite to position and animate the sprite:
scratch-animate-gobo

Now let’s add some code to make the invader move across the screen. Everytime the sprite reach the edge, it should drop down closer to the rocket ship and change direction (left/right movement).
scratch-invader-movement

Adding a Game Over Screen


The games ends when an invader hits the rocket. To implement this we will first need design a Game Over screen/backdrop:
scratch-game-over-screen

Then we will add some code to our Invader sprite to detect when the invader is touching the rocket ship.
scratch-game-over-trigger

Adding a laser beam sprite


To add a laser beam, we will paint a new sprite:
scratch-paint-new-sprite
scratch-paint-laser-beam

Firing the laser beam


The following code will let the user fire a laser beam by pressing the space bar. The laser beam will always be launched from the rocket ship current position:
scratch-fire-laser-beam

Adding a score variable


Let’s make a new variable called score. We will use this variable to score 1 point when the laser beam hits an invader. To do so we will need to go to the variable section:
scratch-variables-section
Then you will click on the “Make a Variable button”.
scratch-make-variable
Give a name to your variable: score and tick the option “For all sprites”
scratch-ball-bouncing-code-complete
Make sure your variable is visible (Tick the checkbox next to the variable itself):
scratch-make-variable-visible
Using our Rocket ship sprite we will edit our code as follows to reset the score to 0 when the game starts:
scratch-reset-score-variable

Then we will add some code to our invader sprite:
scratch-laser-collide-invader

Let’s add some more invaders


We will duplicate our invader sprite 10 times:
scratch-duplicate-gobo-sprite

All we have to do now is re-position each invader sprite one at a time by changing their x and y coordinates in the code:
scratch-invaders-positions

We now have a fully working game!

space-invader-scratch

Extension Task


Add a “Level Complete!” screen that appears when the user scores 10 points (All invaders have been destroyed!).
Tagged with:

Flappy Bird using Scratch

This step by step tutorial will demonstrate how to re-create the game “Flappy Bird” using the online version of Scratch.

Step 1Step 2Step 3Step 4Step 5Extension

Setting up the stage


Start a new project in Scratch and change the stage backdrop to the backdrop called “Blue Sky”
scratch-add-backdrop
scratch-blue-sky-backdrop

The Parrot Sprite


Next, we will delete the Cat sprite and create a new Parrot sprite:
scratch-remove-sprite-cat
scratch-parrot-sprite
We will also resize our Parrot sprite to 25% of its original size:
scracth-parrot-size

Let’s start coding


Using the Parrot sprite, let’s add some code.

First we will make sure the “Blue Sky” backdrop is always displayed when the game starts:
scratch-switch-background

The let’s animate the parrot to make it flap its wings:
scratch-switch-costumes

Controlling the Parrot using the space bar


Every time the user presses the space bar, the parrot should fly upwards.
scratch-control-flappy-bird

Adding Gravity


The idea is that the parrot should constantly be pulled down by gravity.
scratch-gravity-algorithm

Adding a Game Over Screen


The games ends when the parrot hits the ground. To implement this we will first need design a Game Over screen/backdrop:
scratch-game-over-screen

Then we will add some code to our Parrot sprite to detect when the parrot is hitting the ground. (On our “blue sky” backdrop, the ground has a brown color, you will need to use the color picker to retrieve this color):
scratch-sprite-touching-colour
scratch-color-picker

Step 4: Adding a score variable


Let’s make a new variable called score. We will use this variable to score 1 point when the bird flies through as set of pipes. To do so we will need to go to the variable section:
scratch-variables-section
Then you will click on the “Make a Variable button”.
scratch-make-variable
Give a name to your variable: score and tick the option “For all sprites”
scratch-ball-bouncing-code-complete
Make sure your variable is visible (Tick the checkbox next to the variable itself):
scratch-make-variable-visible

Let’s add the pipes


We will need to “paint” a new sprite for the pipe:
scratch-paint-new-sprite
scratch-paint-pipes

For our Parrot sprite we will edit our code as follows to reset the score to 0 when the game starts:
scratch-set-score-to-0

Now let’s add some code to our pipes sprite:
scratch-pipes-algorithm

Finally, we will duplicate our pipes sprite:
scratch-duplicate-sprite
And delay the second set of pipes by a few seconds:
scratch-delay-pipes
You can also edit the costume for the second set of pipes to have a different “gap”.

Extension Task


Add a “splash screen” with basic instructions on how to play the game. The splash screen should include a start button to start the game.

The “Game Over” screen should only be displayed for a few seconds and then switch back to the start screen to let the player play again. In this case the score should automatically be reset to 0.

Tagged with: