diff --git a/boolean_algebra/buffer_gate.py b/boolean_algebra/buffer_gate.py new file mode 100644 index 000000000000..41683152d84f --- /dev/null +++ b/boolean_algebra/buffer_gate.py @@ -0,0 +1,39 @@ +""" +A Buffer Gate is a logic gate in boolean algebra which outputs the same value +as its input. It is used for signal isolation, increasing drive strength, or +introducing propagation delay in digital circuits. + +In digital electronics, buffers are essential for: +- Isolating different circuit sections +- Increasing current drive capability +- Preventing signal degradation +- Creating intentional delays in timing circuits + +Following is the truth table of a Buffer Gate: + ---------------------- + | Input | Output | + ---------------------- + | 0 | 0 | + | 1 | 1 | + ---------------------- + +Refer - https://en.wikipedia.org/wiki/Digital_buffer +""" + + +def buffer_gate(input_1: int) -> int: + """ + Calculate output of a buffer gate + + >>> buffer_gate(0) + 0 + >>> buffer_gate(1) + 1 + """ + return int(bool(input_1)) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/electronics/wheatstone_bridge.py b/electronics/wheatstone_bridge.py index 3529a09339c4..328d10fa20cf 100644 --- a/electronics/wheatstone_bridge.py +++ b/electronics/wheatstone_bridge.py @@ -6,13 +6,32 @@ def wheatstone_solver( resistance_1: float, resistance_2: float, resistance_3: float ) -> float: """ - This function can calculate the unknown resistance in an wheatstone network, - given that the three other resistances in the network are known. - The formula to calculate the same is: + Calculate the unknown resistance (Rx) in a Wheatstone bridge circuit. - --------------- - |Rx=(R2/R1)*R3| - --------------- + A Wheatstone bridge is an electrical circuit used to precisely measure + an unknown resistance. This function calculates Rx when the three other + resistances in the bridge are known. + + Circuit Diagram: + + R1 R2 + +--/\/\/--+--/\/\/--+ + | | | + Vin Vg Vout + | | | + +--/\/\/--+--/\/\/--+ + R3 Rx + + This solver uses the balanced bridge formula: + Rx = (R2/R1) × R3 + + Args: + resistance_1 (R1): First known resistance + resistance_2 (R2): Second known resistance + resistance_3 (R3): Third known resistance + + Returns: + float: The calculated unknown resistance (Rx) Usage examples: >>> wheatstone_solver(resistance_1=2, resistance_2=4, resistance_3=5)