This file contains hidden or 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
| class Natural { | |
| public static final Natural ZERO = new Natural(null); | |
| private Natural predecessor; | |
| private Natural(Natural predecessor) { | |
| this.predecessor = predecessor; | |
| } | |
| public Natural successor() { |
This file contains hidden or 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
| 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 { |
This file contains hidden or 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 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) | |
This file contains hidden or 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
| /// <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); |
This file contains hidden or 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
| /// <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; |