Loading...
More Python Posts
print("test")
from functools import partialdef curry(fn, *args):return partial(fn, *args)add = lambda x, y: x + yadd10 = curry(add, 10)add10(20) # 30
class Solution(object):def floodFill(self, image, sr, sc, newColor):R, C = len(image), len(image[0])color = image[sr][sc]if color == newColor: return imagedef dfs(r, c):if image[r][c] == color:image[r][c] = newColorif r >= 1: dfs(r-1, c)if r+1 < R: dfs(r+1, c)if c >= 1: dfs(r, c-1)if c+1 < C: dfs(r, c+1)dfs(sr, sc)return image
import randomimport timedef generate_maze(width, height):"""Generate a random maze using depth-first search"""maze = [[1 for _ in range(width)] for _ in range(height)]def carve(x, y):maze[y][x] = 0directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]random.shuffle(directions)for dx, dy in directions:nx, ny = x + dx*2, y + dy*2if 0 <= nx < width and 0 <= ny < height and maze[ny][nx] == 1:maze[y + dy][x + dx] = 0carve(nx, ny)carve(1, 1)maze[0][1] = 0 # Entrancemaze[height-1][width-2] = 0 # Exitreturn mazedef print_maze(maze, path=None):"""Print the maze with ASCII characters"""if path is None:path = []for y in range(len(maze)):for x in range(len(maze[0])):if (x, y) in path:print('◍', end=' ')elif maze[y][x] == 0:print(' ', end=' ')else:print('▓', end=' ')print()def solve_maze(maze, start, end):"""Solve the maze using recursive backtracking"""visited = set()path = []def dfs(x, y):if (x, y) == end:path.append((x, y))return Trueif (x, y) in visited or maze[y][x] == 1:return Falsevisited.add((x, y))path.append((x, y))for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:if dfs(x + dx, y + dy):return Truepath.pop()return Falsedfs(*start)return path# Generate and solve a mazewidth, height = 21, 11 # Should be odd numbersmaze = generate_maze(width, height)start = (1, 0)end = (width-2, height-1)print("Generated Maze:")print_maze(maze)print("\nSolving Maze...")time.sleep(2)path = solve_maze(maze, start, end)print("\nSolved Maze:")print_maze(maze, path)
#You are given a two-digit integer n. Return the sum of its digits.#Example#For n = 29 the output should be solution (n) = 11def solution(n):return (n//10 + n%10)
import osimport sysimport argparseimport jsonimport csvimport getpassimport stringimport randomimport refrom datetime import datetimeimport ldapimport requestsfrom requests.packages.urllib3.exceptions import InsecureRequestWarningrequests.packages.urllib3.disable_warnings(InsecureRequestWarning)from requests.auth import HTTPBasicAuthimport validatorsdef create_guac_connection(BASE_URL, auth_token, ldap_group, computer, guac_group_id):'''creates a guac connection'''json_header = {'Accept': 'application/json'}query_parm_payload = { 'token': auth_token }payload_data = {"parentIdentifier":guac_group_id,"name":computer,"protocol":"vnc","parameters":{"port":"5900","read-only":"","swap-red-blue":"","cursor":"","color-depth":"","clipboard-encoding":"","disable-copy":"","disable-paste":"","dest-port":"","recording-exclude-output":"","recording-exclude-mouse":"","recording-include-keys":"","create-recording-path":"","enable-sftp":"true","sftp-port":"","sftp-server-alive-interval":"","enable-audio":"","audio-servername":"","sftp-directory":"","sftp-root-directory":"","sftp-passphrase":"","sftp-private-key":"","sftp-username":"","sftp-password":"","sftp-host-key":"","sftp-hostname":"","recording-name":"","recording-path":"","dest-host":"","password":"asdasd","username":"asdasd","hostname":"nt72310.cvad.unt.edu"},"attributes":{"max-connections":"","max-connections-per-user":"1","weight":"","failover-only":"","guacd-port":"","guacd-encryption":"","guacd-hostname":""}}CREATE_CONNECTION_URL = BASE_URL + "/api/session/data/mysql/connections"create_connection_request = requests.post(CREATE_CONNECTION_URL, headers=json_header, params=query_parm_payload, data=payload_data, verify=False)create_connection_result = create_connection_request.status_codeif create_connection_result == "200":print("Successfully created computer: " + computer)else:print(create_connection_request.json())return create_connection_result