Skip to content

Commit 18ee106

Browse files
authored
Merge pull request #1 from kennyledet/master
changes
2 parents 4a3ad1e + 2140437 commit 18ee106

5 files changed

Lines changed: 69 additions & 7 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Module that cast a decimal number to fraction notation
2+
# Input:
3+
# number: number to cast
4+
# return:
5+
# tuple[0]: is the error, None is returned when the process has no error
6+
# otherwise a string with message of error is returned
7+
# tuple[1]: is number in fraction notation
8+
9+
10+
from fractions import Fraction
11+
12+
def decimalToFraction(number):
13+
if(isinstance(number,(int,float))):
14+
ans = Fraction(number).limit_denominator()
15+
return (None,str(ans))
16+
else:
17+
return ('error','arg must be number')
18+
19+
if __name__ == '__main__':
20+
print(decimalToFraction(3.45))
21+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from decimalToFraction import decimalToFraction
2+
3+
test_input = [2.34, 2.45, "hola", "mundo", 3.90]
4+
test_output_err = [None, None, 'error', 'error', None]
5+
6+
for number, error in zip(test_input,test_output_err):
7+
ans = decimalToFraction(number)
8+
if(ans[0] != error):
9+
print('the code is wrong!!')
10+
else:
11+
print(number,' -> ',ans[1])
12+

Levenshtein_distance/Lua/Yonaba/levenshtein.lua

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
-- Iterative matrix-based method
55
-- See: http://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_full_matrix
66

7-
-- Return the minimum of three elements
8-
local function min(a, b, c)
9-
return math.min(math.min(a, b), c)
10-
end
11-
127
-- Creates a 2D matrix
138
local function matrix(row,col)
149
local m = {}
@@ -30,7 +25,7 @@ local function lev_iter_based(strA,strB)
3025
if (strA:sub(i-1,i-1) == strB:sub(j-1,j-1)) then cost = 0
3126
else cost = 1
3227
end
33-
M[i][j] = min(M[i-1][j]+1,M[i][j-1]+1,M[i-1][j-1]+cost)
28+
M[i][j] = math.min(M[i-1][j]+1,M[i][j-1]+1,M[i-1][j-1]+cost)
3429
end
3530
end
3631
return M[row][col]
@@ -45,7 +40,7 @@ local function lev_recursive_based(strA, strB, s, t)
4540
if s == 0 then return t end
4641
if t == 0 then return s end
4742
local cost = strA:sub(s,s) == strB:sub(t,t) and 0 or 1
48-
return min(
43+
return math.min(
4944
lev_recursive_based(strA, strB, s - 1, t) + 1,
5045
lev_recursive_based(strA, strB, s, t - 1) + 1,
5146
lev_recursive_based(strA, strB, s - 1, t - 1) + cost
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# function that check if a string is palindrome (case sensitive)
2+
# input:
3+
# str: word to check
4+
# return:
5+
# true or false
6+
7+
def palindrome?(str)
8+
str == str.reverse
9+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require "./palindrome"
2+
3+
begin
4+
# raises an ArgumentError with the message "you messed up!"
5+
if palindrome?("hola") == true
6+
raise ArgumentError.new("The code for palindrome is wrong!")
7+
else
8+
print("hola is no-palindrome\n")
9+
end
10+
11+
if palindrome?("ala") == false
12+
raise ArgumentError.new("The code for palindrome is wrong!")
13+
else
14+
print("ala is palindrome\n")
15+
end
16+
17+
if palindrome?("radar") == false
18+
raise ArgumentError.new("The code for palindrome is wrong!")
19+
else
20+
print("radar is palindrome\n")
21+
end
22+
23+
rescue ArgumentError => e
24+
puts e.message
25+
end

0 commit comments

Comments
 (0)