Last active
January 26, 2023 18:11
-
-
Save hexfusion/d6c31efa727fab5a100fdeb20b1fb654 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A WebSocket is a persistent connection between a client and server. | |
WebSockets provide a bidirectional, full-duplex communications channel | |
that operates over HTTP through a single TCP/IP socket connection. | |
Allows for bidirectional communication of a single tcp conn. | |
#!/usr/bin/python3 | |
def binarySearch(arr, x): | |
l = 0 | |
r = len(arr) | |
while (l <= r): | |
m = l + ((r - l) // 2) | |
res = (x == arr[m]) | |
# Check if x is present at mid | |
if (res == 0): | |
return m - 1 | |
# If x greater, ignore left half | |
if (res > 0): | |
l = m + 1 | |
# If x is smaller, ignore right half | |
else: | |
r = m - 1 | |
return -1 | |
# Test array | |
ary = [ | |
"0xec8ffd8970c57e820c5affb0dd332ecd9c0c83297bfd8841686672b41d6ccc38", | |
"0xbcce1694a89e29d4c81bcb4530178604ca3e445482f7bfdfb721cf8bb9eb60d2", | |
"0xc486bb76bfdbedf05c1fbf23cb88efc377280b50fe023c2ef4d1e2954ee549f3", | |
"0x7e503779e7ab5d86e9ebf3cf2278cb0a226ef8cdcc362818dd784ba734cc5bec", | |
"0x1f4cb3d2f37bc4abb144ecf0a6d049d5361fbb8ef48314f4009baa5fc2d4cddd", | |
"0x2ea58c73c47c4f9601efa25a64984fda1fec9db47a833427ba3ad9cb8fde3f5b", | |
"0xfe201af336b3b668b0e21d1bd491a611371669ffd1313e5c021c6581b9f0019c", | |
"0x374c1f72e595a961c23051b65bb8dcfde8c3d383e803acd3b27752f56f8d2503", | |
"0x895fd0d368d09307af69d3ea84caa4ceed982f76e746f051ddb837c22ad97434", | |
"0x422621647cb62cb9a8709df7aa3d7649d9a0d831bb28ffd5d8a55b2eda0cfd7e", | |
"0x58ca2a458b682d13e881c1cf606e47f7b4adabc31f7459eeba076b9714b20c54", | |
"0xe0ae1f59dbc6c1b25cbde128f1c39b8ebc8f1b5620f1e457e93a4000f0a02e16", | |
"0xdcd1ce1e19f520fe09c19069dc65c838c3d51315b7afa5cad91e273a38f63786", | |
"0x56bfaa257734e3b6144fd4819e6761ed74554ab1dfb8e99eb379bd7360c64864", | |
"0x13ae01d2447782a4a81aa591e916d8493a5bdf060788b1ee39b95406d43c974b", | |
"0x667f8317e66201a3081efbf9ce3888c7252ee665c9383e061f3a872d6b1ea0e5", | |
"0x4c2be29e53980055d6944a8daddada3b7b925671b4e0eb47e4c1c9346a2a9b2b", | |
"0xd1119232520bc7f7e896a836bc073aa34aad91934252a918343c5765f6da070a", | |
"0xe9c2d02ef31641383d24ac6a555484e5a2aa0d1fe646c87ef170b313b8623f18", | |
] | |
target = "0xec8ffd8970c57e820c5affb0dd332ecd9c0c83297bfd8841686672b41d6ccc38" | |
ary.sort() | |
print(binarySearch(ary, target)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment