Challenge - 5 Problems
Swarm Simulation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple swarm position update
What is the output of this code that updates drone positions in a swarm simulation?
Drone Programming
positions = [(0,0), (1,1), (2,2)] velocities = [(1,0), (0,1), (-1,-1)] new_positions = [(x+vx, y+vy) for (x,y), (vx,vy) in zip(positions, velocities)] print(new_positions)
Attempts:
2 left
💡 Hint
Think about adding each velocity component to the corresponding position.
✗ Incorrect
Each drone's new position is its old position plus its velocity vector. So (0+1,0+0) = (1,0), (1+0,1+1) = (1,2), (2-1,2-1) = (1,1).
🧠 Conceptual
intermediate1:30remaining
Key feature of swarm simulation frameworks
Which feature is essential for a swarm simulation framework to handle large numbers of drones efficiently?
Attempts:
2 left
💡 Hint
Think about how real swarms work without a single leader.
✗ Incorrect
Swarm frameworks rely on distributed communication and local decisions to scale well and mimic natural swarm behavior.
🔧 Debug
advanced2:30remaining
Identify the error in this drone collision avoidance code
What error does this code produce when running a drone collision avoidance step?
positions = [(0,0), (1,1), (2,2)]
for i, pos in enumerate(positions):
for j, other_pos in enumerate(positions):
if i != j and abs(pos[0] - other_pos[0]) < 1 and abs(pos[1] - other_pos[1]) < 1:
positions[i] = (pos[0]+1, pos[1]+1)
print(positions)
Attempts:
2 left
💡 Hint
Check if modifying list elements during iteration is allowed in Python.
✗ Incorrect
Modifying elements of a list during iteration is allowed in Python as long as the list size doesn't change. Here, positions are updated safely.
📝 Syntax
advanced1:30remaining
Syntax error in drone command sequence
Which option contains a syntax error in this drone command sequence code?
Drone Programming
commands = ['takeoff', 'move_forward', 'land'] for cmd in commands print(f"Executing {cmd}")
Attempts:
2 left
💡 Hint
Look for missing punctuation in the for loop.
✗ Incorrect
Python requires a colon ':' at the end of the for loop declaration line. Option C misses the colon causing a SyntaxError.
🚀 Application
expert2:00remaining
Number of drones after filtering by battery level
Given this code filtering drones with battery above 50%, how many drones remain?
Drone Programming
drones = [{'id':1, 'battery': 45}, {'id':2, 'battery': 75}, {'id':3, 'battery': 55}, {'id':4, 'battery': 30}]
active = [d for d in drones if d['battery'] > 50]
print(len(active))Attempts:
2 left
💡 Hint
Count drones with battery strictly greater than 50.
✗ Incorrect
Only drones with battery 75 and 55 are above 50, so 2 drones remain after filtering.