Skip to content

Commit a834326

Browse files
committed
Added b16, b32, a85, abs, absMax, absMin
1 parent 5492681 commit a834326

File tree

9 files changed

+103
-6
lines changed

9 files changed

+103
-6
lines changed

Maths/3n+1.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ def n31(a):# a = initial number
99
a = 3*a +1
1010
c += 1#counter
1111
l += [a]
12-
print(a)#optional print
13-
print("It took {0} steps.".format(c))#optional finish
12+
1413
return l , c
1514
print(n31(43))
16-
15+
print(n31(98)[0][-1])# = a
16+
print("It took {0} steps.".format(n31(13))[1]))#optional finish
17+
1718
if __name__ == '__main__':
1819
main()

Maths/abs.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def absVal(num):
2+
"""
3+
Function to fins absolute value of numbers.
4+
>>>absVal(-5)
5+
5
6+
>>>absVal(0)
7+
0
8+
"""
9+
if num < 0:
10+
return -num
11+
else:
12+
return num
13+
14+
def main():
15+
print(absVal(-34)) # = 34
16+
17+
if __name__ == '__main__':
18+
main()

Maths/absMax.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from abs import absVal
2+
def absMax(x):
3+
"""
4+
>>>absMax([0,5,1,11])
5+
11
6+
>>absMax([3,-10,-2])
7+
-10
8+
"""
9+
j = x[0]
10+
for i in x:
11+
if absVal(i) < j:
12+
j = i
13+
return j
14+
#BUG: i is apparently a list, TypeError: '<' not supported between instances of 'list' and 'int' in absVal
15+
16+
17+
def main():
18+
a = [1,2,-11]
19+
print(absVal(a)) # = -11
20+
21+
if __name__ == '__main__':
22+
main()

Maths/absMin.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from abs import absVal
2+
def absMin(x):
3+
"""
4+
>>>absMin([0,5,1,11])
5+
0
6+
>>absMin([3,-10,-2])
7+
-2
8+
"""
9+
j = x[0]
10+
for i in x:
11+
if absVal(i) < j:
12+
j = i
13+
return j
14+
15+
def main():
16+
a = [1,2,-11]
17+
print(absMin(a)) # = 1
18+
19+
if __name__ == '__main__':
20+
main()

ciphers/base16.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import base64
2+
3+
def main():
4+
inp = input('->')
5+
encoded = inp.encode('utf-8') #encoded the input (we need a bytes like object)
6+
b16encoded = base64.b16encode(encoded) #b16encoded the encoded string
7+
print(b16encoded)
8+
print(base64.b16decode(b16encoded).decode('utf-8'))#decoded it
9+
10+
if __name__ == '__main__':
11+
main()

ciphers/base32.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import base64
2+
3+
def main():
4+
inp = input('->')
5+
encoded = inp.encode('utf-8') #encoded the input (we need a bytes like object)
6+
b32encoded = base64.b32encode(encoded) #b32encoded the encoded string
7+
print(b32encoded)
8+
print(base64.b32decode(b32encoded).decode('utf-8'))#decoded it
9+
10+
if __name__ == '__main__':
11+
main()

ciphers/base85.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import base64
2+
3+
def main():
4+
inp = input('->')
5+
encoded = inp.encode('utf-8') #encoded the input (we need a bytes like object)
6+
a85encoded = base64.a85encode(encoded) #a85encoded the encoded string
7+
print(a85encoded)
8+
print(base64.a85decode(a85encoded).decode('utf-8'))#decoded it
9+
10+
if __name__ == '__main__':
11+
main()

data_structures/arrays.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
arr = [10, 20, 30, 40]
2-
arr[1] = 30
2+
arr[1] = 30 # set element 1 (20) of array to 30
33
print(arr)

maths/fibonacci_sequence_recursion.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Fibonacci Sequence Using Recursion
22

33
def recur_fibo(n):
4-
return n if n <= 1 else (recur_fibo(n-1) + recur_fibo(n-2))
5-
4+
if n <= 1:
5+
return n
6+
else:
7+
(recur_fibo(n-1) + recur_fibo(n-2))
8+
69
def isPositiveInteger(limit):
710
return limit >= 0
811

0 commit comments

Comments
 (0)