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
| # check string is transformable or not | |
| def detect_digit(s): | |
| for c in range(len(s)): | |
| if s[c] not in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']: | |
| return False | |
| else: | |
| return True | |
| s = input("first string ::: ") |
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
| # PATTERN SEARCHING (REGX) | |
| # help : https://www.geeksforgeeks.org/finite-automata-algorithm-for-pattern-searching/ | |
| class FA: | |
| def __init__(self) -> None: | |
| self.__state_char_mat = None | |
| self.__pattern = "" |
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 typing import List | |
| import sys | |
| # STATUS : incomplete | |
| # https://codeforces.com/problemset/problem/1373/G | |
| rows, k, m, min_changes, cols = 5, 3, 5, 0, 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
| # ===================================== | |
| # itFollows - black scary python virus | |
| class Human(): | |
| def __init__(self): | |
| pass | |
| def __haveSex(self): | |
| pass | |
| def __isAlive(self): |
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
| # cycle detection algo in directed graph | |
| def cycle_exists(G): # - G is a directed graph | |
| color = { u : "white" for u in G } # - All nodes are initially white | |
| found_cycle = [False] # - Define found_cycle as a list so we can change | |
| # its value per reference, see: | |
| # http://stackoverflow.com/questions/11222440/python-variable-reference-assignment | |
| for u in G: # - Visit all nodes. | |
| if color[u] == "white": | |
| dfs_visit(G, u, color, found_cycle) |
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
| # DSG : directed cyclic graph | |
| """ | |
| White >> the vertex hasn't been visited yet | |
| Gray >> we've visited the vertex but haven't visited all vertices in its subtree ... its children | |
| Black >> we've visited all vertices in subtree and left the vertex ... has been saw all its children | |
| NOTE Initially all vertices have white color | |
| NOTE When we visit the vertex, we should paint it with gray color | |
| NOTE When we leave the vertex we paint it with black color | |
| TODO algorithm::::::: |
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
| class graph: | |
| def __init__(self): | |
| self.vertices = {} | |
| self.edges = [] | |
| self.directed_matrix = [] | |
| def add_vertex(self, v): | |
| if type(v) == list: | |
| for node in v: |
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
| # mgcoloring | |
| # SOVLED USING BACKTRACKING | |
| class Graph(): | |
| def __init__(self, vertices): | |
| self.V = vertices | |
| self.graph = [[0 for column in range(vertices)]\ | |
| for row in range(vertices)] |
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
| # NPAgent - n-puzzle | |
| # https://blog.goodaudience.com/solving-8-puzzle-using-a-algorithm-7b509c331288 | |
| class Node: | |
| def __init__(self,data,level,fval): | |
| """ Initialize the node with the data, level of the node and the calculated fvalue """ | |
| self.data = data # 2D dimensional matrix ; eg: [['1', '2', '3'], ['_', '4', '6'], ['7', '5', '8']] |
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
| # path finding with an unknown algorithm!!! | |
| # we want to have a path from D to A with a minimum time | |
| import random | |
| graph = {"A<->B": 2, "A<->C": 2, "B<->D": 6, "C<->D": 2, "D<->E": 5, "A<->E": 3} | |
| path = "D<->A" | |
| nodes = path.split("<->") |