#special triples of positive three-digit integers
#n,n+1,n+2 between 100 and 999
# n, n+1 and n+2 are integers at least equal to 100 and at most equal to 999;
# n,n+1 and n+2 is of the form a2+b2.
# written by MA ZIHAO(z3492796) for COMP9021
L = []
opt_nu

NOTES ON STACKS AND DEPTH FIRST SEARCH
ERIC MARTIN
1
2
4
5
3
6
7
8
11
10
13
12
9
Popping a path from the top of the stack (right of list) and pushing its extensions to the top of the stack.
[1]
[1]
[1, 5], [1, 4], [1, 2]
[1, 5], [1, 4]
[1, 2]
[1, 5], [1

NOTES ON LEVENSHTEIN DISTANCE
ERIC MARTIN
Deletion (cost 1) of a letter x in first word: x
Insertion (cost 1) of a letter x in second word: x
. Match (cost 0) of the same letter x in both words: xx
Substitution (cost 2) of a letter x in first word by a

NOTES ON LINKED LISTS
ERIC MARTIN
def reverse ( s e l f ) :
i f not s e l f . head o r not s e l f . head . n e x t n o d e :
return
node = s e l f . head
w h i l e node . n e x t n o d e . n e x t n o d e :
node = node . n e x t n o d e
l a s t n o d e =

NOTES ON QUEUES AND BREATH FIRST SEARCH
ERIC MARTIN
1
2
3
4
5
6
9
10
7
11
8
12
13
Dequeuing a path from the front of the queue (right of list) and enqueuing its extensions to the back of the queue.
[1]
[1]
[1, 4], [1, 3], [1, 2]
[1, 4], [1, 3]
[1, 2]
[1

import os
#os.chdir('F:\?\Assignment_1\Assignment_1')
triangle = open('triangle_4.txt')
my_crap = [int(j),int(j),1] for j in i.split()] for i in triangle.readlines()]
triangle.close()
#triangle = open('triangle_3.txt')
#print(triangle.read()
n = len(my_cr

Assignment 2 v. 1.8
COMP9021, Session 2, 2015
Aims: The purpose of the assignment is to:
design and implement an interface based on the desired behaviour of an application program;
practice the use of builtin data structures: lists, tuples, sets, and di

Assignment 3
COMP9021, Session 2, 2015
Aims: The purpose of the assignment is to:
process command-line arguments in the style of Unix utilities;
become familiar with trees;
possibly implement recursive solutions;
develop problem solving skills.
Comman

Lab 8
1
R
COMP9021, Session 2, 2015
Doubly linked lists
Modify the module linked_list.py which is part of the material of the 8th lecture into a module
doubly_linked_list.py, to process lists consisting of nodes with a reference to both next and
previous

Lab 10
1
R
COMP9021, Session 2, 2015
Building a general tree
Consider a file named tree.txt containing numbers organised as a tree, a number at a depth of
N in the tree being preceded with N tabs in the file. The file can also contain any number of lines

Lab 9
COMP9021, Session 2, 2015
1
Using linked lists to represent polynomials
Extend the program that implements a class Polynomial from the previous lab to implement the
functions _add_(), _sub_(), _mul_() and _truediv_().
Next is a possible interaction.

Lab 11
1
R
COMP9021, Session 2, 2015
Median and priority queues
Implement a class Median that allows one to manage a list L of values with the following operations:
add a value in logarithmic time complexity;
return the median in constant time complexit

NOTES ON NASH EQUILIBRIUM
ERIC MARTIN
1. 2 2 games, pure strategies, and Pareto optimality
We consider two players, Ruth and Charlie, who both can take one of two possible decisions. Each of the four pairs
(dR , dC ) of possible decisions taken by both pl

NOTES ON PRIME NUMBER SIEVES
ERIC MARTIN
1. Eratosthenes sieve
Let N 2 be given.
In the first version of the sieve, we use a list meant to denote 0, 1, 2, 3, 4,. . . N , and we generate all prime numbers at
most equal to N by flagging to False:
all positi

#
#
poker dice
written by Mazihao(z3492796)
from random import randint
types = cfw_0:'Ace',1:'King',2:'Queen',3:'Jack',4:'10',5:'9'#dictionary
def judge_dice(result):#judge the type of poker hand
times = []
for i in range(6):
times.append(result.count(i)#

# Written by Eric Martin for COMP9021
from random import choice
from itertools import product
from operator import add
import matplotlib.pyplot as plt
def generate_random_walk(length = 50000):
possible_moves = tuple(set(product(range(-4, 5), repeat = 2) -

# Creates 3 classes, Point, Line and Parallelogram.
# A point is determined by 2 coordinates (int or float).
# A line is determined by 2 distinct points.
# A parallelogram is determined by 4 distint lines,
# two of which having the same slope, the other t

#
#
#
#
#
#
#
#
#
#
#
#
#
Solves the n-queen puzzle: place n chess queens on an n x n chessboard so that
no queen is attacked by any other queen.
We generate permutations of [0, 1, ., n-1],
a permutation [k_0, k_1, ., k_cfw_n-1]
requesting to place the qu

#
#
#
#
#
#
#
Prompts the user for the face values of banknotes
and their associated quantities, as well as for an amount,
and if possible, outputs the minimal number of banknotes
needed to match that amount, as well as the detail of
how many banknotes of

Lab 7
1
R
COMP9021, Session 2, 2016
Change-making problem: greedy solution
Write a program greedy_change.py that prompts the user for an amount, and outputs the minimal
number of banknotes needed to yield that amount, as well as the detail of how many ban

#
#
#
#
#
#
#
Prompts the user for an amount, and outputs the minimal number of banknotes
needed to match that amount, as well as the detail of how many banknotes
of each type value are used.
The available banknotes have a face value which is one of
$1, $

NAMES AND VALUES
ERIC MARTIN
We talk of 0, 1, 2, 3.14 as values, but 0, 1, 2, 3.14 are also names of values; we cannot refer to values without naming them.
In the computing world, a value is stored in memory as bits. How a sequence of bits relates to a va

NOTES ON BARNSLEY FERN
ERIC MARTIN
1. Affine transformations
An affine transformation on the plane is a mapping T that preserves collinearity and ratios of distances: given two points
A and B, if C is the middle of the segment [A, B] then T (C) is the mid

NOTES ON LOANS AND SAVINGS
ERIC MARTIN
1. Borrowing or saving money
We consider the situation where Jane has an initial sum of S0 in her account, and at regular intervals, adds to that account
a positive or negative amount (so in effect, adds to or remove

Lab 7
1
R
COMP9021, Session 2, 2015
Change-making problem: greedy solution
Write a program that prompts the user for an amount, and outputs the minimal number of banknotes needed to yield that amount, as well as the detail of how many banknotes of each ty

Lab 4
1
R
COMP9021, Session 2, 2015
A triangle of characters
Write a program that gets a strictly positive integer n as input and outputs a triangle of height n,
following this kind of interaction:
Enter strictly positive number: 13
A
BCB
DEFED
GHIJIHG
KL

Lab 1
COMP9021, Session 2, 2015
Create two sequences of directories,
~/COMP9021/Labs and
~/COMP9021/Lectures.
One way to do this is to, in your home directory, execute the Unix command
mkdir -p COMP9021/Labs COMP9021/Lectures
Download from the courses w

Lab 5
1
R
COMP9021, Session 2, 2016
Most popular name
As in the fifth lecture, we use the data of the National Data on the relative frequency of given names
in the population of U.S. births, stored in a subdirectory named names of the working directory, i

Lab 1
COMP9021, Session 2, 2016
If you have not done so already, create two sequences of directories,
~/COMP9021/Labs and
~/COMP9021/Lectures.
One way to do this is to, in your home directory, execute the Unix command
mkdir -p COMP9021/Labs COMP9021/Lec