Sunday, June 21, 2026

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")


No comments:

Post a Comment

Week 8 Assignments