Command Palette

Search for a command to run...

Hectal
Phase 12: Building a Production LLM Service
LLM Engineering · Exercise 6 of 6 Previous
Advanced

Roll out a prompt to a percentage of users

Write bucket(text): start with h = 0, and for each character do h = (h * 31 + ord(ch)) % 1000003; return h * 7919 % 1000003 % 100.

Write enabled(user_id, flag, percent) that returns True when bucket(flag + ":" + user_id) < percent. The same user must always get the same answer.

What Check tests

  1. bucket matches the course's hash
  2. Buckets are between 0 and 99
  3. 0 percent enables nobody and 100 percent everybody
  4. A higher percentage only adds users
  5. The answer is the same every time

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.