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
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

View file

@ -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]