diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-02-26 12:13:38 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-02-26 12:13:38 +0000 |
| commit | 181fe0922f02017c5d85837dd3d5ce33fc8c6c48 (patch) | |
| tree | 67d136d27013067d42cd4ed5d5524f8c72c56e2c | |
| parent | 29183b30851f09a0975cd4898a9d3ebe503568ff (diff) | |
| download | perlweeklychallenge-club-181fe0922f02017c5d85837dd3d5ce33fc8c6c48.tar.gz perlweeklychallenge-club-181fe0922f02017c5d85837dd3d5ce33fc8c6c48.tar.bz2 perlweeklychallenge-club-181fe0922f02017c5d85837dd3d5ce33fc8c6c48.zip | |
- Added Python solution by Orestis Zekai.
| -rw-r--r-- | challenge-049/orestis-zekai/python/ch-2.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-049/orestis-zekai/python/ch-2.py b/challenge-049/orestis-zekai/python/ch-2.py new file mode 100644 index 0000000000..21ac9b66d5 --- /dev/null +++ b/challenge-049/orestis-zekai/python/ch-2.py @@ -0,0 +1,37 @@ +capacity = 3
+cache = [None for x in range(capacity)]
+print(cache)
+
+def get(pos):
+ global cache
+ if (pos > capacity - 1):
+ return -1
+ val = cache[pos-1]
+ shift(pos)
+ return val
+
+
+def set(pos, n):
+ global cache
+ cache[pos-1] = n
+
+
+def shift(pos1):
+ global cache
+ temp = cache.pop(pos1-1)
+ cache.append(temp)
+
+
+set(1, 3)
+print(cache)
+set(2, 5)
+print(cache)
+set(3, 7)
+print(cache)
+
+print(get(2))
+print(cache)
+print(get(1))
+print(cache)
+print(get(9))
+print(cache)
\ No newline at end of file |
