fix syntax of other and discrete_mathmatics

This commit is contained in:
Doppon 2020-05-14 11:11:55 +09:00
parent 9c1823739c
commit b23765e4c8
2 changed files with 12 additions and 14 deletions

View file

@ -1,16 +1,14 @@
#https://en.wikipedia.org/wiki/Euclidean_algorithm #https://en.wikipedia.org/wiki/Euclidean_algorithm
def euclidean_gcd(a, b) def euclidean_gcd(a, b)
while b != 0 while b != 0
t = b t = b
b = a % b b = a % b
a = t a = t
end end
return a return a
end end
puts "GCD(3, 5) = " + euclidean_gcd(3, 5).to_s puts "GCD(3, 5) = " + euclidean_gcd(3, 5).to_s
puts "GCD(3, 6) = " + euclidean_gcd(3, 6).to_s puts "GCD(3, 6) = " + euclidean_gcd(3, 6).to_s
puts "GCD(6, 3) = " + euclidean_gcd(6, 3).to_s puts "GCD(6, 3) = " + euclidean_gcd(6, 3).to_s

View file

@ -1,11 +1,11 @@
# Fisher and Yates Shuffle is one of the simplest and most popular shuffling algorithm # Fisher and Yates Shuffle is one of the simplest and most popular shuffling algorithm
def fisher_yates_shuffle(array) def fisher_yates_shuffle(array)
n = array.length n = array.length
while n > 0 while n > 0
i = rand(n-=1) i = rand(n-=1)
array[i], array[n] = array[n], array[i] array[i], array[n] = array[n], array[i]
end end
return array return array
end end
arr = [1, 2, 40, 30, 20, 15, 323, 12, 3, 4] arr = [1, 2, 40, 30, 20, 15, 323, 12, 3, 4]