def main(): a = input_int("a = ") b = input_int("b = ") #34, 12 stan wins #15, 24 charlie wins #if a - b < b #if a - b > b #a - bk < b then a - b(k - 1) assert(a > b) turn = 1 while True: assert(a >= 0 and b >= 0) if a == 0 or b == 0: break a, b = swap(a, b) print(a, b, a - b) if (a - b) >= b: print("occurs") if turn == 1: print("Stan wins") else: print("Charlie wins") #break turn^=1 a-=b
def download_chapters(conf: config.Config) -> Optional[Tuple[int, int]]: print("Which chapters do you want to download?") chapter_start = utils.input_int("First chapter? ") chapter_end = utils.input_int( "Last chapter? ", minval=chapter_start, default=chapter_start ) chapters_on_disk = utils.get_chapters_on_disk(conf.book) chapters = list(range(chapter_start, chapter_end + 1)) if any(ch in chapters_on_disk for ch in chapters): if not utils.input_yes_no( "Some of these chapters are already on disk. Do you want to redownload them?" ): chapters = [ch for ch in chapters if ch not in chapters_on_disk] if not chapters: print("All chapters are already on disk. Bye.") return None try: result = Downloader(conf).download_chapters(chapters) if result: return chapter_start, chapter_end return None except: print() raise
def _options(self, item, category, action): options_map = {1: "equip", 2: "drop", 3: "back"} while True: old_item = self.get_equipped(category) print_slow("Currently equipped: {} \n".format(old_item)) print_slow("Selected item : {} \n".format(item)) print_options(options_map) answer = options_map[input_int()] if answer == "equip": self.equip(item, category, old_item) self.view_category(action, category) break elif answer == "drop": while True: print_slow("Are you sure you want to drop item? \n") print_slow("1. Yes \n" + "2. No \n") answer = input_int() if answer == 1: self.drop(item, category) self._options(item, category, action) elif answer == 2: self._options(item, category, action) break else: print_slow("Please choose a valid option") continue
def draw_sector_mode(cur_state): if imgui.button("New sector"): cur_state.cur_sector = map_db.add_new_sector(cur_state.map_data) cur_sect = cur_state.cur_sector if cur_sect != -1: imgui.text("Sector {}".format(cur_sect)) set_sector_group = lambda val: map_db.set_sector_constant( cur_state.map_data, cur_sect, map_db.SECT_GROUP_IDX, val) input_int( "Sector group: ", "##sector{}_".format(cur_sect), map_db.get_sector_constant(cur_state.map_data, cur_sect, map_db.SECT_GROUP_IDX), set_sector_group) #type_getter = lambda: get_sector_type(cur_state, cur_sect) #type_setter = lambda val: set_sector_type(cur_state, cur_sect, val) #attr_getter = lambda attr: get_sector_attribute(cur_state, cur_sect, attr) #attr_setter = lambda attr: lambda val: set_sector_attribute(cur_state, cur_sect, attr, val) #param_getter = lambda param: get_sector_param(cur_state, cur_sect, param) #param_setter = lambda param: lambda val: set_sector_param(cur_state, cur_sect, param, val) imgui.same_line() imgui.text("Sector {}".format(cur_sect)) def set_cur_sector(idx): cur_state.cur_sector = idx draw_list(cur_state, "Sector", "Sector list", map_db.get_all_sectors(cur_state.map_data), set_cur_sector)
def menu_select_reviewers_who_have_num_reviews_in_range(): min = utils.input_int("Find reviewers who have at least this many number of reviews: ") if min is False: return max = utils.input_int("But who have less than this amount: ") if max is False: return if min > max: utils.print_error("Min must be greater than max! (found: min: {} > max: {})".format(min, max)) return conn = sqlite3.connect(DATABASE_NAME) c = conn.cursor() c.execute("SELECT u.name \ FROM USERS u \ LEFT OUTER JOIN Reviews r ON u.email = r.reviewer \ GROUP BY u.name \ HAVING COUNT(r.paper) >= ? AND COUNT(r.paper) <= ?", (min, max)) paged_res = _fetch_all_rows_and_page(c, 5) paged_res.display_pages()
def main(): n = input_int("n = ") A = [-1] * n for i in range(n): A[i] = input_int("%d= " % i) x = 0 for i in range(n): x ^= A[i] if x != 0: print("Alice wins") else: print("Bob wins")
def main(): a = input_int("a = ") b = input_int("b = ") d, x, y = extgcd(a, b) ad = a//d bd = b//d print(a, b, ad, bd) #ad * (X - x) = -bd * (Y - y), X, Y are non-constant variables #X - x = -bd * t, X = -bd * t + x #Y - y = ad * t, Y = ad * t + y for t in range(10): X = -bd * t + x Y = ad * t + y print(X, Y, X * a + Y * b)
def main(): n = input_int("n = ") x = [] for i in range(n): x.append(input_int("coins in %dth mt= " % i)) k = input_int("k = ") a = [] for i in range(k): a.append(input_int("options in %dth mt= " % i)) ini = 0 for i in range(n): ini ^= grundy(x[i], a) print("Alice wins" if ini else "Bob wins")
def room(hero, level, game_level): junction_map = {1: "battle room", 2: "trap room", 3: "aeon chamber"} if game_level == "room": room_choice = 0 print_slow("Which room would you to enter?\n") while room_choice not in junction_map.keys(): print_options(junction_map) choice = input_int() room_choice = junction_map.get(choice) if room_choice == "battle room": enemy = Monster.monster_spawn(level) print_slow("You encounter some dangerous looking" " {}\n".format(enemy.name)) battle_choices(hero, enemy) junction_map.pop(choice) break elif room_choice == "trap room": junction_map.pop(choice) print("Trap room coming soon...") continue # call trap room function elif room_choice == "aeon chamber": junction_map.pop(choice) print("Aeon Chamber coming soon...") # call Aeon chamber function continue else: print("Please choose a valid input...") if game_level == "boss": print_slow("You've entered the lair of a dangerous boss!") print_slow("Boss content coming soon...")
def main(): n = input_int("n = ") p = [-1] * n for i in range(n): p[i] = input_int("p%d = " % i) if n & 1: p.append(0) p.sort() x = 0 for i in range(1, len(p), 2): x ^= (p[i] - p[i - 1] - 1) if x != 0: print("alice wins") else: print("bob wins")
def base_choices(): choice_map = {1: "explore", 2: "inventory", 3: "quit"} choice = 0 while True: print_options(choice_map) choice = choice_map.get(input_int()) if choice in choice_map.values(): break print("Choose a valid option...") return choice
def _get_hero_info(cls): # assigning the hero class based on user input print_slow("Choose from any of the below roles for today!\n") print_options(cls._hero_options) while True: char_class = cls._hero_options.get(input_int()) if char_class: break print("Please choose from the available roles!\n") return char_class
def convert_chapters( conf: config.Config, chapter_start: int = None, chapter_end: int = None ): print("Which chapters do you want to convert?") if chapter_start is not None and chapter_end is not None: print("Enter nothing to convert the chapters just downloaded.") chapter_start = utils.input_int("First chapter? ", default=chapter_start) chapter_end = utils.input_int("Last chapter? ", chapter_start, default=chapter_end) chapters = set(range(chapter_start, chapter_end + 1)) chapters_on_disk = utils.get_chapters_on_disk(conf.book) missing_chapters = chapters - chapters_on_disk if missing_chapters: print("The following chapters are not on disk:") print(utils.format_range_list(utils.group_chapters(missing_chapters))) available_chapters = utils.group_chapters(chapters - missing_chapters) new_range = max(available_chapters, key=len) if utils.input_yes_no( f"Do you want to convert {utils.format_range(*new_range)} instead?" ): chapter_start, chapter_end = new_range else: print("Ok. Bye.") return print("Converting from chapter", chapter_start, "to", chapter_end) print("\nBook converters:") for i, converter in enumerate(converters.CONVERTERS): print("[{}] {}".format(i, converter.name)) converter_id = utils.input_int("Converter: ", 0, i) converters.CONVERTERS[converter_id](conf).convert_chapters( chapter_start, chapter_end )
def main(): N = input_int("N = ") A = input("A = ").split(" ") A = list(map(int, A)) print(A) for i in range(1, len(A)): v = A[i] j = i while j - 1 >= 0 and A[j - 1] > v: A[j] = A[j - 1] print(A) j -= 1 A[j] = v print(A)
def battle_choices(hero, enemy): battle_map = {1: "attack", 2: "flee", 3: "potion"} print_options(battle_map) battle_action = battle_map.get(input_int()) if battle_action == "attack": fight(hero, enemy) # launches battle elif battle_action == "flee": flee(hero, enemy) # attemps to flee the battle room elif battle_action == "potion": potion(hero, enemy) # allows hero to consume potions else: print("Please select a valid input...") battle_choices(hero, enemy) return hero
def _get_website(config: dict): print("[0] Custom") for i, website in enumerate(websites.WEBSITES, 1): print("[{}] {}".format(i, website.name)) website_index = utils.input_int("Website: ", 0, i) if website_index > 0: website = websites.WEBSITES[website_index - 1] config["website"] = website.name config.update(website.create_config()) else: config["website"] = { "toc_url": input("TOC url: "), "toc_start": input("TOC start: "), "toc_end": input("TOC end: "), "toc_link": input("TOC link regex (optional): ") or 'href="(.*?)"', "chapter_url": input("Chapter url: "), "chapter_start": input("Chapter start: "), "chapter_end": input("Chapter end: "), }
def view_inventory(self): while True: clear_screen() print("Inventory:") print_options(self._inventory_options) action = input_int() if action == 1: print_slow("You have {} Coins in your purse\n".format( self.inventory["Coins"])) break elif action > 1 and action < 7: clear_screen() print_slow("You have chosen to see {} : {} \n".format( action, self._inventory_options.get(action))) self.view_category(action, self._inventory_options.get(action)) elif action == 7: clear_screen() break else: print_slow("Choose valid option") continue
def view_category(self, action, category): self.print_inventory(category) # Need to better understand what the point of this # function is, the current implementation is still messy # Also, this should just be a function in the hero class # Since you're making a view of a hero attribute n_invent = self.get_n_inventory(category) + 1 while True: response = input_int() if response < n_invent: item = self.inventory[category][response - 1] clear_screen() self._options(item, category, action) break elif response == n_invent: clear_screen() self.view_inventory() break else: print_slow("Choose valid option") continue
def draw_sector_group_mode(cur_state): if imgui.button("New sector group"): cur_state.cur_sector = map_db.add_new_sector_group(cur_state.map_data) cur_sect_group = cur_state.cur_sector_group if cur_sect_group != -1: imgui.text("Sector Group {}".format(cur_sect_group)) input_int( "Floor height: ", "##sector_group{}_floor_height".format(cur_sect_group), map_db.get_sector_group_param(cur_state.map_data, cur_sect_group, map_db.FLOOR_HEIGHT_IDX), delay(map_db.set_sector_group_param, cur_state.map_data, cur_sect_group, map_db.FLOOR_HEIGHT_IDX)) input_int( "Floor color: ", "##sector_group{}_floor_color".format(cur_sect_group), map_db.get_sector_group_param(cur_state.map_data, cur_sect_group, map_db.FLOOR_COLOR_IDX), delay(map_db.set_sector_group_param, cur_state.map_data, cur_sect_group, map_db.FLOOR_COLOR_IDX)) input_int( "Ceiling height: ", "##sector_group{}_ceil".format(cur_sect_group), map_db.get_sector_group_param(cur_state.map_data, cur_sect_group, map_db.CEIL_HEIGHT_IDX), delay(map_db.set_sector_group_param, cur_state.map_data, cur_sect_group, map_db.CEIL_HEIGHT_IDX)) input_int( "Ceiling color: ", "##sector_group{}_ceil_color".format(cur_sect_group), map_db.get_sector_group_param(cur_state.map_data, cur_sect_group, map_db.CEIL_COLOR_IDX), delay(map_db.set_sector_group_param, cur_state.map_data, cur_sect_group, map_db.CEIL_COLOR_IDX)) input_select( "Type: ", "##sector_group{}_type".format(cur_sect_group), map_db.SECTOR_TYPE_NAMES, map_db.get_sector_group_type(cur_state.map_data, cur_sect_group, 0), delay(map_db.set_sector_group_type, cur_state.map_data, cur_sect_group, 0)) SECTOR_LIGHTS = ["-2", "-1", "0", "1", "2"] input_select( "Light level: ", "##sector{}_light".format(cur_sect_group), SECTOR_LIGHTS, map_db.get_sector_group_param(cur_state.map_data, cur_sect_group, map_db.LIGHT_IDX) + 2, lambda v: map_db.set_sector_group_param( cur_state.map_data, cur_sect_group, map_db.LIGHT_IDX, v - 2)) SECTOR_STATES = ["CLOSED", "GOING_UP", "OPEN", "GOING_DOWN"] input_select( "State: ", "##sector{}_state".format(cur_sect_group), SECTOR_STATES, map_db.get_sector_group_param(cur_state.map_data, cur_sect_group, map_db.STATE_IDX), delay(map_db.set_sector_group_param, cur_state.map_data, cur_sect_group, map_db.STATE_IDX)) input_int( "Orig height: ", "##sector{}_orig_height".format(cur_sect_group), map_db.get_sector_group_param(cur_state.map_data, cur_sect_group, map_db.ORIG_HEIGHT_IDX), delay(map_db.set_sector_group_param, cur_state.map_data, cur_sect_group, map_db.ORIG_HEIGHT_IDX)) def set_cur_sector_group(idx): cur_state.cur_sector_group = idx draw_list(cur_state, "Sector Group", "Sector group list", map_db.get_all_sector_groups(cur_state.map_data), set_cur_sector_group)
def main(): n = input_int("n = ")
def main(): H = input_int("h = ") W = input_int("w = ") print("Alice wins" if grundy(H, W) else "Bob wins")
def main(): a = input_int("a = ") b = input_int("b = ") print("Stan wins" if dfs(a, b) else "Charlie wins")