How to use get_variations method in Slash

Best Python code snippet using slash

day_20.py

Source:day_20.py Github

copy

Full Screen

...52 return order53 for key in keys:54 if k == key:55 continue56 neighbours = get_variations(array, k)57 for neighbour in neighbours:58 placement = is_match(array[key], neighbour)59 if placement:60 order.append((k, key))61 return order62def get_variations(image_dict, image_key: str):63 seen = set()64 all_ = [image_dict[image_key]]65 seen.add(str(image_dict[image_key]))66 assert len(image_dict[image_key]) == len(image_dict[image_key][0])67 assert len(image_dict[image_key]) > 068 rotates = rotate(image_dict[image_key])69 for a in rotates:70 temp = str(a)71 if temp not in seen:72 seen.add(temp)73 all_.append(a)74 for x in all_[:]:75 flips = flip(x)76 for b in flips:77 temp = str(b)78 if temp not in seen:79 seen.add(temp)80 all_.append(b)81 return all_82def part_01(array):83 keys = list(array.keys())84 response = dfs(array, keys)85 total = get_image_graph(response)86 corners = [k for k, v in total.items() if len(v) == 2]87 return math.prod([int(i) for i in corners]), corners, total88def get_image_graph(response):89 total = dict()90 for resp in set(response):91 a, b = resp92 if a not in total:93 total[a] = set()94 if b not in total:95 total[b] = set()96 total[a].add(b)97 total[b].add(a)98 return total99def part_02(image_dict: Dict[str, List[List[str]]], corners, total):100 stack = []101 while len(stack) != 2:102 stack.clear()103 corner = corners.pop()104 stack = get_starting_stack(image_dict, total, corner)105 used_keys = [k[0] for k in stack]106 # get the header row107 while len(stack) < math.sqrt(len(image_dict)):108 key, image = stack[-1]109 # print(f"Searching for {key} in the neighbours of {total[key]}")110 for ii in total[key]:111 if ii in used_keys:112 continue113 for new in get_variations(image_dict, ii):114 new_result = is_match(image, new, direction="r")115 if new_result:116 stack.append((ii, new))117 used_keys.append(ii)118 temp_stack = stack[:]119 temp_used_keys = used_keys[:]120 while len(stack) != len(image_dict):121 stack = temp_stack[:]122 used_keys = temp_used_keys[:]123 for s in stack:124 key, image = s125 for ii in total[key]:126 if ii in used_keys:127 continue128 for new in get_variations(image_dict, ii):129 new_result = is_match(image, new, direction="d")130 if new_result:131 stack.append((ii, new))132 used_keys.append(ii)133 break134 squared = math.sqrt(len(image_dict))135 return get_image_stitched(stack, squared)136def print_stack(stack, squared):137 for i, s in enumerate(stack, 1):138 print(s[0], end=" ")139 if i % int(squared) == 0:140 print()141 print("=" * 50)142 count = 1143 for j in range(len(stack)):144 for i, s in enumerate(stack, 1):145 print("".join(s[1][j]), end=" ")146 if i % int(squared) == 0:147 print()148 if count % int(squared) == 0:149 print()150 count += 1151def get_starting_stack(image_dict: dict, total: dict, corner: str):152 stack = []153 key1, key2 = total[corner]154 image1 = image_dict[key1]155 image2 = image_dict[key2]156 for n in get_variations(image_dict, corner):157 result1 = is_match(n, image1, direction="r")158 result2 = is_match(n, image2, direction="r")159 if result1:160 for nn in get_variations(image_dict, key2):161 result_new = is_match(n, nn, direction="d")162 if result1 and result_new:163 stack.append((corner, n))164 stack.append((key1, image1))165 break166 if result2:167 for nnn in get_variations(image_dict, key1):168 result_new = is_match(n, nnn, direction="d")169 if result2 and result_new:170 stack.append((corner, n))171 stack.append((key2, image2))172 break173 return stack174def display_image(image, index):175 display.generic_out(176 image, {".": "white", "#": "green", "M": "red"}, "day_20", index177 )178m1 = re.compile(r".{18}#.")179m2 = re.compile(r"#.{4}##.{4}##.{4}###")180m3 = re.compile(r".#.{2}#.{2}#.{2}#.{2}#.{2}#.{3}")181def get_monsters(r):182 # display_image(r, -1)183 displays = dict()184 targets = dict()185 waters = sum(v.count("#") for v in r)186 s = {"0": r}187 n = get_variations(s, "0")188 for index, lines in enumerate(n):189 displays[index] = []190 lines = list(lines)191 targets[index] = 0192 while lines:193 try:194 t1 = lines.pop(0)195 t2 = lines.pop(0)196 t3 = lines.pop(0)197 except IndexError:198 continue199 r1 = m1.findall("".join(t1))200 r2 = m2.findall("".join(t2))201 r3 = m3.findall("".join(t3))...

Full Screen

Full Screen

parse.py

Source:parse.py Github

copy

Full Screen

...32 if translit.find(k) != -1:33 translit = translit.replace(k, v)34 syn.add(unicodedata.normalize('NFC', translit))35 return list(syn)36def get_variations(orig, curated_proc=False):37 variations = set([orig])38 parsed = tokenizer.ads_parse_author_name(orig)39 last = normalize(parsed.get('last'))40 first = normalize(parsed.get('first'))41 middle = normalize(parsed.get('middle'))42 prefix = normalize(parsed.get('prefix'))43 suffix = normalize(parsed.get('suffix'))44 print >>sys.stderr, "%s %s %s" % (last, first, middle)45 if parsed.keys() == ['last']:46 # all we got was last name47 variations.add(last + ",.*")48 else:49 variations.add(last + ",")50 if first:51 if middle:52 if len(first) > 1:53 variations.add(last + ", " + first)54 variations.add(last + ", " + first[0])55 if len(middle) > 1:56 variations.add(last + ", " + first + " " + middle + r"\b.*")57 variations.add(last + ", " + first[0] + " " + middle[0] + r"\b.*")58 if not curated_proc:59 variations.add(last + ", " + first + " " + middle[0] + r"\b.*")60 elif len(middle) == 1 and not curated_proc:61 variations.add(last + ", " + first[0] + " " + middle + ".*")62 variations.add(last + ", " + first + " " + middle + ".*")63 else:64 variations.add(last + ", " + first + "\w*")65 if len(middle) > 1:66 variations.add(last + ", " + first + "\w* " + middle + r"\b.*")67 if not curated_proc:68 variations.add(last + ", " + first + "\w* " + middle[0] + r"\b.*")69 elif len(middle) == 1:70 variations.add(last + ", " + first + "\w* " + middle + r".*")71 else:72 #variations.add('g) ' +last + ", " + first)73 if len(first) > 1:74 variations.add(last + ", " + first + r"\b.*")75 variations.add(last + ", " + first[0])76 if not curated_proc:77 variations.add(last + ", " + first[0] + r"\b.*")78 elif len(first) == 1:79 variations.add(last + ", " + first + ".*")80 variations = list(variations)81 variations.sort(key=len)82 variations.reverse()83 return variations84 85def proc_synonyms(orig):86 proc_syn = []87 orig = set(orig)88 for a in orig:89 targets = orig.copy()90 targets.remove(a)91# targets = [x.replace(',','\,') for x in targets]92# proc_syn.append(('<span class="key">%s</span> => ' % a) + ", ".join(['<span class="target">%s</span>' % x for x in targets]))93# targets = [x + r'\b.*' for x in targets]94 exp_targets = set()95 [exp_targets.update(get_variations(x, curated_proc=True)) for x in targets]96 exp_targets = [x.replace(',','\,') for x in exp_targets]97# for key in get_variations(a, curated_proc=True):98 key = '<span class="key">%s</span>' % a99 proc_syn.append(key + " => " + ", ".join(['<span class="target">%s</span>' % x for x in exp_targets]))100 return proc_syn101@app.route('/')102def author_form():103 return flask.render_template('form.html', base_path=BASE_PATH)104@app.route('/index')105def author_index():106 results = []107 author = flask.request.args.get('author')108 results.append({ 'heading': 'Original', 'id': 'index-orig', 'names': [author] })109 normalized = normalize(author)110 results.append({ 'heading': 'Normalized', 'id': 'index-norm', 'names': [normalized] })111 syn = gen_synonyms(normalized)112 results.append({ 'heading': 'Auto-generated Synonyms', 'id': 'index-auto-syn', 'names': syn })113 results.append({ 'heading': 'Indexed Value', 'id': 'indexed', 'names': [normalized] })114 return flask.jsonify(result=results)115@app.route('/query')116def author_query():117 results = []118 author = flask.request.args.get('author')119 results.append({ 'heading': 'Original', 'id': 'query-orig', 'names': [author] })120 normalized = normalize(author)121 results.append({ 'heading': 'Normalized', 'id': 'query-norm', 'names': [normalized] })122 variations = get_variations(normalized)123 results.append({ 'heading': 'Name Variations', 'id': 'query-variations', 'names': variations })124 return flask.jsonify(result=results)125@app.route('/auto_gen_synonyms')126def get_gen_synonyms():127 results = set()128 input = flask.request.args.get('author')129 orig = re.split(r'\s*;\s*', input)130 results.update(orig)131 for name in orig:132 results.update(gen_synonyms(name))133 results = list(results)134 results.sort(key=len)135 results.reverse()136 return flask.jsonify(result=results)137@app.route('/synonym')138def author_synonyms():139 results = []140 input = flask.request.args.get('author')141 orig_syn = [normalize(x) for x in re.split(r'\s*\n\s*', input)]142 results.append({ 'heading': 'Original', 'id': 'original', 'names': orig_syn })143 expanded_syn = set(orig_syn)144 for orig in orig_syn:145 expanded_syn.update(gen_synonyms(orig))146 expanded_syn = list(expanded_syn)147 results.append({ 'heading': 'Auto-generated Synonyms', 'id': 'syn-auto-syn', 'names': expanded_syn })148 proc_syn = proc_synonyms(expanded_syn)149 results.append({ 'heading': 'Processed', 'id': 'processed', 'names': proc_syn })150 return flask.jsonify(result=results)151@app.route('/variations')152def variations():153 input = flask.request.args.get('author')154 results = get_variations(input, curated_proc=True)155 return flask.jsonify(result=results)156if __name__ == '__main__':157 app.debug = True...

Full Screen

Full Screen

cracker.py

Source:cracker.py Github

copy

Full Screen

...37 verify_password("".join(char_tuple), hashes)38def mutated_dictionary_attack(hashes, dictionary_file):39 with open(dictionary_file, 'r', encoding="latin-1") as dictionary:40 for line in dictionary:41 for variant in get_variations(line, 0):42 if hash_password(variant) in hashes:43 hashes[hash_password(variant)] = variant44def get_variations(password, index):45 variations = []46 if index < len(password):47 try:48 for char_alternative in character_alternatives[password[index]]:49 variation = password[:index] + char_alternative + password[index + 1:]50 variations.append(variation)51 variations.extend(get_variations(variation, index + 1))52 variations.extend(get_variations(password, index + 1))53 except:54 pass55 return variations56characters = "`1234567890-=~!@#$%^&*()_+qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM,./;\'[]\<>?:\"{}| "57character_alternatives = {58 'a': ['A', '@', '4'],59 'b': ['C', '8', '6'],60 'c': ['C', '<', '{', '[', '('],61 'd': ['D', '0'],62 'e': ['E', '3'],63 'f': ['F'],64 'g': ['G', '[', '-', '6', '9'],65 'h': ['H', '4'],66 'i': ['I', '1', '!', '|', '9'],...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful