seed: curriculum content
This commit is contained in:
45
1.solar-system/3.strings/02.the-slicer/index.md
Normal file
45
1.solar-system/3.strings/02.the-slicer/index.md
Normal file
@@ -0,0 +1,45 @@
|
||||
---
|
||||
type: challenge
|
||||
title: "The Slicer"
|
||||
xp: 50
|
||||
duration: 25
|
||||
difficulty: 2
|
||||
---
|
||||
|
||||
# The Slicer
|
||||
|
||||
> **[INCOMING — Mission Control, Earth]**
|
||||
>
|
||||
> Cadet, *slicing* grabs a chunk of a string instead of one character.
|
||||
> The syntax is `s[start:end]` — `start` is included, `end` is not.
|
||||
>
|
||||
> ```python
|
||||
> s = "ANDROMEDA"
|
||||
> s[0:3] # "AND"
|
||||
> s[3:7] # "ROME"
|
||||
> s[-2:] # "DA"
|
||||
> ```
|
||||
>
|
||||
> Telemetry packets always arrive in this exact format (length 30):
|
||||
>
|
||||
> ```
|
||||
> TIMESTAMP=YYYY-MM-DDTHH:MM:SSZ
|
||||
> ```
|
||||
>
|
||||
> Implement `extract(header)` that returns a tuple `(date, time)`:
|
||||
>
|
||||
> - `date` = `YYYY-MM-DD` (10 chars)
|
||||
> - `time` = `HH:MM:SS` (8 chars)
|
||||
>
|
||||
> Figure out which slice positions hold each piece.
|
||||
>
|
||||
> [END TRANSMISSION]
|
||||
|
||||
## Your Task
|
||||
|
||||
In `starter/starter.py`, return `(date, time)` extracted with slicing.
|
||||
|
||||
## Objectives
|
||||
|
||||
- `extract("TIMESTAMP=2026-05-04T14:32:01Z")` → `("2026-05-04", "14:32:01")`
|
||||
- Works for any header in the same fixed format
|
||||
16
1.solar-system/3.strings/02.the-slicer/starter/starter.py
Normal file
16
1.solar-system/3.strings/02.the-slicer/starter/starter.py
Normal file
@@ -0,0 +1,16 @@
|
||||
def extract(header):
|
||||
"""Extract date and time from a fixed-format packet header.
|
||||
|
||||
Header format (always exactly this shape):
|
||||
TIMESTAMP=YYYY-MM-DDTHH:MM:SSZ
|
||||
Length 30. Example:
|
||||
TIMESTAMP=2026-05-04T14:32:01Z
|
||||
|
||||
Return a tuple (date, time) where:
|
||||
date = "YYYY-MM-DD" (10 chars)
|
||||
time = "HH:MM:SS" (8 chars)
|
||||
|
||||
extract("TIMESTAMP=2026-05-04T14:32:01Z")
|
||||
-> ("2026-05-04", "14:32:01")
|
||||
"""
|
||||
pass
|
||||
@@ -0,0 +1,13 @@
|
||||
from solution import extract
|
||||
|
||||
|
||||
def test_basic():
|
||||
assert extract("TIMESTAMP=2026-05-04T14:32:01Z") == ("2026-05-04", "14:32:01")
|
||||
|
||||
|
||||
def test_apollo():
|
||||
assert extract("TIMESTAMP=1969-07-20T13:32:00Z") == ("1969-07-20", "13:32:00")
|
||||
|
||||
|
||||
def test_end_of_century():
|
||||
assert extract("TIMESTAMP=2099-12-31T23:59:59Z") == ("2099-12-31", "23:59:59")
|
||||
Reference in New Issue
Block a user