fork download
  1. def find_port(ports, target):
  2. """
  3. Returns the first integer in ports that equals the target or is greater.
  4. If there is no solution, returns -1.
  5.  
  6. Args:
  7. ports (list): A list of port numbers.
  8. target (int): The target port number.
  9.  
  10. Returns:
  11. int: The first port number greater than or equal to the target, or -1 if not found.
  12. """
  13. # Iterate over the ports and return the first one that's greater than or equal to the target
  14. for port in ports:
  15. if port >= target:
  16. return port
  17.  
  18. # If no port is greater than or equal to the target, return -1
  19. return -1
  20.  
  21. # Example usage:
  22. ports = [80, 22, 443, 21]
  23. target = 25
  24. print(find_port(ports, target)) # Output: 80
Success #stdin #stdout 0.11s 14132KB
stdin
Standard input is empty
stdout
80