Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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()
.data
str1: .asciiz "Enter input string: "
getc1: .asciiz "Enter char to replace: "
getc2: .asciiz "Enter char to replace with: "
ret1: .asciiz "Original string: "
ret2: .asciiz "Substitute "
ret3: .asciiz "Result String: "
arrow: .asciiz " -> "
@montycheese
montycheese / redirect.html
Created January 31, 2016 00:03
redirect to page via javascript
<html>
<head>
</head>
<body>
<h1>Website currently down...</h1>
<h2>You will be redirected to my GitHub page</h2>
</body>
</html>
<script>
@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 / ZapposGiftProgram.py
Last active July 18, 2016 11:38
Requires Python Libraries: requests, json.
#! /usr/bin/env python2.7
# Author:****
# Education: ****
# Email: ****
# Phone: 808-633-****
# Purpose: ZapposGiftProgram.py is my submission for Zappos' 2015 Summer
# Software Engineering Internship application. The program prompts the user for two
# inputs: the amount of money they want to spend, and how many gifts they want to purchase.
# The program searches through Zappos's website using its API and returns a series of
@montycheese
montycheese / ShiftCypher.py
Created December 1, 2014 01:01
Shift Cypher encryption and decryption
import string
REPLACE_SPACE = None
def map_alphabet():
alphabet = string.lowercase
map = dict()
map[" "] = REPLACE_SPACE # if spaces are found in code
for idx in range(0, 26):
map[alphabet[idx]] = idx