Welcome to Glance
Do you already use Glance?
See it for yourself
Here's one most people can't do.
Give it a real try first. Stuck? Open Glance and the answer's right there.
To solve this, reach for integration by parts — the rule ∫ u dv = uv − ∫ v du.
Step 1 — split the problem into two parts. Let u = x and dv = e^(2x) dx. Then du = dx, and v = ½e^(2x).
Step 2 — drop those into the rule. ∫ x·e^(2x) dx = x·½e^(2x) − ∫ ½e^(2x) dx, which tidies up to ½x·e^(2x) − ½∫ e^(2x) dx.
Step 3 — finish the one integral that's left. ∫ e^(2x) dx = ½e^(2x), so that last term becomes ¼e^(2x).
So the answer is ½x·e^(2x) − ¼e^(2x) + C. Always add + C for an indefinite integral.
import heapq
from dataclasses import dataclass, field
@dataclass(order=True)
class Task:
priority: int
task_id: str = field(compare=False)
attempts: int = field(default=0, compare=False)
completed: bool = field(default=False, compare=False)
class Scheduler:
def __init__(self):
self.queue = []
self.tasks = {}
self.completed = set()
def add_task(self, task_id, priority):
task = Task(priority, task_id)
self.tasks[task_id] = task
heapq.heappush(self.queue, task)
def execute_next(self, worker):
if not self.queue:
return None
task = heapq.heappop(self.queue)
if task.completed:
return None
task.attempts += 1
try:
result = worker(task)
task.completed = True
self.completed.add(task.task_id)
return result
except Exception:
if task.attempts <= 3:
heapq.heappush(self.queue, task)
Here's everything wrong with this scheduler.
1. The equality bug — the subtle, fatal one. Task uses @dataclass(order=True), but every field except priority is compare=False. So when two tasks share a priority, Python falls through to compare the next field — and isn't allowed to use any of them. heapq then throws TypeError: '<' not supported between instances of 'Task'. Fix: give Task a tiebreaker, like an insertion counter, or order on priority alone.
2. execute_next silently throws away the queue. If the task it pops is already completed, it returns None and stops — discarding every other task still waiting behind it. It should skip that one and keep going.
3. A failed task vanishes without a trace. In except Exception it re-queues the task while attempts <= 3, but the function returns nothing — the caller just gets None with no idea it failed, and after three tries the task is dropped in silence.
4. add_task's argument order is a trap. The method is add_task(self, task_id, priority) but it builds Task(priority, task_id). It only works because of the order you happen to pass them; one slip and it breaks quietly. Pass by name: Task(priority=priority, task_id=task_id).
5. Small one: double-check __init__ really has the double underscores, not a lookalike.
Bottom line: it runs fine — until two tasks tie on priority. Then it crashes.
Which choice best states the main idea of the text?
A is the correct answer. Here's the reasoning.
The setup: people feel lying is usually wrong but sometimes okay. If our duty to be truthful isn't absolute, what grounds our opposition to lying at all?
Pallikkathayil's answer: respect other people's agency — their ability to make informed choices. False beliefs get in the way of that, so we should generally promote true beliefs, except when lying would prevent a worse harm.
Why A fits: it captures exactly that — a duty to respect agency that commits us to truthfulness, while leaving room for exceptions.
Why not the others: B asks how to tell which lies are okay (wrong focus). C says the duty is 'inviolable', but the passage allows exceptions. D says there are no grounds for opposing lying — the opposite of the point.
Answer: A.
That's Glance. On any problem, in any app.