Skip to content

Instantly share code, notes, and snippets.

View coderodde's full-sized avatar

Rodion Efremov coderodde

View GitHub Profile
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public final class FastRabinKarpHashFunction {
private final int[] map;
private final int[] factors;
private final int q;
@coderodde
coderodde / portable_program
Last active November 27, 2015 09:44
A pseudoportable C program
#! /bin/bash
# Below, XXXX asks for random characters in order to make a unique file name.
# Mac OSX seems to ignore XXXX, yet Ubuntu requires them.
# Create a temporary file name for the source code:
TMP_SOURCE_FILE="$(mktemp -t sourceXXXX).c"
# Create a temporary file name for the executable file:
TMP_PROGRAM_FILE="$(mktemp -t programXXXX)"
#! /bin/bash
# Create a temporary file name for the executable file:
TMP_PROGRAM_FILE="$(mktemp programXXXXXX)"
# Compile the embedded C program:
gcc -o "$TMP_PROGRAM_FILE" -x c - <<- END_OF_SOURCE
#include <stdio.h>
int main(int argc, char* argv[])
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
uint64_t read_time_stamp_counter()
{
uint32_t my_edx;
uint32_t my_eax;
asm ("cpuid\n\t"
import java.util.Arrays;
import java.util.Random;
public class Mergesort {
public static int[] mergeSort(int[] arr) {
if (arr.length <= 1) {
return arr;
}
@coderodde
coderodde / sylvester.py
Created April 25, 2016 11:43
Computing Sylvester numbers for CR
from time import clock
def sylvester_number_original(n):
if n == 0:
return 2
return sylvester_number_original(n - 1) * (sylvester_number_original(n - 1) - 1) + 1
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Random;
public class MovingAverageV2 {
private final Queue<BigDecimal> window = new ArrayDeque<>();
private final int period;
/******************
* File: execres.c *
******************/
#include "execres.h"
#include <stdlib.h>
PExecResult execTime( void* (*code)( void*), void* param ){
PExecResult result = (PExecResult) malloc( sizeof(ExecResult) );
package net.coderodde.util;
/**
* This class contains static utility methods for dealing with matrices of
* {@code double} values.
*
* @author Rodion "rodde" Efremov
* @version 1.6
*/
public class MatrixUtils {
package net.coderodde.util;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Random;