Skip to content

Instantly share code, notes, and snippets.

@richardbwest
richardbwest / typewriter with input.py
Created December 3, 2020 13:37
How to do typewriter text with inputs in python
import sys,time
message = "please enter your name: "
def typewriter(message):
for char in message:
sys.stdout.write(char)
sys.stdout.flush()
if char != "\n":
import random,time,os
l = [i for i in range(10)]
random.shuffle(l)
def redraw(arrow = "↑",shift=0,moved_right=False):
os.system('cls')
print()
print("Outer Index:",index, "\tCurrentValue: ",currentValue, "\tInner Index:",currentPosition)
print()
@richardbwest
richardbwest / bubblesort.py
Created November 4, 2020 23:26
Bubble Sort Algorithm Tutorial
import time,random
l = []
for i in range(20):
l.append(random.randint(1,1000))
def bubble_sort(l):
l = l[:]
while True:
swapped = False
@richardbwest
richardbwest / maze_solver.py
Last active June 25, 2020 15:15
Recursive Maze Solving Algorithm in Python Demonstrating Tree Recursion
import csv,os,time,sys,random
def get_maze(file):
f = open(file,'r')
reader = csv.reader(f)
maze = []
for line in reader:
maze.append(line)
return maze
@richardbwest
richardbwest / filefoldertraversalrecursion.py
Created June 2, 2020 02:04
Recursive File System Traversal
# Adapted from - http://openbookproject.net/thinkcs/python/english3e/recursion.html
def get_dirlist(path):
"""
Return a sorted list of all entries in path.
This returns just the names, not the full path to the names.
"""
try:
dirlist = os.listdir(path)
dirlist.sort()
@richardbwest
richardbwest / bruteforceforloop.py
Created June 2, 2020 01:47
Brute force for loop version
chars = "abcdefghijklmNO123£$%"
for a in chars:
print(a)
for b in chars:
print(a+b)
for c in chars:
print(a+b+c)
for d in chars:
print(a+b+c+d)
@richardbwest
richardbwest / bruteforcerecursive.py
Created June 2, 2020 01:27
Brute Force Recursive Demo
chars = "abcABC123£$%" #Add as many chars as you like to the test (or generate using and ord to chr range)
maxlen = 4 #Maximum password length to generate.
def brute(current):
print(current)
if len(current) == maxlen:
return
for letter in chars:
@richardbwest
richardbwest / matchlists1.py
Last active September 10, 2019 14:03
matching lists code wip
a=[[9, 15, 25],[4, 14, 18, 25],[11, 12,24, 25],[4, 8, 9, 26]]
b=[[2, 4, 7, 13, 14],[3, 5, 8, 13, 14],[6, 9, 10, 13, 14],[5, 6, 7, 13, 15],[3, 4, 9, 13, 15],[2, 8, 12, 13, 15],[4, 6, 8, 14, 15],[2, 5, 9, 14, 15]]
#Basically i would like to match 2d list to another 2d list.
<iframe src="https://scratch.mit.edu/projects/PROJECTID/embed" width="800" height="600"></iframe>
<iframe src="https://scratch.mit.edu/projects/PROJECTID/embed" width="800" height="600"></iframe>