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 / TICKETS5.cpp
Created May 21, 2015 13:28
TICKETS (Codechef parctice)
#include <cstdio>
using namespace std;
bool dfa(){ // Check what a DFA (Deterministic Finite Automaton) is and how it works.
int state = 0; // DFAs are a bit complex for beginners, because it's an abstract mathematical
char a = getchar(); // concept. But on the other hand the logic used for this specific problem
char b = getchar(); // is very basic. Hence just the basic idea of the DFA concept should suffice.
if(a==b) state = 2;
char ch;
while((ch=getchar()) != '\n'){
@GnsP
GnsP / SUBGCD.cpp
Last active August 29, 2015 14:21
SUBARRAY GCD
#include <iostream>
using namespace std;
long long gcd(long long a, long long b){ // Find the GCD of two numbers using euclidian algorithm
if(b==0) return a;
return gcd(b, a%b);
}
int main(){
long long T, N, x, g;
@GnsP
GnsP / prime_ap_seq.py
Last active August 29, 2015 14:21
A project euler problem
"""
The arithmetic sequence 1487, 4817, 8147, in which each of the terms increase by
3330 is unusual in 2 ways. (i) each of the terms are prime (ii) there are permutations
of each other.
There is one more 4 digit sequence like this. Find the 12digit number formed by
concatenating them.
"""
########################################################################################
@GnsP
GnsP / KINGSHIP.c
Last active August 29, 2015 14:20
/* CHEF AND KINGSHIP, Codechef, easy
*
* This is probably the easiest problem I have posted here. The logic is very
* simple. To minimize the cost i.e. the sum of product of population of cities
* the optimal way is to construct roads from the city with minimum population
* to every other city. :D (think and try to mathematically prove why).
*
* Hence now the solution is as easy as finding the minimum population and sum of
* all other populations and just multiply the sum and the min.
*
#include <iostream>
#include <vector> // a vector is a dynamically resizable array.
// ( Read about it from any standard C++ text book )
#include <algorithm> // include "algorithm" to use pre defined functions for
// commonly used algorithms like search, sort, max_element
// min_element etc
using namespace std;
int main(){
#include <iostream>
using namespace std;
/*
///////////////////////////////////////////////////////////////////////////////////
//
// This commented out code was used to generate the array of prime palindromes :D
//
// But there is a glitch , I am using fermat's primality test to check if a number is
// prime or not. Fermat's primality test is a probabilistic test, meaning it can go wrong
@GnsP
GnsP / gsoc_boost_ublas.md
Last active August 29, 2015 14:17
GSoC'15 Proposal for Boost.uBLAS Algorithms

##GSoC'15 Proposal for Boost.uBLAS Algorithms

###Personal Details

  • Name : Ganesh Prasad Sahoo
  • University : National Institute of Technology, Rourkela, India
  • Course/Major : Computer Science and Engineering
  • Degree Program : B.Tech.
  • Email : [email protected]

###Availability

@GnsP
GnsP / wikispider
Created March 14, 2015 06:00
wikipedia crawler and downloader
#!/usr/bin/python3
'''
This script is a web crawler (spider) that searches the wikipedia pages on a
given keyword recursively and returns only relevant pages that contain relevant
info on the given topic in their contents section. It also creates a directory
under the present working directory and saves the webpages for further reading.
It also builds a graph representation of the dependencies among the webpages to
show the user how the pages and the fields are interlinked.
@GnsP
GnsP / tmp_random_access_expt.cpp
Created February 26, 2015 13:00
TMP Random Access Container
#define STATIC_ASSERT(expr) { char assertion_stage[((expr) ? 0:-1)]; }
#define RANDOM_ACCESS_CONTAINER_META(KEY_TYPE, val_type, name) \
template<KEY_TYPE KEY> \
struct meta_container_##name##_{ \
typedef val_type value_type; \
typedef KEY_TYPE key_type; \
static const value_type value = static_cast<value_type>(0); \
}; \
typedef KEY_TYPE meta_container_##name##_key_type_; \
#include <stdio.h>
int main(){
int a, b, c; // a, b and c are two integers
scanf("%d %d", &a, &b); // read a and b from user input
c = a + b;
printf("%d \n", c); // print the value of c
return 0; // 0 is returned to indicate that
// the program exited without errors
}