aboutsummaryrefslogtreecommitdiff
path: root/challenge-049/orestis-zekai/python/ch-2.py
blob: 21ac9b66d55731f7a1a16f2233efade827f01144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)