File tree Expand file tree Collapse file tree 7 files changed +43
-33
lines changed Expand file tree Collapse file tree 7 files changed +43
-33
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 3
3
4
4
def main ():
5
5
left , right = first_step ()
6
- second_step (left , right )
6
+ diff = second_step (left , right )
7
+ third_step (diff )
7
8
8
9
9
10
def first_step ():
@@ -22,7 +23,34 @@ def first_step():
22
23
23
24
24
25
def second_step (left , right ):
25
- pass
26
+ diff = difflib .ndiff (left .splitlines (keepends = True ), right .splitlines (keepends = True ))
27
+ result = "" .join (diff )
28
+ return result
29
+
30
+
31
+ def third_step (diff ):
32
+ plus = open ("swan/plus.png" , "wb" )
33
+ subtraction = open ("swan/subtraction.png" , "wb" )
34
+ space = open ("swan/space.png" , "wb" )
35
+ lines = diff .split ("\n " )
36
+ for line in lines :
37
+ if len (line ) > 0 :
38
+ first_byte = line [0 ]
39
+ if first_byte == "+" :
40
+ write_file (plus , line )
41
+ elif first_byte == "-" :
42
+ write_file (subtraction , line )
43
+ elif first_byte == " " :
44
+ write_file (space , line )
45
+
46
+
47
+ def write_file (file , strings ):
48
+ sub_strings = strings [2 :]
49
+ ary = sub_strings .split (" " )
50
+ for point in ary :
51
+ if point .isalnum ():
52
+ b = bytes .fromhex (point )
53
+ file .write (b )
26
54
27
55
28
56
if __name__ == "__main__" :
Original file line number Diff line number Diff line change 2
2
Solve Problems in http://www.pythonchallenge.com
3
3
4
4
#### 18
5
+ ``` python
6
+ import difflib
7
+ ```
5
8
- the obvious different between two picture is brightness.
6
9
7
10
``` shell
8
11
gunzip deltas.gz
9
12
```
13
+ - png file start with: 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A
14
+ - 0x89 is png's magic number,all jpg file start with 0xFF
15
+ - 0x50 decode in utf-8 is P, 0x4E for N, 0x47 for G
16
+ - use three tag "+", "-", " " to describe the difference between two files
17
+ > when you say a php file, there is some function in it
18
+ - Loop: http://www.pythonchallenge.com/pc/def/linkedlist.php
19
+ - RPC: http://www.pythonchallenge.com/pc/phonebook.php
10
20
11
21
#### 17
12
22
result: http://www.pythonchallenge.com/pc/return/balloons.html
Original file line number Diff line number Diff line change 1
- def main ():
2
- file = open ("swan/plus.png " , "rb" )
1
+ def read_bin_file ():
2
+ file = open ("evil/0.jpg " , "rb" )
3
3
bs = []
4
4
while True :
5
5
b = file .read ()
@@ -11,4 +11,4 @@ def main():
11
11
12
12
13
13
if __name__ == "__main__" :
14
- main ()
14
+ read_bin_file ()
You can’t perform that action at this time.
0 commit comments