From efd533331d6a7f0c51ef857af448a6c84c3084ed Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 12 Feb 2016 15:01:00 +0100 Subject: Removed spaces in path --- Assignment5/2a.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Assignment5/2a.py (limited to 'Assignment5/2a.py') diff --git a/Assignment5/2a.py b/Assignment5/2a.py new file mode 100644 index 0000000..0b55cee --- /dev/null +++ b/Assignment5/2a.py @@ -0,0 +1,14 @@ +import random, hashlib, collections + +def duplicates(table): + return [key for key, values in table.items() if len(values) > 1] + +def hash(msg): # we use only the first 3 bytes, as a toy example + return hashlib.md5(str(msg).encode('utf-8')).digest()[:3] + +lookup = collections.defaultdict(list) # lookup table +while duplicates(lookup) == []: # as long as there are no duplicates + input = random.getrandbits(64) # 64 bits is sufficient to assume no input occurs twice + lookup[hash(input)].append(input) + +print(len(lookup)) \ No newline at end of file -- cgit v1.2.3