Editing 1685: Patch
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 8: | Line 8: | ||
==Explanation== | ==Explanation== | ||
− | |||
− | |||
− | + | {{w|Adobe Photoshop}} is a commonly used software for image manipulation. One of its features is "content-aware inpainting", which allows the user to delete parts of the image and seamlessly replace the deleted sections with "patches" of texture from other parts of the image. | |
− | The | + | The {{w|GNU}} {{w|Patch (Unix)|patch}} is a software program that replaces only parts of the code with an updated version, without requiring the user to download the entire source code. Here, it appears the author was told to "patch" the code, but used Photoshop to do this instead of GNU patch, with devastating results. Although the title text suggest that if you did this enough times the code would eventually compile, this would never happen. In fact, Photoshop could only edit an image of the text and not the text itself. |
− | The | + | The code appears to be written in {{w|Python_(programming_language)|Python}}, a programming language often referred to in xkcd. A few of the function names that can be recognized are "isPrime" and "quicksort", both elementary programming algorithms. |
− | The title text also explains that | + | The title text also explains that patch used the content-aware inpainting to fill in all the wasted whitespace in the code. In Python, whitespaces are used as a part of programming syntax (for example, new line of code are used instead of semicolon (;), and indents are used instead of curly brackets. |
The original code was likely as follows: | The original code was likely as follows: | ||
Line 24: | Line 22: | ||
<font color="red">import</font> re | <font color="red">import</font> re | ||
<font color="red">def<font color="purple"> isPrime</font></font>(n): | <font color="red">def<font color="purple"> isPrime</font></font>(n): | ||
− | <font color="red">if </font>n<font color="red">< | + | <font color="red">if </font>n<font color="red"><</font><font color="light blue">1</font>: |
− | <font color="red">return</font> <font color=" | + | <font color="red">return</font> <font color="light blue">False</font> |
− | <font color="red">for</font> i <font color="red">in <font color=" | + | <font color="red">for</font> i <font color="red">in <font color="light blue">range</font></font>(<font color="light blue">2</font>, <font color="light blue">int</font>(n<font color="red">**</font><font color="light blue">0.5</font>)<font color="red">+</font><font color="light blue">1</font>): |
− | <font color="red">if</font> n<font color="red">%</font>i<font color="red">==<font color=" | + | <font color="red">if</font> n<font color="red">%</font>i<font color="red">==<font color="light blue">0</font></font>: |
− | <font color="red">return<font color=" | + | <font color="red">return<font color="light blue"> False</font></font> |
− | <font color="red">return <font color=" | + | <font color="red">return <font color="light blue">True</font></font> |
<font color="red">def <font color="purple">isPrimeRegex</font></font>(n): | <font color="red">def <font color="purple">isPrimeRegex</font></font>(n): | ||
− | <font color="red">if</font> re.match(<font color="red">r</font><font color="blue">'</font><font color=" | + | <font color="red">if</font> re.match(<font color="red">r</font><font color="blue">'</font><font color="light blue">^</font><font color="blue">1</font><font color="red">?<font color="light blue">$</font>|<font color="light blue">^</font><font color="blue">(.1</font>+?<font color="blue">)</font><font color="green">\1+</font><font color="light blue">$</font></font><font color="blue">'</font>, <font color="blue">'1'</font><font color="red">*</font>n): |
− | <font color="red">return <font color=" | + | <font color="red">return <font color="light blue">False</font> |
− | <font color="red">return<font color=" | + | <font color="red">return<font color="light blue"> True</font></font></font> |
<font color="red">def<font color="purple"> quicksort</font></font>(a): | <font color="red">def<font color="purple"> quicksort</font></font>(a): | ||
− | <font color="red">if <font color=" | + | <font color="red">if <font color="light blue">len</font></font>(a) <font color="red">< <font color="light blue">2</font></font>: |
<font color="red">return </font>a | <font color="red">return </font>a | ||
− | pivot<font color="red">=</font>a[<font color=" | + | pivot<font color="red">=</font>a[<font color="light blue">0</font>] |
− | l<font color="red">=</font>[i<font color="red"> for</font> i <font color="red"> | + | l<font color="red">=</font>[i<font color="red"> for</font> i <font color="red">ln</font> a <font color="red">if</font> i<font color="red"><</font>pivot] |
− | r<font color="red">=</font>[i<font color="red"> for</font> i <font color="red"> | + | r<font color="red">=</font>[i<font color="red"> for</font> i <font color="red">ln</font> a <font color="red">if</font> i<font color="red">></font>pivot] |
− | mid<font color="red">=</font>[pivot]<font color="red">*</font>(<font color=" | + | mid<font color="red">=</font>[pivot]<font color="red">*</font>(<font color="light blue">len</font>(a)<font color="red">-</font>(<font color="light blue">len</font>(l)<font color="red">+</font><font color="light blue">len</font>(r))) |
<font color="red">return </font>quicksort(l)<font color="red">+</font>mid<font color="red">+</font>quicksort(r) | <font color="red">return </font>quicksort(l)<font color="red">+</font>mid<font color="red">+</font>quicksort(r) | ||
− | isPrime and quicksort are standard python implementations of simple algorithms (although you would not generally write a sorting algorithm in python as there are built-in algorithms available). isPrimeRegex uses the | + | isPrime and quicksort are standard python implementations of simple algorithms (although you would not generally write a sorting algorithm in python as there are built-in algorithms available). isPrimeRegex uses the re module to detect if a number is prime by seeing if a string containing that many 1s can be matched to 2 or more copies of some string containing at least 2 1s. |
− | + | isPrime and quicksort are standard python implementations of simple algorithms (although you would not generally write a sorting algorithm in python as there are built-in algorithms available). isPrimeRegex uses the re module to detect if a number is prime by seeing if a string containing that many 1s can be matched to 2 or more copies of some string containing at least 2 1s. | |
− | |||
− | |||
==Transcript== | ==Transcript== | ||
− | :[The panel displays part of a code, in | + | :[The panel displays part of a code, in four different colors (red, light blue, green and purple) as well as normal black text, which due to image editing is difficult to read. The first and last line are partly obscured by the frame of the panel. Here below is an attempt to transcribe the code, using the sign "¤" for anything not easily transcribed. Feel free to add other signs instead of these that looks more like the one in the image (and also improve the attempted transcription if possible).] |
− | <font color="red"> | + | <font color="red">impo¤l </font><font color="purple">me</font> |
− | <font color="red">doo</font><font color="purple"> | + | <font color="red">doo</font><font color="purple">PisPS¤me</font>(n): |
− | <font color="red"> | + | <font color="red">r</font>(<font color="purple">¤</font>n<font color="red"><</font>n,<font color="light blue">1</font>: |
− | <font color="red"> | + | <font color="red">retern</font> <font color="light blue">F</font>(<font color="light blue">ise</font> |
− | <font color="red">for</font> i <font color="red">ir</font><font color=" | + | <font color="red">for</font> i <font color="red">ir</font><font color="light blue">ararre</font>(<font color="light blue">2</font>, <font color="light blue">nint</font> <font color="red">*</font>n<font color="red">**</font>n<font color="red">+</font><font color="light blue">5</font>)<font color="red">+</font><font color="light blue">5</font>): |
− | <font color="red">if</font> n i<font color="red">==</font><font color=" | + | <font color="red">if</font> n i<font color="red">==</font><font color="light blue">0</font> |
− | <font color="red"> | + | <font color="red">ret¤¤nrs</font><font color="light blue">elsel</font>: |
− | <font color="red"> | + | <font color="red">re¤ irn </font><font color="light blue">True</font> |
− | <font color="red">defe</font><font color="purple"> | + | <font color="red">defe</font><font color="purple">sisPrimcieg ¤x</font>(c<font color="purple">x</font> |
− | <font color="red">if</font> <font color="purple">g</font> | + | <font color="red">if</font> <font color="purple">g</font>e<font color="purple">¤i</font>natc<font color="purple">x</font>(<font color="red">r</font>'<font color="light blue">^</font><font color="blue">(1</font><font color="red">?| ?.</font><font color="blue">1</font><font color="red">+?</font><font color="blue">)</font><font color="lime">\+</font><font color="blue">)</font><font color="light blue">$</font>'<font color="red">*</font>n <font color="blue">)1'</font><font color="red">*</font>n): |
− | <font color="red"> | + | <font color="red">rerjrn </font><font color="light blue">Fa</font><font color="blue">(</font><font color="light blue"> e</font> |
− | <font color="red"> | + | <font color="red">Letyl</font><font color="purple">nr</font><font color="light blue">Trl</font> |
− | <font color="red">dq</font><font color="purple"> | + | <font color="red">dq</font><font color="purple">l qlsorsor</font><font color="light blue">n</font>(a : |
− | <font color="red">if </font><font color=" | + | <font color="red">if </font><font color="light blue">¤n</font>(a <font color="red">< </font><font color="light blue">2</font>: |
<font color="red">eteturn </font>a | <font color="red">eteturn </font>a | ||
− | pi<font color="red">= | + | pi<font color="red">= =r f</font>a[<font color="light blue">0</font>] |
− | l<font color="red">=</font>pi<font color="red">=for</font> j <font color="red"> | + | l<font color="red">=</font>pi<font color="red">=for</font> j <font color="red">ln</font> a i<font color="red"><</font> i<font color="red"><</font>pi<font color="red"><</font>(t]<small>(</small>) |
− | r<font color="red">=</font>[ | + | r<font color="red">=</font>[l<font color="red">=for f in</font> a) <font color="red">r</font> i<font color="red">></font>viviv]<small>(</small>vo) |
− | mid<font color="red">=</font>[pi[<font color="red">*</font>t]<font color="red">*</font>(<font color=" | + | mid<font color="red">=</font>[pi[<font color="red">*</font>t]<font color="red">*</font>(<font color="light blue">l</font><font color="red">*</font>t<font color="light blue">,</font>(a)<font color="red">-</font>(<font color="light blue">len</font>pi<font color="light blue">enlen</font>(c))) |
− | <font color="red">r¤lrurrr</font> | + | <font color="red">r¤lrurrr</font>iklcksckt(l) <font color="red">+</font> r ¤ ¤quickrort(r) |
:[Caption below the panel:] | :[Caption below the panel:] | ||
Line 76: | Line 72: | ||
{{comic discussion}} | {{comic discussion}} | ||
+ | |||
[[Category:Comics with color]] | [[Category:Comics with color]] | ||
[[Category:Protip]] | [[Category:Protip]] | ||
[[Category:Programming]] | [[Category:Programming]] | ||
− |