~/problems / Simulation & OOP design / Object-oriented design and extensible simulations

Note-taking system with timestamps and search

easy 2 levels ~30 min

Level 1 Notes with IDs and timestamps

Build the in-memory core of a personal note-taking app, SecondBrainSystem. Every call that changes something is given the current time as an integer timestamp; timestamps never go down from one call to the next (equal is allowed).

Implement:

  • SecondBrainSystem(): an empty system.
  • create_note(timestamp, title, content) -> str: store a new note and return its id. Ids are "note_1", "note_2", … in creation order, and are never reused, even after a delete. The note's created_at and updated_at are both timestamp.
  • get_note(note_id) -> dict | None: the note as {"id": ..., "title": ..., "content": ..., "created_at": ..., "updated_at": ...}, or None if there is no such note. Return a fresh dict: changing it must not change the stored note.
  • update_note(timestamp, note_id, title=None, content=None) -> bool: replace the title and/or content (a None argument leaves that field alone) and set updated_at = timestamp. Return False, changing nothing, if the note doesn't exist.
  • delete_note(note_id) -> bool: remove the note; False if it doesn't exist.
sb = SecondBrainSystem()
sb.create_note(10, "Groceries", "eggs, milk")   # "note_1"
sb.create_note(12, "Ideas", "")                 # "note_2"
sb.update_note(15, "note_1", content="eggs")    # True
sb.get_note("note_1")
# {"id": "note_1", "title": "Groceries", "content": "eggs", "created_at": 10, "updated_at": 15}
sb.delete_note("note_2")                        # True
sb.create_note(20, "Ideas v2", "...")           # "note_3" (note_2 is not reused)
sb.update_note(21, "note_2", title="x")         # False

Titles and contents are arbitrary strings (possibly empty).

Level 2 unlocks when level 1 passes.

Topic: Object-oriented design and extensible simulations. Classes that survive new requirements: games, payments, subscriptions, refactors.

0:00
Ctrl ' run · Ctrl ↵ submit
esc