From b23765e4c81e804a9b37b3da4406fa908976f502 Mon Sep 17 00:00:00 2001 From: Doppon Date: Thu, 14 May 2020 11:11:55 +0900 Subject: [PATCH] fix syntax of other and discrete_mathmatics --- discrete_mathematics/euclidean_gcd.rb | 14 ++++++-------- other/fisher_yates.rb | 12 ++++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/discrete_mathematics/euclidean_gcd.rb b/discrete_mathematics/euclidean_gcd.rb index 942fd36..4d3c8c4 100644 --- a/discrete_mathematics/euclidean_gcd.rb +++ b/discrete_mathematics/euclidean_gcd.rb @@ -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 - - diff --git a/other/fisher_yates.rb b/other/fisher_yates.rb index c28d429..8496c4f 100644 --- a/other/fisher_yates.rb +++ b/other/fisher_yates.rb @@ -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]