Skip to content

Commit

Permalink
Added b16, b32, a85, abs, absMax, absMin
Browse files Browse the repository at this point in the history
  • Loading branch information
erensunerr committed Nov 3, 2018
1 parent 5492681 commit a834326
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Maths/3n+1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ def n31(a):# a = initial number
a = 3*a +1
c += 1#counter
l += [a]
print(a)#optional print
print("It took {0} steps.".format(c))#optional finish

return l , c
print(n31(43))

print(n31(98)[0][-1])# = a
print("It took {0} steps.".format(n31(13))[1]))#optional finish

if __name__ == '__main__':
main()
18 changes: 18 additions & 0 deletions Maths/abs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def absVal(num):
"""
Function to fins absolute value of numbers.
>>>absVal(-5)
5
>>>absVal(0)
0
"""
if num < 0:
return -num
else:
return num

def main():
print(absVal(-34)) # = 34

if __name__ == '__main__':
main()
22 changes: 22 additions & 0 deletions Maths/absMax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from abs import absVal
def absMax(x):
"""
>>>absMax([0,5,1,11])
11
>>absMax([3,-10,-2])
-10
"""
j = x[0]
for i in x:
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


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

if __name__ == '__main__':
main()
20 changes: 20 additions & 0 deletions Maths/absMin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from abs import absVal
def absMin(x):
"""
>>>absMin([0,5,1,11])
0
>>absMin([3,-10,-2])
-2
"""
j = x[0]
for i in x:
if absVal(i) < j:
j = i
return j

def main():
a = [1,2,-11]
print(absMin(a)) # = 1

if __name__ == '__main__':
main()
11 changes: 11 additions & 0 deletions ciphers/base16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import base64

def main():
inp = input('->')
encoded = inp.encode('utf-8') #encoded the input (we need a bytes like object)
b16encoded = base64.b16encode(encoded) #b16encoded the encoded string
print(b16encoded)
print(base64.b16decode(b16encoded).decode('utf-8'))#decoded it

if __name__ == '__main__':
main()
11 changes: 11 additions & 0 deletions ciphers/base32.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import base64

def main():
inp = input('->')
encoded = inp.encode('utf-8') #encoded the input (we need a bytes like object)
b32encoded = base64.b32encode(encoded) #b32encoded the encoded string
print(b32encoded)
print(base64.b32decode(b32encoded).decode('utf-8'))#decoded it

if __name__ == '__main__':
main()
11 changes: 11 additions & 0 deletions ciphers/base85.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import base64

def main():
inp = input('->')
encoded = inp.encode('utf-8') #encoded the input (we need a bytes like object)
a85encoded = base64.a85encode(encoded) #a85encoded the encoded string
print(a85encoded)
print(base64.a85decode(a85encoded).decode('utf-8'))#decoded it

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion data_structures/arrays.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
arr = [10, 20, 30, 40]
arr[1] = 30
arr[1] = 30 # set element 1 (20) of array to 30
print(arr)
7 changes: 5 additions & 2 deletions maths/fibonacci_sequence_recursion.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Fibonacci Sequence Using Recursion

def recur_fibo(n):
return n if n <= 1 else (recur_fibo(n-1) + recur_fibo(n-2))

if n <= 1:
return n
else:
(recur_fibo(n-1) + recur_fibo(n-2))

def isPositiveInteger(limit):
return limit >= 0

Expand Down

0 comments on commit a834326

Please sign in to comment.