├── .idea
├── dictionaries
│ └── UniVoid.xml
└── vcs.xml
├── H22
├── 1-3.py
├── 1-4.py
├── 1.py
├── 10.txt
├── 1000.txt
├── 5.py
├── 7.txt
└── draw_rect.py
├── H23
├── 1.txt
├── 2.py
├── 3.py
├── 4.py
├── 5.py
├── 6.py
├── __init__.py
├── c1.txt
├── c2.txt
├── compress.py
├── decompress.py
├── s1.txt
├── s2.txt
└── s3.txt
├── H24
├── 0.py
├── 1.py
├── 2.py
├── 2_ans.py
├── 3.py
├── 3_ans.py
├── 4.py
├── 4_ans.py
├── 5.py
├── 5_bf.py
├── 5_math.py
├── 5_math_ans.py
├── canvas.txt
├── data1.txt
├── data2.txt
├── draw.py
├── output.txt
└── printf.py
├── H25
├── 1.py
├── 2.py
├── 3.py
├── 4.py
├── 5.py
├── 6.py
├── prog1.txt
└── prog2.txt
├── H26
├── 1.py
├── 2.py
├── 3.py
├── 4.py
└── 6.py
├── H27
├── 1.py
├── 2.py
├── 3.py
├── 4.py
├── 5.py
├── 6.py
├── 7.py
├── program.txt
└── program1.txt
├── H28
├── 1.py
├── 2.py
├── 3.py
├── 4.py
├── 5.py
├── 6.py
└── 7.py
├── H29
└── 6115
│ ├── 1.py
│ ├── 2.py
│ ├── 3.py
│ └── num.py
└── README.md
/.idea/dictionaries/UniVoid.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/H22/1-3.py:
--------------------------------------------------------------------------------
1 | class Rect(object):
2 | x, y, w, h, flag = 0, 0, 0, 0, 0
3 |
4 | def __init__(self, x, y, w, h):
5 | self.x, self.y, self.w, self.h = x, y, w, h
6 |
7 | def set_flag(self, flag):
8 | self.flag = flag
9 |
10 |
11 | def is_intersect(rect1, rect2):
12 | #judged by center point
13 | x1 = rect1.x + float(rect1.w)/2
14 | y1 = rect1.y + float(rect1.h)/2
15 | x2 = rect2.x + float(rect2.w)/2
16 | y2 = rect2.y + float(rect2.h)/2
17 | if abs(x1-x2) == float(rect1.w+rect2.w)/2 and abs(y1-y2) == float(rect1.h+rect2.h)/2:
18 | return False
19 | elif abs(x1-x2) <= float(rect1.w+rect2.w)/2 and abs(y1-y2) <= float(rect1.h+rect2.h)/2:
20 | return True
21 |
22 |
23 | def find(recList, rect):
24 | if recList[rect.flag] == rect:
25 | return rect
26 | else:
27 | return find(recList, recList[rect.flag])
28 |
29 |
30 | def union(recList, rect1, rect2):
31 | root1 = find(recList, rect1)
32 | root2 = find(recList, rect2)
33 | if root1 != root2:
34 | root1.flag = recList.index(root2)
35 | return 0
36 |
37 |
38 | rectList = []
39 | MAX_X = 1000
40 | MAX_Y = 1000
41 |
42 | # NOTICE "10.txt" for Q.1 & "1000.txt" for Q.3
43 | with open("1000.txt", "r") as fin:
44 | for line in fin:
45 | tmp = line.split(" ")
46 | r = Rect(int(tmp[0]), int(tmp[1]), int(tmp[2]), int(tmp[3]))
47 | rectList.append(r)
48 | r.set_flag(len(rectList)-1)
49 |
50 |
51 | # maximum thickness
52 | maxT = 0
53 | f = [[0 for x in range(MAX_X)] for y in range(MAX_Y)]
54 | for rect in rectList:
55 | for i in range(rect.x, rect.x + rect.w):
56 | for j in range(rect.y, rect.y + rect.h):
57 | f[i][j] += 1
58 | for i in range(0, MAX_X):
59 | for j in range(0, MAX_Y):
60 | maxT = max(maxT, f[i][j])
61 | print "Maximum thickness is {}".format(maxT)
62 |
63 |
64 | # the number of clusters
65 | for i in range(0, len(rectList)-1):
66 | for j in range(i+1, len(rectList)):
67 | rect1 = rectList[i]
68 | rect2 = rectList[j]
69 | if is_intersect(rect1, rect2):
70 | union(rectList, rect1, rect2)
71 | sum = 0
72 | for rect in rectList:
73 | if find(rectList, rect) == rect:
74 | sum += 1
75 | print "The number of clusters is {}".format(sum)
76 |
77 |
78 | # the maximum number of cluster elements
79 | dic = {}
80 | for rect in rectList:
81 | tmp = find(rectList, rect)
82 | if tmp in dic:
83 | dic[tmp] += 1
84 | else:
85 | dic[tmp] = 1
86 | # for key, value in dic.iteritems():
87 | # print key, value
88 | print "The maximum number of cluster elements is {}".format(dic[max(dic, key=dic.get)])
89 |
90 |
91 | # the maximum cluster area for a single cluster
92 | import Queue
93 | ans = 0
94 | for i in range(0, MAX_X):
95 | for j in range(0, MAX_Y):
96 | if f[i][j] > 0:
97 | q = Queue.Queue()
98 | sum = 1
99 | f[i][j] = 0
100 | q.put((i, j))
101 | while not q.empty():
102 | x, y = q.get()
103 | for (dx, dy) in [(-1,0), (0, -1), (1, 0), (0, 1)]:
104 | nx, ny = x + dx, y + dy
105 | if (nx >= 0) and (ny >= 0) and (nx <= MAX_X) and (ny <= MAX_Y):
106 | if f[nx][ny] > 0:
107 | sum += 1
108 | f[nx][ny] = 0
109 | q.put((nx, ny))
110 |
111 | ans = max(ans, sum)
112 |
113 | print "the maximum cluster area for a single cluster is {}".format(ans)
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/H22/1-4.py:
--------------------------------------------------------------------------------
1 | import copy
2 | from draw_rect import draw_rect
3 |
4 | MAX_X = 1000
5 | MAX_Y = 1000
6 |
7 |
8 | class Rect(object):
9 | x, y, w, h, flag = 0, 0, 0, 0, 0
10 |
11 | def __init__(self, x, y, w, h):
12 | self.x, self.y, self.w, self.h = x, y, w, h
13 |
14 | def set_flag(self, flag):
15 | self.flag = flag
16 |
17 |
18 | def is_intersect(rect1, rect2):
19 | #judged by center point
20 | x1 = rect1.x + float(rect1.w)/2
21 | y1 = rect1.y + float(rect1.h)/2
22 | x2 = rect2.x + float(rect2.w)/2
23 | y2 = rect2.y + float(rect2.h)/2
24 | if abs(x1-x2) == float(rect1.w+rect2.w)/2 and abs(y1-y2) == float(rect1.h+rect2.h)/2:
25 | return False
26 | elif abs(x1-x2) <= float(rect1.w+rect2.w)/2 and abs(y1-y2) <= float(rect1.h+rect2.h)/2:
27 | return True
28 |
29 |
30 | def find(recList, rect):
31 | if recList[rect.flag] == rect:
32 | return rect
33 | else:
34 | return find(recList, recList[rect.flag])
35 |
36 |
37 | def union(recList, rect1, rect2):
38 | root1 = find(recList, rect1)
39 | root2 = find(recList, rect2)
40 | if root1 != root2:
41 | root1.flag = recList.index(root2)
42 | return 0
43 |
44 |
45 | def get_area(bol, x, y, flag=False):
46 | q.queue.clear()
47 | sum = 1
48 | if flag:
49 | l = list()
50 | l.append((x, y))
51 |
52 | bol[x][y] = 0
53 | q.put((x, y))
54 |
55 | while not q.empty():
56 | x, y = q.get()
57 | for (dx, dy) in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
58 | nx, ny = x + dx, y + dy
59 | if (nx >= 0) and (ny >= 0) and (nx < MAX_X) and (ny < MAX_Y):
60 | if bol[nx][ny] > 0:
61 | sum += 1
62 | bol[nx][ny] = 0
63 | q.put((nx, ny))
64 | if flag:
65 | l.append((nx, ny))
66 | if flag:
67 | return l
68 | else:
69 | return sum
70 |
71 |
72 | rectList = []
73 |
74 | # NOTICE "10.txt" for Q.1 & "1000.txt" for Q.3
75 | with open("1000.txt", "r") as fin:
76 | for line in fin:
77 | tmp = line.split(" ")
78 | r = Rect(int(tmp[0]), int(tmp[1]), int(tmp[2]), int(tmp[3]))
79 | rectList.append(r)
80 | r.set_flag(len(rectList)-1)
81 |
82 |
83 | # draw the map
84 | f = [[0 for x in range(MAX_X)] for y in range(MAX_Y)]
85 | for rect in rectList:
86 | for i in range(rect.x, rect.x + rect.w):
87 | for j in range(rect.y, rect.y + rect.h):
88 | f[i][j] += 1
89 |
90 |
91 | # NOTCIE Answer for Q.2
92 | sum = 0
93 | for i in range(0, MAX_X):
94 | for j in range(0, MAX_Y):
95 | if f[i][j] > 0:
96 | sum += 1
97 | print "The summation of the area of all 1000 rectangles by 1000.txt is {}".format(sum)
98 |
99 |
100 | # maximum thickness
101 | maxT = 0
102 | for i in range(0, MAX_X):
103 | for j in range(0, MAX_Y):
104 | maxT = max(maxT, f[i][j])
105 | print "Maximum thickness is {}".format(maxT)
106 |
107 |
108 | # the number of clusters
109 | for i in range(0, len(rectList)-1):
110 | for j in range(i+1, len(rectList)):
111 | rect1 = rectList[i]
112 | rect2 = rectList[j]
113 | if is_intersect(rect1, rect2):
114 | union(rectList, rect1, rect2)
115 | sum = 0
116 | for rect in rectList:
117 | if find(rectList, rect) == rect:
118 | sum += 1
119 | print "The number of clusters is {}".format(sum)
120 |
121 |
122 | # the maximum number of cluster elements
123 | dic = {}
124 | for rect in rectList:
125 | tmp = find(rectList, rect)
126 | if tmp in dic:
127 | dic[tmp] += 1
128 | else:
129 | dic[tmp] = 1
130 | # for key, value in dic.iteritems():
131 | # print key, value
132 | print "The maximum number of cluster elements is {}".format(dic[max(dic, key=dic.get)])
133 |
134 |
135 | # the maximum cluster area for a single cluster
136 | import Queue
137 | ans = 0
138 | ansx = 0
139 | ansy = 0
140 | bol = copy.deepcopy(f)
141 | q = Queue.Queue()
142 | for i in range(0, MAX_X):
143 | for j in range(0, MAX_Y):
144 | if bol[i][j] > 0:
145 | sum = get_area(bol, i, j)
146 |
147 | if ans < sum:
148 | ansx = i
149 | ansy = j
150 | ans = sum
151 |
152 | print "the maximum cluster area for a single cluster is {}".format(ans)
153 |
154 |
155 | # Q.4
156 | wR = 5
157 | hR = 10
158 | # Q.4-1
159 | sum = 0
160 | # # iterate the left-top coordinate of R
161 | # for i in range(0, MAX_X - wR):
162 | # for j in range(0, MAX_Y - hR):
163 | # flag = 0
164 | # if f[i][j] == maxT:
165 | # print i, j
166 | #
167 | # #iterate the area in R
168 | # for ir in range(i, i + wR):
169 | # for jr in range(j, j + hR):
170 | # if f[ir][jr] == maxT:
171 | # sum += 1
172 | # flag = 1
173 | # if flag:
174 | # break
175 | # if flag:
176 | # break
177 |
178 | # Only (843, 109) and (844, 109) are max thickness...
179 | # so? Let's do some hack
180 | a = 2 # the length of max thickness rect
181 | b = 1 # the height of max thickness rect
182 | sum += (a + wR - 1) * (b + hR - 1)
183 | print "the number of possible arrangements of R is {}".format(sum)
184 |
185 | #Q.4-2
186 |
187 | l = get_area(copy.deepcopy(f), ansx, ansy, flag=True)
188 | draw_rect(l) # what the fucking shape...
189 |
190 | # as brute as I am...
191 | # holy shit I don't care, time should not be wasted on this
192 | ''' idea:
193 | step.1 extract boundary of this shape %'$'%&$&%$&
194 | step.2 try all rect Rs adjoined
195 | step.3 sum up the number of Rs adjoined but not overlapped
196 |
197 | '''
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
--------------------------------------------------------------------------------
/H22/1.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/univoid/CI_AT/9aef00cb4591f6bb015a493248458c0925d231c6/H22/1.py
--------------------------------------------------------------------------------
/H22/10.txt:
--------------------------------------------------------------------------------
1 | 5 1 7 3
2 | 0 15 8 4
3 | 3 3 8 6
4 | 17 0 1 2
5 | 0 12 1 6
6 | 7 12 3 3
7 | 5 17 4 2
8 | 13 4 4 2
9 | 11 9 5 5
10 | 10 3 8 5
11 |
--------------------------------------------------------------------------------
/H22/1000.txt:
--------------------------------------------------------------------------------
1 | 756 448 26 31
2 | 734 145 8 40
3 | 818 65 40 45
4 | 131 491 10 23
5 | 337 689 10 10
6 | 233 146 39 7
7 | 548 9 28 34
8 | 404 931 19 11
9 | 139 11 26 47
10 | 251 639 24 48
11 | 732 325 4 40
12 | 62 404 35 37
13 | 204 467 4 39
14 | 892 455 42 33
15 | 458 804 8 28
16 | 91 322 28 23
17 | 838 376 5 34
18 | 419 228 49 12
19 | 55 524 15 19
20 | 915 866 31 36
21 | 25 88 34 12
22 | 204 339 9 47
23 | 841 568 41 15
24 | 471 356 14 50
25 | 316 793 20 35
26 | 417 660 32 39
27 | 207 520 13 29
28 | 79 885 21 30
29 | 945 200 20 20
30 | 48 917 34 39
31 | 334 257 16 37
32 | 359 54 47 33
33 | 821 10 28 37
34 | 797 21 26 43
35 | 623 452 42 2
36 | 140 750 38 28
37 | 506 658 13 35
38 | 359 369 9 10
39 | 921 135 48 27
40 | 626 965 24 19
41 | 714 391 29 27
42 | 940 736 34 3
43 | 412 785 49 26
44 | 583 78 27 28
45 | 975 618 18 18
46 | 726 879 42 43
47 | 717 827 38 12
48 | 621 11 29 39
49 | 536 721 5 9
50 | 487 293 7 32
51 | 617 423 14 49
52 | 525 501 36 9
53 | 436 255 35 23
54 | 24 250 28 7
55 | 58 949 4 32
56 | 853 19 5 31
57 | 583 430 29 18
58 | 343 739 11 32
59 | 247 277 10 44
60 | 489 308 37 4
61 | 374 230 39 36
62 | 493 486 42 44
63 | 948 38 46 33
64 | 6 532 33 25
65 | 178 474 10 8
66 | 714 369 14 21
67 | 631 213 6 9
68 | 452 992 13 6
69 | 201 948 25 16
70 | 602 182 16 16
71 | 433 742 1 46
72 | 271 902 47 8
73 | 508 324 18 26
74 | 499 667 17 42
75 | 798 579 47 7
76 | 709 67 18 1
77 | 866 284 44 45
78 | 558 36 10 1
79 | 262 436 39 21
80 | 607 293 22 23
81 | 774 188 22 25
82 | 556 210 29 15
83 | 367 799 30 9
84 | 54 571 8 46
85 | 141 380 32 23
86 | 53 93 17 35
87 | 481 44 24 15
88 | 79 874 42 19
89 | 527 731 40 46
90 | 104 968 29 25
91 | 548 867 2 24
92 | 602 691 20 3
93 | 540 399 12 12
94 | 846 727 22 18
95 | 385 707 38 11
96 | 665 962 27 20
97 | 245 673 12 8
98 | 61 830 39 48
99 | 908 358 39 45
100 | 122 311 9 32
101 | 775 368 12 28
102 | 271 342 50 35
103 | 942 866 11 22
104 | 425 717 4 38
105 | 369 691 34 27
106 | 580 392 14 18
107 | 764 501 7 41
108 | 587 226 25 25
109 | 40 326 28 32
110 | 531 625 36 14
111 | 915 662 19 33
112 | 595 337 22 50
113 | 335 626 41 7
114 | 37 550 5 33
115 | 186 234 39 36
116 | 683 500 46 13
117 | 218 751 40 18
118 | 151 853 44 29
119 | 957 518 15 17
120 | 499 834 27 39
121 | 228 165 7 26
122 | 842 355 26 28
123 | 561 45 24 43
124 | 442 835 4 21
125 | 183 856 44 11
126 | 925 176 29 2
127 | 819 112 18 18
128 | 826 28 22 42
129 | 632 516 13 11
130 | 93 20 5 16
131 | 303 559 23 23
132 | 280 51 12 38
133 | 949 110 33 8
134 | 321 175 16 17
135 | 610 108 5 20
136 | 133 96 8 45
137 | 13 20 45 18
138 | 911 558 12 44
139 | 33 291 13 46
140 | 566 386 34 13
141 | 698 576 37 40
142 | 105 74 23 8
143 | 147 910 10 18
144 | 330 236 22 32
145 | 719 431 7 46
146 | 981 232 14 25
147 | 227 395 35 44
148 | 270 689 23 25
149 | 439 709 47 50
150 | 528 942 17 34
151 | 674 609 19 38
152 | 727 43 20 47
153 | 713 762 1 47
154 | 638 745 31 50
155 | 378 444 48 29
156 | 685 899 28 14
157 | 5 251 25 23
158 | 43 106 46 34
159 | 166 673 16 29
160 | 985 368 8 43
161 | 881 13 23 40
162 | 905 148 16 18
163 | 141 833 24 40
164 | 416 416 5 3
165 | 338 658 5 8
166 | 316 625 19 8
167 | 572 838 17 43
168 | 689 316 43 17
169 | 535 406 29 8
170 | 843 81 27 39
171 | 372 642 24 48
172 | 146 301 13 44
173 | 316 916 47 28
174 | 926 112 22 9
175 | 319 637 5 44
176 | 851 839 32 47
177 | 248 760 49 47
178 | 484 800 33 6
179 | 809 624 24 40
180 | 226 94 38 9
181 | 659 199 49 37
182 | 197 356 16 27
183 | 646 219 36 17
184 | 365 656 46 27
185 | 68 73 9 14
186 | 714 103 30 34
187 | 713 116 11 30
188 | 170 941 38 38
189 | 513 628 24 17
190 | 48 907 31 26
191 | 233 456 23 44
192 | 129 107 43 45
193 | 236 927 9 13
194 | 946 463 12 32
195 | 227 345 35 43
196 | 628 823 38 12
197 | 138 464 33 33
198 | 133 327 13 2
199 | 388 678 35 21
200 | 654 491 48 43
201 | 872 15 7 32
202 | 490 366 2 18
203 | 641 32 33 42
204 | 756 42 46 25
205 | 4 581 21 32
206 | 827 126 15 3
207 | 500 415 45 14
208 | 124 335 26 31
209 | 339 852 8 41
210 | 172 91 45 37
211 | 721 104 43 3
212 | 170 958 6 26
213 | 333 161 44 21
214 | 599 946 4 36
215 | 857 294 8 15
216 | 358 596 12 7
217 | 589 494 9 37
218 | 882 338 34 17
219 | 584 551 2 9
220 | 277 220 36 35
221 | 466 488 12 23
222 | 615 69 29 2
223 | 819 881 38 21
224 | 277 860 46 23
225 | 921 306 7 41
226 | 506 330 15 44
227 | 837 268 30 48
228 | 960 772 24 12
229 | 23 172 25 50
230 | 615 51 43 30
231 | 969 363 17 45
232 | 584 870 37 49
233 | 630 300 48 26
234 | 176 914 11 22
235 | 670 585 29 34
236 | 0 757 41 17
237 | 470 679 40 39
238 | 528 256 43 1
239 | 561 537 9 6
240 | 609 649 5 43
241 | 670 81 33 38
242 | 642 383 45 11
243 | 687 590 8 32
244 | 441 773 9 19
245 | 129 984 36 14
246 | 870 213 32 16
247 | 458 410 4 1
248 | 489 456 5 31
249 | 817 741 18 41
250 | 967 213 2 37
251 | 163 232 32 8
252 | 592 118 35 15
253 | 146 196 41 45
254 | 674 238 47 6
255 | 4 758 6 13
256 | 739 176 34 10
257 | 430 367 37 32
258 | 790 663 38 33
259 | 76 299 36 10
260 | 807 839 9 10
261 | 358 372 3 12
262 | 796 536 20 47
263 | 929 98 17 23
264 | 795 372 9 18
265 | 161 935 49 4
266 | 641 901 41 32
267 | 807 428 23 33
268 | 938 23 11 33
269 | 661 807 3 11
270 | 51 306 14 3
271 | 387 812 39 42
272 | 874 365 50 39
273 | 628 831 42 30
274 | 643 166 50 10
275 | 448 236 8 23
276 | 229 932 45 41
277 | 77 256 35 17
278 | 407 327 29 33
279 | 509 196 22 10
280 | 216 655 33 14
281 | 824 714 5 28
282 | 751 339 16 11
283 | 453 258 24 24
284 | 882 737 44 37
285 | 620 828 43 18
286 | 906 657 39 33
287 | 668 241 25 19
288 | 194 638 47 13
289 | 418 851 17 10
290 | 476 660 12 21
291 | 143 383 28 31
292 | 389 453 43 23
293 | 389 380 23 23
294 | 20 688 5 32
295 | 363 295 28 30
296 | 270 267 37 46
297 | 496 961 10 31
298 | 848 335 42 10
299 | 896 865 5 41
300 | 492 276 25 43
301 | 227 451 19 15
302 | 812 764 9 4
303 | 744 473 40 1
304 | 749 940 35 2
305 | 151 932 8 32
306 | 150 824 10 18
307 | 28 420 49 13
308 | 800 109 45 22
309 | 876 9 16 22
310 | 231 461 11 36
311 | 399 748 2 44
312 | 25 847 31 29
313 | 223 862 31 12
314 | 125 426 38 48
315 | 464 750 7 17
316 | 101 877 46 46
317 | 659 403 12 37
318 | 100 445 20 22
319 | 371 747 18 22
320 | 504 67 21 31
321 | 457 317 45 2
322 | 185 453 18 14
323 | 259 954 35 37
324 | 719 334 33 44
325 | 926 503 37 2
326 | 968 351 30 45
327 | 475 725 40 8
328 | 358 806 5 4
329 | 10 74 5 23
330 | 645 257 19 17
331 | 3 729 34 36
332 | 300 633 10 22
333 | 788 458 25 44
334 | 23 193 34 42
335 | 550 657 11 46
336 | 298 143 22 13
337 | 892 394 3 34
338 | 670 944 3 44
339 | 963 534 26 34
340 | 372 89 41 31
341 | 41 331 36 42
342 | 274 221 23 4
343 | 763 7 35 16
344 | 654 913 19 17
345 | 284 41 48 16
346 | 575 605 32 5
347 | 418 118 1 12
348 | 377 839 35 45
349 | 495 351 17 22
350 | 34 108 12 6
351 | 272 852 36 48
352 | 602 632 2 2
353 | 572 470 21 34
354 | 717 236 47 48
355 | 255 659 42 9
356 | 77 124 37 15
357 | 192 879 10 21
358 | 475 417 9 2
359 | 304 655 23 8
360 | 722 976 35 11
361 | 135 54 16 27
362 | 772 641 7 39
363 | 588 220 26 36
364 | 693 155 48 12
365 | 938 925 6 14
366 | 73 695 50 37
367 | 284 698 3 46
368 | 967 648 10 44
369 | 159 203 7 42
370 | 774 598 2 21
371 | 127 172 3 35
372 | 416 350 50 26
373 | 850 37 47 32
374 | 819 224 28 39
375 | 130 639 46 36
376 | 585 867 3 19
377 | 589 665 17 5
378 | 629 366 28 39
379 | 806 757 2 50
380 | 681 880 38 50
381 | 498 603 34 11
382 | 552 736 29 39
383 | 84 137 39 48
384 | 288 764 20 24
385 | 273 780 9 35
386 | 538 227 29 30
387 | 620 256 35 21
388 | 725 898 28 41
389 | 411 473 43 6
390 | 273 570 6 13
391 | 85 385 42 39
392 | 483 787 28 1
393 | 241 691 21 44
394 | 690 823 9 41
395 | 538 670 35 13
396 | 732 220 21 44
397 | 380 363 45 24
398 | 705 169 14 31
399 | 208 915 16 42
400 | 836 74 50 15
401 | 101 167 33 47
402 | 314 473 27 42
403 | 508 775 27 48
404 | 20 386 9 31
405 | 969 559 13 12
406 | 802 851 19 12
407 | 11 207 5 41
408 | 77 884 34 39
409 | 362 601 18 38
410 | 131 821 14 37
411 | 707 936 5 13
412 | 766 104 11 32
413 | 682 936 9 43
414 | 488 602 49 26
415 | 85 183 42 32
416 | 457 97 16 21
417 | 546 119 7 5
418 | 185 463 8 11
419 | 264 670 48 24
420 | 126 949 40 37
421 | 184 619 28 50
422 | 144 590 16 3
423 | 872 767 18 12
424 | 912 238 26 24
425 | 337 851 50 22
426 | 433 812 28 46
427 | 421 920 31 41
428 | 817 82 38 49
429 | 734 586 45 39
430 | 339 389 13 1
431 | 927 599 18 17
432 | 152 577 35 30
433 | 663 118 33 29
434 | 327 880 33 23
435 | 1 956 17 11
436 | 973 626 14 48
437 | 902 833 22 1
438 | 72 765 4 41
439 | 589 942 16 43
440 | 649 432 17 20
441 | 506 675 48 8
442 | 195 499 3 26
443 | 773 370 25 38
444 | 147 723 13 50
445 | 258 887 32 34
446 | 370 71 29 2
447 | 235 745 42 18
448 | 9 840 50 50
449 | 89 565 9 11
450 | 41 401 38 26
451 | 938 6 2 14
452 | 32 217 9 30
453 | 502 345 5 31
454 | 607 115 29 45
455 | 660 241 12 20
456 | 608 355 19 9
457 | 76 685 49 44
458 | 825 280 30 30
459 | 788 109 10 29
460 | 62 207 19 4
461 | 394 164 49 44
462 | 888 275 10 14
463 | 224 924 47 7
464 | 288 668 23 29
465 | 869 663 10 21
466 | 198 333 44 11
467 | 545 140 33 16
468 | 183 860 23 38
469 | 716 913 35 23
470 | 816 721 20 29
471 | 743 80 29 31
472 | 77 244 35 14
473 | 845 909 4 18
474 | 880 278 20 42
475 | 416 910 17 31
476 | 730 878 50 8
477 | 746 263 43 45
478 | 834 103 2 5
479 | 771 291 35 32
480 | 0 460 13 44
481 | 752 795 14 5
482 | 938 213 22 7
483 | 350 701 13 30
484 | 265 445 16 1
485 | 9 403 1 16
486 | 749 656 39 44
487 | 397 148 50 5
488 | 408 62 21 7
489 | 620 520 26 34
490 | 315 786 43 42
491 | 613 20 41 47
492 | 864 724 11 10
493 | 234 549 37 1
494 | 819 327 50 46
495 | 430 988 25 2
496 | 122 796 6 4
497 | 547 315 31 20
498 | 727 217 26 8
499 | 649 772 22 10
500 | 549 577 19 16
501 | 393 455 2 42
502 | 880 438 18 45
503 | 68 374 41 14
504 | 715 557 20 15
505 | 469 613 33 2
506 | 222 871 2 1
507 | 353 119 33 27
508 | 203 906 15 30
509 | 941 815 42 40
510 | 682 359 29 36
511 | 739 345 3 16
512 | 467 312 19 50
513 | 664 552 46 6
514 | 616 912 33 27
515 | 341 785 34 40
516 | 941 128 41 26
517 | 330 314 34 3
518 | 561 963 45 25
519 | 245 52 12 44
520 | 427 110 48 3
521 | 304 82 16 6
522 | 347 226 37 22
523 | 193 922 16 10
524 | 33 575 9 42
525 | 314 446 14 39
526 | 146 993 3 3
527 | 905 756 8 24
528 | 319 20 33 1
529 | 785 663 7 22
530 | 193 695 42 8
531 | 266 582 14 14
532 | 205 912 8 30
533 | 141 584 29 10
534 | 99 408 26 35
535 | 946 232 41 14
536 | 771 542 32 17
537 | 465 856 37 37
538 | 169 510 46 26
539 | 568 307 30 9
540 | 138 314 30 1
541 | 861 681 42 3
542 | 403 751 24 4
543 | 504 295 16 19
544 | 238 218 49 10
545 | 901 48 47 30
546 | 60 923 15 31
547 | 780 390 24 17
548 | 41 344 22 18
549 | 439 580 17 29
550 | 443 178 7 19
551 | 131 856 18 24
552 | 667 13 17 19
553 | 341 799 41 41
554 | 632 212 17 26
555 | 285 276 31 10
556 | 312 410 39 50
557 | 659 175 41 5
558 | 559 27 48 26
559 | 59 943 33 36
560 | 147 375 22 10
561 | 384 480 21 6
562 | 573 56 31 7
563 | 509 113 34 5
564 | 136 507 28 23
565 | 769 560 33 40
566 | 523 374 46 36
567 | 452 560 21 11
568 | 535 199 42 35
569 | 702 689 34 5
570 | 783 695 18 10
571 | 324 844 41 10
572 | 502 676 47 7
573 | 91 453 49 49
574 | 177 64 27 9
575 | 469 232 7 27
576 | 535 893 10 23
577 | 98 953 16 30
578 | 947 475 17 46
579 | 36 581 36 19
580 | 827 87 36 48
581 | 783 510 12 6
582 | 2 97 31 6
583 | 503 543 9 1
584 | 104 454 35 26
585 | 122 238 23 40
586 | 596 648 47 41
587 | 362 709 48 5
588 | 849 745 13 44
589 | 700 631 11 35
590 | 664 754 20 8
591 | 494 497 24 46
592 | 262 298 12 10
593 | 287 699 14 31
594 | 524 298 17 27
595 | 855 414 42 42
596 | 923 648 34 30
597 | 470 337 27 40
598 | 373 383 26 42
599 | 712 178 42 10
600 | 904 275 12 45
601 | 242 724 35 19
602 | 28 692 18 46
603 | 647 163 10 40
604 | 968 323 31 26
605 | 327 29 22 22
606 | 895 49 5 17
607 | 289 585 48 12
608 | 877 42 49 38
609 | 574 108 25 9
610 | 335 42 20 3
611 | 633 891 8 33
612 | 506 510 43 14
613 | 148 523 1 5
614 | 47 470 1 33
615 | 291 626 42 25
616 | 82 687 16 45
617 | 233 222 48 30
618 | 634 538 37 2
619 | 715 933 17 8
620 | 296 315 15 24
621 | 818 869 48 3
622 | 301 513 15 50
623 | 127 224 19 10
624 | 34 113 16 33
625 | 290 731 40 49
626 | 920 675 50 31
627 | 383 946 38 8
628 | 223 954 34 16
629 | 461 977 3 22
630 | 864 101 13 34
631 | 167 682 26 33
632 | 68 852 30 17
633 | 96 261 20 17
634 | 103 794 49 34
635 | 444 619 21 22
636 | 398 210 36 36
637 | 186 398 39 22
638 | 877 405 14 8
639 | 101 680 10 10
640 | 124 906 24 37
641 | 855 540 49 1
642 | 360 85 3 11
643 | 463 715 42 13
644 | 92 172 23 15
645 | 372 28 17 37
646 | 607 761 25 18
647 | 410 254 4 10
648 | 765 938 23 50
649 | 147 914 9 13
650 | 377 328 23 41
651 | 18 829 19 10
652 | 212 985 25 11
653 | 495 69 19 27
654 | 686 142 43 2
655 | 636 670 10 8
656 | 31 695 38 1
657 | 486 750 38 23
658 | 142 206 8 14
659 | 538 787 14 14
660 | 839 504 20 46
661 | 410 307 13 40
662 | 319 308 41 42
663 | 859 297 41 1
664 | 568 170 18 4
665 | 120 573 46 30
666 | 320 306 7 44
667 | 167 352 10 24
668 | 918 14 24 2
669 | 242 414 19 45
670 | 624 334 2 14
671 | 807 325 22 43
672 | 654 673 10 4
673 | 950 394 27 28
674 | 757 751 1 32
675 | 587 21 20 29
676 | 460 915 48 32
677 | 344 296 43 47
678 | 564 650 11 4
679 | 723 42 24 8
680 | 399 508 5 20
681 | 836 170 45 5
682 | 894 252 17 33
683 | 0 931 16 43
684 | 496 754 29 36
685 | 382 21 19 11
686 | 186 507 21 48
687 | 501 688 8 5
688 | 580 634 11 42
689 | 925 935 3 15
690 | 622 34 4 15
691 | 85 437 41 16
692 | 726 747 31 5
693 | 482 723 39 24
694 | 382 425 21 26
695 | 713 957 46 10
696 | 837 50 42 27
697 | 440 419 18 7
698 | 450 679 50 43
699 | 721 604 48 13
700 | 845 741 26 29
701 | 885 317 1 31
702 | 227 416 28 16
703 | 869 412 7 13
704 | 231 460 13 16
705 | 872 49 22 23
706 | 199 447 27 3
707 | 619 669 22 22
708 | 808 94 46 25
709 | 746 178 7 28
710 | 670 303 23 46
711 | 822 671 36 3
712 | 301 386 8 36
713 | 723 22 17 5
714 | 310 294 46 20
715 | 556 664 9 30
716 | 659 346 21 12
717 | 332 311 27 33
718 | 597 951 30 2
719 | 130 939 27 33
720 | 649 807 13 38
721 | 63 220 14 44
722 | 120 185 32 4
723 | 68 430 6 36
724 | 476 385 30 50
725 | 752 916 2 3
726 | 896 336 48 36
727 | 175 393 36 36
728 | 920 686 44 26
729 | 218 194 45 23
730 | 932 532 41 9
731 | 931 474 17 27
732 | 282 582 15 44
733 | 544 812 20 40
734 | 679 491 23 13
735 | 151 522 48 40
736 | 374 360 19 28
737 | 924 414 10 50
738 | 235 505 13 7
739 | 612 472 29 41
740 | 638 418 6 21
741 | 546 803 18 28
742 | 194 7 34 19
743 | 850 344 40 13
744 | 646 750 11 32
745 | 629 680 37 49
746 | 706 65 20 26
747 | 309 528 3 25
748 | 109 547 29 1
749 | 666 181 46 16
750 | 952 284 36 2
751 | 85 479 23 35
752 | 634 856 37 15
753 | 861 313 8 43
754 | 780 322 12 17
755 | 782 886 45 8
756 | 894 525 30 8
757 | 356 620 45 31
758 | 893 356 18 8
759 | 933 308 13 27
760 | 605 299 49 34
761 | 814 63 19 32
762 | 840 802 28 16
763 | 920 886 9 21
764 | 512 717 24 15
765 | 802 276 6 30
766 | 932 52 7 28
767 | 739 537 13 2
768 | 205 664 14 12
769 | 644 932 6 5
770 | 73 877 8 40
771 | 772 152 24 24
772 | 509 578 9 1
773 | 293 312 48 21
774 | 229 422 14 11
775 | 97 495 7 15
776 | 905 256 1 11
777 | 318 773 29 32
778 | 126 410 28 49
779 | 281 22 29 14
780 | 18 388 20 26
781 | 779 580 49 44
782 | 383 79 15 30
783 | 283 656 31 18
784 | 227 541 49 12
785 | 191 780 22 25
786 | 897 882 4 22
787 | 104 580 10 34
788 | 561 348 13 5
789 | 456 584 46 38
790 | 799 903 4 18
791 | 821 332 24 41
792 | 876 981 32 15
793 | 670 616 41 20
794 | 77 305 48 48
795 | 25 916 22 39
796 | 61 349 23 45
797 | 439 213 19 36
798 | 434 305 17 7
799 | 907 895 19 45
800 | 54 716 10 38
801 | 980 47 1 37
802 | 360 743 21 45
803 | 195 42 42 14
804 | 440 906 49 12
805 | 250 610 23 46
806 | 617 887 19 43
807 | 815 920 50 49
808 | 371 312 6 19
809 | 256 440 11 43
810 | 832 256 3 33
811 | 290 417 10 34
812 | 157 175 15 10
813 | 245 644 30 16
814 | 542 80 1 42
815 | 247 422 2 44
816 | 559 0 27 25
817 | 416 102 13 4
818 | 809 823 10 36
819 | 693 337 49 30
820 | 271 618 27 34
821 | 88 335 20 25
822 | 673 493 24 23
823 | 454 3 15 23
824 | 841 107 9 44
825 | 871 189 49 7
826 | 718 302 5 49
827 | 214 273 27 2
828 | 889 546 33 28
829 | 226 818 21 47
830 | 657 338 13 28
831 | 596 811 44 14
832 | 715 167 33 10
833 | 818 720 8 15
834 | 180 840 36 28
835 | 737 933 7 9
836 | 627 749 12 23
837 | 241 104 36 41
838 | 111 301 35 41
839 | 732 177 7 23
840 | 654 131 21 41
841 | 141 902 40 1
842 | 193 864 19 43
843 | 197 187 25 48
844 | 55 909 7 47
845 | 733 251 1 8
846 | 238 459 35 26
847 | 127 663 42 19
848 | 811 741 23 50
849 | 594 840 36 40
850 | 215 927 44 42
851 | 236 499 41 9
852 | 0 332 28 50
853 | 354 50 2 33
854 | 238 934 8 49
855 | 830 20 1 38
856 | 219 616 24 41
857 | 184 261 4 16
858 | 534 436 44 48
859 | 400 179 30 20
860 | 920 443 45 2
861 | 819 456 5 49
862 | 584 881 12 45
863 | 141 453 35 7
864 | 655 177 44 12
865 | 780 695 7 30
866 | 103 491 38 8
867 | 391 897 44 6
868 | 121 405 26 31
869 | 702 283 30 14
870 | 639 631 34 28
871 | 488 309 10 7
872 | 419 473 36 39
873 | 103 165 15 45
874 | 539 591 14 25
875 | 888 122 28 23
876 | 564 44 23 14
877 | 844 282 21 4
878 | 418 602 32 5
879 | 507 377 18 32
880 | 857 308 29 22
881 | 571 381 21 10
882 | 759 649 12 38
883 | 199 400 15 19
884 | 4 584 40 6
885 | 913 86 26 40
886 | 867 663 20 26
887 | 34 514 3 10
888 | 945 374 2 18
889 | 724 548 34 41
890 | 606 979 28 1
891 | 17 638 15 46
892 | 848 756 2 50
893 | 39 839 24 30
894 | 236 519 7 10
895 | 557 431 6 7
896 | 785 786 21 17
897 | 10 233 13 30
898 | 915 726 18 26
899 | 754 462 47 27
900 | 26 276 35 34
901 | 626 337 29 44
902 | 933 18 44 34
903 | 192 270 9 20
904 | 65 678 29 33
905 | 394 451 8 48
906 | 893 471 17 28
907 | 450 875 2 45
908 | 813 456 3 25
909 | 481 764 49 46
910 | 385 686 20 27
911 | 37 436 16 17
912 | 336 53 35 34
913 | 99 736 26 12
914 | 802 445 3 4
915 | 546 564 5 12
916 | 389 342 8 26
917 | 46 723 29 50
918 | 234 380 15 2
919 | 12 457 43 44
920 | 446 48 29 21
921 | 357 904 38 3
922 | 630 444 29 45
923 | 400 294 1 26
924 | 361 831 4 7
925 | 910 478 29 26
926 | 921 512 50 35
927 | 406 720 7 43
928 | 222 54 47 3
929 | 482 673 18 22
930 | 696 644 33 30
931 | 467 398 47 17
932 | 631 36 37 29
933 | 32 384 20 29
934 | 333 155 10 20
935 | 353 356 49 14
936 | 220 350 46 16
937 | 589 504 41 47
938 | 830 408 31 48
939 | 50 736 39 4
940 | 794 144 40 29
941 | 965 495 11 26
942 | 819 22 47 28
943 | 220 652 7 6
944 | 419 355 33 35
945 | 88 278 31 12
946 | 317 890 11 29
947 | 642 941 11 1
948 | 34 971 22 12
949 | 677 364 1 30
950 | 473 813 24 46
951 | 806 69 44 48
952 | 865 79 12 2
953 | 623 896 10 20
954 | 744 551 17 17
955 | 344 263 49 22
956 | 656 575 45 2
957 | 286 470 40 49
958 | 809 720 48 16
959 | 857 922 34 26
960 | 706 895 32 23
961 | 717 62 3 34
962 | 325 522 47 16
963 | 203 100 30 22
964 | 869 263 8 40
965 | 400 326 9 47
966 | 491 522 2 3
967 | 204 774 46 30
968 | 700 519 6 9
969 | 525 352 9 29
970 | 551 10 44 12
971 | 892 284 17 30
972 | 459 949 24 14
973 | 507 687 25 50
974 | 552 862 38 25
975 | 246 402 49 30
976 | 987 567 7 20
977 | 541 647 45 35
978 | 648 809 47 10
979 | 591 548 28 41
980 | 14 441 19 35
981 | 561 63 44 5
982 | 775 792 50 46
983 | 71 144 6 13
984 | 233 136 30 15
985 | 455 63 17 25
986 | 556 949 2 13
987 | 520 852 18 42
988 | 424 916 1 5
989 | 350 264 29 6
990 | 414 918 47 41
991 | 114 48 26 27
992 | 128 797 48 3
993 | 829 79 2 37
994 | 87 928 36 14
995 | 634 315 8 27
996 | 828 765 31 44
997 | 893 442 10 15
998 | 12 303 32 49
999 | 651 17 23 28
1000 | 223 773 6 17
1001 |
--------------------------------------------------------------------------------
/H22/5.py:
--------------------------------------------------------------------------------
1 | ''' idea:
2 | step.1 initialize a queue Q
3 | step.2 put a rectangle R into Q and set attr of R = 1
4 | step.3 analyze all the overlapped rectangles of R with other rectangle in Q
5 | step.4 put all those rectangle (e.g. B = R overlap A ) into Q and set attr deep of B = max(R, A) + 1
6 | step.5 repeat step.2~4 until all rectangles were in Q
7 | step.6 print the final answer = max
8 | '''
--------------------------------------------------------------------------------
/H22/7.txt:
--------------------------------------------------------------------------------
1 | 1 1 6 4
2 | 4 2 2 2
3 | 5 3 6 4
4 | 13 0 2 8
5 | 15 6 1 1
6 | 16 2 1 7
7 | 11 1 5 2
8 |
--------------------------------------------------------------------------------
/H22/draw_rect.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plt
2 |
3 |
4 | def draw_rect(l):
5 | plt.scatter(*zip(*l))
6 | plt.show()
7 |
--------------------------------------------------------------------------------
/H23/1.txt:
--------------------------------------------------------------------------------
1 | aabbbaaabbbacabbbaabbbacaa
2 | aabbccdd000dd002aa
--------------------------------------------------------------------------------
/H23/2.py:
--------------------------------------------------------------------------------
1 | def cal_num_indic_str(file):
2 | list = []
3 | with open(file, "r") as strFile:
4 | s = strFile.read()
5 | i = 0
6 | while i < len(s):
7 |
8 | if unicode(s[i]).isdecimal():
9 | num = s[i:i+3]
10 | if num not in list:
11 | list.append(num)
12 | i += 2
13 | i += 1
14 | return len(list)
15 |
16 | print "the number of replacement-indication strings in c1.txt is {}".format(cal_num_indic_str("c1.txt"))
17 | print "the number of replacement-indication strings in c1.txt is {}".format(cal_num_indic_str("c2.txt"))
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/H23/3.py:
--------------------------------------------------------------------------------
1 | from compress import make_dic
2 |
3 | with open("s1.txt", "r") as strFile:
4 | s = strFile.read()
5 | dic = make_dic(s)
6 | print len(dic)
7 | print dic
8 |
--------------------------------------------------------------------------------
/H23/4.py:
--------------------------------------------------------------------------------
1 | from compress import compress_str
2 |
3 | with open("s1.txt", "r") as strFile:
4 | s = strFile.read()
5 | print "compressed string of s1.txt is \"{}\"".format(compress_str(s))
6 |
7 | with open("s2.txt", "r") as strFile:
8 | s = strFile.read()
9 | print "compressed string of s2.txt is \"{}\"".format(compress_str(s))
10 |
11 |
12 |
--------------------------------------------------------------------------------
/H23/5.py:
--------------------------------------------------------------------------------
1 | from decompress import decompress_str
2 |
3 | with open("c1.txt", "r") as strFile:
4 | s = strFile.read()
5 | print "the original string of c1.txt is \"{}\"".format(decompress_str(s))
6 |
7 |
8 | with open("c2.txt", "r") as strFile:
9 | s = strFile.read()
10 | # print "the original string of c2.txt is \"{}\"".format(decompress_str(s))
11 | print decompress_str(s)
--------------------------------------------------------------------------------
/H23/6.py:
--------------------------------------------------------------------------------
1 | from compress import compress_str
2 | from decompress import decompress_str
3 | import filecmp
4 |
5 |
6 | def slice_compress(fin, fout):
7 | max_size = 1000
8 | with open(fin, "r") as inFile:
9 | with open(fout, "w") as outFile:
10 | while True:
11 | buf = inFile.read(max_size)
12 | if not buf:
13 | break
14 | outFile.write(compress_str(buf))
15 | outFile.write("&")
16 |
17 |
18 | def slice_decompress(fin, fout):
19 | with open(fin, "r") as inFile:
20 | with open(fout, "w") as outFile:
21 | while True:
22 | buf = ""
23 | while True:
24 | c = inFile.read(1)
25 | if not c or c == "&":
26 | break
27 | buf += c
28 |
29 | if not buf:
30 | break
31 |
32 | outFile.write(decompress_str(buf))
33 |
34 | slice_compress("s3.txt", "compress6.txt")
35 | print "File compression completed"
36 | slice_decompress("compress6.txt", "decompress6.txt")
37 | print "File decompression completed"
38 |
39 | if filecmp.cmp("s3.txt", "decompress6.txt"):
40 | print "The processes is correct"
41 | else:
42 | print "Sad......"
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/H23/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/univoid/CI_AT/9aef00cb4591f6bb015a493248458c0925d231c6/H23/__init__.py
--------------------------------------------------------------------------------
/H23/c1.txt:
--------------------------------------------------------------------------------
1 | she sells seashells by the009ore.022014000lls are surely009ells.
--------------------------------------------------------------------------------
/H23/c2.txt:
--------------------------------------------------------------------------------
1 | peter piper picked a peck of pickled peppers018024030036rs 000006012. if070005011017023029035ers, wheres the020026032038070005011d .194194194194194. she sells seashells by246246 by the236ore.264241227lls are surely236ells. so if226232241on264270e, im sure226232270281ls. .,397397397397397 but,226aid, the butters bitter. if i put it in my batter, it will make479tter456r. but a bit of be509u485that would498480ter534r. so she bough524530u459535 than h511538459and she469t i625483644the482r was not456581twas534574y bo509592526532538tter.
--------------------------------------------------------------------------------
/H23/compress.py:
--------------------------------------------------------------------------------
1 | def make_dic(s):
2 | dic = {}
3 | i = 0
4 | while i+6 < len(s):
5 | if s[i:i+6] not in dic:
6 | val = str(i)
7 | while len(val) < 3:
8 | val = "0" + val
9 | dic[s[i:i+6]] = val
10 | i += 1
11 | return dic
12 |
13 | def compress_str(s):
14 | dic = make_dic(s)
15 | s_ans = str()
16 | i = 0
17 | while i < len(s):
18 | substr = s[i:i+6]
19 | if substr in dic and int(dic[substr]) != i:
20 | s_ans += dic[substr]
21 | i += 6
22 | else:
23 | s_ans += s[i]
24 | i += 1
25 | return s_ans
26 |
27 |
28 |
--------------------------------------------------------------------------------
/H23/decompress.py:
--------------------------------------------------------------------------------
1 | def decompress_str(s):
2 | s_ans = str()
3 | i = 0
4 |
5 | while i < len(s):
6 | if unicode(s[i]).isdecimal():
7 | num = int(s[i:i+3])
8 | if num+6 <= len(s_ans):
9 | s_ans += s_ans[num:num+6]
10 | else:
11 | suffix = len(s_ans)-num
12 | s_ans += s_ans[num:len(s_ans)] * (6 / suffix) + s_ans[num:num + 6 % suffix]
13 |
14 | i += 3
15 | else:
16 | s_ans += s[i]
17 | i += 1
18 |
19 | return s_ans
20 |
--------------------------------------------------------------------------------
/H23/s1.txt:
--------------------------------------------------------------------------------
1 | london bridge is falling down, falling down, falling down, london bridge is falling down,
--------------------------------------------------------------------------------
/H23/s2.txt:
--------------------------------------------------------------------------------
1 | london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady.
--------------------------------------------------------------------------------
/H23/s3.txt:
--------------------------------------------------------------------------------
1 | london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxx london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... london bridge is broken down, falling down, falling down. london bridge is falling down, my fair lady. ...... build it up with wood and clay, wood and clay, wood and clay, build it up with wood and clay, my fair lady. ...... wood and clay will wash away, wash away, wash away, wood and clay will wash away, my fair lady. ...... build it up with bricks and mortar, bricks and mortar, bricks and mortar, build it up with bricks and mortar, my fair lady. ...... bricks and mortar will not stay, will not stay, will not stay, bricks and mortar will not stay, my fair lady. ........................ build it up with iron and steel, iron and steel, iron and steel, build it up with iron and steel, my fair lady. .,.,.,.,.,.,.,.,.,.,.,.,., iron and steel will bend and bow, bend and bow, bend and bow, iron and steel will bend and bow, my fair ah ah ah ah ah ah ah lady. build it up with silver and gold, silver and gold, silver and gold, build it up with silver and gold, my fair ahhhhhhhhhhhhhhhhhh lady. ................................... ..... london bridge is falling down, falling down, falling down, london bridge is falling down,
--------------------------------------------------------------------------------
/H24/0.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/univoid/CI_AT/9aef00cb4591f6bb015a493248458c0925d231c6/H24/0.py
--------------------------------------------------------------------------------
/H24/1.py:
--------------------------------------------------------------------------------
1 | f = open("data1.txt", "r")
2 | dList = []
3 | for line in f:
4 | tmp = eval(line)
5 | dList.append(tmp)
6 |
7 | print max(dList, key=lambda x: x[1])
8 |
--------------------------------------------------------------------------------
/H24/2.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plt
2 |
3 |
4 | f = open("data1.txt", "r")
5 | dList = []
6 | for line in f:
7 | tmp = eval(line)
8 | dList.append(tmp)
9 |
10 | plt.scatter(*zip(*dList))
11 | plt.show()
12 |
13 |
14 |
--------------------------------------------------------------------------------
/H24/2_ans.py:
--------------------------------------------------------------------------------
1 |
2 | from draw import initial_canvas, draw_canvas, draw_point
3 |
4 | # initialise canvas (32*2 col, 32 row)
5 | canvas = [[" " for x in range(64)] for y in range(32)]
6 | initial_canvas(canvas)
7 |
8 | # read data
9 | f = open("data1.txt", "r")
10 | dList = []
11 | for line in f:
12 | tmp = eval(line)
13 | dList.append(tmp)
14 |
15 | for (x, y) in dList:
16 | draw_point(x, y, canvas, mark='*')
17 |
18 | draw_canvas(canvas)
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/H24/3.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import matplotlib.pyplot as plt
3 |
4 |
5 | def graph(formula, x_range):
6 | x = np.array(x_range)
7 | y = eval(formula)
8 | plt.ylim(0, 30)
9 | plt.xlim(0, 30)
10 | plt.plot(x, y)
11 | plt.show()
12 |
13 |
14 | a = 0.5
15 | b = 10
16 | graph("{a} * x + {b}".format(a=a, b=b), range(0, 30))
--------------------------------------------------------------------------------
/H24/3_ans.py:
--------------------------------------------------------------------------------
1 | from math import ceil
2 | from draw import initial_canvas, draw_canvas, draw_point
3 |
4 | # initialise canvas (32*2 col, 32 row)
5 | canvas = [[" " for x in range(64)] for y in range(32)]
6 | initial_canvas(canvas)
7 |
8 | a = 0.5
9 | b = 10
10 | for x in range(0, 30, int(ceil(1/a))):
11 | draw_point(x, a*x+b, canvas, mark='o')
12 |
13 | draw_canvas(canvas)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/H24/4.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import matplotlib.pyplot as plt
3 |
4 |
5 | def graph(formula, x_range):
6 | x = np.array(x_range)
7 | y = eval(formula)
8 | plt.ylim(0, 30)
9 | plt.xlim(0, 30)
10 | plt.plot(x, y)
11 | plt.show()
12 |
13 | def lsa(dl):
14 | xl, yl = zip(*dl)
15 | n = len(dl)
16 | d = n * sum(x ** 2 for x in xl) - sum(xl) ** 2 # Denominator
17 | a = float((n*sum(x * y for (x, y) in dl) - sum(xl) * sum(yl))) / d
18 | b = float(sum(x ** 2 for x in xl) * sum(yl) - sum(x * y for (x, y) in dl) * sum(xl)) / d
19 |
20 | return a, b
21 |
22 |
23 | f = open("data1.txt", "r")
24 | dList = []
25 | for line in f:
26 | tmp = eval(line)
27 | dList.append(tmp)
28 |
29 | # test
30 | # dList = map(lambda x: (x[0], min(30, x[1]+3)), dList)
31 |
32 | a, b = lsa(dList)
33 | print a, b
34 |
35 | plt.scatter(*zip(*dList))
36 | graph("{a} * x + {b}".format(a=a, b=b), range(0, 30))
37 |
--------------------------------------------------------------------------------
/H24/4_ans.py:
--------------------------------------------------------------------------------
1 | from math import ceil
2 | from draw import initial_canvas, draw_point, draw_canvas
3 |
4 | def lsa(dl):
5 | xl, yl = zip(*dl)
6 | n = len(dl)
7 | d = n * sum(x ** 2 for x in xl) - sum(xl) ** 2 # Denominator
8 | a = float((n*sum(x * y for (x, y) in dl) - sum(xl) * sum(yl))) / d
9 | b = float(sum(x ** 2 for x in xl) * sum(yl) - sum(x * y for (x, y) in dl) * sum(xl)) / d
10 |
11 | return a, b
12 |
13 |
14 | f = open("data1.txt", "r")
15 | dList = []
16 | for line in f:
17 | tmp = eval(line)
18 | dList.append(tmp)
19 |
20 | # test
21 | # dList = map(lambda x: (x[0], min(30, x[1]+3)), dList)
22 | # draw scatter
23 | canvas = [[" " for x in range(64)] for y in range(32)]
24 | initial_canvas(canvas)
25 | for (x,y) in dList:
26 | draw_point(x, y, canvas, mark='*')
27 |
28 | #draw fit
29 | a, b = lsa(dList)
30 | print a, b
31 | for x in range(0, 30, int(ceil(1/a))):
32 | print x, a * x + b
33 | draw_point(x, a*x+b, canvas, mark='o')
34 |
35 | draw_canvas(canvas)
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/H24/5.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import matplotlib.pyplot as plt
3 |
4 |
5 | def graph(formula, x_range):
6 | x = np.array(x_range)
7 | y = eval(formula)
8 | plt.ylim(0, 30)
9 | plt.xlim(0, 30)
10 | plt.plot(x, y)
11 | plt.show()
12 |
13 | def lsa(dl):
14 | xl, yl = zip(*dl)
15 | n = len(dl)
16 | d = n * sum(x ** 2 for x in xl) - sum(xl) ** 2 # Denominator
17 | a = float((n*sum(x * y for (x, y) in dl) - sum(xl) * sum(yl))) / d
18 | b = float(sum(x ** 2 for x in xl) * sum(yl) - sum(x * y for (x, y) in dl) * sum(xl)) / d
19 |
20 | return a, b
21 |
22 |
23 | f = open("data1.txt", "r")
24 | dList = []
25 | for line in f:
26 | tmp = eval(line)
27 | dList.append(tmp)
28 |
29 | # test
30 | # dList = map(lambda x: (x[0], min(30, x[1]+3)), dList)
31 |
32 | a, b = lsa(dList)
33 | print a, b
34 |
35 | plt.scatter(*zip(*dList))
36 | graph("{a} * x + {b}".format(a=a, b=b), range(0, 30))
37 |
--------------------------------------------------------------------------------
/H24/5_bf.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import matplotlib.pyplot as plt
3 | import sys
4 |
5 |
6 | def graph(formula, x_range):
7 | x = np.array(x_range)
8 | y = eval(formula)
9 | plt.ylim(0, 30)
10 | plt.xlim(0, 30)
11 | plt.plot(x, y)
12 |
13 |
14 | def cale(a, b, dl):
15 | return sum((y - (a*x+b)) ** 2 for (x, y) in dl)
16 |
17 |
18 | def lsa(dl):
19 | xl, yl = zip(*dl)
20 | n = len(dl)
21 | d = n * sum(x ** 2 for x in xl) - sum(xl) ** 2 # Denominator
22 | a = float((n*sum(x * y for (x, y) in dl) - sum(xl) * sum(yl))) / d
23 | b = float(sum(x ** 2 for x in xl) * sum(yl) - sum(x * y for (x, y) in dl) * sum(xl)) / d
24 | e = cale(a, b, dl)
25 | return a, b, e
26 |
27 |
28 | def binse(l, r, dl, x0, y0):
29 | if abs(l-r) < 0.1:
30 | return l
31 |
32 | mid = (l + r) / 2
33 | a = (l + mid)/2
34 | b = y0 - a * x0
35 | e1 = cale(a, b, dl)
36 | a = (r+mid)/2
37 | b = y0 - a * x0
38 | e2 = cale(a, b, dl)
39 | if e1 < e2:
40 | return binse(l, mid, dl, x0, y0)
41 | else:
42 | return binse(mid, r, dl, x0, y0)
43 |
44 |
45 | f = open("data2.txt", "r")
46 | dList = []
47 | for line in f:
48 | tmp = eval(line)
49 | dList.append(tmp)
50 |
51 | e = sys.maxint
52 | ea1 = 0
53 | eb1 = 0
54 | ea2 = 0
55 | eb2 = 0
56 | ex = 0
57 | ey = 0
58 | for k in range(2, len(dList)-1):
59 | a1, b1, e1 = lsa(dList[:k])
60 | for xm in range(dList[k-1][0], dList[k][0]):
61 | ym = int(a1 * xm + b1)
62 | a2 = binse(0.0, 30.0, dList[k:], xm, ym)
63 | b2 = ym - a2 * xm
64 | e2 = cale(a2, b2, dList[k:])
65 | print k,a2, e2
66 | if e > e1 + e2:
67 | ea1 = a1
68 | eb1 = b1
69 | ea2 = a2
70 | eb2 = b2
71 | ex = xm
72 | ey = ym
73 | e = e1 + e2
74 |
75 |
76 | plt.scatter(*zip(*dList))
77 | print "({}, {})".format(ex, ey)
78 | graph("{a} * x + {b}".format(a=ea1, b=eb1), range(0, 30))
79 | graph("{a} * x + {b}".format(a=ea2, b=eb2), range(0, 30))
80 | plt.show()
--------------------------------------------------------------------------------
/H24/5_math.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import matplotlib.pyplot as plt
3 | import sys
4 |
5 |
6 | def graph(formula, x_range):
7 | x = np.array(x_range)
8 | y = eval(formula)
9 | plt.ylim(0, 30)
10 | plt.xlim(0, 30)
11 | plt.plot(x, y)
12 |
13 |
14 | def cale(a, b, dl):
15 | return sum((y - (a*x+b)) ** 2 for (x, y) in dl)
16 |
17 |
18 | def lsa(dl):
19 | xl, yl = zip(*dl)
20 | n = len(dl)
21 | d = n * sum(x ** 2 for x in xl) - sum(xl) ** 2 # Denominator
22 | a = float((n*sum(x * y for (x, y) in dl) - sum(xl) * sum(yl))) / d
23 | b = float(sum(x ** 2 for x in xl) * sum(yl) - sum(x * y for (x, y) in dl) * sum(xl)) / d
24 | e = cale(a, b, dl)
25 | return a, b, e
26 |
27 |
28 | def get_a(dl, x0, y0):
29 | return float(sum((y-y0)*(x-x0) for (x, y) in dl))/((sum((x-x0)**2 for (x, y) in dl)))
30 |
31 |
32 | f = open("data2.txt", "r")
33 | dList = []
34 | for line in f:
35 | tmp = eval(line)
36 | dList.append(tmp)
37 |
38 | e = sys.maxint
39 | ea1 = 0
40 | eb1 = 0
41 | ea2 = 0
42 | eb2 = 0
43 | ex = 0
44 | ey = 0
45 | for k in range(2, len(dList)-1):
46 | a1, b1, e1 = lsa(dList[:k])
47 | for xm in range(dList[k-1][0], dList[k][0]):
48 | ym = int(a1 * xm + b1)
49 | # some math trick
50 | a2 = get_a(dList[k:], xm, ym)
51 | b2 = ym - a2 * xm
52 | e2 = cale(a2, b2, dList[k:])
53 | # print k, a2, e2
54 | if e > e1 + e2:
55 | ea1 = a1
56 | eb1 = b1
57 | ea2 = a2
58 | eb2 = b2
59 | ex = xm
60 | ey = ym
61 | e = e1 + e2
62 |
63 |
64 | plt.scatter(*zip(*dList))
65 | print "turn point ({}, {})".format(ex, ey)
66 | graph("{a} * x + {b}".format(a=ea1, b=eb1), range(0, 30))
67 | graph("{a} * x + {b}".format(a=ea2, b=eb2), range(0, 30))
68 | plt.show()
--------------------------------------------------------------------------------
/H24/5_math_ans.py:
--------------------------------------------------------------------------------
1 | import sys
2 | from math import ceil
3 | from draw import initial_canvas, draw_point, draw_canvas
4 |
5 | def graph(formula, x_range):
6 | x = np.array(x_range)
7 | y = eval(formula)
8 | plt.ylim(0, 30)
9 | plt.xlim(0, 30)
10 | plt.plot(x, y)
11 |
12 |
13 | def cale(a, b, dl):
14 | return sum((y - (a*x+b)) ** 2 for (x, y) in dl)
15 |
16 |
17 | def lsa(dl):
18 | xl, yl = zip(*dl)
19 | n = len(dl)
20 | d = n * sum(x ** 2 for x in xl) - sum(xl) ** 2 # Denominator
21 | a = float((n*sum(x * y for (x, y) in dl) - sum(xl) * sum(yl))) / d
22 | b = float(sum(x ** 2 for x in xl) * sum(yl) - sum(x * y for (x, y) in dl) * sum(xl)) / d
23 | e = cale(a, b, dl)
24 | return a, b, e
25 |
26 |
27 | def get_a(dl, x0, y0):
28 | return float(sum((y-y0)*(x-x0) for (x, y) in dl))/((sum((x-x0)**2 for (x, y) in dl)))
29 |
30 |
31 | f = open("data2.txt", "r")
32 | dList = []
33 | for line in f:
34 | tmp = eval(line)
35 | dList.append(tmp)
36 |
37 | e = sys.maxint
38 | ea1 = 0
39 | eb1 = 0
40 | ea2 = 0
41 | eb2 = 0
42 | ex = 0
43 | ey = 0
44 | for k in range(2, len(dList)-1):
45 | a1, b1, e1 = lsa(dList[:k])
46 | for xm in range(dList[k-1][0], dList[k][0]):
47 | ym = int(a1 * xm + b1)
48 | # some math trick
49 | a2 = get_a(dList[k:], xm, ym)
50 | b2 = ym - a2 * xm
51 | e2 = cale(a2, b2, dList[k:])
52 | # print k, a2, e2
53 | if e > e1 + e2:
54 | ea1 = a1
55 | eb1 = b1
56 | ea2 = a2
57 | eb2 = b2
58 | ex = xm
59 | ey = ym
60 | e = e1 + e2
61 |
62 | # draw scatter
63 | canvas = [[" " for x in range(64)] for y in range(32)]
64 | initial_canvas(canvas)
65 | for (x,y) in dList:
66 | draw_point(x, y, canvas, mark='*')
67 |
68 | print "turn point: ({}, {})".format(ex, ey)
69 | # draw fit
70 | for x in range(0, ex, int(ceil(1/ea1))):
71 | if ea1 * x + eb1 < 0:
72 | continue
73 | draw_point(x, ea1*x+eb1, canvas, mark='o')
74 |
75 | for x in range(ex, 30, int(ceil(1/ea2))):
76 | if ea2 * x + eb2 > 30:
77 | break
78 | draw_point(x, ea2*x+eb2, canvas, mark='o')
79 |
80 | draw_canvas(canvas)
81 |
--------------------------------------------------------------------------------
/H24/canvas.txt:
--------------------------------------------------------------------------------
1 | 30|
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | 20|
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | 10|
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | 0+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32 | 0 10 20 30
--------------------------------------------------------------------------------
/H24/data1.txt:
--------------------------------------------------------------------------------
1 | (1,2)
2 | (2,3)
3 | (3,2)
4 | (4,3)
5 | (5,5)
6 | (6,7)
7 | (7,8)
8 | (8,4)
9 | (9,5)
10 | (10,12)
11 | (11,12)
12 | (12,13)
13 | (13,14)
14 | (14,17)
15 | (15,12)
16 | (16,20)
17 | (17,25)
18 | (18,23)
19 | (19,24)
20 | (20,23)
21 | (21,21)
22 | (22,23)
23 | (23,22)
24 | (24,18)
25 | (25,27)
26 | (26,23)
27 | (27,30)
28 | (28,29)
29 | (29,21)
30 | (30,29)
--------------------------------------------------------------------------------
/H24/data2.txt:
--------------------------------------------------------------------------------
1 | (1,1)
2 | (2,2)
3 | (3,3)
4 | (4,4)
5 | (5,5)
6 | (6,6)
7 | (7,7)
8 | (7,7)
9 | (8,10)
10 | (9,12)
11 | (10,13)
12 | (11,15)
13 | (12,18)
14 | (13,20)
15 | (14,21)
16 | (15,23)
17 | (16,26)
18 | (17,28)
19 | (18,29)
--------------------------------------------------------------------------------
/H24/draw.py:
--------------------------------------------------------------------------------
1 | from printf import printf
2 |
3 | def draw_point(x, y, canvas, mark='*'):
4 | x = int(x)
5 | # if ceil depended on 2nd of Decimal point
6 | y = int(y + 0.05)
7 | canvas[30-y][2*x+2] = mark
8 |
9 |
10 | def initial_canvas(canvas):
11 | fc = open("canvas.txt", "r")
12 | y = 0
13 | x = 0
14 | for line in fc:
15 | line = line.replace("\n", "")
16 | for c in line:
17 | canvas[y][x] = c
18 | x += 1
19 | y += 1
20 | x = 0
21 |
22 |
23 | def draw_canvas(canvas):
24 | with open("output.txt", "w") as outFile:
25 | for row in canvas:
26 | for c in row:
27 | printf(c, outFile)
28 | print >> outFile
29 |
--------------------------------------------------------------------------------
/H24/output.txt:
--------------------------------------------------------------------------------
1 | 30|
2 | | o
3 | | *
4 | | o
5 | | *
6 | | o
7 | |
8 | | o
9 | |
10 | | o
11 | 20| *
12 | | o
13 | | *
14 | | o
15 | |
16 | | o
17 | |
18 | | o
19 | | *
20 | | o
21 | 10| *
22 | | o
23 | |
24 | | o
25 | | o
26 | | o
27 | | o
28 | | o
29 | | o
30 | | o
31 | 0o - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32 | 0 10 20 30
33 |
--------------------------------------------------------------------------------
/H24/printf.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 |
3 | def printf(str, depend):
4 | print(str, end='', file=depend)
--------------------------------------------------------------------------------
/H25/1.py:
--------------------------------------------------------------------------------
1 | class Sentence(object):
2 | def __init__(self, action, a, b):
3 | self.action = action
4 | self.a = a
5 | self.b = b
6 |
7 | f = open("prog1.txt", "r")
8 | proList = []
9 |
10 | for line in f:
11 | tmp = line.split(" ")
12 | stn = Sentence(tmp[0], tmp[1], tmp[2])
13 | proList.append(stn)
14 |
15 | for stn in proList:
16 | print stn.a
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/H25/2.py:
--------------------------------------------------------------------------------
1 | class Sentence(object):
2 | def __init__(self, action, a, b):
3 | self.action = action
4 | self.a = a
5 | self.b = b
6 |
7 | f = open("prog1.txt", "r")
8 | proList = []
9 |
10 | for line in f:
11 | tmp = line.split(" ")
12 | stn = Sentence(tmp[0], tmp[1], tmp[2])
13 | proList.append(stn)
14 |
15 | for stn in proList:
16 | print stn.a
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/H25/3.py:
--------------------------------------------------------------------------------
1 | class Sentence(object):
2 | def __init__(self, action, a, b):
3 | self.action = action
4 | self.a = a
5 | self.b = b
6 |
7 | f = open("prog2.txt", "r")
8 | proList = []
9 |
10 | for line in f:
11 | tmp = line.strip().split(" ")
12 | stn = Sentence(tmp[0], tmp[1], tmp[2])
13 | proList.append(stn)
14 |
15 | point = 0
16 | memo = {}
17 | while point != len(proList):
18 | c = proList[point]
19 | action = c.action
20 | a = c.a
21 | b = c.b
22 | if action == "SET":
23 | memo[a] = memo[b] if (b in memo) else int(b)
24 |
25 | elif action == "ADD":
26 | if a in memo:
27 | memo[b] += memo[a]
28 | else:
29 | memo[b] += int(a)
30 |
31 | elif action == "PRN":
32 | print memo[a], memo[b]
33 | break
34 |
35 | point += 1
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/H25/4.py:
--------------------------------------------------------------------------------
1 | class Sentence(object):
2 | def __init__(self, action, a, b):
3 | self.action = action
4 | self.a = a
5 | self.b = b
6 |
7 | f = open("prog1.txt", "r")
8 | proList = []
9 |
10 | for line in f:
11 | tmp = line.strip().split(" ")
12 | stn = Sentence(tmp[0], tmp[1], tmp[2])
13 | proList.append(stn)
14 |
15 | point = 0
16 | memo = {}
17 | while point != len(proList):
18 | c = proList[point]
19 | action = c.action
20 | a = c.a
21 | b = c.b
22 | if action == "SET":
23 | memo[a] = memo[b] if (b in memo) else int(b)
24 | point += 1
25 |
26 | elif action == "ADD":
27 | if a in memo:
28 | memo[b] += memo[a]
29 | else:
30 | memo[b] += int(a)
31 |
32 | point += 1
33 |
34 | elif action == "PRN":
35 | print memo[a], memo[b]
36 | break
37 |
38 | elif action == "CMP":
39 | point += 1
40 | cmpA = memo[a] if (a in memo) else int(a)
41 | cmpB = memo[b] if (b in memo) else int(b)
42 | if cmpA == cmpB:
43 | point += 1
44 |
45 | elif action == "JMP":
46 | point += int(a)
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/H25/5.py:
--------------------------------------------------------------------------------
1 | class Sentence(object):
2 | def __init__(self, action, a, b):
3 | self.action = action
4 | self.a = a
5 | self.b = b
6 |
7 | f = open("prog1.txt", "r")
8 | proList = []
9 |
10 | for line in f:
11 | tmp = line.strip().split(" ")
12 | stn = Sentence(tmp[0], tmp[1], tmp[2])
13 | proList.append(stn)
14 |
15 | point = 0
16 | recPos = 0
17 | memo = {}
18 | while point != len(proList):
19 | c = proList[point]
20 | action = c.action
21 | a = c.a
22 | b = c.b
23 | if action == "SET":
24 | memo[a] = memo[b] if (b in memo) else int(b)
25 | point += 1
26 |
27 | elif action == "ADD":
28 | if a in memo:
29 | memo[b] += memo[a]
30 | else:
31 | memo[b] += int(a)
32 |
33 | point += 1
34 |
35 | elif action == "PRN":
36 | print memo[a], memo[b]
37 | break
38 |
39 | elif action == "CMP":
40 | point += 1
41 | cmpA = memo[a] if (a in memo) else int(a)
42 | cmpB = memo[b] if (b in memo) else int(b)
43 | if cmpA == cmpB:
44 | point += 1
45 |
46 | elif action == "JMP":
47 | point += int(a)
48 |
49 | elif action == "SUB":
50 | recPos = point
51 | point += int(a)
52 |
53 | elif action == "BAK":
54 | point = recPos
55 |
56 | elif action == "CAL":
57 | pass
58 |
59 | elif action == "RET":
60 | pass
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/H25/6.py:
--------------------------------------------------------------------------------
1 | class Sentence(object):
2 | def __init__(self, action, a, b):
3 | self.action = action
4 | self.a = a
5 | self.b = b
6 |
7 | f = open("prog1.txt", "r")
8 | proList = []
9 |
10 | for line in f:
11 | tmp = line.strip().split(" ")
12 | stn = Sentence(tmp[0], tmp[1], tmp[2])
13 | proList.append(stn)
14 |
15 | point = 0
16 | recPos = 0
17 | recPosFunc = 0
18 | memoGlobal = {}
19 | memoLocal = {}
20 | memo = memoGlobal
21 | while point != len(proList):
22 | c = proList[point]
23 | action = c.action
24 | a = c.a
25 | b = c.b
26 | if action == "SET":
27 | memo[a] = memo[b] if (b in memo) else int(b)
28 | point += 1
29 |
30 | elif action == "ADD":
31 | if a in memo:
32 | memo[b] += memo[a]
33 | else:
34 | memo[b] += int(a)
35 |
36 | point += 1
37 |
38 | elif action == "PRN":
39 | print memo[a], memo[b]
40 | break
41 |
42 | elif action == "CMP":
43 | point += 1
44 | cmpA = memo[a] if (a in memo) else int(a)
45 | cmpB = memo[b] if (b in memo) else int(b)
46 | if cmpA == cmpB:
47 | point += 1
48 |
49 | elif action == "JMP":
50 | point += int(a)
51 |
52 | elif action == "SUB":
53 | recPos = point
54 | point += int(a)
55 |
56 | elif action == "BAK":
57 | point = recPos
58 |
59 | elif action == "CAL":
60 | memoLocal.clear()
61 | memoLocal[b] = memo[b]
62 | memo = memoLocal
63 | recPosFunc = point
64 | point += int(a)
65 |
66 | elif action == "RET":
67 | memoGlobal[a] = memo[a]
68 | memo = memoGlobal
69 | point = recPosFunc
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/H25/prog1.txt:
--------------------------------------------------------------------------------
1 | SET x 1
2 | SET y 0
3 | ADD x y
4 | ADD 1 x
5 | CMP x 10
6 | JMP -3 0
7 | PRN x y
--------------------------------------------------------------------------------
/H25/prog2.txt:
--------------------------------------------------------------------------------
1 | SET x 1
2 | SET y 0
3 | ADD x y
4 | ADD 1 x
5 | PRN x y
--------------------------------------------------------------------------------
/H26/1.py:
--------------------------------------------------------------------------------
1 | def computesA(d):
2 | return (int(10/d)+1) ** 2
3 | d = raw_input()
4 | print computesA(float(d))
5 |
--------------------------------------------------------------------------------
/H26/2.py:
--------------------------------------------------------------------------------
1 | from math import sqrt, ceil, floor
2 | def computesA0(d):
3 | return (int(10/d)+1) ** 2
4 |
5 | def computesA1(d):
6 | sum = 0
7 | for i in range(0, int(10/d)+1):
8 | y = i * d
9 | xl = 5 - sqrt(10 * y - y ** 2)
10 | xr = 5 + sqrt(10 * y - y ** 2)
11 | sum += floor(xr/d) - ceil(xl/d) + 1
12 | # print "{}: ({}, {}) sum = {}".format(y, int(xl/d), int(xr/d), sum)
13 |
14 | return float(sum)
15 |
16 | d = float(raw_input())
17 | print computesA1(d)/(computesA0(d) * 4)
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/H26/3.py:
--------------------------------------------------------------------------------
1 | from math import sqrt
2 | def areaK(n):
3 | if n == 0:
4 | return 25 * sqrt(3)
5 | elif n == 1:
6 | return 4.0/3 * areaK(0)
7 | else:
8 | return 13.0/9 * areaK(n-1) - 4.0/9 * areaK(n-2)
9 |
10 | print "K{} = {}".format(2, areaK(2))
11 |
12 |
--------------------------------------------------------------------------------
/H26/4.py:
--------------------------------------------------------------------------------
1 | from math import sqrt
2 |
3 | def area_k(n):
4 | if n == 0:
5 | return 25 * sqrt(3)
6 | elif n == 1:
7 | return 4.0/3 * area_k(0)
8 | else:
9 | return 13.0/9 * area_k(n - 1) - 4.0 / 9 * area_k(n - 2)
10 |
11 | n = int(raw_input("input n: "))
12 | print "K{} = {}".format(n, area_k(n))
13 |
--------------------------------------------------------------------------------
/H26/6.py:
--------------------------------------------------------------------------------
1 | # 分治 @lj
2 | def check_in_area(n, x, y):
3 | pass
4 |
5 |
--------------------------------------------------------------------------------
/H27/1.py:
--------------------------------------------------------------------------------
1 | f = open("program.txt", "r")
2 | sum = 0
3 | for line in f:
4 | tmp = filter(lambda c: c == ";", line)
5 | sum += len(tmp)
6 |
7 | print sum
8 |
--------------------------------------------------------------------------------
/H27/2.py:
--------------------------------------------------------------------------------
1 | f = open("program.txt", "r")
2 | num = 0
3 | for line in f:
4 | num += 1
5 | if "main" in line:
6 | print "line {}: {}".format(num, line)
7 |
8 |
--------------------------------------------------------------------------------
/H27/3.py:
--------------------------------------------------------------------------------
1 | f = open("program.txt", "r")
2 | pre = ""
3 | flag = 0
4 |
5 | for line in f:
6 |
7 | if line == pre:
8 | flag = 1
9 | elif flag == 1:
10 | print pre
11 | flag = 0
12 |
13 | pre = line
14 |
15 | # deal with last line
16 | if flag == 1:
17 | print pre
18 | flag = 0
19 |
--------------------------------------------------------------------------------
/H27/4.py:
--------------------------------------------------------------------------------
1 | f = open("program.txt", "r")
2 | d = {}
3 | total = 0
4 | for line in f:
5 | if d.has_key(line):
6 | if d[line] == 1:
7 | print line
8 | total += 1
9 | d[line] += 1
10 | else:
11 | d[line] = 1
12 |
13 | print total
14 |
--------------------------------------------------------------------------------
/H27/5.py:
--------------------------------------------------------------------------------
1 | f = open("program1.txt", "r")
2 | sl = []
3 | for line in f:
4 | if len(line) >= 20:
5 | sl.append(line)
6 |
7 | sl.sort(key=lambda x: -len(x))
8 | #print sl
9 |
10 | total = 0
11 | for i, a in enumerate(sl):
12 | for j, b in enumerate(sl[i+1:]):
13 | error = len(a)-len(b) + len(filter(lambda c: c==" ", a[len(b):]))
14 |
15 | if error >= 5:
16 | break
17 |
18 | for k in range(0, len(b)):
19 | if a[k] != b[k]:
20 | error += 1
21 | if error >=5:
22 | break
23 |
24 | if error < 5:
25 | total += 1
26 | print "similar pair {}:\n{}\n{}\n".format(total, a, b)
27 |
28 | print "process completed."
29 | print "Sum of pairs: {}".format(total)
30 |
--------------------------------------------------------------------------------
/H27/6.py:
--------------------------------------------------------------------------------
1 | # too lazy to write out
--------------------------------------------------------------------------------
/H27/7.py:
--------------------------------------------------------------------------------
1 | # too lazy to write out
--------------------------------------------------------------------------------
/H27/program.txt:
--------------------------------------------------------------------------------
1 | a = 1;
2 | main a = a + 1;
3 | a = a + 1;
4 | a = a + 1;
5 | a = a + 1;
6 | b = a;
7 | a = 1;
8 | ;;;;;;main;;;;;;
9 | b = 3;
10 | b = 3;
11 |
--------------------------------------------------------------------------------
/H27/program1.txt:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #define UNPLACED (-1)
5 | #define EDGE_TILES (2)
6 | #define NUM_TILES (EDGE_TILES * EDGE_TILES)
7 | int put_germ(int size);
8 | int check_position(int foot, int size, int already);
9 | int put_foot(int size, int already);
10 | int judge_infection(int left, int right, int germ);
11 | int myrand(int key);
12 |
13 | int put_germ(int size) {
14 | char key;
15 | int location;
16 |
17 | printf("input 1 key: ");
18 | scanf("%c", &key);
19 | printf("now germ is in 0x%x \n", key);
20 | location = myrand(key) % size + 1;
21 | return location;
22 | }
23 |
24 | int check_position(int foot, int size, int already) {
25 | if ((foot < 1) || (foot > size)) {
26 | printf("out of range");
27 | return 0;
28 | } else if (already == foot) {
29 | printf("This title has been used\n");
30 | return 0;
31 | } else {
32 | return 1;
33 | }
34 | }
35 |
36 | int put_foot(int size, int already) {
37 | int position;
38 |
39 | do {
40 | printf(" range[1-%d]: ", size);
41 | scanf("%d", &position);
42 | } while(check_position(position, size, already) == 0);
43 | return position;
44 | }
45 |
46 | int judge_infection(int left, int right, int germ) {
47 | if ((germ - left) * (germ -right) == 0) {
48 | return 1;
49 | } else {
50 | return 0;
51 | }
52 | }
53 |
54 | int myrand(int key) {
55 | return key * key;
56 | }
57 |
58 | int main(void) {
59 | int germ;
60 | int left, right;
61 |
62 | germ = put_germ(NUM_TILES);
63 | printf("Left foot");
64 | left = put_foot(NUM_TILES, UNPLACED);
65 | printf("Right foot");
66 | right = put_foot(NUM_TILES, left);
67 | if (judge_infection(left, right, germ) == 1) {
68 | printf("BINGO!!!\n");
69 | } else {
70 | printf("Safe\n");
71 | }
72 |
73 | printf("Germ is in %d \n", germ);
74 | return 0;
75 | }
76 |
--------------------------------------------------------------------------------
/H28/1.py:
--------------------------------------------------------------------------------
1 | str = raw_input()[::-1]
2 | sum = 0
3 |
4 | for i, c in enumerate(str):
5 | sum += (ord(c) - ord('0')) * 4**i
6 |
7 | print sum
8 |
--------------------------------------------------------------------------------
/H28/2.py:
--------------------------------------------------------------------------------
1 | str = raw_input()[::-1]
2 | sum = 0
3 | for i, c in enumerate(str):
4 | sum += (ord(c)-ord('a')) * 8**i
5 |
6 | print sum
7 |
8 |
--------------------------------------------------------------------------------
/H28/3.py:
--------------------------------------------------------------------------------
1 | roman = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
2 |
3 | str = raw_input()[::-1]
4 | sum = 0
5 | max = 0
6 | for i, c in enumerate(str):
7 | certain = roman[c]
8 | if certain >= max:
9 | sum += certain
10 | max = certain
11 | elif certain < max:
12 | sum -= certain
13 |
14 | print sum
15 |
16 |
--------------------------------------------------------------------------------
/H28/4.py:
--------------------------------------------------------------------------------
1 | roman = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}
2 |
3 | str = raw_input()[::-1]
4 | sum = 0
5 | max = 0
6 | for i,c in enumerate(str):
7 | certain = roman[c]
8 | if certain >= max:
9 | sum += certain
10 | max = certain
11 | elif certain < max:
12 | sum -= certain
13 |
14 | print sum
15 |
16 |
--------------------------------------------------------------------------------
/H28/5.py:
--------------------------------------------------------------------------------
1 | roman = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}
2 | decimal = {"1000":"M", "500":"D", "100":"C", "50":"L", "10":"X", "5":"V", "1":"I"}
3 | d = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
4 | r = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
5 | str = ''
6 | num = int(raw_input())
7 | for i in range(0,len(d)):
8 | j = num / d[i]
9 | str += r[i] * j
10 | num = num % d[i]
11 |
12 | print str
13 |
14 |
15 |
--------------------------------------------------------------------------------
/H28/6.py:
--------------------------------------------------------------------------------
1 | roman = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}
2 | decimal = {"1000":"M", "500":"D", "100":"C", "50":"L", "10":"X", "5":"V", "1":"I"}
3 | d = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
4 | r = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
5 | str = ''
6 | num = int(raw_input())
7 | for i in range(0, len(d)):
8 | j = num / d[i]
9 | str += r[i] * j
10 | num = num % d[i]
11 |
12 | print str
13 |
14 |
15 |
--------------------------------------------------------------------------------
/H28/7.py:
--------------------------------------------------------------------------------
1 | dic = {"one":1, "two":2, "three":3, "four":4, "five":5,
2 | "six":6, "seven":7, "eight":8, "nine":9, "ten":10,
3 | "eleven":11, "twelve":12, "thirteen":13, "fourteen":14,
4 | "fifteen":15, "sixteen":16, "seventeen":17, "eighteen":18,
5 | "nineteen":19, "twenty":20, "thirty":30, "forty":40, "fifty":50,
6 | "sixty":60, "seventy":70, "eighty":80, "ninety":90, "hundred":100, "thousand":1000}
7 |
8 | str = raw_input()
9 | arr = str.split(' ')
10 | ans = 0
11 | sum = 0
12 | for item in arr:
13 | now = dic[item]
14 | # print now
15 | if ((item == "thousand") or (item == "hundred")):
16 | ans += max(1,sum) * now
17 | sum = 0
18 | else:
19 | sum += now
20 | ans += sum
21 |
22 | print ans
23 |
--------------------------------------------------------------------------------
/H29/6115/1.py:
--------------------------------------------------------------------------------
1 | from num import numList
2 |
3 |
4 | def printNum(inputList):
5 | with open("out1.txt", "w") as outFile:
6 |
7 | for row in range(0, 5):
8 | s = ""
9 | for num in inputList:
10 | for c in numList[num][row]:
11 | s += c
12 | s += " "
13 | s += "\n"
14 | # DEBUG<1>
15 | # print s
16 | outFile.writelines(s)
17 | return True
18 |
19 | s = raw_input()
20 | inputList = []
21 | for c in s:
22 | inputList.append(int(c))
23 |
24 | print "The number is {}".format(inputList)
25 |
26 | if printNum(inputList):
27 | print "The answer has been printed at out1.txt"
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/H29/6115/2.py:
--------------------------------------------------------------------------------
1 | from num import recognizeNumHash, hashList
2 | def sliceStr(s):
3 | seq = []
4 | # [x, y]: from x to y
5 | seq.append([0, 0])
6 | i = 0
7 | while i+2 < len(s):
8 | c1 = s[i]
9 | c2 = s[i+1]
10 | c3 = s[i+2]
11 | if c1 == "*" and c2 == " " and c3 == " ":
12 | seq[-1][1] = i+1
13 | if i+3 < len(s)-2:
14 | seq.append([i+3, i+3])
15 | i += 1
16 |
17 | return seq
18 |
19 | def getMatrix(x,y,inList):
20 | m = []
21 | for i in range(0,5):
22 | line = []
23 | for j in range(x, y):
24 | c = inList[i][j]
25 | line.append(c)
26 | m.append(line)
27 | return m
28 |
29 |
30 |
31 |
32 | with open("out1.txt", "r") as inFile:
33 | inList = []
34 | for line in inFile:
35 | cList = []
36 | for c in line:
37 | cList.append(c)
38 | inList.append(cList)
39 |
40 | # DEBUG<2>
41 | # print inList
42 | # for line in strList:
43 | # print line
44 |
45 | # none of " " in the line[4] expect the ones between two pictographic
46 | # the point of the first cha of each number
47 | slicePointSeq = sliceStr(inList[4])
48 | print slicePointSeq
49 |
50 | # recognization
51 | ans = []
52 | for rang in slicePointSeq:
53 | x = rang[0]
54 | y = rang[1]
55 |
56 | m = getMatrix(x, y, inList)
57 | # print m
58 | hashNum = recognizeNumHash(m)
59 | # print hashNum
60 | num = hashList.index(hashNum)
61 | ans.append(num)
62 | str = ""
63 | for item in ans:
64 | str += unicode(item)
65 | print "The Number is {}".format(str)
66 |
67 |
68 |
--------------------------------------------------------------------------------
/H29/6115/3.py:
--------------------------------------------------------------------------------
1 | from num import numList
2 |
3 | rowMax = 5
4 | def printNum(inputList):
5 | with open("out3.txt", "w") as outFile:
6 |
7 | for row in range(0, rowMax):
8 | s = ""
9 | j = 0
10 | for num in inputList:
11 | for c in num[row]:
12 | s += c
13 | if j < len(whitC):
14 | for k in range(0, whitC[j]):
15 | s += " "
16 | j += 1
17 | s += "\n"
18 | # DEBUG<1>
19 | # print s
20 | outFile.writelines(s)
21 | return True
22 |
23 | def getMatrix(i, vert):
24 | num = numList[i]
25 | m = []
26 | for j in range(0, vert):
27 | if i == 1:
28 | m.append([" "])
29 | else:
30 | m.append([" ", " ", " ", " "])
31 | for line in num:
32 | m.append(line)
33 | for j in range(0, rowMax - vert - 5):
34 | if i == 1:
35 | m.append([" "])
36 | else:
37 | m.append([" ", " ", " ", " "])
38 | return m
39 |
40 | s = raw_input()
41 | inputList = s.split(",")
42 | num = []
43 | for c in inputList[0]:
44 | num.append(int(c))
45 |
46 | vert = []
47 | whitC = []
48 | for i in range(1, len(inputList)):
49 | if i % 2:
50 | vert.append(int(inputList[i]))
51 | else:
52 | whitC.append(int(inputList[i]))
53 |
54 |
55 | print "The number is {}".format(num)
56 | print vert
57 | print whitC
58 | rowMax = 5 + max(vert)
59 | ans = []
60 | j = 0
61 | for i in num:
62 | m = getMatrix(i, vert[j])
63 | j += 1
64 | ans.append(m)
65 |
66 | if printNum(ans):
67 | print "The answer has been printed at out3.txt"
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/H29/6115/num.py:
--------------------------------------------------------------------------------
1 | numList = []
2 | # 0
3 | numList.append([["*", "*", "*", "*"],
4 | ["|", " ", " ", "|"],
5 | ["*", " ", " ", "*"],
6 | ["|", " ", " ", "|"],
7 | ["*", "*", "*", "*"]
8 | ])
9 | # 1
10 | numList.append([["*"],
11 | ["|"],
12 | ["*"],
13 | ["|"],
14 | ["*"]
15 | ])
16 | # 2
17 | numList.append([["*", "*", "*", "*"],
18 | [" ", " ", " ", "|"],
19 | ["*", "*", "*", "*"],
20 | ["|", " ", " ", " "],
21 | ["*", "*", "*", "*"]
22 | ])
23 | # 3
24 | numList.append([["*", "*", "*", "*"],
25 | [" ", " ", " ", "|"],
26 | ["*", "*", "*", "*"],
27 | [" ", " ", " ", "|"],
28 | ["*", "*", "*", "*"]
29 | ])
30 | # 4
31 | numList.append([["*", " ", " ", "*"],
32 | ["|", " ", " ", "|"],
33 | ["*", "*", "*", "*"],
34 | [" ", " ", " ", "|"],
35 | [" ", " ", " ", "*"]
36 | ])
37 | # 5
38 | numList.append([["*", "*", "*", "*"],
39 | ["|", " ", " ", " "],
40 | ["*", "*", "*", "*"],
41 | [" ", " ", " ", "|"],
42 | ["*", "*", "*", "*"]
43 | ])
44 | # 6
45 | numList.append([["*", " ", " ", " "],
46 | ["|", " ", " ", " "],
47 | ["*", "*", "*", "*"],
48 | ["|", " ", " ", "|"],
49 | ["*", "*", "*", "*"]
50 | ])
51 | # 7
52 | numList.append([["*", "*", "*", "*"],
53 | [" ", " ", " ", "|"],
54 | [" ", " ", " ", "*"],
55 | [" ", " ", " ", "|"],
56 | [" ", " ", " ", "*"]
57 | ])
58 | # 8
59 | numList.append([["*", "*", "*", "*"],
60 | ["|", " ", " ", "|"],
61 | ["*", "*", "*", "*"],
62 | ["|", " ", " ", "|"],
63 | ["*", "*", "*", "*"]
64 | ])
65 | # 9
66 | numList.append([["*", "*", "*", "*"],
67 | ["|", " ", " ", "|"],
68 | ["*", "*", "*", "*"],
69 | [" ", " ", " ", "|"],
70 | [" ", " ", " ", "*"]
71 | ])
72 |
73 | def recognizeNumHash(m):
74 | hashNum = 0
75 | counter = 0
76 | for line in m:
77 | for c in line:
78 | if c == "*" : tmp = 1
79 | if c == " " : tmp = 0
80 | if c == "|" : tmp = 3
81 | counter += 1
82 | hashNum += (counter * ((513) ** tmp)) % 4755137
83 | return hashNum
84 |
85 | hashList = [6925035, 6420646, 1122686, 1953129, 6477084, 5877823, 6301710, 1910121, 6935787, 6479644]
86 | # DEBUG
87 | # for item in numList:
88 | # hashList.append(recognizeNumHash(item))
89 | # print hashList
90 |
91 |
92 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 創造情報院試過去問
2 |
--------------------------------------------------------------------------------