Skip to content

Instantly share code, notes, and snippets.

@dangffn
dangffn / sudoku_solver.py
Last active November 30, 2022 14:55
Sudoku Solver
class Coord:
"""
Coordinates for the row / col / block indices in the puzzle
"""
def __init__(self, y, x):
self.y = y
self.x = x
self.blky = (int(self.y / 3) * 3) + int(self.x / 3)
self.blkx = ((self.y % 3) * 3) + (self.x % 3)
self.idx = (y * 9) + x
@dangffn
dangffn / sudoku_validate.py
Created November 30, 2022 14:41
Sudoku Validator
def has_repeating(lst):
for i in range(1, 10):
if lst.count(i) > 1 or lst.count(str(i)) > 1:
return False
return True
def get_row(arr, row):
return arr[row]
def get_col(arr, col):
@dangffn
dangffn / RegularExpressions.py
Created November 28, 2022 21:55
Regular Expression Matching (No Regex)
class Part:
def __init__(self, c):
self.match = lambda x: False
self.many = False
self.literal = False
self.char = c
if c == ".":
self.match = lambda x: True
@dangffn
dangffn / lookup_vs_shuffle.py
Created September 28, 2022 16:34
Array lookup vs. Random.shuffle
#!/usr/bin/env python3
from random import shuffle
import time
import sys
# the number of times to repeat the test functions
iterations = int(sys.argv[1]) if len(sys.argv) > 1 else 10_000
@dangffn
dangffn / wordy.py
Last active August 15, 2022 17:08
Wordlist generator based on specified words, suffixes, actions and join strings
#!/usr/bin/env python3
import argparse
import sys
"""
Generate a customized wordlist based on target words
Mutate a list of input words based on actions, suffixes and join strings
By: Dan Griffin
@dangffn
dangffn / roman_numerals.py
Created March 17, 2022 00:35
Convert to and from roman numerals
#!/usr/bin/env python3
import argparse
class RomanNumerals:
SYMBOLS = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
NUMBERS = {val: key for key, val in SYMBOLS.items()}
@dangffn
dangffn / macvendor.py
Last active August 14, 2021 04:05
Search a sqlite database file for MAC address vendors and OUIs
#!/usr/bin/python3
# Search for MAC addresses and vendor names in a sqlite database
# Download the database as a CSV here https://macaddress.io/database-download/csv
# Load the CSV into a sqlite DB table name oui
# You can use DB Browser for Sqlite https://sqlitebrowser.org/
import sqlite3
import math
"""
Test question attempt
Checks to see if gears will fit on a beam given a list of peg positions
"""
class Gears:
@dangffn
dangffn / SBoard.py
Last active March 10, 2019 00:27
Place tokens on a 10x10 grid, once placed will tell you the distance to the farthest tiles that make 4 corners of a square
class SBoard:
def __init__(self):
self.placed_tokens = 0
self.grid = [["." for x in range(10)] for y in range(10)]
def getNumTokens(self):
return self.placed_tokens
def placeToken(self, y, x):
if y < 0 or y > 9 or x < 0 or x > 9 or self.grid[y][x] != ".":