How to use fact_set method in Slash

Best Python code snippet using slash

Euler_1_10.py

Source:Euler_1_10.py Github

copy

Full Screen

1# EULER PROBLEMS 1- 102######################### EULER - 13# a = int(input())4# ans = []5# i = 16# while i < a:7# if i % 3 ==0 or i % 5 == 0:8# ans.append(i)9# i += 110# else:11# pass12# i += 113# print(sum(ans))14######################### EULER - 215# def fibo_sumeven():16# a = 117# b = 218# terms = [a, b]19# i = 020# addy = 021# check = True22# while check:23# addy = terms[i] + terms[i + 1]24# if addy < 4000000:25# terms.append(addy)26# i += 127# check = True28# elif addy >= 4000000:29# check = False30# alpha = []31# for i in terms:32# if i % 2 ==0:33# alpha.append(i)34# else:35# pass36# return sum(alpha)37# x = fibo_sumeven()38# print(x)39######################### EULER - 340# def prime_test(a): #a > 141# if a != 2 and a % 2 == 0:42# return "not prime"43# elif a == 2 or a % 2 != 0:44# i = 245# count = 046# if a == i:47# return "prime"48# elif a != i:49# while i < a:50# if a % i != 0:51# count += 152# i += 153# elif a % i == 0:54# count = 055# break56# if count == 0:57# return "not prime"58# elif count > 0:59# return "prime"60 61# d = int(input("Number: "))62# divisor = 263# dividend = d64# while dividend >= divisor:65# check = prime_test(divisor)66# if check == 'prime' and dividend % divisor == 0:67# condi = True68# while condi:69# div = dividend // divisor70# dividend = div71# if dividend % divisor == 0:72# continue73# elif dividend % divisor != 0 and dividend != 1:74# divisor += 175# condi = False76# elif dividend == 1:77# condi = False78# elif check == 'prime' and dividend % divisor != 0:79# divisor += 180# elif check == 'not prime':81# divisor += 182# print(f"Greatest Prime Divisor: {divisor}")83######################### EULER - 484# def str_rev(a):85# check = []86# for i in range(0, len(a)):87# alpha = a[-1* (i + 1)]88# check.append(alpha)89# return ''.join(check)90 91# combi = []92# for i in range(100, 1000):93# for j in range(100, 1000):94# combi.append(i * j)95# palins = []96# for alpha in combi:97# if str(alpha) == str_rev(str(alpha)):98# palins.append(alpha)99# else:100# pass101# print(max(palins))102 103######################### EULER - 5104# def prime_test(a): #a > 1105# if a != 2 and a % 2 == 0:106# return "not prime"107# elif a == 2 or a % 2 != 0:108# i = 2109# count = 0110# if a == i:111# return "prime"112# elif a != i:113# while i < a:114# if a % i != 0:115# count += 1116# i += 1117# elif a % i == 0:118# count = 0119# break120# if count == 0:121# return "not prime"122# elif count > 0:123# return "prime"124 125# def prime_fact(d):126# divisor = 2127# dividend = d128# divs_req = []129# while dividend >= divisor:130# check = prime_test(divisor)131# if check == 'prime' and dividend % divisor == 0:132# condi = True133# while condi:134# div = dividend // divisor135# dividend = div136# divs_req.append(divisor)137# if dividend % divisor == 0:138# continue139# elif dividend % divisor != 0 and dividend != 1:140# divisor += 1141# condi = False142# elif dividend == 1:143# condi = False144# elif check == 'prime' and dividend % divisor != 0:145# divisor += 1146# elif check == 'not prime':147# divisor += 1148# return divs_req149# print(f"Greatest Prime Divisor: {divisor}")150# print(f"Prime Factorization: {divs_req}")151# LCM152# def lcm_nos(a): #a is a list of the numbers153# fact = []154# fact_set = []155# common_count = {}156# common_min = {}157# final = 1158# for i in range(0, len(a)): 159# fact.append(prime_fact(a[i]))160# fact_set.append(set(prime_fact(a[i])))161# for j in range(1, len(fact_set)):162# fact_set[0] = fact_set[0].union(fact_set[j])163# for alpha in fact_set[0]:164# common_count[str(alpha)+"s"] = []165# for beta in fact:166# common_count[str(alpha)+"s"].append(beta.count(alpha))167# for k in fact_set[0]:168# common_min["min_"+str(k)+"s"] = max(common_count[str(k)+"s"])169# if common_min["min_"+str(k)+"s"] != 0:170# final *= k ** common_min["min_"+str(k)+"s"]171# else:172# pass 173# return final174# x= lcm_nos(list(range(1,20)))175# print(x)176# HCF not asked in Euler 5 but noted here for completeness of HCF & LCM stuff177#Extra178# def hcf_nos(a): #a is a list of the numbers179# fact = []180# fact_set = []181# common_count = {}182# common_min = {}183# final = 1184# for i in range(0, len(a)): 185# fact.append(prime_fact(a[i]))186# fact_set.append(set(prime_fact(a[i])))187# for j in range(1, len(fact_set)):188# fact_set[0] = fact_set[0].union(fact_set[j])189# for alpha in fact_set[0]:190# common_count[str(alpha)+"s"] = []191# # common_min["min_"+str(alpha)+"s"] = []192# for beta in fact:193# common_count[str(alpha)+"s"].append(beta.count(alpha))194# # common_min["min_"+str(alpha)+"s"].append(min(common_count[str(alpha)+"s"]))195# for k in fact_set[0]:196# common_min["min_"+str(k)+"s"] = min(common_count[str(k)+"s"])197# if common_min["min_"+str(k)+"s"] != 0:198# final *= k ** common_min["min_"+str(k)+"s"]199# else:200# pass201# return final202# x= hcf_nos([8, 12, 20])203# print(x)204######################### EULER - 6205# def ans(n):206# a = []207# b = []208# for i in range(1, n+1):209# a.append(i**2)210# b.append(i)211# alpha = sum(a)212# beta = (sum(b)) ** 2213# req = alpha - beta214# return abs(req)215# x = ans(100)216# print(x)217######################### EULER - 7218# n = int(input("Number: "))219# count_prime = 0220# that_prime = 0221# i = 2222# while count_prime != n:223# if prime_test(i) == 'prime':224# that_prime = i225# count_prime += 1226# i += 1227# else:228# i += 1229# print(that_prime)230######################### EULER - 8231# number = """232# 73167176531330624919225119674426574742355349194934233# 96983520312774506326239578318016984801869478851843234# 85861560789112949495459501737958331952853208805511235# 12540698747158523863050715693290963295227443043557236# 66896648950445244523161731856403098711121722383113237# 62229893423380308135336276614282806444486645238749238# 30358907296290491560440772390713810515859307960866239# 70172427121883998797908792274921901699720888093776240# 65727333001053367881220235421809751254540594752243241# 52584907711670556013604839586446706324415722155397242# 53697817977846174064955149290862569321978468622482243# 83972241375657056057490261407972968652414535100474244# 82166370484403199890008895243450658541227588666881245# 16427171479924442928230863465674813919123162824586246# 17866458359124566529476545682848912883142607690042247# 24219022671055626321111109370544217506941658960408248# 07198403850962455444362981230987879927244284909188249# 84580156166097919133875499200524063689912560717606250# 05886116467109405077541002256983155200055935729725251# 71636269561882670428252483600823257530420752963450"""252# numby = list(number)253# for i in numby:254# if i == '\n':255# numby.remove(i)256# else:257# pass258# alpha = ''.join(numby)259# start = 0260# end = 13261# greatest = 1262# prod = 1263# those_digs = 0264# while end != 1000:265# quad = alpha[start:end]266# for digit in quad:267# prod *= int(digit)268# if prod > greatest:269# greatest = prod270# those_digs = quad271# else:272# pass273# prod = 1274# start += 1275# end += 1276# print(f"Greatest Product: {greatest}")277# print(f"Corresponding {end - start} digits: {those_digs}")278######################### EULER - 9279# import math as m280# def pyth_trip():281# a = []282# b = []283# c = []284# triplets = []285# prod = 1286 287# for alpha in range(1, 1001):288# a.append(alpha**2)289# b.append(alpha**2)290# c.append(alpha**2)291# for i in a:292# for j in b:293# if j > i:294# for k in c:295# if k > j:296# if (i + j == k) and (int(m.sqrt(i)) + int(m.sqrt(j)) + int(m.sqrt(k)) == 1000):297# triplets.append([int(m.sqrt(i)), int(m.sqrt(j)), int(m.sqrt(k))])298# else:299# pass300# else:301# pass302# else:303# pass304 305# for z in triplets:306# for y in z:307# prod *= y308 309# print(f"Product of Pytho_Triplet: {prod}")310# print(f"Pytho_Triplet: {triplets}")311 312# pyth_trip()313 314######################### EULER - 10315# def prime_test(a): #a > 1316# if a != 2 and a % 2 == 0:317# return "not prime"318# elif a == 2 or a % 2 != 0:319# i = 2320# count = 0321# if a == i:322# return "prime"323# elif a != i:324# while i < a:325# if a % i != 0:326# count += 1327# i += 1328# elif a % i == 0:329# count = 0330# break331# if count == 0:332# return "not prime"333# elif count > 0:334# return "prime"335# def no_primes(b): # b > 0336# primes= []337# if b == 1:338# return primes339# elif b == 2:340# primes.append(b)341# return primes342# elif b > 2:343# primes.append(2)344# j = 3345# while j <= b:346# alpha = prime_test(j)347# if alpha == 'prime':348# primes.append(j)349# j += 1350# elif alpha == 'not prime':351# j += 1 352# return primes353# main1 = [i for i in range(1, 2000000, 2) if (i % 10 != 5 or i == 5)]354# listy = no_primes(20000) #with 20000 time=54 sec, with 40000, time=1.44 min355# for k in listy:356# main1 = [i for i in main1 if (i % k != 0 or i == k)]357# main1.remove(1)358# main1.insert(0,2)359# # print(main1[0:30])360# print(len(main1))...

Full Screen

Full Screen

factory.py

Source:factory.py Github

copy

Full Screen

1import random2from tile import *3# number of tiles per factory4F_SIZE = 45def make_bag():6 ls = [t0] * 20 + [t1] * 20 + [t2] * 20 + [t3] * 20 + [t4] * 207 random.shuffle(ls)8 return ls9def necessary_factories(players):10 return 2 * (players - 2) + 511def split_by(ls, n):12 if len(ls) == 0:13 return []14 elif len(ls) < n:15 return [ls]16 else:17 rec = split_by(ls[n:], n)18 rec.insert(0, ls[:n])19 return rec20class FactorySet(object):21 def __init__(self, middle, factories):22 self.middle = middle23 self.factories = factories24 25def restock(bag, n):26 bag_cp = [b for b in bag]27 random.shuffle(bag_cp)28 shuffled_bag = bag_cp29 tiles = shuffled_bag[:F_SIZE * n]30 new_bag = shuffled_bag[F_SIZE * n - 1:]31 factories = split_by(tiles, F_SIZE)32 return new_bag, FactorySet([one_tile], factories)33def partition_by(pred, ls):34 ans = []35 other = []36 for t in ls:37 if pred(t):38 list.append(ans, t)39 else:40 list.append(other, t)41 return ans, other42def partition_factory(tile, f):43 return partition_by(lambda x: x == tile or x == one_tile, f)44def pull_from_factory(i, tile, fact_set):45 if i < 0:46 same, diff = partition_factory(tile, fact_set.middle)47 return same, FactorySet(diff, fact_set.factories) 48 else:49 desired_factory = fact_set.factories[i]50 same, diff = partition_factory(tile, desired_factory)51 return same, FactorySet(diff + fact_set.middle, 52 [[] if j == i else fact_set.factories[j] 53 for j in range(len(fact_set.factories))])54################################55# Printing Utilities #56################################57def fact_to_los(f, i):58 label = "f-" + str(i) + (" " * F_SIZE)59 tiles = ""60 for t in f:61 tiles = tiles + tile_to_str(t)62 return ["|" + label, "| " + (" " * (F_SIZE - len(f))) + tiles + " "]63def mid_to_los(m):64 label = "middle" + (" " * max(0, len(m) - 4))65 tiles = ""66 for t in m:67 tiles = tiles + tile_to_str(t)...

Full Screen

Full Screen

ssgp_eval.py

Source:ssgp_eval.py Github

copy

Full Screen

1from typing import List, FrozenSet, Tuple2import argparse3from tqdm import tqdm4from .ie_eval import factseq2set5from nltk.stem import WordNetLemmatizer6lemmatizer = WordNetLemmatizer()7def preprocess_ssgp(fact_set: FrozenSet[Tuple[str, str, str]]) -> FrozenSet[Tuple[str, str, str]]:8 kept_facts = []9 for fact in fact_set:10 if not (fact[0].endswith("'") or fact[2].endswith("'")):11 kept_facts.append(fact)12 return frozenset(kept_facts)13def lemmatize_relations(fact_set: FrozenSet[Tuple[str, str, str]])\14 -> FrozenSet[Tuple[str, str, str]]:15 new_facts = []16 for fact in fact_set:17 new_facts.append(18 (fact[0], lemmatizer.lemmatize(fact[1], pos='v'), fact[2])19 )20 return frozenset(new_facts)21def read_graph_list(filename: str, ssgp: bool = False,22 ref: bool = False) -> List[FrozenSet[Tuple[str, str, str]]]:23 res = []24 with open(filename) as f:25 for line in tqdm(f):26 fact_set = factseq2set(line.strip().split())27 if ssgp:28 fact_set = preprocess_ssgp(fact_set)29 if ref:30 fact_set = lemmatize_relations(fact_set)31 res.append(fact_set)32 return res33def main(args: argparse.Namespace):34 hypo = read_graph_list(args.hypo, ssgp=True)35 ref = read_graph_list(args.ref, ref=True)36 correct_retrieved = 037 retrieved = 038 correct = 039 for h, r in tqdm(zip(hypo, ref)):40 correct_retrieved += len(h & r)41 retrieved += len(h)42 correct += len(r)43 precision = float(correct_retrieved) / float(retrieved)44 recall = float(correct_retrieved) / float(correct)45 f1_score = 2. * ((precision * recall) / (precision + recall + 1e-13))46 print('P {:.1f}'.format(precision*100))47 print('R {:.1f}'.format(recall*100))48 print('F1 {:.1f}'.format(f1_score*100))49if __name__ == '__main__':50 p = argparse.ArgumentParser()51 p.add_argument('hypo')52 p.add_argument('ref')53 args = p.parse_args()...

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