Skip to content

Instantly share code, notes, and snippets.

@montycheese
montycheese / str.asm
Created November 3, 2015 14:32
map a char freq in MIPS assembly lang
.data
str1: .asciiz "Enter String: "
#.align 2
getc: .asciiz "Enter char: "
#.align 2
ret: .asciiz "Character <ch> occurs in string <string> <n> times"
buffer: .space 100 #space to store our string
L1: .space 2 #space for our char
L2: .space 4 #space for our char’s frequency in string
@montycheese
montycheese / word_ladder.py
Created October 20, 2015 13:47
solves a word ladder given a dictionary
from string import ascii_lowercase as alphabet
d = {"dog","dig", "din", "dag","fog",
"god", "fig", "ape", "dot", "got",
"bog", "bag","bat","cat"
}
def transform(w1, w2):
frontier = [[w1]]
explored = set()
@montycheese
montycheese / CheckSubTree.java
Created October 9, 2015 15:12
check if a binary tree is the subtree of another. (Cannot assume that they are BST, and duplicates may be present, on either side of the original.)
public class CheckSubTre {
TreeNode<Integer> t1, t2;
//t2 might be subset of t1
public CheckSubTre(TreeNode<Integer> t1, TreeNode<Integer> t2){
this.t1 = t1;this.t2=t2;
}
public boolean check(TreeNode<Integer> t1, TreeNode<Integer> t2){
if(t1 == t2){
@montycheese
montycheese / SortStack.java
Created September 10, 2015 20:05
No data structures except an extra stack can be used to sort our original stack. smallest elements on top.
//No data structures except an extra stack can be used to sort our original stack. smallest elements on top.
import java.util.Arrays;
import java.util.Stack;
public class SortStack<T extends Comparable> {
private Stack<T> main, storage;
private T temp;
public SortStack(Stack<T> s){
main = s;
@montycheese
montycheese / IntersectingNodes.java
Created September 10, 2015 04:23
Finds intersecting nodes between two linked lists if any
import java.util.HashSet;
public class IntersectingNodes {
HashSet<NodeCustom> hs = new HashSet<>();
NodeCustom head1;
NodeCustom head2;
public IntersectingNodes(NodeCustom n1, NodeCustom n2){
this.head1 = n1;
this.head2 = n2;
@montycheese
montycheese / knightsTour.cpp
Created August 20, 2015 20:00
Knights tour iterative solution
#include <iostream>
#define B_SIZE 8
using std::cout;
using std::cin;
using std::endl;
bool checkBounds(int currentRow, int currentCol, int horiz, int vert);
int move(int currentRow, int currentCol, int * newCoordinates, int step);
void recordMove(int row, int col);
@montycheese
montycheese / decisionTree.js
Created July 2, 2015 04:16
Customer service decision tree in javascript
<script>
$(document).ready( function () {
$('#customerTripsTable').DataTable();
$('#customerNotesTable').DataTable();
} );
//reset all children nodes in tree if the parent is clicked
document.getElementById("contacttype").onclick = destroyChildren;
//listener for contact type dropdown
document.getElementById("contacttype").onchange = function() {
var selected = document.getElementById("contacttype").value;
@montycheese
montycheese / ReverseInt.php
Last active August 29, 2015 14:20
Reversing an integer in PHP with pure tail recursion
function reverseInt($n){
return reverseIntAcc(0, $n);
}
function reverseIntAcc($acc, $n){
if ($n == 0){
return $acc;
}
$acc *= 10;
return reverseIntAcc($acc + ($n % 10) , floor($n / 10));
@montycheese
montycheese / pharm_analysis.py
Last active August 29, 2015 14:17
Analysis of Pharmaceutical web scraping results
import os
#File extensions to scrape
EXT = '.txt'
#filter out files to parse within entire directory
files = [
file for file in os.listdir('.')
if os.path.isfile(file)
and file.endswith('.txt')
and file.startswith('no_')
@montycheese
montycheese / acronym.py
Created January 14, 2015 15:50
Acronym expander
abbvr = {
"lol": "laugh out loud",
"dw": "don't worry",
"hf": "have fun",
"gg": "good game",
"brb": "be right back",
"g2g": "got to go",
"wtf": "what the fuck",
"wp": "well played",
"gl": "good luck",