Skip to content

Instantly share code, notes, and snippets.

View wildonion's full-sized avatar
💭
future.await;

dewo wildonion

💭
future.await;
View GitHub Profile
@wildonion
wildonion / cst.py
Created October 28, 2020 11:59
check string is transformable or not
# 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 ::: ")
@wildonion
wildonion / ps.py
Created October 28, 2020 12:01
pattern searching problem
# 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 = ""
@wildonion
wildonion / cf.py
Last active October 28, 2020 12:36
some codeforces problems
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
@wildonion
wildonion / if.py
Last active October 28, 2020 12:37
black scary python virus based on "It Follows" movie
# =====================================
# itFollows - black scary python virus
class Human():
def __init__(self):
pass
def __haveSex(self):
pass
def __isAlive(self):
@wildonion
wildonion / cycle_detection.py
Created October 28, 2020 12:13
cycle detection
# 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)
@wildonion
wildonion / directed_cyclic.py
Created October 28, 2020 12:14
directed cyclic graph
# 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:::::::
@wildonion
wildonion / directed_matrix.py
Created October 28, 2020 12:15
directed matrix
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:
@wildonion
wildonion / mgcoloring.py
Created October 28, 2020 12:15
map coloring using backtracking algo
# 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)]
@wildonion
wildonion / npagent.py
Created October 28, 2020 12:16
n-puzzle problem
# 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']]
@wildonion
wildonion / path_finding.py
Last active October 28, 2020 12:35
path finding greedy algorithm
# 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("<->")