-
Notifications
You must be signed in to change notification settings - Fork 1
/
example3.py
54 lines (43 loc) · 1.35 KB
/
example3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import logging
from time import sleep
from mpcurses import MPcurses
from screen_layouts.example3_sl import get_screen_layout
logger = logging.getLogger(__name__)
def is_prime(num):
if num == 1:
return False
for i in range(2, num):
if (num % i) == 0:
return False
break
else:
return True
def check_primes(data, shared_data):
range_split = data['range'].split('-')
lower = int(range_split[0])
upper = int(range_split[1]) + 1
logger.debug('total of {} numbers'.format(upper - lower))
for number in range(lower, upper):
logger.debug('checking {}/{}'.format(str(number).zfill(6), str(range_split[1]).zfill(6)))
if is_prime(number):
logger.debug('prime')
else:
logger.debug('not prime')
def main():
MPcurses(
function=check_primes,
process_data=[
{'range': '00001-10000'},
{'range': '10001-20000'},
{'range': '20001-30000'},
{'range': '30001-40000'},
{'range': '40001-50000'},
{'range': '50001-60000'},
{'range': '60001-70000'},
{'range': '70001-80000'},
{'range': '80001-90000'},
{'range': '90001-100000'}
],
screen_layout=get_screen_layout()).execute()
if __name__ == '__main__':
main()