More results...

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

My Python Turtle Roller Coaster

rollercoasterIn this challenge we will use Python Turtle to draw the track of a roller coaster.

We have created three procedures for you to use when drawing the track. Each procedure takes two parameters as follows:

  • straightLine(distance, speed): To draw a straight line. The distance is given as a number of pixels (e.g. 100) and the speed as a number between 1 and 6 to represent when the roller coaster is going up hill (low speed) or down hill (high speed).
  • turnLeft(angle, radius): to draw a turn / arc of a specific angle in degrees (e.g. 180 for a u-turn), and a radius to represent how sharp the turn is. (Sharp turn = low radius e.g. 10).
  • turnRight(angle, radius): Same as above but to turn to the right.

Our Roller Coaster (Overhead view)


Your Challenge


Complete the track of your own roller coaster by completing the code below, making good use of the 3 procedures straightLine(distance, speed), turnLeft(angle, radius) and turnRight(angle, radius).

Tagged with:

Triangular Numbers using LMC

triangular-number-10A triangular number correspond to the number of dots that would appear in an equilateral triangle when using a basic triangular pattern to build the triangule.

The triangular numbers sequence contains all the triangular numbers in order.

The first 10 numbers of the triangular number sequence are:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …

trinagular-number-sequence

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

Triangular Number Calculation
1 =1
3 =1+2
6 =1+2+3
10 =1+2+3+4
15 =1+2+3+4+5

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 triangular numbers of this 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: ,

Triangular Numbers

triangular-number-10A triangular number correspond to the number of dots that would appear in an equilateral triangle when using a basic triangular pattern to build the triangule.

The triangular numbers sequence contains all the triangular numbers in order.

The first 10 numbers of the triangular number sequence are:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …

trinagular-number-sequence

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

Triangular Number Calculation
1 =1
3 =1+2
6 =1+2+3
10 =1+2+3+4
15 =1+2+3+4+5

So using an iterative approach in Python we can easily write a script to work out the first 100 triangular numbers:

This short program is a good example of:
iteration-label

Finding the nth term in the sequence


The following mathematical formula can be used to find the nth triangular number in this sequence:

nth term = n(n+1)/2

Other Number Sequences


The following Python challenges will get you to work with different types of number sequences and series:

Series vs. Sequence?


Did you know?
The main difference between a series and a sequence is that a series is the sum of the terms of a sequence.
So let’s investigate the following Python challenges based on series:

Extra Challenge


You may also enjoy the following challenge:

Tagged with:

My Timetable in HTML / CSS

my-timetable

Learning Objectives


In this challenge we are learning how to draw and format a table on a web page using a range of HTML tags and CSS properties.

HTML Tables


First you may want to read a bit more about how HTML tables are built using the <TABLE>, <THEAD>, <TBODY>, <TR>, <TH> and <TD> HTML tags.

CSS Code


Remember the key syntax for CSS is as follows:
css-syntax

In this challenge we will use various CSS properties such as:

  • font-family:
  • font-size:
  • color:
  • font-weight:
  • font-style:
  • text-align:
  • padding:
  • background-color:
  • etc.

You can learn more about all these CSS properties on w3schools.com.

We will also use different types of selectors such as:

  • TAG
  • .class
  • #id
  • element child-element
  • element child-element:first-child

You can learn more about CSS selectors on w3schools.com.

My Timetable


We have created a timetable for you.

Task 1: By changing the HTML code, you can now change the content of this timetable: you can add your own lessons to reproduce your own timetable. You may want to change the structure of the day (e.g. Does your school day consist of 5 lessons?) by adding or deleting rows to this timetable.

Task 2: By changing the CSS code, you can now change the look & feel of your timetable. Change the colour scheme, the choice of fonts, the spacing (padding / margin) between table cells, etc.

See the Pen My Timetable by 101 Computing (@101Computing) on CodePen.


Press the “Edit on CodePen” button at the top of this codepen to open in full screen mode

Tagged with:

Minesweeper in Javascript

minesweeperIn this blog post we will work on the classic game of Minesweeper. Minesweeper is a single-player puzzle video game. The objective of the game is to clear a rectangular board containing hidden “mines” or bombs without detonating any of them, with help from clues about the number of neighbouring mines in each field. The game originates from the 1960s, and has been written for many computing platforms in use today.

We have created a fully working version of the game using HTML, CSS and JavaScript. Your task will be to reverse-engineer the code to be able to improve this game further.

Full Code

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

Your Challenge


Improve this code further to:

  • Calculate and display a score in real time (number of cells that have been visited).
  • Allow the user to add a cross to a cell (by right clicking?) to indicate the position of a mine.
  • Allow the user to choose a difficulty level or change some settings (e.g. Number of mines, size of the grid).
  • Add a timer to the game.

Fetching Data using a Multiplexer

In our previous blog posts we have looked at a few logic gates circuits used inside a CPU to perform binary additions (Half adders and full adders) and to retain a bit of information using a D-Type flip-flop circuit (Data Cell).

By studying assembly language (using the LMC simulator) we have aslo investigated how the CPU uses the FDE cycle to fetch an instruction, decode it and execute it.

The purpose of this blog post is to investigate how the CPU can fetch data (data or instructions) from memory as this is an essential part of the FDE cycle.

Multiplexer?


A multiplexer is a logic gates circuit used to fetch a bit of data from memory at a given memory address. A processor has several multiplexers (MUX) controlling the data and address buses. Multiplexers are switches allowing the processor to select data from multiple data sources. To select which data source should be used a multiplexer has one or more control lines (a.ka. Selectors). The output of a multiplexer is the selected data.

Let’s investiagte a basic multiplexer used to select data from two data cells. With only two data cells (A and B) you only need 1 bit to code their address:

  • Address 0 = Input A
  • Address 1 = Input B
Multiplexer - 2 Inputs

Multiplexer – 2 Inputs

The Truth Table of this 2-input Multiplexer is:

Multiplexer 2 Inputs - Truth Table

Multiplexer 2 Inputs – Truth Table

By combining two of these multiplexers together we can select between 4 inputs, A, B, C and D.

Multiplexer - 4 Inputs

Multiplexer – 4 Inputs

In this multiplexer we have two selectors: S1, S2 to get the following outputs from the 4 memory addresses: 00,10,01 and 11:

Multiplexer 4 Inputs - Truth Table

Multiplexer 4 Inputs – Truth Table

This is how our 4-input multiplexer behaves:

Multiplexer 4 Inputs

Multiplexer 4 Inputs

By combining more of these multiplexers together we can fetch data from 4-bit memory locations or 8-bit memory locations and so on.

Note that:

  • With 1 multiplexer (2 inputs, 1 selector) we can fetch data from 2 memory locations.
  • With 2 multiplexers (4 inputs, 2 selectors) we can fetch data from 4 memory locations.
  • With 3 multiplexers (8 inputs, 3 selectors) we can fetch data from 8 memory locations.
  • With 4 multiplexers (16 inputs, 4 selectors) we can fetch data from 16 memory locations.
  • With N multiplexers (2N inputs, N selectors) we can fetch data from 2N memory locations.

From bits to Bytes


Previously, (see blog post) we have seen that a data cell consists of a D-Type flip-flop logic gates circuit and holds one bit of data.

In the CPU, registers, Level 1 cache and in he RAM, memory units use such data cells.
By lining up 8 data cells in parallel, we can then store 1 Byte (8-bits) of data.

To retrieve the content of an 8-bit memory unit, we can connect 8 multiplexers in parallel.

Address Bus & Data Bus


The “wires” between the multiplexers and the data cells are called buses. In an 8-bit processor each bus consists of 8 wires in parallel.

The buses that connect the inputs (e.g. A,B,C,D in the diagram above) are called data buses as they carry the actual data to be fetched.

The buses that connect the selectors (e.g. S1 and S2) are called address buses as they carry the address of where the data is to be fetched from. The more wires in the address bus, the more memory locations can be reached (2N), so:

  • For an address bus of 8 wires you can reach 256 memory locations,
  • with 16 wires (2-Byte addresses) you can reach over 64,000 memory locations,
  • with 32 wires (4-Byte addresses) you can reach over 4,000,000,000 memory locations. (e.g. 4GB RAM)

electronic-circuit

Data or Instructions?


Through the FDE cycle, the CPU has to fetch instructions (lines of machine code to execute) as well as data (e.g. oerands). In a Von Neumann processor architecture, both instructions and data are stored in the same locations using the same format. The same multiplexers can hence be used to fetch either data or instructions.

Tagged with: ,

Happy New Year Animation

happy-new-year-textIn this challenge we will use Python code to create a text-based (ASCII) animation to be used as a final countdown before the new year!

Our countdown timer will be based on a for loop to count down from 5 to 0. It will also make use of the sleep() function from the time library to allow 1 second between each iteration of the for loop.

Check our two animations below:

5-4-3-2-1 Hapy New Year! - Version 1.0Version 2.0

Version 1.0



Version 2.0


This animation makes use of 10 procedures called one(), two(), three(),…, up to ten() to improve the output of our countdown timer. These procedures are all stored in a module called myNumbers.


More Text-Based Animations


Visit this blog post to find the code for more text-based animations and start creating your own animations.

Tagged with: ,

Little Man Computer – Max Function

LMC-MaxIn this challenge we will create a computer program using LMC (Little Man Computer) that takes two inputs and outputs the larger (max) of the two inputs.

By completing this challenge we will investigate the use of the branching instructions BRP and BRA to create an IF THEN ELSE selection.

Flowchart


We have produced the flowchart of our max algorithm using LMC instructions:
LMC_Flowchart_Max

LMC Simulators


You can now type and test this code using one of the following online LMC Simulators:

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.
Tagged with: ,

Little Man Computer: Countdown Timer

countdown_animatedIn this challenge we will create a computer program using LMC (Little Man Computer) that takes a number as an input (e.g. 5) and outputs a countdown from this value. (e.g: 5.4.3.2.1.0).

By completing this challenge we will investigate the use of the branching instruction BRP to create a looping effect.

Flowchart


We have produced the flowchart of our countdown timer using LMC instructions:
LMC-Flowchart-Countdown

LMC Simulators


You can now type and test this code using one of the following online LMC Simulators:

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.
Tagged with: ,

Little Man Computer: Mini Challenges

By completing this set of 12 mini challenges you will write programs using Little Man Computer using all the instructions of the LMC instruction set (See below). You will start with basic Input / Process / Output challenges based on sequencing. You will then investigate branching instructions (BRP, BRZ, BRA) to write programs using selection (a.k.a. branching) and iteration (a.k.a. loops).

LMC Simulators

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.

Mini Challenges


LMC-Challenge-1

LMC-Challenge-2

LMC-Challenge-3

LMC-Challenge-4

LMC-Challenge-5

LMC-Challenge-6

LMC-Challenge-7

LMC-Challenge-8

LMC-Challenge-9

LMC-Challenge-10

LMC-Challenge-11

LMC-Challenge-12

Tagged with: ,