/root/compile: line 2: $'\r': command not foundThe above means you need to dos2unix the file.
| const dgram = require('dgram'); | |
| const socket = dgram.createSocket('udp4'); | |
| //var port = 4242 | |
| //var port = 8087 | |
| var port = 18999 | |
| var address = "192.168.14.151" | |
| var msg = '<?xml version="1.0" standalone="yes"?><event version="2.0" uid="J-01334" type="a-h-A-M-F-U-M" time="2005-04-05T11:43:38.07Z" start="2005-04-05T11:43:38.07Z" stale="2005-04-05T11:45:38.07Z"><detail></detail><point lat="30.0090027" lon="-85.9578735" ce="45.3" hae="-42.6" le="99.5"/></event>' |
| """ | |
| https://www.algoexpert.io/questions/Two%20Number%20Sum | |
| O(nlogn) time | O(1) space | |
| This algorithm sorts the arrays and then puts two index | |
| pointers at the edges and then advances towards the | |
| middle to find a solution. | |
| """ | |
| def twoNumberSum(array, targetSum): | |
| # sort array (really a list) first |
| """ | |
| https://www.algoexpert.io/questions/Find%20Closest%20Value%20In%20BST | |
| Average: Theta(logn) time | Theta(logn) space | |
| Worst: O(n) time | O(n) space | |
| This solution takes up O(n) space because of recursion. | |
| float('inf') is used to set a unbounded upper value for comparison | |
| """ |
| """ | |
| https://www.algoexpert.io/questions/Branch%20Sums | |
| """ | |
| class BinaryTree: | |
| def __init__(self, value): | |
| self.value = value | |
| self.left = None | |
| self.right = None |
| """ | |
| https://practice.geeksforgeeks.org/problems/finding-middle-element-in-a-linked-list/1 | |
| - Use "tortoise and the hare" method to find the middle | |
| - Use a pointer that increments half the "speed" of another pointer | |
| """ | |
| def findMid(head): | |
| if head is None: | |
| return None |
| """ | |
| https://practice.geeksforgeeks.org/problems/height-of-binary-tree/1 | |
| - use recursion to find the height | |
| - use max on left and right branch on every recursion (add 1 every iteration) | |
| """ | |
| def height(root): | |
| if root is None: | |
| return 0 | |
| return 1 + max(height(root.left), height(root.right)) |
| """ | |
| https://practice.geeksforgeeks.org/problems/inorder-traversal/1 | |
| """ | |
| def InOrder(root): | |
| if root is None: | |
| return | |
| InOrder(root.left) | |
| # Parallel sorting of lists | |
| data = zip(list1, list2) | |
| data.sort() | |
| list1, list2 = map(lambda t: list(t), zip(*data)) |
| """ | |
| https://py.checkio.org/forum/post/9298/sorted-function-explanation-please/ | |
| This will sort a list of tuples by strings (second tuple item) | |
| and then by number in reversed order when strings are equal. | |
| """ | |
| list_of_tuples = [(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b')] | |
| list_of_tuples.sort(key=lambda t:(t[1], -t[0])) | |
| print(list_of_tuples) |