This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://en.literateprograms.org/Merge_sort_(C_Plus_Plus) | |
#include <algorithm> | |
#include <iterator> | |
#include <iostream> | |
// Note: InputIterator must allow the minus operator -- i.e. RandomAccess | |
// The end element is AFTER the last element | |
// output refers to the iterator for the first output item | |
// You can mix and match different input and output iterators (i.e. vectors, arrays etc.) | |
template <typename InputIterator, typename OutputIterator> void mergesort(InputIterator start, InputIterator end, OutputIterator output){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.spoj.pl/problems/PALIN/ | |
// Concept: http://www.algorithmist.com/index.php/SPOJ_PALIN | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
bool lessThan(vector<int> obj1, vector<int> obj2); | |
void helper(const vector<int> &input, vector<int> &output, int stage=0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.spoj.pl/problems/PRIME1/ | |
//http://www.swageroo.com/wordpress/spoj-problem-2-prime-generator-prime1/ | |
#include <iostream> | |
using namespace std; | |
int main(){ | |
int count; | |
cin >> count; | |
while(count--){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mean medium and mode | |
#include <iostream> | |
#include <algorithm> | |
#include <iterator> | |
#include <vector> | |
#include <map> | |
using namespace std; | |
// This is a variant of merge sort that does mode counts and sums all the items. | |
template <typename InputIterator, typename OutputIterator, typename ValueType, typename SumType> void mergesort(InputIterator start, InputIterator end, OutputIterator output, SumType &sum, map<ValueType, int> &mode){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Because I'm lazy and I used a C++11 syntax to initialise a vector, you have to use G++ to compile this, | |
// Compile with something like g++ -pedantic -std=c++0x RadixSort.cpp | |
// Or for the more pedantic g++ -pedantic -std=c++0x -Wall -Wextra -Werror=return-type -Wno-reorder RadixSort.cpp | |
// Reference http://en.wikipedia.org/wiki/Radix_sort | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> // Required | |
#include <iterator> // Required | |
#include <queue> // Required | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Quicksort - see makefile for compiling options with G++. | |
// Will not compile in VS2012 due to initialiser syntax in main() for std::vector | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> // Required | |
#include <iterator> //Required | |
#include <stdlib.h> // Required | |
#include <time.h> // Required | |
// Function Prototypes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def strip(content): | |
"""Strip Empty Variables""" | |
if (type(content) is list): | |
return strip_list(content) | |
elif (type(content) is dict): | |
return strip_dictionary(content) | |
elif (content): | |
return content | |
else: | |
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_to_string(lst, delim=''): | |
"""Concatenate a list of strings to one single string. Specify a delimiter to append to end of each fragment""" | |
return reduce((lambda a, b: a + delim + b), lst) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git grep -I -E "[^\n]\'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git grep -I -E '^.+[ ]+$' |
OlderNewer