Sunday, June 21, 2026

Week 8 Assignments

 

Week 8 Notesz


import sys
sys.setrecursionlimit(1000000000)

#
# Solution Template for Robot Vacuum
# Australian Informatics Olympiad 2021
# This file is provided to assist with reading of input and writing of output 
# for the problem. You may modify this file however you wish, or
# you may choose not to use this file at all.
#

# K is the number of instructions.
K = 0

# instrs contains the sequence of instructions.
instrs = ""å

answer = 0

# Read the value of K and the sequence of instructions.
K = int(input().strip())
instrs = input().strip()

# TODO: This is where you should compute your solution. Store the fewest number
# of instructions you need to add to the end of the sequence into the variable
# answer.

x, y = 0, 0

for i in instrs:
    if i == "N":
        y += 1
    elif i == "E":
        x += 1
    elif i == "S":
        y -= 1
    else:
        x -= 1

answer = abs(x) + abs(y)

# Write the answer.
print(answer)


# Python Problem Solver
# Week 8 Example 2: Archaeologist's Challenge
#

import math

thalf = 5730
c14 = float(input("Input the current Carbon-14 to Carbon-12 ratio: "))
age = int(-(thalf / math.log(2) * math.log(c14)))

print(f"The age of the artefact is around {age} years.")


# Python Problem Solver
# Week 8 Example 3: How Security is Your Password
#

N = 52
L = 10

c = N**L
sec = c//1000000000
days = sec//86400
years = days//365
days -= years * 365
rsec = sec - (years * 365 + days) * 86400
hours = rsec//3600
minutes = (rsec - hours * 3600)//60
seconds = rsec - hours * 3600 - minutes * 60

print(f"The password will be cracked in {years} years, {days} days, {hours} hours, {minutes} moinutes and {seconds} seconds")


Saturday, June 13, 2026

Week 7 Assignments

Week 7 Notes


# Python Problem Solver
# Week 7 Example 1: YOLO
#

line = input()
# Split input into a list of words in list2
list1 = line.split()
# list2 is used for output
list2 = []

for word in list1:
    # For each word in list1, append its 1st character to the end of list2
    list2.append(word[0])

# Join all the "1st characters" into 1 string and conver to upper case
print("".join(list2).upper())


# Python Problem Solver
# Week 7 Example 2: Optical Illusions
#

from turtle import *

speed(10)

def drawCircle(x, y, r, c):
    penup()
    pencolor(c)
    fillcolor(c)
    goto(x, y - r)
    pendown()
    begin_fill()
    circle(r)
    end_fill()
    penup()
    hideturtle()

# Pay attention to all the coordinates are calcuated
drawCircle(-50, 0, 30, "purple")
drawCircle(-150, 0, 50, "black")
drawCircle(-50, 100, 50, "black")
drawCircle(50, 0, 50, "black")
drawCircle(-50, -100, 50, "black")

drawCircle(250, 0, 30, "purple")
drawCircle(310, 0, 10, "black")
drawCircle(250, -60, 10, "black")
drawCircle(190, 0, 10, "black")
drawCircle(250, 60, 10, "black")

input()


# Python Problem Solver
# Week 7 Example 3: Calculating Pi
#

N = int(input())

sum = 0
for n in range(1, N+1):
    sum += 1/(n*n)
answer = (sum * 6) ** .5
print(f"The {N}-th approximation of Pi is {answer}")

Saturday, June 6, 2026

Week 6 Assignments

Week 6 Notes



# Python Problem Solver
# Week 6 Example 1: World Population in 2025
#
year = 2025
population = 8_230_000_000
while population < 10_000_000_000:
    population *= 1.01
    year += 1
print(f"By year {year}, world population will be {int(population):,}")


import sys
sys.setrecursionlimit(1000000000)

#
# Solution Template for Buried Treasure
# Australian Informatics Olympiad 2025
# This file is provided to assist with reading of input and writing of output
# for the problem. You may modify this file however you wish, or
# you may choose not to use this file at all.
#

# N is the number of clues.
N = 0
# L is the number of locations.
L = 0

# A and B contain clues. Note that the lists start from 0, and so the first
# clue is (A[0], B[0]) and the last clue is (A[N-1], B[N-1]).
A = []
B = []

# Read the values of N, L, and the clues.
N, L = map(int, input().strip().split())
for i in range(0, N):
  input_vars = list(map(int, input().strip().split()))
  A.append(input_vars[0])
  B.append(input_vars[1])

# TODO: This is where you should compute your solution. Store the number of
# locations that are consistent with all N clues into the variable answer.

answer = 0

left = 1
right = L

for i in range(N):
    if A[i] > left:
        left = A[i]
    if B[i] < right:
        right = B[i]

if left <= right:
    answer = right - left + 1
# Write the answer.
print(answer)

Week 8 Assignments