File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1+ # Shuffles an array with Fisher-Yates algorithm
2+ def fisher_yates ( arr )
3+ rng = Random . new ( )
4+ i = arr . length - 1
5+ while i >= 0
6+ j = rng . rand ( i + 1 )
7+ temp = arr [ i ]
8+ arr [ i ] = arr [ j ]
9+ arr [ j ] = temp
10+ i -= 1
11+ end
12+ return arr
13+ end
Original file line number Diff line number Diff line change 1+ # take two binary strings and returns the Hamming Distance between them
2+ def hamming_distance ( string1 , string2 )
3+ if string1 . length != string2 . length
4+ return "Strings must be the same length."
5+ else
6+ total = 0
7+ for i in 0 ...string1 . length
8+ if string1 [ i ] != string2 [ i ]
9+ total += 1
10+ end
11+ end
12+ return total
13+ end
14+ end
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ Edmonds-Karp | :+1: | | | | | | | |
2626ElevatorAlgorithm | :+1 : | | | | | | | |
2727Fast Fourier Transform | | | | | :+1 : | | | |
2828Fibonacci | :+1 : | :+1 : | | :+1 : | :+1 : | :+1 : | | :+1 : | :+1 : | :+1 : | :+1 :
29- FisherYatesShuffle | :+1 : | | | | :+1 : | :+1 : | | :+1 : |
29+ FisherYatesShuffle | :+1 : | | | | :+1 : | :+1 : | | :+1 : | : +1 : |
3030FloodFill Algorithm | :+1 : | | | | | | | |
3131Floyd'sAlgorithm | :+1 : | :+1 : | | | :+1 : | | | |
3232GreatestCommonDivisor | :+1 : |:+1 : | :+1 : | :+1 : | :+1 : | | | |
You can’t perform that action at this time.
0 commit comments