Skip to content

absMax fix bug. #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Maths/3n+1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ def n31(a):# a = initial number
return l , c
print(n31(43))
print(n31(98)[0][-1])# = a
print(n31(13))
print("It took {0} steps.".format(n31(13)[1]))#optional finish

if __name__ == '__main__':
main()

"""
算法题:

输入一个数,偶数时则砍掉一半;奇数时,则(3n+1)砍掉一半,最后直到得到1.问,进行了多少次?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嘿,哥儿们,国外仓库不要用中文噢~

Do not use Chinese characters, please :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK! I Know!Thanks!


"""
11 changes: 9 additions & 2 deletions Maths/abs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
def absVal(num):
"""
Function to fins absolute value of numbers.
>>>absVal(-5)
#>>>absVal(-5)
5
>>>absVal(0)
#>>>absVal(0)
0
"""
if num < 0:
Expand All @@ -16,3 +16,10 @@ def main():

if __name__ == '__main__':
main()

"""

绝对值

"""

17 changes: 11 additions & 6 deletions Maths/absMax.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
from abs import absVal
from Maths.abs import absVal

def absMax(x):
"""
>>>absMax([0,5,1,11])
#>>>absMax([0,5,1,11])
11
>>absMax([3,-10,-2])
-10
"""
j = x[0]
for i in x:
if absVal(i) < j:
if absVal(i) > j:
j = i
return j
#BUG: i is apparently a list, TypeError: '<' not supported between instances of 'list' and 'int' in absVal

#BUG fix

def main():
a = [1,2,-11]
print(absVal(a)) # = -11
a = [3, 2, -11, -12]
print(absMax(a)) # = -11

if __name__ == '__main__':
main()

"""
print abs Max
"""
6 changes: 3 additions & 3 deletions Maths/absMin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from abs import absVal
from Maths.abs import absVal
def absMin(x):
"""
>>>absMin([0,5,1,11])
# >>>absMin([0,5,1,11])
0
>>absMin([3,-10,-2])
# >>absMin([3,-10,-2])
-2
"""
j = absVal(x[0])
Expand Down
12 changes: 12 additions & 0 deletions strings/min_cost.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Insert A APython
Insert l AlPython
Insert g AlgPython
Insert o AlgoPython
Replace P with r Algorython
Replace y with i Algorithon
Copy t Algorithon
Copy h Algorithon
Replace o with m Algorithmn
Replace n with s Algorithms

Minimum cost: 10
Expand Down