Best Python code snippet using fMBT_python
exp.py
Source:exp.py  
1from pwn import *2from pprint import pprint3import numpy as np4from pwnlib.util.sh_string import test_all5def trans_diag(diag_num,b_i,e_i,forward=True):6    '''7    Given a numpy diagonal number,8    the starting index and ending index within that9    diagonal, and a Boolean denoting which diagonal10    to read from, return a list of tuples of the starting11    and ending index.12    '''13    print("Diagonal params:",diag_num,b_i,e_i,forward)14    d_start = None15    start = None16    end = None17    if forward:18        if diag_num <= 0:19            d_start = (abs(diag_num),0)20        else:21            d_start = (0,diag_num)22        start = (d_start[0]+b_i, d_start[1]+b_i)23        end = (d_start[0]+e_i, d_start[1]+e_i)24    else:25        if diag_num <= 0:26            d_start = (0, diag_num+14)27        else:28            d_start = (diag_num, 14)29        start = (d_start[0]+b_i,d_start[1]-b_i)30        end = (d_start[0]+e_i,d_start[1]-e_i)31    return start, end32r = remote('word-search.ctf.fifthdoma.in',4243)33res = r.recv().decode('utf-8').split('\n')34print(res)35#Retrieve word list and grid data36words = []37grid = []38split_str = '   0  1  2  3  4  5  6  7  8  9 10 11 12 13 14'39split_pos = res.index(split_str)40for i in range(1,split_pos):41    words.append(res[i])42for i in range(split_pos+1,len(res)-2):43    grid.append(res[i][3:].split("  "))44print(words)45#print(grid)46#Perform search47test_lst = words[:1]48grid = np.array(grid) #Convert to numpy matrix49print(grid)50for word in words:51    start_pos = None #row, column52    end_pos = None53    found = False54    word_rev = word[::-1]55    #Check columns56    for i in range(15):57        col = ''.join(grid[:,i])58        if word in col or word_rev in col:59            print("I found in column!")60            if word in col:61                start_pos = (col.index(word),i)62                end_pos = (col.index(word)+len(word)-1,i)63            else:64                end_pos = (col.index(word_rev),i)65                start_pos = (col.index(word_rev)+len(word_rev)-1,i)66            print(start_pos,end_pos)67            found = True68            break69    #Check rows70    if not found:71        for i in range(15):72            row = ''.join(grid[i,:])73            if word in row or word_rev in row:74                print("I found in row!")75                if word in row:76                    start_pos = (i, row.index(word))77                    end_pos = (i,row.index(word)+len(word)-1)78                else:79                    end_pos = (i, row.index(word_rev))80                    start_pos = (i,row.index(word_rev)+len(word_rev)-1)81                print(start_pos,end_pos)82                found = True83                break84    if not found:85        #Forward diagonal86        for i in range(-15,15):87            diag = ''.join(grid.diagonal(i))88            if word in diag or word_rev in diag:89                if word in diag:90                    start_pos, end_pos = trans_diag(i, diag.index(word), diag.index(word)+len(word)-1)91                else:92                    start_pos, end_pos = trans_diag(i, diag.index(word_rev)+len(word_rev)-1, diag.index(word_rev))93                print("I found in diagonal!")94                print(start_pos,end_pos)95                found = True96                break97        #Backward diagonal98        for i in range(-15,15):99            diag = ''.join(np.rot90(grid).diagonal(i))100            if word in diag or word_rev in diag:101                if word in diag:102                    start_pos, end_pos = trans_diag(i, diag.index(word), diag.index(word)+len(word)-1, False)103                else:104                    start_pos, end_pos = trans_diag(i, diag.index(word_rev)+len(word_rev)-1, diag.index(word_rev), False)105                print("I found in other diagonal!")106                print(start_pos,end_pos)107                found = True108                break109    if not found:110        print("Houston we got a problem")111    if start_pos:112        start = str(start_pos[0]) + ", " + str(start_pos[1])113        end = str(end_pos[0]) + ", " + str(end_pos[1])114        r.sendline(start.encode('utf-8'))115        res = r.recv().decode('utf-8')116        print(res)117        r.sendline(end.encode('utf-8'))118        res = r.recv().decode('utf-8')119        print(res)120#r.interactive()...b.py
Source:b.py  
1from math import *2n = int(input())3x = []4y = []5r = []6for i in range(n): 7    xa, ya, ra = map(int, input().split())8    x.append(xa)9    y.append(ya)10    r.append(ra)11def is_between(gamma, alpha, beta):12    if alpha < -pi + 1e-4 and beta > pi - 1e-4:13        return True14    return (gamma - alpha) % (2 * pi) < (beta - alpha) % (2 * pi)15ans = 016def length(u, v):17    if u < -pi + 1e-4 and v > pi - 1e-4:18        return v - u19    else:20        return (v - u) % (2 * pi)21for i in range(n):22    flag = False23    start = [-pi]24    end = [pi]25    for j in range(i + 1, n):26        x1, y1, r1 = (x[j]- x[i]) / r[i], (y[j] - y[i]) / r[i], r[j] / r[i]27        d = sqrt(x1 ** 2 + y1 ** 2)28        if d >= 1 + r1 or d <= 1 - r1:29            d_start = pi30            d_end = -pi31        elif d <= r1 - 1:32            flag = True33            continue34        else:35            a = (1 - r1 ** 2 + d ** 2) / (2 * d)36            h = sqrt(1 - a ** 2)37            x2 = a * x1 / d38            y2 = a * y1 / d39            x3 = x2 + h * y1 / d40            x4 = x2 - h * y1 / d41            y3 = y2 + h * x1 / d42            y4 = y2 - h * x1 / d43            alpha = atan2(y3, x3)44            beta = atan2(y4, x4)45            gamma = atan2(y1, x1)46            d_start, d_end = alpha, beta47            if not is_between(gamma, alpha, beta):48                d_start, d_end = d_end, d_start49        for k in range(len(start)):50            u, v = start[k], end[k]51            if is_between(d_start, u, v):52                if is_between(d_end, u, v):53                    if is_between(d_end, u, d_start):54                        end[k] = d_start55                        start[k] = d_end56                    else:57                        start[k], end[k] = u, d_start58                        start += [d_end]59                        end += [v]60                else:61                    end[k] = d_start62            else:63                if is_between(d_end, u, v):64                    start[k] = d_end65    if not flag:66        ans += r[i] * sum(length(start[k], end[k]) for k in range(len(end)))67print(ans)68        69        70        ...day2.py
Source:day2.py  
1def part1():2	h_start = 03	d_start = 04	with open('inputs/day2.txt') as f:5		for line in f:6			instruction = line.rstrip()7			direction = instruction.split(" ")[0]8			steps = int(instruction.split(" ")[1])9			if direction == "forward":10				h_start += steps11			elif direction == "down":12				d_start += steps13			elif direction == "up":14				d_start -= steps15	f.close()16	print(h_start*d_start)17def part2():18	h_start = 019	d_start = 020	aim = 021	with open('inputs/day2.txt') as f:22		for line in f:23			instruction = line.rstrip()24			direction = instruction.split(" ")[0]25			steps = int(instruction.split(" ")[1])26			if direction == "forward":27				h_start += steps28				d_start += aim * steps29			elif direction == "down":30				aim += steps31			elif direction == "up":32				aim -= steps33	f.close()34	print(h_start*d_start)35if __name__ == "__main__":36	print("Part 1:")37	part1()38	print("\nPart 2:")...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!!
