#!/usr/bin/python3
# =================================================================
# From: www.youtube.com/watch?v=5vbk0TwkokM
# How on Earth does ^.?$|^(..+?)\1+$ produce primes?
# =================================================================
import re
import user_interface as ui
regx = re.compile(r'^.?$|^(..+?)\1+$')
while True:
print()
s = ui.get_user_input('Please enter a positive integer: ')
if not s: break
tf,n = ui.is_integer(s)
if tf is not True:
print()
print(f'bad input ({s}) - try again')
continue
if n < 0:
print()
print(f'input is not a positive integer ({n}) - try again')
continue
x = re.match(regx,'1'*n)
if x is not None:
print()
print(f'{n} is not a prime number')
else:
print()
print(f'{n} is a prime number')