THINK FIRST·CODE LATER

← All labs

Choose the level of detail for zooming

Problem

Input: a line width W (pixels), then lines view START END (dates). Data is recorded every 5 minutes.

For each view, choose the finest aggregation level among 5 minutes (300 s), hour (3,600 s), day (86,400 s), week (7 days) and 30 days such that the number of points ⌊span / level⌋ is at most W; if even 30 days gives more than W points, use 30 days and add (still too many). Print:

view 2026-03-01..2026-03-08 (7 days): aggregate per hour -> 168 points

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

v8-4-data-1.txt

width 800
view 2026-03-01 2026-03-02
view 2026-03-01 2026-03-08
view 2026-01-01 2026-12-31
view 2016-01-01 2026-01-01
What your program must print for v8-4-data-1.txt
view 2026-03-01..2026-03-02 (1 days): aggregate per 5 minutes -> 288 points
view 2026-03-01..2026-03-08 (7 days): aggregate per hour -> 168 points
view 2026-01-01..2026-12-31 (364 days): aggregate per day -> 364 points
view 2016-01-01..2026-01-01 (3653 days): aggregate per week -> 521 points

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), in the folder that holds both files:

python my_lab.py < v8-4-data-1.txt

Windows PowerShell (the default terminal of VS Code on Windows) does not understand <:

Get-Content v8-4-data-1.txt | python my_lab.py

PyCharm: Run → Edit Configurations → tick Redirect input from and choose the file.

Jupyter: put this at the top of the cell that holds your program:

import sys
sys.stdin = open("v8-4-data-1.txt", encoding="utf-8")

Write it here, in Jupyter or in your IDE, then paste it. Run it on the sample input yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.