-
Notifications
You must be signed in to change notification settings - Fork 0
/
7 kyu Letterbox Paint-Squad.py
71 lines (48 loc) · 1.73 KB
/
7 kyu Letterbox Paint-Squad.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
https://www.codewars.com/kata/597d75744f4190857a00008d/train/python
Story
You and a group of friends are earning some extra money in the school holidays by re-painting the numbers on people's letterboxes for a small fee.
Since there are 10 of you in the group each person just concentrates on painting one digit! For example, somebody will paint only the 1's, somebody else will paint only the 2's and so on...
But at the end of the day you realise not everybody did the same amount of work.
To avoid any fights you need to distribute the money fairly. That's where this Kata comes in.
Kata Task
Given the start and end letterbox numbers, write a method to return the frequency of all 10 digits painted.
Example
For start = 125, and end = 132
The letterboxes are
125 = 1, 2, 5
126 = 1, 2, 6
127 = 1, 2, 7
128 = 1, 2, 8
129 = 1, 2, 9
130 = 1, 3, 0
131 = 1, 3, 1
132 = 1, 3, 2
The digit frequencies are:
0 is painted 1 time
1 is painted 9 times
2 is painted 6 times
etc...
and so the method would return [1,9,6,3,0,1,1,1,1,1]
Notes
0 < start <= end
In C, the returned value will be free'd.
"""
def paint_letterboxes(start, finish):
dct = {'0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0}
lst_first = []
lst_second = []
lst_answer = []
for i in range(start, finish + 1):
lst_first.append(i)
lst_first = [str(i) for i in lst_first]
for row in lst_first:
for elem in row:
lst_second.append(elem)
for i in lst_second:
if i in dct.keys():
dct[i] += 1
for k in dct.values():
lst_answer.append(k)
return lst_answer
print(paint_letterboxes(125, 132)) # [1,9,6,3,0,1,1,1,1,1]