Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit c973bc2

Browse files
committed
mock questions
1 parent 4470dcc commit c973bc2

24 files changed

+2350
-0
lines changed

Diff for: exam_mock/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Minimal Solutions
2+
3+
## Q1
4+
5+
```py
6+
def odd_even_swap(word):
7+
l = list(word)
8+
for i in range(0, len(l) - 1, 2):
9+
l[i], l[i + 1] = l[i + 1], l[i]
10+
return "".join(l)
11+
```
12+
13+
## Q2
14+
15+
```py
16+
from math import sqrt
17+
18+
def closest_pair(coord_list):
19+
s = set()
20+
for i, a in enumerate(coord_list):
21+
for b in map(lambda x: coord_list[x], range(i + 1, len(coord_list))):
22+
s.add((sqrt(sum(map(lambda x: (x[0] - x[1]) ** 2, zip(a, b)))), a, b))
23+
return list(map(lambda x: {x[1], x[2]}, [min(s, key=lambda x: x[0])]))[0]
24+
```
25+
26+
## Q3
27+
28+
```py
29+
def top5_bigram_frequency(filename):
30+
c = {}
31+
for l in map(lambda x: x.strip().lower().split(" "), open("q3/" + filename)):
32+
for i in range(len(l) - 1):
33+
c[" ".join(l[i : i + 2])] = c.get(" ".join(l[i : i + 2]), 0) + 1
34+
return dict(sorted(c.items(), key=lambda x: x[1], reverse=True)[0:5])
35+
```
36+
37+
## Q4
38+
39+
```py
40+
def get_winner(board):
41+
l = len(board)
42+
for i in range(l):
43+
if len(set(board[i][j] for j in range(l))) == 1 and board[i][0] != " ":
44+
return board[i][0]
45+
if len(set(board[j][i] for j in range(l))) == 1 and board[0][i] != " ":
46+
return board[0][i]
47+
if len(set(board[i][i] for i in range(l))) == 1 and board[0][0] != " ":
48+
return board[0][0]
49+
if len(set(board[i][l - i - 1] for i in range(l))) == 1 and board[0][l - 1] != " ":
50+
return board[0][l - 1]
51+
if any(map(lambda x: x == " ", [c for r in board for c in r])):
52+
return None
53+
return "draw"
54+
```

Diff for: exam_mock/exam.pdf

118 KB
Binary file not shown.

Diff for: exam_mock/skeleton/q1/q1.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def odd_even_swap(word):
2+
l = list(word)
3+
for i in range(0, len(l) - 1, 2):
4+
l[i], l[i + 1] = l[i + 1], l[i]
5+
return "".join(l)

Diff for: exam_mock/skeleton/q1/test_q1.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from q1 import odd_even_swap
2+
3+
4+
def test_odd():
5+
word = "abcdefghi"
6+
swapped = odd_even_swap(word)
7+
expected = "badcfehgi"
8+
print(swapped)
9+
assert swapped == expected
10+
11+
12+
def test_even():
13+
word = "Python Programming"
14+
swapped = odd_even_swap(word)
15+
expected = "yPhtnoP orrgmaimgn"
16+
print(swapped)
17+
assert swapped == expected
18+
19+
20+
if __name__ == "__main__":
21+
test_odd()
22+
test_even()
23+

Diff for: exam_mock/skeleton/q2/q2.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# from math import inf, sqrt
2+
3+
4+
# def closest_pair(coord_list):
5+
# s = (inf,)
6+
# for a in coord_list:
7+
# for b in coord_list:
8+
# if a != b:
9+
# d = 0
10+
# for i, va in enumerate(a):
11+
# d += (va - b[i]) ** 2
12+
# s = min(s, (sqrt(d), a, b), key=lambda x: x[0])
13+
# return {s[1], s[2]}
14+
15+
from math import sqrt
16+
17+
18+
def closest_pair(coord_list):
19+
s = set()
20+
for i, a in enumerate(coord_list):
21+
for b in map(lambda x: coord_list[x], range(i + 1, len(coord_list))):
22+
s.add((sqrt(sum(map(lambda x: (x[0] - x[1]) ** 2, zip(a, b)))), a, b))
23+
return list(map(lambda x: {x[1], x[2]}, [min(s, key=lambda x: x[0])]))[0]

Diff for: exam_mock/skeleton/q2/test_q2.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from q2 import closest_pair
2+
3+
4+
def test_2d():
5+
coord_list = [(1, 2), (3, 5), (5, 4), (2, 1), (5, 2)]
6+
closest = closest_pair(coord_list)
7+
expected = {(1, 2), (2, 1)}
8+
print(closest)
9+
assert closest == expected
10+
11+
12+
def test_3d():
13+
coord_list = [(1, 1, 1), (2, 3, 1), (3, 3, 2), (1, 3, 3), (4, 1, 1), (3, 4, 4)]
14+
closest = closest_pair(coord_list)
15+
expected = {(2, 3, 1), (3, 3, 2)}
16+
print(closest)
17+
assert closest == expected
18+
19+
20+
if __name__ == "__main__":
21+
test_2d()
22+
test_3d()
23+

Diff for: exam_mock/skeleton/q3/baby.txt

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Ooh whoa ooh whoa ooh whoa
2+
You know you love me I know you care
3+
Just shout whenever and I 'll be there
4+
You are my love you are my heart
5+
And we will never ever ever be apart
6+
Are we an item Girl quit playin
7+
We 're just friends what are you sayin
8+
Said there 's another look right in my eyes
9+
My first love broke my heart for the first time
10+
And I was like baby baby baby oh
11+
Like baby baby baby no
12+
Like baby baby baby oh
13+
I thought you 'd always be mine mine
14+
Baby baby baby oh
15+
Like baby baby baby no
16+
Like baby baby baby ooh
17+
I thought you 'd always be mine mine
18+
Oh for you I would have done whatever
19+
And I just ca n't believe we ai n't together
20+
And I wan na play it cool
21+
But I 'm losin you
22+
I 'll buy you anything
23+
I 'll buy you any ring
24+
And I 'm in pieces baby fix me
25+
And just shake me 'til you wake me from this bad dream
26+
I 'm goin down down down down
27+
And I ca n't just believe my first love wo n't be around
28+
And I 'm like baby baby baby oh
29+
Like baby baby baby no
30+
Like baby baby baby oh
31+
I thought you 'd always be mine mine
32+
Baby baby baby oh
33+
Like baby baby baby no
34+
Like baby baby baby ooh
35+
I thought you 'd always be mine mine
36+
Luda when I was thirteen I had my first love
37+
There was nobody that compared to my baby
38+
And nobody came between us nor could ever come above
39+
She had me goin crazy
40+
Oh I was starstruck
41+
She woke me up daily
42+
Do n't need no Starbucks woo
43+
She made my heart pound
44+
And skip a beat when I see her in the street and
45+
At school on the playground
46+
But I really wan na see her on the weekend
47+
She know she got me dazin
48+
'Cause she was so amazin
49+
And now my heart is breakin
50+
But I just keep on sayin
51+
Baby baby baby oh
52+
Like baby baby baby no
53+
Like baby baby baby oh
54+
I thought you 'd always be mine mine
55+
Baby baby baby oh
56+
Like baby baby baby no
57+
Like baby baby baby ooh
58+
I thought you 'd always be mine mine
59+
I 'm gone
60+
Yeah yeah yeah
61+
Yeah yeah yeah now I 'm all gone
62+
Yeah yeah yeah
63+
Yeah yeah yeah now I 'm all gone
64+
Yeah yeah yeah
65+
Yeah yeah yeah now I 'm all gone
66+
Gone gone gone I 'm gone

0 commit comments

Comments
 (0)