Skip to content

Commit 2c088fb

Browse files
authored
Add custom_equation and fn_w_counter functions
Implement custom equation and counter functions
1 parent 6ca8a7e commit 2c088fb

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import inspect
2+
3+
4+
custom_power = lambda x=0, /, e=1: x ** e
5+
6+
7+
def custom_equation(
8+
x: int = 0,
9+
y: int = 0,
10+
/,
11+
a: int = 1,
12+
b: int = 1,
13+
*,
14+
c: int = 1
15+
) -> float:
16+
"""
17+
Evaluate the custom equation.
18+
19+
:param x: First integer base.
20+
:param y: Second integer base.
21+
:param a: Power used for ``x``.
22+
:param b: Power used for ``y``.
23+
:param c: Keyword-only divisor.
24+
:return: The floating-point result of ``(x**a + y**b) / c``.
25+
"""
26+
return float((x ** a + y ** b) / c)
27+
28+
29+
_counter_state = {
30+
"total": 0,
31+
"callers": {}
32+
}
33+
34+
35+
def fn_w_counter() -> tuple[int, dict[str, int]]:
36+
frame = inspect.currentframe()
37+
caller_frame = frame.f_back if frame else None
38+
caller_name = "<unknown>"
39+
40+
if caller_frame is not None:
41+
caller_name = caller_frame.f_globals.get("__name__", "<unknown>")
42+
43+
_counter_state["total"] += 1
44+
_counter_state["callers"][caller_name] = _counter_state["callers"].get(caller_name, 0) + 1
45+
46+
return _counter_state["total"], dict(_counter_state["callers"])

0 commit comments

Comments
 (0)