Bob and Alice are two hackers working on an embedded system with a severe computational constraint - there is a bug in their low-cost microcontroller making OR operations significantly slower than any other operation on the chipset.
When they profiled their micropython code, they found that OR operations were up to 5x slower than any other operation.
def authorize_access(request): # A user is denied if they are on a blacklist OR # their account is expired if (user_is_blacklisted(request.user_id) or account_is_expired(request.account) return "Access denied" return "Access granted"
Let’s take a moment to understand the problem. The
authorize_access
function is used to check if a user is authorized to access a resource. Theor
operation is used to combine the conditions. How could we rewrite this function to avoid the OR operation?
Entries Tagged - "education"
Feb 26 2025Truth Functional Logic for Hackers - Part One