This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from math import pow | |
a = random.randint(2, 10) | |
def gcd(a, b): | |
if a < b: | |
return gcd(b, a) | |
elif a % b == 0: | |
return b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def GCD(a,b): | |
g = [max(a,b),min(a,b)] | |
mass = [[max(a,b),min(a,b)]] | |
while g[0] != 0 and g[1] != 0: | |
g[0], g[1] = g[1], g[0] % g[1] | |
mass.append([g[0],g[1]]) | |
return mass, g[0] | |
def euclid_ext(a, b): | |
if b == 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def check(exp): | |
if len(exp) == 1 and exp[0] in ["r","l","R","L"]: | |
return f"{exp}0" | |
else: | |
return exp | |
def mutation(vector,y,x,val): | |
if vector == "right": x+= val |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import re | |
def top_3_words(text): | |
c = collections.Counter(re.findall(r"[a-z']*[a-z]+[a-z']*", text.lower())) | |
return [i[0] for i in c.most_common(3)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import factorial | |
def expand(expr): | |
print(expr) | |
expr = expr.split("^") # Splitting expression | |
expr[0] = expr[0][1:-1:1] | |
m = list(expr[0]) | |
m.reverse() | |
sign = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Numerics; | |
public static class Kata | |
{ | |
public static string sumStrings(string a, string b) | |
{ | |
if (BigInteger.TryParse(a, out _) == false || BigInteger.TryParse(b, out _) == false ){return "5";} | |
return (BigInteger.Parse(a)+BigInteger.Parse(b)).ToString(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy import*;circleIntersection=lambda a,b,r:r*r*(lambda q:q<1and arccos(q)-q*(1-q*q)**.5)(hypot(*subtract(b,a))/r/2)//.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def spiralize(w): | |
arr = [[0 for _ in range(w)] for _ in range(w)] | |
for i in range(w): | |
arr[0][i] = 1 | |
x,y = w-1,1 | |
k = w-1 | |
arrow = (-1,1) | |
while k>0: | |
for i in range(k): | |
arr[y+arrow[1]*i][x] = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def path_finder(maze): | |
res = list(map(list,maze.split())) | |
res[0][0] = 0 | |
moves = [(0,0)] | |
for move in moves: | |
y,x = move | |
if y+1 < len(res) and res[y+1][x] == ".": | |
res[y+1][x] = res[y][x] + 1 | |
moves.append((y+1,x)) | |
if y+1 == len(res)-1 and x == len(res)-1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def path_finder(maze): | |
res = list(map(list,maze.split())) | |
res[0][0] = 0 | |
wasd = "" | |
a = 0 | |
moves = [(0,0)] | |
for move in moves: | |
y,x = move | |
if y+1 < len(res) and res[y+1][x] == ".": | |
res[y+1][x] = res[y][x] + 1 |
NewerOlder