Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit 0cb614f

Browse files
author
Kalpak Take
authored
find y in ( b ** y = x) using logarithmic function (integers)
1 parent d946241 commit 0cb614f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

logarithm_integer.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# Exhaustive numeration (iteration)
3+
# Simple implementation of logarithmic function
4+
# I love math!
5+
6+
# log(b, x) <=> b ** y = x
7+
# So we have to find y!
8+
9+
# Don't use it for decimal numbers
10+
def logarithm_integer(b, x):
11+
if (b > 0 and b != 1) and x > 0:
12+
for i in range(x):
13+
if b ** i == x:
14+
return i
15+
return -1
16+
else:
17+
return "Invalid input for logarithm"
18+
19+
# Test
20+
print("log(6, 216) -> " + str(logarithm_integer(6, 216)))
21+
print("log(5, 625) -> " + str(logarithm_integer(5, 25)))
22+
print("log(4, 16) -> " + str(logarithm_integer(4, 16)))
23+
print("log(2, 16) -> " + str(logarithm_integer(2, 16)))
24+
print("log(3, 6) -> " + str(logarithm_integer(3, 6)))
25+
print("log(0, 16) -> " + str(logarithm_integer(0, 16)))

0 commit comments

Comments
 (0)