Skip to content

Instantly share code, notes, and snippets.

@douglas-vaz
douglas-vaz / sjf.py
Created September 13, 2012 17:44
Shortest Job First Scheduling Algorithm Implementation
#!/usr/bin/python2
print 'Enter number of processes'
n, proc_in, time, proc_queue = int(raw_input()), [], 0, []
for i in xrange(n):
proc = []
print 'Enter PID'
proc.append(raw_input())
print 'Enter arrival time'
proc.append(int(raw_input()))
@douglas-vaz
douglas-vaz / fcfs.py
Created September 13, 2012 17:46
First Come, Fist Serve Scheduling Algorithm Implementation
#!/usr/bin/python2
print 'Enter number of processes'
n, proc_queue, time = int(raw_input()), [], 0
for i in xrange(n):
proc = []
print 'Enter PID'
proc.append(raw_input())
print 'Enter arrival time'
proc.append(int(raw_input()))
@douglas-vaz
douglas-vaz / Turing.py
Created October 14, 2012 13:36
Turing Machine to accept the language {0^m1^m: m >= 1}
print "Enter string"
inp = list(raw_input()) + [' ']
R, L = lambda f:f+1, lambda f:f-1
state, i = 0, 0
machine = [{'0':[1,'X',R], 'Y':[3,'Y',R]}, {'0':[1,'0',R], 'Y':[1,'Y',R], '1':[2,'Y',L]}, {'Y':[2,'Y',L], '0':[2,'0',L], 'X':[0,'X',R]},{'Y':[3,'Y',R], ' ':[4,' ',R]},{}]
while state != 4:
print inp[i],': State = ',state,
# -*- coding: utf-8 -*-
"""
pygments.console
~~~~~~~~~~~~~~~~
Format colored console output.
:copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@douglas-vaz
douglas-vaz / rmconfirm.sh
Created December 16, 2012 14:43
Script that confirms an "rm" call. Add "alias rm=rmconfirm.sh" to ~/.bashrc
#!/bin/bash
inp="No";
echo "Are you SURE you want to delete file(s) in $(pwd)? (No/yes)"
read inp
if [ "$inp" == "yes" ];then
echo "Removing..."
rm $@
else
exit 1
@douglas-vaz
douglas-vaz / canvas.html
Created January 9, 2013 08:54
Stretch canvas
<!DOCTYPE html>
<html>
<head>
<title>Test Game</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#gameCanvas').width(window.innerWidth);
$('#gameCanvas').height(window.innerHeight);
});
@douglas-vaz
douglas-vaz / graph_search.cpp
Created March 2, 2013 19:57
Breadth First Search and Depth First Search in C++
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
class Node{
#!/usr/bin/python3
def whazaa(n):
for i in range(1,n):
if i % 15 == 0:
print('Whazaa')
elif i % 3 == 0:
print('Hip')
elif i % 5 == 0:
print('Hop')
else:
@douglas-vaz
douglas-vaz / water_jug.cpp
Last active February 25, 2024 17:06
Solution to the Water Jug problem in C++
/**
* Based on the paper "A Heuristic for Solving the Generalized Water Jug Problem
* Florin Leon, Mihai Zaharia, Dan Galea
*/
#include <iostream>
using namespace std;
class Jug{
@douglas-vaz
douglas-vaz / tic_tac_toe.cpp
Last active December 16, 2015 22:38
Simple AI implementation of Tic-Tac-Toe
#include <iostream>
using namespace std;
enum players {X = 1, O = 2};
class TicTacToe{
short state[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
const short strategy[9] = { 1, 3, 1, 3, 5, 3, 1, 3, 1};