Пример #1
0
def elim_results(soup, event_id, max_round_num):
    ELIM_ERR_MSG = 'Could not interpret elimation round results for event {}'.format(event_id)
    bracket_pairs = soup.find('div', class_='top-bracket-slider').find_all('div', class_='dual-players')
    bracket_pairs = [pair for pair in bracket_pairs if len(pair.find_all('div', class_='player')) == 2]
    results_table = []
    print '{} matches found in elimination rounds'.format(len(bracket_pairs))
    for idx, pair in enumerate(bracket_pairs):
        players = list(pair.find_all('div', class_='player'))
        p1 = players[0].text.strip().lstrip('()12345678 ')
        p2 = players[1].text.strip().lstrip('()12345678 ')
        p1_part = p1.partition(',')
        p2_part = p2.partition(',')
        strong = pair.find('strong').text.strip().lstrip('()12345678 ')
        result_raw = ''
        if strong == p1 or len(p1_part[2]) > 0 and len(p2_part[2]) == 0:
            result_raw = 'Won ' + p1_part[2]
        if strong == p2 or len(p2_part[2]) > 0 and len(p2_part[2]) == 0:
            if len(result_raw) > 0:
                raise Exception(ELIM_ERR_MSG)
            result_raw = 'Lost ' + utils.str_reverse(p2_part[2])
        if len(result_raw)==0:
            raise Exception(ELIM_ERR_MSG)
        p1_name_raw = utils.standardize_name(p1_part[0])
        p2_name_raw = utils.standardize_name(p2_part[0])
        if len(bracket_pairs) == 7:
            if idx < 4:
                round_num = max_round_num + 1
            elif idx < 6:
                round_num = max_round_num + 2
            else:
                round_num = max_round_num + 3
        elif len(bracket_pairs) == 3:
            if idx < 2:
                round_num = max_round_num + 1
            else:
                round_num = max_round_num + 2
        else:
            round_num = max_round_num + 1

        row = {
            'p1_name_raw' : p1_name_raw,
            'p2_name_raw' : p2_name_raw,
            'result_raw' : result_raw,
            'round_num' : round_num,
            'event_id' : event_id,
            'elim' : 1,
            'vs' : 'vs.'
        }
        results_table.append(row)

    upload_round_results(results_table, event_id, max_round_num + 1)
Пример #2
0
bases.

Find the sum of all numbers, less than one million, which are palindromic
in base 10 and base 2.

(Please note that the palindromic number, in either base, may not include
leading zeros.)
"""

from utils import str_reverse, is_palindrome

result = 0

# single-digit palindromes
for i in range(10):
  if is_palindrome(bin(i)[2:]):
    result += i
# ... and beyond
for i in range(1,1000):
  s = str(i)
  rev_s = str_reverse(s)

  num = int(s + str_reverse(s))
  if num<1000000 and is_palindrome(bin(num)[2:]):
    result += num
  for d in range(10):
    num = int(s + str(d) + rev_s)
    if num<1000000 and is_palindrome(bin(num)[2:]):
      result += num

print result