Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import sys, bracket, itertools
- from collections import defaultdict
- class Info:
- pass
- def get_info(n, notations=True, predicates=True, stats=True):
- info = Info()
- brackets, is_prime = bracket.get_brackets(n, include_primality=True)
- info.bracket_notation = brackets
- abc = brackets.replace('<>', 'a')
- for letter in 'abcdefghij':
- abc = abc.replace('<'+letter+'>', chr(ord(letter)+1))
- info.abc_notation = abc
- p = abc.replace('<', 'p<')
- for letter in 'abcdefghij':
- p = p.replace(letter, 'p'*(ord(letter)-96)+'1')
- info.p_notation = p
- digits_list = []
- last_bracket = ''
- for char in brackets:
- if char == last_bracket:
- digits_list[-1] += 1
- else:
- digits_list.append(1)
- last_bracket = char
- digits = ''.join(map(str,digits_list))
- info.digit_notation = digits
- depth = []
- current_depth = 0
- max_depth = 0
- add = True
- for digit in digits_list[:-1]:
- if add:
- current_depth += digit
- else:
- current_depth -= digit
- depth.append('*' * current_depth)
- add = not add
- if current_depth > max_depth:
- max_depth = current_depth
- info.depth_notation = '\n'.join(''.join(row) for row in itertools.zip_longest(*depth, fillvalue=' '))
- info.is_prime = is_prime
- symmetrical = True
- b = 0
- numbers = {abc}
- while numbers:
- nonabc = set()
- for number in numbers:
- factors = defaultdict(int)
- factor = ''
- depth = 0
- for symbol in number:
- if symbol == '<':
- depth += 1
- elif symbol == '>':
- depth -= 1
- if depth > max_depth:
- max_depth = depth
- factor += symbol
- if depth == 0:
- factors[factor] += 1
- if '<' in factor:
- nonabc.add(factor[1:-1])
- factor = ''
- found_single = False
- for factor, count in factors.items():
- if count % 2 == 1:
- if found_single:
- symmetrical = False
- break
- else:
- found_single = True
- if not symmetrical:
- break
- if not symmetrical:
- break
- numbers = nonabc
- info.is_symmetrical = symmetrical
- info.is_alphabetical = not ('<' in abc)
- info.length = len(brackets)
- info.reversals= len(digits) - 1
- info.max_depth = max_depth
- factors = bracket.factor(n)
- info.factors = len(factors)
- info.smoothness = max(factors)
- info.necessary_brackets = abc.count('<')*2
- return info
- if __name__ == '__main__':
- n = int(sys.argv[1] if len(sys.argv) > 1 else sys.stdin.read())
- print(n)
- info = get_info(n)
- print(info.bracket_notation)
- print(info.abc_notation)
- print(info.p_notation)
- print(info.digit_notation)
- print('[code]')
- print(info.depth_notation)
- print('[/code]')
- print()
- print('Prime: {0}'.format('Yes' if info.is_prime else 'No'))
- print('Symmetrical: {0}'.format('Yes' if info.is_symmetrical else 'No'))
- print('Alphabetical: {0}'.format('Yes' if info.is_alphabetical else 'No'))
- print()
- print('Length: {0}'.format(info.length))
- print('Reversals: {0}'.format(info.reversals))
- print('Max Depth: {0}'.format(info.max_depth))
- print('Factors: {0}'.format(info.factors))
- print('Smoothness: {0}'.format(info.smoothness))
- print('Necessary Brackets: {0}'.format(info.necessary_brackets))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement