mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-18 10:26:54 +01:00
fix syntax of other and discrete_mathmatics
This commit is contained in:
parent
9c1823739c
commit
b23765e4c8
2 changed files with 12 additions and 14 deletions
|
@ -1,16 +1,14 @@
|
|||
#https://en.wikipedia.org/wiki/Euclidean_algorithm
|
||||
|
||||
def euclidean_gcd(a, b)
|
||||
while b != 0
|
||||
t = b
|
||||
b = a % b
|
||||
a = t
|
||||
end
|
||||
return a
|
||||
while b != 0
|
||||
t = b
|
||||
b = a % b
|
||||
a = t
|
||||
end
|
||||
return a
|
||||
end
|
||||
|
||||
puts "GCD(3, 5) = " + euclidean_gcd(3, 5).to_s
|
||||
puts "GCD(3, 6) = " + euclidean_gcd(3, 6).to_s
|
||||
puts "GCD(6, 3) = " + euclidean_gcd(6, 3).to_s
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# Fisher and Yates Shuffle is one of the simplest and most popular shuffling algorithm
|
||||
def fisher_yates_shuffle(array)
|
||||
n = array.length
|
||||
while n > 0
|
||||
i = rand(n-=1)
|
||||
array[i], array[n] = array[n], array[i]
|
||||
end
|
||||
return array
|
||||
n = array.length
|
||||
while n > 0
|
||||
i = rand(n-=1)
|
||||
array[i], array[n] = array[n], array[i]
|
||||
end
|
||||
return array
|
||||
end
|
||||
|
||||
arr = [1, 2, 40, 30, 20, 15, 323, 12, 3, 4]
|
||||
|
|
Loading…
Reference in a new issue