omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / tasks / queue-definition / oracle.py
| 1 | # Independent reference for "Queue/Definition" (Python 3, standard library only). |
| 2 | # expected.txt is this program's stdout; omc never produced it. |
| 3 | from collections import deque |
| 4 | q = deque() |
| 5 | def empty(): |
| 6 | print("empty:", "no" if q else "yes") |
| 7 | def push(v): |
| 8 | q.append(v) |
| 9 | print("push", v) |
| 10 | def pop(): |
| 11 | if not q: |
| 12 | print("pop from an empty queue: error") |
| 13 | return False |
| 14 | print("pop", q.popleft()) |
| 15 | return True |
| 16 | empty() |
| 17 | for i in range(1, 7): |
| 18 | push(11 * i) |
| 19 | for _ in range(4): |
| 20 | pop() |
| 21 | for i in range(7, 12): |
| 22 | push(-11 * i) |
| 23 | empty() |
| 24 | while pop(): |
| 25 | pass |
| 26 | empty() |