Skip to content

Commit 464ee24

Browse files
authored
Merge pull request thuva4#366 from langlk/fisher-yates
Add Ruby Fisher-Yates implementation
2 parents 7480583 + c349dd9 commit 464ee24

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Edmonds-Karp | :+1: | | | | | | | |
2626
ElevatorAlgorithm | :+1: | | | | | | | |
2727
Fast Fourier Transform | | | | | :+1: | | | |
2828
Fibonacci | :+1: | :+1: | | :+1: | :+1: | :+1: | | :+1: | :+1: | :+1: | :+1:
29-
FisherYatesShuffle | :+1: | | | | :+1: | :+1: | | :+1: |
29+
FisherYatesShuffle | :+1: | | | | :+1: | :+1: | | :+1: | :+1: |
3030
FloodFill Algorithm | :+1: | | | | | | | |
3131
Floyd'sAlgorithm | :+1: | :+1: | | | :+1: | | | |
3232
GreatestCommonDivisor | :+1: |:+1:| :+1: | :+1: | :+1: | | | |

0 commit comments

Comments
 (0)