Skip to content

Instantly share code, notes, and snippets.

@Hydrotoast
Hydrotoast / gist:2866520
Created June 4, 2012 05:27
BST Recursive Pseudocode
def insertNode(root, newNode, data):
if root is null:
root = newNode
root.data = data
elif data < root.left:
root.left = insertNode(root.left, newNode, data);
else:
root.right = insertNode(root.right, newNode, data);
return root
@Hydrotoast
Hydrotoast / gist:3995461
Created November 1, 2012 18:09
General Approach for Adversarial Search
int AI::IterativeDeepening(const State& state, int alpha, int beta, int depth) {
if (cutoff(state, depth))
return eval(state);
int result = 0;
for (Move* move : moves) {
State newState = state.clone();
result = max(result, newState.makeMove(state));
}
return result;
}
@Hydrotoast
Hydrotoast / HashTable.cpp
Created November 7, 2012 11:20
Standard Hash Table Implementation
/**
* Gio Borje
* 41894135
*/
#include "HashMap.h"
using namespace std;
/**
* Initializes the node with the specified parameters
#ifndef BOARD_CONFIG_H
#define BOARD_CONFIG_H
class BoardConfig {
public:
unsigned int rows;
unsigned int cols;
unsigned int kLength;
bool gravityFlag;
@Hydrotoast
Hydrotoast / gist:4188102
Created December 2, 2012 10:32
FriendZoneAlgorithm
def analyze(other, weights):
return reduce(lamda base, items: base + items[0] * items[1], zip(other, weights), 0)
def friend_zone(other):
friend_zone_dict[other] = True
def FriendZone():
while date_is_ongoing:
certainty_of_others_feelings_of_me = analyze(other)
if certainty_of_others_feelings_of_me >= threshold_of_romantic_felings:
@Hydrotoast
Hydrotoast / gist:4243800
Created December 9, 2012 07:34
Anticipated Game Loop
CppCKPlayer player = new CppCKPlayer(dllNameStr, playerInt, BoardModel model);
while (!game.isEnd()) {
// Opponent makes a move
Cell cell;
cell.row = opponentMove.row;
cell.col = opponentMove.col;
Mark m = (opponentMove.mark == 'X') ? Mark.A : Mark.B;
player.updateBoard(cell, mark);
Cell c = player.getMove();
@Hydrotoast
Hydrotoast / Output
Created December 9, 2012 14:19
Simple C++ Unit Tester
Sorted List Tests Running
=========================
canAdd SUCCESS
canIterate SUCCESS
canClear SUCCESS
canPrintReverse SUCCESS
canPrintStrings SUCCESS
canCopy SUCCESS
canAssign SUCCESS
@Hydrotoast
Hydrotoast / gist:4257243
Created December 11, 2012 09:14
Linear Classification
LinearClassify(w, b, x):
""" Computes a class of a two-class classifier using an n - 1 dimensional hyperplane """
dot_product = sum(i * j for i, j in zip(w, x))
if dot_product > b:
return 1
else:
return 0
@Hydrotoast
Hydrotoast / ChristmasTree.py
Created December 14, 2012 04:22
Creates a simple christmas tree.
def CreateTree(half_width):
for i in range(half_width):
print(' ' * (half_width - i), '*' * (2 * i - 1))
for i in range(half_width >> 2):
print(' ' * (half_width - 1), '+')
# CreateTree(6)
# *
# ***
# *****
#include <iostream>
#include "emmintrin.h"
using namespace std;
int main(int argc, char* argv[]) {
const LENGTH = 1 << 10;
const SSE_LENGTH = LENGTH >> 2;
// Set constant vectors