From ec7c8516f7443e76233aa0f44d06c074f88498f0 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Wed, 1 Jul 2020 14:40:40 +0100 Subject: Implement part 1/3 for "Memo" After hearing from a Jane Street recruiter, I decided to dust off some of the DS&As knowledge. I found this article online, which outlines an example problem called "Memo": https://blog.janestreet.com/what-a-jane-street-dev-interview-is-like/ Here's part 1 of the solution in Python. --- scratch/data_structures_and_algorithms/memo.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 scratch/data_structures_and_algorithms/memo.py (limited to 'scratch/data_structures_and_algorithms') diff --git a/scratch/data_structures_and_algorithms/memo.py b/scratch/data_structures_and_algorithms/memo.py new file mode 100644 index 000000000000..8195f32c931c --- /dev/null +++ b/scratch/data_structures_and_algorithms/memo.py @@ -0,0 +1,19 @@ +import time +import random + +memo = {} + + +def f(x): + if x in memo: + print("Hit.\t\tf({})".format(x)) + return memo[x] + else: + print("Computing...\tf({})".format(x)) + time.sleep(0.25) + res = random.randint(0, 10) + memo[x] = res + return res + + +[f(random.randint(0, 10)) for _ in range(10)] -- cgit 1.4.1