-- Aug 25 In-Class Exercise
Scheme:
gcd(14, 30), 30 != 0 ->
gcd(30, 14), 30%14 = 2 ->
gcd(14, 2), 14%2 = 0 ->
gcd(2, 0), since v = 0, we return 2.
Prolog:
gcd(14, 30, U), 30 != 0 ->
gcd(14, 30, X), 30 != 0, Y = 14, and gcd(30, 14, X) ->
gcd(30, 14, U), 14 != 0 ->
gcd(30, 14, X), 14 != 0, Y = 2, and gcd(14, 2, X) ->
gcd(14, 2, U), 2 != 0 ->
gcd(14, 2, X), 2 != 0, Y = 0, and gcd(2, 0, X) ->
gcd(2, 0, U), 0 == 0, U = 2, so we return 2.
(
Edited: 2021-08-25)
Scheme:
gcd(14, 30), 30 != 0 ->
gcd(30, 14), 30%14 = 2 ->
gcd(14, 2), 14%2 = 0 ->
gcd(2, 0), since v = 0, we return 2.
Prolog:
gcd(14, 30, U), 30 != 0 ->
gcd(14, 30, X), 30 != 0, Y = 14, and gcd(30, 14, X) ->
gcd(30, 14, U), 14 != 0 ->
gcd(30, 14, X), 14 != 0, Y = 2, and gcd(14, 2, X) ->
gcd(14, 2, U), 2 != 0 ->
gcd(14, 2, X), 2 != 0, Y = 0, and gcd(2, 0, X) ->
gcd(2, 0, U), 0 == 0, U = 2, so we return 2.