from beam import function
def is_prime(n: int) -> bool:
if n < 2:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
@function(cpu=0.1)
def count_primes_in_range(start: int, stop: int) -> int:
"""
Returns the number of prime numbers in the range [start, stop).
"""
return sum(is_prime(i) for i in range(start, stop))
def main():
# Each tuple represents (start, stop)
ranges = [
(0, 10),
(10, 20),
(20, 30)
]
# .map() will launch a remote container for each tuple
for result in count_primes_in_range.map(ranges):
print(result)
if __name__ == "__main__":
main()