def generate_rylais_order_dictionary(session): rylais_dict = {} # array structure: [[wins_without, losses_without], # [wins_built_first, losses_built_first], ... [wins_built_last, losses_built_last]] for profile in session.query(dbProfile).filter_by(patch='5.14'): if profile.champ_id not in rylais_dict: rylais_dict[profile.champ_id] = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]] if profile.has_rylais: build_order = str_to_array(profile.build_order) rylais_index = build_order.index(3116) + 1 if profile.result: rylais_dict[profile.champ_id][rylais_index][0] += 1 else: rylais_dict[profile.champ_id][rylais_index][1] += 1 else: if profile.result: rylais_dict[profile.champ_id][0][0] += 1 else: rylais_dict[profile.champ_id][0][1] += 1 return rylais_dict
def generate_rylais_json(session, min_purchased=125): rylais_data = session.query(RylaisOrder).filter( RylaisOrder.total_games_built >= min_purchased) print(rylais_data.count()) json_array = [] with open('../static/json/rylais.json', 'wb') as f: for row in rylais_data: wins = str_to_array(row.wins)[1:] winrates = str_to_array_float(row.winrates)[1:] percent_build = row.percent_build built_winrate = row.built_winrate not_build_winrate = row.not_built_winrate built_first_count = wins[0] built_second_count = wins[1] built_third_count = wins[2] built_first_percent = winrates[0] built_second_percent = winrates[1] built_third_percent = winrates[2] percent_change = round( ((built_winrate - not_build_winrate) / not_build_winrate) * 100.0, 1) json_array.append({ "championName": champion_name_dict[row.champ_id], "percentBuilt": percent_build, "builtFirstWins": built_first_count, "builtSecondWins": built_second_count, "builtThirdWins": built_third_count, "builtFirstWinPercent": built_first_percent, "builtSecondWinPercent": built_second_percent, "builtThirdWinPercent": built_third_percent, "builtWinrate": built_winrate, "notBuiltWinrate": not_build_winrate, "percentDifference": percent_change }) json.dump(json_array, f)
self.code_col = encoded[-3:] self.row = None self.col = None @property def coord(self): return self.row, self.col def __str__(self): return f'{self.coord} => {self.code_row} + {self.code_col}' def __repr__(self): return str(self) argv = [SeatCode(x) for x in helper.str_to_array(raw)] seats = np.zeros((128, 8)) def decode(lower_char: str, upper_char: str, lower_idx: int, upper_idx: int, code: str, debug: bool = True) -> int: if code.replace(upper_char, '').replace(lower_char, '') != '': raise ValueError( f'Unexpected char: {code.replace(upper_char, "").replace(lower_char, "")} in code: {code}. ' f'Expected only `{upper_char}` or `{lower_char}`.') # elif (upper_idx - lower_idx) % 2 != 0: # raise ValueError(f'Expected even number length. U:{upper_idx} L:{lower_idx}')
CPU times: user 10.5 ms, sys: 527 µs, total: 11 ms Wall time: 10.5 ms Out[10]: 878724 %time d1.check_sum(d1.data, 0, 2, 2020) CPU times: user 1.35 s, sys: 6.06 ms, total: 1.36 s Wall time: 1.36 s Out[11]: 201251610 ``` """ import numpy as np import helper import runner raw = runner.get_data(1) argv = helper.to_int_array(helper.str_to_array(raw)) def check_sum(data, current_sum, count, match): length = data.size for i in range(0, length): total_sum = current_sum + data[i] if count == 0: if total_sum == match: return data[i] else: continue else: found = check_sum(data, total_sum, count - 1, match) if found is not None: return found * data[i]
self.codec = codec matches = re.match(r'([0-9]+)-([0-9]+) ([\w]{1}): ([\w]+)', codec) self.min_count = int(matches.group(1)) self.max_count = int(matches.group(2)) self.char = matches.group(3) self.psswd = matches.group(4) self.char_count = self.psswd.count(self.char) self.p1_valid = False self.p2_valid = False def __str__(self): return f'/ {str(self.valid):5} / {self.char_count:2} => Count: {self.min_count:2} - {self.max_count:2} of {self.char} in self{self.psswd}' argv = [InputCodec(x) for x in helper.str_to_array(raw)] def part1(data): for i in argv: if i.char_count >= i.min_count and i.char_count <= i.max_count: i.p1_valid = True else: i.p1_valid = False return len([x for x in argv if x.p1_valid]) def part2(data): for i in argv: if (i.psswd[i.min_count - 1] == i.char) != (i.psswd[i.max_count - 1]
import runner import helper import numpy as np raw = runner.get_data(3) argv = helper.str_to_array(raw) maze = np.array([list(x) for x in argv]) def part1(data): print(f'{maze.shape}') slope = [3, 1] print(f'Check passed: {check_can_end(maze.shape, slope)}') return find_num_of_trees(slope) def part2(data): slopes = [ [1, 1], [3, 1], [5, 1], [7, 1], [1, 2], ] counts = [find_num_of_trees(x) for x in slopes] result = 1 for i in counts: result = result * i return result, counts