Best Python code snippet using autotest_python
day14_chocolate_charts.py
Source:day14_chocolate_charts.py
...15 self.scores.append(int(digit))16 self.elf1 = (1 + self.elf1 + self.scores[self.elf1]) % len(self.scores)17 self.elf2 = (1 + self.elf2 + self.scores[self.elf2]) % len(self.scores)18 # end while19 def find_recipe(self, recipe_str):20 found = False21 n_chars = len(recipe_str)22 pattern = [int(i) for i in recipe_str]23 while not found:24 new_recipe = str(self.scores[self.elf1] + self.scores[self.elf2])25 for digit in new_recipe:26 self.scores.append(int(digit))27 curr_score = self.scores[-n_chars:]28 if curr_score == pattern:29 found = True30 break31 32 self.elf1 = (1 + self.elf1 + self.scores[self.elf1]) % len(self.scores)33 self.elf2 = (1 + self.elf2 + self.scores[self.elf2]) % len(self.scores)34 return len(self.scores)-n_chars35 # end while36 def get_scores(self, start, num):37 # print(self.elf1, self.elf2)38 return "".join(map(str, self.scores[start:start+num]))39 def display_scores(self, start, num):40 # print(self.elf1, self.elf2)41 print("".join(map(str, self.scores[start:start+num])))42test = Recipes()43test.add_recipe(20)44assert (test.get_scores(9,10) == "5158916779")45test = Recipes()46assert (test.find_recipe("51589") == 9)47test = Recipes()48assert (test.find_recipe("01245") == 5)49test = Recipes()50assert (test.find_recipe("92510") == 18)51test = Recipes()52assert (test.find_recipe("59414") == 2018)53"""54Total time: 1 sec55"""56START = time.time()57part1 = Recipes()58part1.add_recipe(846601+20)59print(part1.get_scores(846601, 10))60print("Total time = {0:f} ms".format((time.time()-START)*1000))61"""62Total time: 28 secs63"""64START = time.time()65part2 = Recipes()66print(part2.find_recipe("846601"))...
views.py
Source:views.py
1from django.shortcuts import render, redirect2from django.urls import reverse3from django.db.models import Q4from book_recipes.models import Recipes, Ingredients5from book_recipes.forms import RecipesFilterForms6def home(request):7 """ÐÐ»Ð°Ð²Ð½Ð°Ñ ÑÑÑаниÑа. РедиÑÐµÐºÑ Ð½Ð° `/recipes_list`"""8 response = redirect(reverse("recipes_list"))9 return response10def recipes_list(request):11 try:12 find_recipe = request.GET.get("find_recipe")13 except (ValueError, TypeError):14 find_recipe = None15 query = Q()16 if find_recipe:17 query.add(18 Q(pk=find_recipe), Q.AND,19 )20 recs = Recipes.objects.filter(query)21 ingrs = Ingredients.objects.all()22 filter_recipes = RecipesFilterForms()23 filter_ingredients = Ingredients.objects.values('ingredient').distinct()24 return render(request, 'book_recipes/recipes_list.html', {"recs": recs,25 "ingrs": ingrs,26 "filter_recipes": filter_recipes,27 'filter_ingredients': filter_ingredients,28 })29def search_ingredients(request):30 recs = Recipes.objects.all()31 ingrs = Ingredients.objects.all()32 recipes_list = []33 check_ingrs = request.GET.getlist('check_ingrs')34 for check_ingr in check_ingrs:35 for ingr in ingrs:36 if ingr.ingredient==check_ingr:37 recipes_list.append(ingr.recipes_id)38 recipes_list = list(set(recipes_list))39 return render(request, 'book_recipes/search_ingredients.html', {'check_ingrs': check_ingrs,40 "ingrs": ingrs,41 "recs": recs,42 "recipes_list": recipes_list,...
day14.py
Source:day14.py
...12 s.append(next_recipe)13 i = (i + 1 + s[i]) % len(s)14 j = (j + 1 + s[j]) % len(s)15 return ''.join(str(v) for v in s[n:n+10])16def find_recipe(needle, s=None):17 if s is None:18 s = '37'19 i = 020 j = 121 while s.find(needle, -len(needle) - 2) == -1:22 si = int(s[i])23 sj = int(s[j])24 next_recipe = si + sj25 s += str(next_recipe)26 i = (i + 1 + si) % len(s)27 j = (j + 1 + sj) % len(s)28 return s.find(needle)29if __name__ == '__main__':30 from aocd.models import Puzzle31 assert get_recipes(9) == '5158916779'32 assert get_recipes(5) == '0124515891'33 assert get_recipes(18) == '9251071085'34 assert get_recipes(2018) == '5941429882'35 assert find_recipe('51589') == 936 assert find_recipe('01245') == 537 assert find_recipe('92510') == 1838 assert find_recipe('59414') == 201839 puz = Puzzle(2018, 14)40 puz.answer_a = get_recipes(int(puz.input_data))41 print(f'Part 1: {puz.answer_a}')42 puz.answer_b = find_recipe(puz.input_data)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!