LLM Quest — Interactive Fill-in-the-Blanks

Angular 17 • Standalone
Type into the highlighted blanks inside the code. Press Tab to jump to the next blank • Ctrl/‎⌘ + Enter runs checks • Your progress autosaves.

Level 1 - Clients, Token Grants, Reallocations

register_clientgrant_tokensreallocate_tokens

Implement a minimal LLM service with client registration, token grants, and token reallocation between clients.

  • register_client(self, timestamp, client_id) -> bool
  • grant_tokens(self, timestamp, client_id, amount) -> int | None
  • reallocate_tokens(self, timestamp, source_client_id, target_client_id, amount) -> int | None

Return updated token balances on success; None for invalid ops.



  class LLMService:
    def __init__(self):
        # ?? balances: client_id -> token balance
        self._balances = 
  

  
  
    
      
    
    
  

    # e.g., {}

    # (optional) timed processing; no-op at Level 1
    def _tick(self, now: int) -> None:
        
  

  
  
    
      
    
    
  

    # e.g., pass

    def _exists(self, c_id: str) -> bool:
        return 
  

  
  
    
      
    
    
  

    # e.g., c_id in self._balances

    def register_client(self, timestamp: int, client_id: str) -> bool:
        self._tick(timestamp)
        if 
  

  
  
    
      
    
    
  

  :  # e.g., self._exists(client_id)
            return False
        self._balances[client_id] = 
  

  
  
    
      
    
    
  

    # e.g., 0
        return True

    def grant_tokens(self, timestamp: int, client_id: str, amount: int):
        self._tick(timestamp)
        if not self._exists(client_id) or 
  

  
  
    
      
    
    
  

  :  # invalid amount?
            return None
        self._balances[client_id] += 
  

  
  
    
      
    
    
  

  
        return self._balances[client_id]

    def reallocate_tokens(self, timestamp: int, source_id: str, target_id: str, amount: int):
        self._tick(timestamp)
        if 
  

  
  
    
      
    
    
  

  :  # missing clients or same id or invalid amount?
            return None
        if self._balances[source_id] < 
  

  
  
    
      
    
    
  

  :
            return None
        self._balances[source_id] -= 
  

  
  
    
      
    
    
  

  
        self._balances[target_id] += 
  

  
  
    
      
    
    
  

  
        return self._balances[source_id]
  

          
Quick Self-Checks
Duplicate register -> False
Grant to missing -> None
Self reallocation -> None
Insufficient reallocation -> None
Hint: acceptable answers
l1_bal_zero → e.g., 0
l1_balances_init → e.g., {}
l1_create_exists_cond → e.g., self._exists(client_id)
l1_deposit_add → e.g., amount
l1_deposit_invalid_amount → e.g., amount < 0
l1_exists → e.g., c_id in self._balances
l1_tick → e.g., passfreeform
l1_transfer_add_amount → e.g., amount
l1_transfer_compare_amount → e.g., amount
l1_transfer_invalid_cond → e.g., not self._exists(source_id) or not self._exists(target_id) or source_id == target_id or amount < 0
l1_transfer_sub_amount → e.g., amount
Global Rules: timestamps are ints; process timed events at the start of each public call; amounts are ints ≥ 0; rebate = amount * 2 // 100; return None for invalid operations unless stated.