Skip to content

Instantly share code, notes, and snippets.

class Natural {
public static final Natural ZERO = new Natural(null);
private Natural predecessor;
private Natural(Natural predecessor) {
this.predecessor = predecessor;
}
public Natural successor() {
@eidanch
eidanch / Speed.java
Last active May 5, 2017 07:38
Example of using the synchronized a game of speed
import java.util.Stack;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
/**
*
* Created by Eidan Cohen on 07/09/2016.
*/
public class Speed {
def egcd(a,b):
if a < b:
x,y,d = egcd(b,a)
return y,x,d
if b == 0:
return (1,0,a)
if b == 1:
return (0,1,1)
@eidanch
eidanch / Median.cs
Created July 12, 2015 09:12
Two implementation of the median function in C#
/// <summary>
/// Finds the median in an array
/// Uses an efficient sorting on a copy of the array
/// </summary>
/// <param name="array">The array</param>
/// <returns>The median of the array</returns>
public static int SortBasedMedian(int[] array)
{
int[] copy = (int[])array.Clone();
Array.Sort(copy);
@eidanch
eidanch / CommonSubstring.cs
Created July 12, 2015 09:09
An implementation of the "longest common continuous substring" method in C#.
/// <summary>
/// Returns the longest common continuous substring of two given strings
/// </summary>
/// <param name="a">The first string</param>
/// <param name="b">The second string</param>
/// <returns>The longest common continuous substring</returns>
public static string CommonSubstring(string a, string b)
{
int bestLength = 0;