Skip to content

Instantly share code, notes, and snippets.

View GnsP's full-sized avatar
👽
avant-garde

Ganesh Prasad GnsP

👽
avant-garde
View GitHub Profile
@GnsP
GnsP / BFS_example.cpp
Created September 26, 2015 15:22
Example of BFS, level EASY
/*
* DEMO OF BFS (Breadth First Search)
***************************************
*
* PROBLEM STATEMENT
*-------------------
* Given an undirected graph consisting of N nodes (labelled 1 to N) where
* a specific given node S represents the start position and an edge between
* any two nodes is of length 6 units in the graph.
*
@GnsP
GnsP / gist:ac4f7ddf17fde10d4e6d
Created August 17, 2015 10:29
stopAndWait.py
#!/usr/bin/env python
import socket
import os
import sys
PACKET_SIZE = 1024
class Server:
def __init__(self, port, timeout=0.5):
tree = [0 for x in range(1000)]
def countNodes(root):
pass
def addChildren(children, parent):
tree[parent<<1] = children[0]
tree[parent<<1|1] = children[1]
@GnsP
GnsP / modularTest.cpp
Created August 4, 2015 09:56
test file for modular arithmatic suit
#include <iostream>
#include "modular.hpp"
using namespace std;
int main(){
modular<7> a,b,c,d;
a=3;
b=8;
c=-5;
cout<<a()<<" "<<b()<<" "<<c()<<endl; // expected 3 1 2
@GnsP
GnsP / modular.hpp
Created August 4, 2015 09:55
Modular Arithmatic Suit
#ifndef NETSEC_MODULAR_HPP_INCLUDED__
#define NETSEC_MODULAR_HPP_INCLUDED__
class modularInverseException: public std::exception{
virtual const char *what() const throw(){
return "Modular Inverse does not exist in this case.";
}
} modularInverseDoesNotExist;
template<int Mod>
@GnsP
GnsP / ATOMS.cpp
Last active August 29, 2015 14:24
Breaking Into Atoms (Codechef Practice Problem)
/*
* *WARNING*
* If you are not familiar with bit manipulations and bitwise programming
* go study them first.
*
**************************************************************************
*
* This is the solution to the practice problem 'Breaking into Atoms'
* on Codechef. Link to problem : http://www.codechef.com/problems/ATOMS
*
@GnsP
GnsP / spoj_farida.cpp
Last active August 29, 2015 14:24
Princess Farida (DP Problem from SPOJ)
/*
* This is the solution to problem 'Princess Farida' on SPOJ. Link : http://www.spoj.com/problems/FARIDA/
*
* The problem can be solved using Dynamic Programming, the recurrence
* relation for the DP is :
* DP[i] = INPUT[i] + MAX( DP[i-2], DP[i-3] ) ... Think yourself 'why ?'
*
* Now, as we see that the DP requires only upto 3rd previous term, we can
* minimize the storage required to 4 values only and use a cyclic array
* for the DP. Carefully study the solution to see how.
@GnsP
GnsP / css_validator.py
Created June 6, 2015 13:09
CSS Validator
#!/usr/bin/env python
'''
CSS Validator Automation Script
*******************************
Validates all css files in a given directory and writes
errors and warnings to log files in a separate directory.
Ganesh Prasad Sahoo (c) 2015
@GnsP
GnsP / boiler.cpp
Created May 30, 2015 04:27
Competitive Coding Boilerplate
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
@GnsP
GnsP / TWSTR.cpp
Created May 26, 2015 15:54
This is probably the most abstract piece of memory consuming shit I've ever written. And holy crap, it got accepted in the 1st attempt itself :o
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>