CodeShell.kr - Offset

Challenge

一张 CSV,每行给出本地时间、UTC 偏移和一个字母。难度在于要先把所有行归一到同一时区,排序才有意义。

A matter of time

时间问题。

1
https://codeshell.kr/challenges/misc-offset/

Solution

附件 misc-offset.csv 每行给出本地时间、该地 UTC 偏移和一个字母。

Step 1:按行序读字母没有意义。

Step 2:把每行归一到 UTC 再按真实时间排序,字母依次拼出:

1
AFTERHOURS

Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
"""CodeShell.kr — Offset (Misc, 50p) solver.

misc-offset.csv gives a local timestamp, a UTC offset and a mark letter per
row. Normalising every row to UTC and sorting by real time recovers the word.

Usage: uv run python solvers/offset.py
"""

import csv
from datetime import datetime, timedelta
from pathlib import Path

CSV = "assets/challenge-files/misc-offset.csv"


def main():
rows = []
for r in csv.DictReader(open(CSV)):
local = datetime.strptime(r["local_time"], "%Y-%m-%d %H:%M")
sign = 1 if r["utc_offset"][0] == "+" else -1
hh, mm = (int(x) for x in r["utc_offset"][1:].split(":"))
utc = local - sign * timedelta(hours=hh, minutes=mm)
rows.append((utc, r["mark"], r["local_time"], r["utc_offset"]))

for utc, mark, local, off in sorted(rows):
print(f"{utc} {local} {off} {mark}")
print("answer:", "".join(m for _, m, _, _ in sorted(rows)))


if __name__ == "__main__":
main()
CodeShell{AFTERHOURS}