<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.explainxkcd.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Lgstarn</id>
		<title>explain xkcd - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://www.explainxkcd.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Lgstarn"/>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php/Special:Contributions/Lgstarn"/>
		<updated>2026-05-19T21:28:36Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=1685:_Patch&amp;diff=358389</id>
		<title>1685: Patch</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=1685:_Patch&amp;diff=358389"/>
				<updated>2024-12-01T15:50:01Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */ Adding additional explanation of isPrimeRegex&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 1685&lt;br /&gt;
| date      = May 25, 2016&lt;br /&gt;
| title     = Patch&lt;br /&gt;
| image     = patch.png&lt;br /&gt;
| titletext = My optimizer uses content-aware inpainting to fill in all the wasted whitespace in the code, repeating the process until it compiles.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{w|Adobe Photoshop}} is a commonly used application for image manipulation. One of its features is the Patch tool, which allows the user to overwrite parts of the image, replacing them with a copy of another area of the same image. It is often used for “patching up” photographs by overwriting scratches or other visible damage to the photo. Another of Photoshop’s features is “content-aware fill”, which could also be described as “content-aware inpainting”. It works similarly to the Patch tool, but automatically generates a replacement texture from the area surrounding the deleted part instead of copying a user-specified area exactly.&lt;br /&gt;
&lt;br /&gt;
{{w|GNU}} {{w|Patch (Unix)|patch}} is a program that replaces only parts of 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.{{citation needed}} Although the title text suggests that if you did this enough times the code would eventually compile, this would be so unlikely to happen that it is effectively imposible. In fact, Photoshop could only edit an image of the text and not the text itself. However, it could work if optical character recognition (OCR) were integrated into the workflow as well.&lt;br /&gt;
&lt;br /&gt;
The comic blurs the difference between {{w|text_file|text}} (in which letters and symbols represent discrete values, such as 65 being the number for the letter A in the ASCII encoding standard, and it's relatively easy for a program compiler to interpret combinations of these values as keywords and other programming constructs) and {{w|Raster_graphics|graphics}} (where the letters and symbols in the comic are actually represented by a pattern of colored dots), playing with the idea that the ''patch'' metaphor can be used on both (although with different meanings). There are common and straightforward processes for converting text information to images, such as printing, which can convert text to a graphics format very faithfully. The reverse, however, requires the use of {{w|optical character recognition}} (OCR), which attempts to figure out which letter or symbol certain patterns of dots &amp;quot;look like&amp;quot;. OCR could be effective in converting some of the image in the comic back to usable text; however, it would fail on some of those patterns that have been mangled and don't look like any existing characters or symbols. A compiler can only operate on text data, so converting the graphic back into text would be a requirement to even begin to attempt to compile it, a step omitted in the title text.&lt;br /&gt;
&lt;br /&gt;
The code appears to be written in {{w|Python_(programming_language)|Python}}, a programming language often referred to in xkcd, such as in [[353: Python]]. A few of the function names that can be recognized are &amp;quot;isPrime&amp;quot; and &amp;quot;quicksort&amp;quot;, both elementary programming algorithms. It was also apparently originally edited using a Python-aware programming text editor, which is able to use different colors for different programming elements. For example, it appears to use red for keywords, blue for variables, and black for other elements; however, because of the mangling from the use of the wrong patching program, that doesn't appear to be consistent. Since the patching replaced graphical elements rather than whole characters, there are examples of symbols that are combinations of two different characters, and when the original two characters were rendered in different colors the resulting non-character could be in two colors, or the resulting &amp;quot;word&amp;quot; might be rendered in multiple colors.&lt;br /&gt;
&lt;br /&gt;
The comic brings to attention the high rate of Adobe Photoshop piracy. GNU Patch is available for free, even [http://gnuwin32.sourceforge.net/packages/patch.htm for Windows], and Mac OS X. So the comic implies that Adobe Photoshop, a subscription to which costs $20/month, is more available than GNU patch. According to [http://blog.epicedits.com/2008/03/28/60-of-photoshop-users-are-pirates/ this poll], 58% of Photoshop copies were pirated.&lt;br /&gt;
&lt;br /&gt;
The title text also explains that the patch used the content-aware inpainting to fill in all the wasted whitespace in the code. In most programming languages, whitespace is necessary to separate words, so this would combine words that shouldn’t be combined and create invalid code. Since the code in the image is Python, the code will be messed up even more, because Python uses whitespace as a part of its programming syntax. For example, statements are separated by newlines instead of by semicolons (;), and indentation is used instead of brackets to determine the scope of each section of code.&lt;br /&gt;
&lt;br /&gt;
The original code was likely as follows:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;import&amp;lt;/font&amp;gt; re&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;def&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt; isPrime&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;(n):&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if &amp;lt;/font&amp;gt;n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;=&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;:&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return&amp;lt;/font&amp;gt; &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;False&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;for&amp;lt;/font&amp;gt; i &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;in &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;range&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;2&amp;lt;/font&amp;gt;, &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;int&amp;lt;/font&amp;gt;(n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;**&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;0.5&amp;lt;/font&amp;gt;)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;):&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;%&amp;lt;/font&amp;gt;i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;==&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;0&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;:&lt;br /&gt;
 			&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt; False&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;True&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;def &amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;isPrimeRegex&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;(n):&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; re.match(&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;r&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;'&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;^&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;?&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;$&amp;lt;/font&amp;gt;|&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;^&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;(11&amp;lt;/font&amp;gt;+?&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;)&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;\1+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;$&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;'&amp;lt;/font&amp;gt;, &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;'1'&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;n): &lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;False&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt; True&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;def&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt; quicksort&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;(a):&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;len&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;(a) &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt; &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;2&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;:&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return &amp;lt;/font&amp;gt;a&lt;br /&gt;
 	pivot&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;a[&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;0&amp;lt;/font&amp;gt;]&lt;br /&gt;
 	l&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;[i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt; for&amp;lt;/font&amp;gt; i &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;in&amp;lt;/font&amp;gt; a &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;&amp;lt;/font&amp;gt;pivot]&lt;br /&gt;
 	r&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;[i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt; for&amp;lt;/font&amp;gt; i &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;in&amp;lt;/font&amp;gt; a &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;gt;&amp;lt;/font&amp;gt;pivot]&lt;br /&gt;
 	mid&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;[pivot]&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;len&amp;lt;/font&amp;gt;(a)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;-&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;len&amp;lt;/font&amp;gt;(l)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;len&amp;lt;/font&amp;gt;(r)))&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return &amp;lt;/font&amp;gt;quicksort(l)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;mid&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;quicksort(r)&lt;br /&gt;
&lt;br /&gt;
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 [https://docs.python.org/library/re.html 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. This works by transforming the number into the [https://en.wikipedia.org/wiki/Unary_numeral_system unary numeral system] and seeing if there is a repeating patterns of 1s, i.e. the number is [https://en.wikipedia.org/wiki/Composite_number composite] and thus not prime. In more detail, the expression &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;'1'&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;n converts the whole number n into a string of &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;'1'&amp;lt;/font&amp;gt; repeated n times. The regex then matches against this string. The first regex component &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;^&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;?&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;$&amp;lt;/font&amp;gt; finds the edge cases of 0 and 1 (not prime) as &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;^&amp;lt;/font&amp;gt; is the beginning of the line, &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;?&amp;lt;/font&amp;gt; means one or zero 1s, and &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;$&amp;lt;/font&amp;gt; is the end of the line. This matches only a blank string (the number 0) or a &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;'1'&amp;lt;/font&amp;gt; (the number 1). The second regex expression is separated from the first by |, a logical &amp;quot;or&amp;quot;, so either expression will cause a match. The regex &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;^&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;(11&amp;lt;/font&amp;gt;+?&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;)&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;\1+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;$&amp;lt;/font&amp;gt; selects for a repeating pattern (the content inside the parenthesis) an additional one or more times as indicated by &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;\1+&amp;lt;/font&amp;gt;. The pattern inside the parenthesis is a string of 1s longer than 2 (thus filtering out the edge case of 2, which is a prime number) using the property of composite numbers that they must be two non-prime numbers multiplied together. Altogether, the entire line between &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;^&amp;lt;/font&amp;gt; and &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;$&amp;lt;/font&amp;gt; must be precisely a pattern of 2 or more ones with this pattern repeated 1 or more times. If either of these two statements is true (0 or 1 or a repeated pattern greater than length 2), the number is not a prime. Interesting benchmarks of this &amp;quot;useless skill&amp;quot; isPrimeRegex method in comparison to the naive isPrime method can be found [https://geelaw.blog/entries/regex-prime-js-benchmark/ here].&lt;br /&gt;
&lt;br /&gt;
The comic two comics back [[1683: Digital Data]], also related to turning digital data into bad copies. Less than a month before quicksort was mentioned in [[1667: Algorithms]], and a month before that another &amp;quot;easy&amp;quot; solution to a programming problem was released in [[1654: Universal Install Script]].&lt;br /&gt;
&lt;br /&gt;
Using a Photoshop tool for a task it is not intended for was also used in [[1784: Bad Map Projection: Liquid Resize]], where [https://helpx.adobe.com/photoshop/using/content-aware-scaling.html Photoshop's content-aware resizing tool] was a very questionable choice to use for a Map Projection.&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
:[The panel displays part of a code, in five different colors (red, purple, light blue, blue, and green) as well as normal black text, which due to image editing is difficult to read. The first and last lines are partly obscured by the frame of the panel. Here below is an attempt to transcribe the code, using the sign &amp;quot;¤&amp;quot; for anything not easily transcribed. Feel free to add other signs instead of these that look more like the one in the image (and also improve the attempted transcription if possible).]&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;impoɞt&amp;lt;/font&amp;gt; &amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;ne&amp;lt;/font&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;doo&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;PisPʂnme&amp;lt;/font&amp;gt;(n):&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;⫠&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;¤&amp;lt;/font&amp;gt;n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;&amp;lt;/font&amp;gt;n,&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;:&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;retɐrn&amp;lt;/font&amp;gt; &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;F&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;ise&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;for&amp;lt;/font&amp;gt; i &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;ir&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;arar𝞬e&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;2&amp;lt;/font&amp;gt;, &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;ninߙ&amp;lt;/font&amp;gt; &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;**&amp;lt;/font&amp;gt;n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;5&amp;lt;/font&amp;gt;)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;5&amp;lt;/font&amp;gt;):&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; n i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;==&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;0&amp;lt;/font&amp;gt;&lt;br /&gt;
 			&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;re力¤𝑟nr&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;₅ɵlsel&amp;lt;/font&amp;gt;:&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;re&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;𝗿&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;⃓rn &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;True&amp;lt;/font&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;defe&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;𝟧isPrimϵieg˓x&amp;lt;/font&amp;gt;(c&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;x&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; &amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;g&amp;lt;/font&amp;gt;ƨ&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;¤i&amp;lt;/font&amp;gt;natc&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;x&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;r&amp;lt;/font&amp;gt;'&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;^&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;(1&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;?| ?.&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+?&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;)&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;lime&amp;quot;&amp;gt;\+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;)&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;$&amp;lt;/font&amp;gt;'&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;n &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;⎞1'&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;n):&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;rerɹrn &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;Fa&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;(&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt; e&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;ιetu⃓&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;nr&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;TrꙆ&amp;lt;/font&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;dq&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;⃓ q⃓soʀsor&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;η&amp;lt;/font&amp;gt;(a :&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;¤n&amp;lt;/font&amp;gt;(a  &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt; &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;2&amp;lt;/font&amp;gt;:&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;eteturn &amp;lt;/font&amp;gt;a&lt;br /&gt;
 	pi&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=꞊ᵣ f&amp;lt;/font&amp;gt;a[&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;0&amp;lt;/font&amp;gt;]&lt;br /&gt;
 	l&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;pi&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=for&amp;lt;/font&amp;gt; j &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;ın&amp;lt;/font&amp;gt; a i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;&amp;lt;/font&amp;gt; i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;&amp;lt;/font&amp;gt;pi&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;&amp;lt;/font&amp;gt;(t]&amp;lt;small&amp;gt;(&amp;lt;/small&amp;gt;)&lt;br /&gt;
 	r&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;[ı&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=for 𝟋 in&amp;lt;/font&amp;gt; a) &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;r&amp;lt;/font&amp;gt; i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;gt;&amp;lt;/font&amp;gt;viviv]&amp;lt;small&amp;gt;(&amp;lt;/small&amp;gt;vo)&lt;br /&gt;
 	mid&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;[pi[&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;t]&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;l&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;t&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;ˌ&amp;lt;/font&amp;gt;(a)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;-&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;⟘en&amp;lt;/font&amp;gt;pᚆ&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;enlen&amp;lt;/font&amp;gt;(c)))&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;r¤lrurrr&amp;lt;/font&amp;gt;ikıcksckt(l) &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt; r ¤ ¤quickrprt(r)&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:Protip: If you don't have access to the GNU ''patch'' tool, you can use the Photoshop one.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
[[Category:Comics with color]]&lt;br /&gt;
[[Category:Protip]]&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
[[Category:Photography]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=1685:_Patch&amp;diff=358387</id>
		<title>1685: Patch</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=1685:_Patch&amp;diff=358387"/>
				<updated>2024-12-01T15:05:07Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */ Adding background on isPrimeRegex&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 1685&lt;br /&gt;
| date      = May 25, 2016&lt;br /&gt;
| title     = Patch&lt;br /&gt;
| image     = patch.png&lt;br /&gt;
| titletext = My optimizer uses content-aware inpainting to fill in all the wasted whitespace in the code, repeating the process until it compiles.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{w|Adobe Photoshop}} is a commonly used application for image manipulation. One of its features is the Patch tool, which allows the user to overwrite parts of the image, replacing them with a copy of another area of the same image. It is often used for “patching up” photographs by overwriting scratches or other visible damage to the photo. Another of Photoshop’s features is “content-aware fill”, which could also be described as “content-aware inpainting”. It works similarly to the Patch tool, but automatically generates a replacement texture from the area surrounding the deleted part instead of copying a user-specified area exactly.&lt;br /&gt;
&lt;br /&gt;
{{w|GNU}} {{w|Patch (Unix)|patch}} is a program that replaces only parts of 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.{{citation needed}} Although the title text suggests that if you did this enough times the code would eventually compile, this would be so unlikely to happen that it is effectively imposible. In fact, Photoshop could only edit an image of the text and not the text itself. However, it could work if optical character recognition (OCR) were integrated into the workflow as well.&lt;br /&gt;
&lt;br /&gt;
The comic blurs the difference between {{w|text_file|text}} (in which letters and symbols represent discrete values, such as 65 being the number for the letter A in the ASCII encoding standard, and it's relatively easy for a program compiler to interpret combinations of these values as keywords and other programming constructs) and {{w|Raster_graphics|graphics}} (where the letters and symbols in the comic are actually represented by a pattern of colored dots), playing with the idea that the ''patch'' metaphor can be used on both (although with different meanings). There are common and straightforward processes for converting text information to images, such as printing, which can convert text to a graphics format very faithfully. The reverse, however, requires the use of {{w|optical character recognition}} (OCR), which attempts to figure out which letter or symbol certain patterns of dots &amp;quot;look like&amp;quot;. OCR could be effective in converting some of the image in the comic back to usable text; however, it would fail on some of those patterns that have been mangled and don't look like any existing characters or symbols. A compiler can only operate on text data, so converting the graphic back into text would be a requirement to even begin to attempt to compile it, a step omitted in the title text.&lt;br /&gt;
&lt;br /&gt;
The code appears to be written in {{w|Python_(programming_language)|Python}}, a programming language often referred to in xkcd, such as in [[353: Python]]. A few of the function names that can be recognized are &amp;quot;isPrime&amp;quot; and &amp;quot;quicksort&amp;quot;, both elementary programming algorithms. It was also apparently originally edited using a Python-aware programming text editor, which is able to use different colors for different programming elements. For example, it appears to use red for keywords, blue for variables, and black for other elements; however, because of the mangling from the use of the wrong patching program, that doesn't appear to be consistent. Since the patching replaced graphical elements rather than whole characters, there are examples of symbols that are combinations of two different characters, and when the original two characters were rendered in different colors the resulting non-character could be in two colors, or the resulting &amp;quot;word&amp;quot; might be rendered in multiple colors.&lt;br /&gt;
&lt;br /&gt;
The comic brings to attention the high rate of Adobe Photoshop piracy. GNU Patch is available for free, even [http://gnuwin32.sourceforge.net/packages/patch.htm for Windows], and Mac OS X. So the comic implies that Adobe Photoshop, a subscription to which costs $20/month, is more available than GNU patch. According to [http://blog.epicedits.com/2008/03/28/60-of-photoshop-users-are-pirates/ this poll], 58% of Photoshop copies were pirated.&lt;br /&gt;
&lt;br /&gt;
The title text also explains that the patch used the content-aware inpainting to fill in all the wasted whitespace in the code. In most programming languages, whitespace is necessary to separate words, so this would combine words that shouldn’t be combined and create invalid code. Since the code in the image is Python, the code will be messed up even more, because Python uses whitespace as a part of its programming syntax. For example, statements are separated by newlines instead of by semicolons (;), and indentation is used instead of brackets to determine the scope of each section of code.&lt;br /&gt;
&lt;br /&gt;
The original code was likely as follows:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;import&amp;lt;/font&amp;gt; re&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;def&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt; isPrime&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;(n):&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if &amp;lt;/font&amp;gt;n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;=&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;:&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return&amp;lt;/font&amp;gt; &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;False&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;for&amp;lt;/font&amp;gt; i &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;in &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;range&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;2&amp;lt;/font&amp;gt;, &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;int&amp;lt;/font&amp;gt;(n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;**&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;0.5&amp;lt;/font&amp;gt;)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;):&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;%&amp;lt;/font&amp;gt;i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;==&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;0&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;:&lt;br /&gt;
 			&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt; False&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;True&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;def &amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;isPrimeRegex&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;(n):&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; re.match(&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;r&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;'&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;^&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;?&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;$&amp;lt;/font&amp;gt;|&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;^&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;(11&amp;lt;/font&amp;gt;+?&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;)&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;\1+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;$&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;'&amp;lt;/font&amp;gt;, &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;'1'&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;n): &lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;False&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt; True&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;def&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt; quicksort&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;(a):&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;len&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;(a) &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt; &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;2&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;:&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return &amp;lt;/font&amp;gt;a&lt;br /&gt;
 	pivot&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;a[&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;0&amp;lt;/font&amp;gt;]&lt;br /&gt;
 	l&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;[i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt; for&amp;lt;/font&amp;gt; i &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;in&amp;lt;/font&amp;gt; a &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;&amp;lt;/font&amp;gt;pivot]&lt;br /&gt;
 	r&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;[i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt; for&amp;lt;/font&amp;gt; i &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;in&amp;lt;/font&amp;gt; a &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;gt;&amp;lt;/font&amp;gt;pivot]&lt;br /&gt;
 	mid&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;[pivot]&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;len&amp;lt;/font&amp;gt;(a)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;-&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;len&amp;lt;/font&amp;gt;(l)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;len&amp;lt;/font&amp;gt;(r)))&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;return &amp;lt;/font&amp;gt;quicksort(l)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;mid&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;quicksort(r)&lt;br /&gt;
&lt;br /&gt;
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 [https://docs.python.org/library/re.html 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. This works by transforming the number into the [https://en.wikipedia.org/wiki/Unary_numeral_system unary numeral system] and seeing if there is a repeating patterns of 1s, i.e. the number is [https://en.wikipedia.org/wiki/Composite_number composite] and thus not prime. The first regex component filters out the edge cases of 0 and 1. Interesting benchmarks of this &amp;quot;useless skill&amp;quot; isPrimeRegex method in comparison to the naive isPrime method can be found [https://geelaw.blog/entries/regex-prime-js-benchmark/ here].&lt;br /&gt;
&lt;br /&gt;
The comic two comics back [[1683: Digital Data]], also related to turning digital data into bad copies. Less than a month before quicksort was mentioned in [[1667: Algorithms]], and a month before that another &amp;quot;easy&amp;quot; solution to a programming problem was released in [[1654: Universal Install Script]].&lt;br /&gt;
&lt;br /&gt;
Using a Photoshop tool for a task it is not intended for was also used in [[1784: Bad Map Projection: Liquid Resize]], where [https://helpx.adobe.com/photoshop/using/content-aware-scaling.html Photoshop's content-aware resizing tool] was a very questionable choice to use for a Map Projection.&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
:[The panel displays part of a code, in five different colors (red, purple, light blue, blue, and green) as well as normal black text, which due to image editing is difficult to read. The first and last lines are partly obscured by the frame of the panel. Here below is an attempt to transcribe the code, using the sign &amp;quot;¤&amp;quot; for anything not easily transcribed. Feel free to add other signs instead of these that look more like the one in the image (and also improve the attempted transcription if possible).]&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;impoɞt&amp;lt;/font&amp;gt; &amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;ne&amp;lt;/font&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;doo&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;PisPʂnme&amp;lt;/font&amp;gt;(n):&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;⫠&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;¤&amp;lt;/font&amp;gt;n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;&amp;lt;/font&amp;gt;n,&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;:&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;retɐrn&amp;lt;/font&amp;gt; &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;F&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;ise&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;for&amp;lt;/font&amp;gt; i &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;ir&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;arar𝞬e&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;2&amp;lt;/font&amp;gt;, &amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;ninߙ&amp;lt;/font&amp;gt; &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;**&amp;lt;/font&amp;gt;n&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;5&amp;lt;/font&amp;gt;)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;5&amp;lt;/font&amp;gt;):&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; n i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;==&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;0&amp;lt;/font&amp;gt;&lt;br /&gt;
 			&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;re力¤𝑟nr&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;₅ɵlsel&amp;lt;/font&amp;gt;:&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;re&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;𝗿&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;⃓rn &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;True&amp;lt;/font&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;defe&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;𝟧isPrimϵieg˓x&amp;lt;/font&amp;gt;(c&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;x&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if&amp;lt;/font&amp;gt; &amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;g&amp;lt;/font&amp;gt;ƨ&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;¤i&amp;lt;/font&amp;gt;natc&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;x&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;r&amp;lt;/font&amp;gt;'&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;^&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;(1&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;?| ?.&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;1&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+?&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;)&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;lime&amp;quot;&amp;gt;\+&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;)&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;$&amp;lt;/font&amp;gt;'&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;n &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;⎞1'&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;n):&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;rerɹrn &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;Fa&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;(&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt; e&amp;lt;/font&amp;gt;&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;ιetu⃓&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;nr&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;TrꙆ&amp;lt;/font&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;dq&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;purple&amp;quot;&amp;gt;⃓ q⃓soʀsor&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;η&amp;lt;/font&amp;gt;(a :&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;if &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;¤n&amp;lt;/font&amp;gt;(a  &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt; &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;2&amp;lt;/font&amp;gt;:&lt;br /&gt;
 		&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;eteturn &amp;lt;/font&amp;gt;a&lt;br /&gt;
 	pi&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=꞊ᵣ f&amp;lt;/font&amp;gt;a[&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;0&amp;lt;/font&amp;gt;]&lt;br /&gt;
 	l&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;pi&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=for&amp;lt;/font&amp;gt; j &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;ın&amp;lt;/font&amp;gt; a i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;&amp;lt;/font&amp;gt; i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;&amp;lt;/font&amp;gt;pi&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;lt;&amp;lt;/font&amp;gt;(t]&amp;lt;small&amp;gt;(&amp;lt;/small&amp;gt;)&lt;br /&gt;
 	r&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;[ı&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=for 𝟋 in&amp;lt;/font&amp;gt; a) &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;r&amp;lt;/font&amp;gt; i&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&amp;gt;&amp;lt;/font&amp;gt;viviv]&amp;lt;small&amp;gt;(&amp;lt;/small&amp;gt;vo)&lt;br /&gt;
 	mid&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;=&amp;lt;/font&amp;gt;[pi[&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;t]&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;l&amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;*&amp;lt;/font&amp;gt;t&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;ˌ&amp;lt;/font&amp;gt;(a)&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;-&amp;lt;/font&amp;gt;(&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;⟘en&amp;lt;/font&amp;gt;pᚆ&amp;lt;font color=&amp;quot;#44A1FF&amp;quot;&amp;gt;enlen&amp;lt;/font&amp;gt;(c)))&lt;br /&gt;
 	&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;r¤lrurrr&amp;lt;/font&amp;gt;ikıcksckt(l) &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;+&amp;lt;/font&amp;gt; r ¤ ¤quickrprt(r)&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:Protip: If you don't have access to the GNU ''patch'' tool, you can use the Photoshop one.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
[[Category:Comics with color]]&lt;br /&gt;
[[Category:Protip]]&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
[[Category:Photography]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357765</id>
		<title>3015: D&amp;D Combinatorics</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357765"/>
				<updated>2024-11-24T13:00:10Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3015&lt;br /&gt;
| date      = November 22, 2024&lt;br /&gt;
| title     = D&amp;amp;D Combinatorics&lt;br /&gt;
| image     = dnd_combinatorics_2x.png&lt;br /&gt;
| imagesize = 328x446px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = Look, you can't complain about this after giving us so many scenarios involving N locked chests and M unlabeled keys.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created by a BOT THAT GRABBED A CURSED ARROW - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
Dungeons and Dragons (D&amp;amp;D) is a role-playing game that usually has a &amp;quot;Dungeon Master&amp;quot; (narrator) that takes a team of players through scenarios where they attack monsters and go on quests.&lt;br /&gt;
&lt;br /&gt;
Often, there will be semi-random events: e.g., when attacking a monster, often a player will roll a die and deal damage based on the result. D&amp;amp;D uses a variety of dice, from regular d6 (6-sided, cubic dice) to other polyhedral dice, with the number of faces denoted by dX (e.g., d10 is a 10-sided die, with numbers from 1 to 10 on it). Common sets include: d4, d6, d8, d10, d12, d20, and occasionally d100 (typically not, however, the [[2626:_d65536|d65536]]).{{cn}}&lt;br /&gt;
&lt;br /&gt;
With these, you can simulate events with a wide variety of denominators. In this case, Cueball gives a {{w|combinatorics|combinatorial}} problem:&lt;br /&gt;
&lt;br /&gt;
* There are 10 arrows.&lt;br /&gt;
* 5 arrows are cursed.&lt;br /&gt;
* You randomly take two.&lt;br /&gt;
* What are the odds that neither of them are cursed?&lt;br /&gt;
&lt;br /&gt;
Calculating using {{w|binomial coefficients}}, there are “10 choose 2” (45) ways to choose two arrows, of which there are “5 choose 2” (10) ways to choose 2 arrows that are non-cursed. As a result, the odds of taking all non-cursed arrows is 10/45, which simplifies to 2/9. &lt;br /&gt;
&lt;br /&gt;
To see this in a different way, the probability of choosing one non-cursed arrow is 5/10, which then must be multiplied by the probability of choosing the second non-cursed arrow, which is now 4/9, giving 20/90 or 2/9, the same result as before.&lt;br /&gt;
&lt;br /&gt;
The Dungeon Master (DM) in this case [[356: Nerd Sniping|has to]] map that probability into rolling multiple dice, whose sums are also not evenly distributed: i.e. if rolling 3d6 (3 six-sided dice) and a d4 (1 four-sided die), the sums can range from 4 to 22. It's pretty hard to do this in one's head, but it does happen that the odds of rolling 16 or more with this combination is 2/9, matching the probability that we want to simulate. Here's a table of all the 6*6*6*4=864 possible outcomes -&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ All possible combinations of rolls for 3d6 + 1d4&lt;br /&gt;
|-&lt;br /&gt;
!Total!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14!!15!!16!!17!!18!!19!!20!!21!!22&lt;br /&gt;
|-&lt;br /&gt;
|Ways to roll it||1||4||10||20||34||52||71||88||100||104||100||88&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 71&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 52&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 34&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 20&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 10&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
71+52+34+20+10+4+1 = 192&lt;br /&gt;
&lt;br /&gt;
192/864 = 2/9, which matches the desired probability from earlier. The table of outcomes can either be bruteforced with a program, or can be derived using generating functions.&lt;br /&gt;
&lt;br /&gt;
The caption elaborates that the DM has a degree in the relevant field, and is unable to resist applying this to the D&amp;amp;D game when the opportunity arises - opportunities that Cueball eagerly provides for this very reason.&lt;br /&gt;
&lt;br /&gt;
There are several much easier ways of implementing this operation. First, literally present 10 similar-looking arrows, or other objects that are taken to represent arrows (cards, for example), with the assigned information of whether each one is cursed hidden away from Cueball, and then let Cueball pick any two. Even just with D&amp;amp;D dice, the DM could ask Cueball to roll a 1d10 for the first arrow, and for the second, roll another 1d10 and reroll if Cueball gets the same number as before. If 1-5 represents the cursed arrows and 6-10 represents the non-cursed arrows, following the convention that lower rolls are bad in D&amp;amp;D, then this achieves the same result without coming up with a more complex solution. These two approaches work well without requiring understanding probabilities, but to achieve the required odds just using two d6 dice, a 2/9 probability can be found by saying Cueball would succeed with a 9, 11, or 12 (4/36, 2/36, and 1/36 probability, respectively, giving 8/36 = 2/9). Using a d100 with 89 or higher gives a 22% percent chance as an approximation to 2/9 = 22.222..%, which may be sufficient.&lt;br /&gt;
&lt;br /&gt;
One could argue that the above solutions do not have the &amp;quot;polished&amp;quot; D&amp;amp;D feel of rolling a certain number of dice, adding them up, and seeing if the result is greater than or equal to a given required total. This is a commonly used mechanic for difficulty checks, hit calculations, and other such chance-based events in D&amp;amp;D. The DM may feel that this dice format is a requirement, but this approach is far too clunky for most DMs to be practical. It may be inferred that as the DM's mind tends towards more combinatorial solutions, she is either unable or unwilling to consider more straightforward and less time-consuming solutions to this cursed arrow problem.&lt;br /&gt;
&lt;br /&gt;
The title text claims that Randall only started doing this to the DM after she herself insisted on forcing another combinatorial puzzle on the players several times, involving a bunch of locked treasure chests and a multitude of keys to unlock them with. This might be a reference to an M-of-N encryption system, where a system has ''n'' valid passwords (instead of just one) but requires ''m'' of those passwords to be given before it will open; it is assumed m is greater than 1 but less than n. While this is easy enough to implement in a computer system, it would be extremely cumbersome to build for a physical lock with keys, and spreading the mechanism across multiple separate treasure chests would be impossible without literal magic (luckily, magic is in plentiful supply in a typical Dungeons and Dragons game).{{cn}}&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:[Cueball, Megan, Ponytail, White Hat, and Knit Cap are sitting at a table. Everyone is looking at Cueball. Ponytail is facepalming. The table is covered in sheets of paper and assorted dice.]&amp;lt;br&amp;gt;&lt;br /&gt;
:Cueball: I grab 2 of the 10 arrows without looking and fire them, hoping I didn't grab one of the 5 cursed ones. Did I?&lt;br /&gt;
:Ponytail: Sigh. Umm. Okay.&lt;br /&gt;
:Ponytail: Roll... Uh... Hang on...&lt;br /&gt;
:Ponytail: Roll 3d6 and a d4. You need... 16 or better to avoid the cursed arrows.&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:I got '''''way''''' more annoying to play D&amp;amp;D with once I learned that our DM has a combinatorics degree and can't resist puzzles.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Comics featuring Megan]]&lt;br /&gt;
[[Category:Comics featuring Ponytail]]&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Knit Cap]]&lt;br /&gt;
[[Category:Games]]&lt;br /&gt;
[[Category:Math]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357763</id>
		<title>3015: D&amp;D Combinatorics</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357763"/>
				<updated>2024-11-24T12:50:29Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3015&lt;br /&gt;
| date      = November 22, 2024&lt;br /&gt;
| title     = D&amp;amp;D Combinatorics&lt;br /&gt;
| image     = dnd_combinatorics_2x.png&lt;br /&gt;
| imagesize = 328x446px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = Look, you can't complain about this after giving us so many scenarios involving N locked chests and M unlabeled keys.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created by a BOT THAT GRABBED A CURSED ARROW - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
Dungeons and Dragons (D&amp;amp;D) is a role-playing game that usually has a &amp;quot;Dungeon Master&amp;quot; (narrator) that takes a team of players through scenarios where they attack monsters and go on quests.&lt;br /&gt;
&lt;br /&gt;
Often, there will be semi-random events: e.g., when attacking a monster, often a player will roll a die and deal damage based on the result. D&amp;amp;D uses a variety of dice, from regular d6 (6-sided, cubic dice) to other polyhedral dice, with the number of faces denoted by dX (e.g., d10 is a 10-sided die, with numbers from 1 to 10 on it). Common sets include: d4, d6, d8, d10, d12, d20, and occasionally d100 (typically not, however, the [[2626:_d65536|d65536]]).{{cn}}&lt;br /&gt;
&lt;br /&gt;
With these, you can simulate events with a wide variety of denominators. In this case, Cueball gives a {{w|combinatorics|combinatorial}} problem:&lt;br /&gt;
&lt;br /&gt;
* There are 10 arrows.&lt;br /&gt;
* 5 arrows are cursed.&lt;br /&gt;
* You randomly take two.&lt;br /&gt;
* What are the odds that neither of them are cursed?&lt;br /&gt;
&lt;br /&gt;
Calculating using {{w|binomial coefficients}}, there are “10 choose 2” (45) ways to choose two arrows, of which there are “5 choose 2” (10) ways to choose 2 arrows that are non-cursed. As a result, the odds of taking all non-cursed arrows is 10/45, which simplifies to 2/9. &lt;br /&gt;
&lt;br /&gt;
To see this in a different way, the probability of choosing one non-cursed arrow is 5/10, which then must be multiplied by the probability of choosing the second non-cursed arrow, which is now 4/9, giving 20/90 or 2/9, the same result as before.&lt;br /&gt;
&lt;br /&gt;
The Dungeon Master (DM) in this case [[356: Nerd Sniping|has to]] map that probability into rolling multiple dice, whose sums are also not evenly distributed: i.e. if rolling 3d6 (3 six-sided dice) and a d4 (1 four-sided die), the sums can range from 4 to 22. It's pretty hard to do this in one's head, but it does happen that the odds of rolling 16 or more with this combination is 2/9, matching the probability that we want to simulate. Here's a table of all the 6*6*6*4=864 possible outcomes -&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ All possible combinations of rolls for 3d6 + 1d4&lt;br /&gt;
|-&lt;br /&gt;
!Total!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14!!15!!16!!17!!18!!19!!20!!21!!22&lt;br /&gt;
|-&lt;br /&gt;
|Ways to roll it||1||4||10||20||34||52||71||88||100||104||100||88&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 71&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 52&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 34&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 20&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 10&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
71+52+34+20+10+4+1 = 192&lt;br /&gt;
&lt;br /&gt;
192/864 = 2/9, which matches the desired probability from earlier. The table of outcomes can either be bruteforced with a program, or can be derived using generating functions.&lt;br /&gt;
&lt;br /&gt;
The caption elaborates that the DM has a degree in the relevant field, and is unable to resist applying this to the D&amp;amp;D game when the opportunity arises - opportunities that Cueball eagerly provides for this very reason.&lt;br /&gt;
&lt;br /&gt;
There are several much easier ways of implementing this operation. First, literally present 10 similar-looking arrows, or other objects that are taken to represent arrows (cards, for example), with the assigned information of whether each one is cursed hidden away from Cueball, and then let Cueball pick any two. Even just with D&amp;amp;D dice, the DM could ask Cueball to roll a 1d10 for the first arrow, and for the second, roll another 1d10 and reroll if Cueball gets the same number. If 1-5 represents the cursed arrows and 6-10 represents the non-cursed arrows, following the convention that lower rolls are bad in D&amp;amp;D, then this achieves the same result without coming up with a more complex solution. These two approaches work well without requiring understanding probabilities, but to achieve the required odds just using two d6 dice, a 2/9 probability can be found by saying Cueball would succeed with a 9, 11, or 12 (4/36, 2/36, and 1/36 probability, respectively, giving 8/36 = 2/9). Using a d100 with 89 or higher gives a 22% percent chance as an approximation to 2/9 = 22.222..%, which may be sufficient.&lt;br /&gt;
&lt;br /&gt;
One could argue that the above solutions do not have the &amp;quot;polished&amp;quot; D&amp;amp;D feel of rolling a certain number of dice, adding them up, and seeing if the result is greater than or equal to a given required total. This is a commonly used mechanic for difficulty checks, hit calculations, and other such chance-based events in D&amp;amp;D. The DM may feel that this dice format is a requirement, but this approach is far too clunky for most DMs to be practical. It may be inferred that as the DM's mind tends towards more combinatorial solutions, she is either unable or unwilling to consider more straightforward and less time-consuming solutions to this cursed arrow problem.&lt;br /&gt;
&lt;br /&gt;
The title text claims that Randall only started doing this to the DM after she herself insisted on forcing another combinatorial puzzle on the players several times, involving a bunch of locked treasure chests and a multitude of keys to unlock them with. This might be a reference to an M-of-N encryption system, where a system has ''n'' valid passwords (instead of just one) but requires ''m'' of those passwords to be given before it will open; it is assumed m is greater than 1 but less than n. While this is easy enough to implement in a computer system, it would be extremely cumbersome to build for a physical lock with keys, and spreading the mechanism across multiple separate treasure chests would be impossible without literal magic (luckily, magic is in plentiful supply in a typical Dungeons and Dragons game).{{cn}}&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:[Cueball, Megan, Ponytail, White Hat, and Knit Cap are sitting at a table. Everyone is looking at Cueball. Ponytail is facepalming. The table is covered in sheets of paper and assorted dice.]&amp;lt;br&amp;gt;&lt;br /&gt;
:Cueball: I grab 2 of the 10 arrows without looking and fire them, hoping I didn't grab one of the 5 cursed ones. Did I?&lt;br /&gt;
:Ponytail: Sigh. Umm. Okay.&lt;br /&gt;
:Ponytail: Roll... Uh... Hang on...&lt;br /&gt;
:Ponytail: Roll 3d6 and a d4. You need... 16 or better to avoid the cursed arrows.&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:I got '''''way''''' more annoying to play D&amp;amp;D with once I learned that our DM has a combinatorics degree and can't resist puzzles.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Comics featuring Megan]]&lt;br /&gt;
[[Category:Comics featuring Ponytail]]&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Knit Cap]]&lt;br /&gt;
[[Category:Games]]&lt;br /&gt;
[[Category:Math]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357761</id>
		<title>3015: D&amp;D Combinatorics</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357761"/>
				<updated>2024-11-24T12:42:26Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3015&lt;br /&gt;
| date      = November 22, 2024&lt;br /&gt;
| title     = D&amp;amp;D Combinatorics&lt;br /&gt;
| image     = dnd_combinatorics_2x.png&lt;br /&gt;
| imagesize = 328x446px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = Look, you can't complain about this after giving us so many scenarios involving N locked chests and M unlabeled keys.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created by a BOT THAT GRABBED A CURSED ARROW - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
Dungeons and Dragons (D&amp;amp;D) is a role-playing game that usually has a &amp;quot;Dungeon Master&amp;quot; (narrator) that takes a team of players through scenarios where they attack monsters and go on quests.&lt;br /&gt;
&lt;br /&gt;
Often, there will be semi-random events: e.g., when attacking a monster, often a player will roll a die and deal damage based on the result. D&amp;amp;D uses a variety of dice, from regular d6 (6-sided, cubic dice) to other polyhedral dice, with the number of faces denoted by dX (e.g., d10 is a 10-sided die, with numbers from 1 to 10 on it). Common sets include: d4, d6, d8, d10, d12, d20, and occasionally d100 (typically not, however, the [[2626:_d65536|d65536]]).{{cn}}&lt;br /&gt;
&lt;br /&gt;
With these, you can simulate events with a wide variety of denominators. In this case, Cueball gives a {{w|combinatorics|combinatorial}} problem:&lt;br /&gt;
&lt;br /&gt;
* There are 10 arrows.&lt;br /&gt;
* 5 arrows are cursed.&lt;br /&gt;
* You randomly take two.&lt;br /&gt;
* What are the odds that neither of them are cursed?&lt;br /&gt;
&lt;br /&gt;
Calculating using {{w|binomial coefficients}}, there are “10 choose 2” (45) ways to choose two arrows, of which there are “5 choose 2” (10) ways to choose 2 arrows that are non-cursed. As a result, the odds of taking all non-cursed arrows is 10/45, which simplifies to 2/9. &lt;br /&gt;
&lt;br /&gt;
To see this in a different way, the probability of choosing one non-cursed arrow is 5/10, which then must be multiplied by the probability of choosing the second non-cursed arrow, which is now 4/9, giving 20/90 or 2/9, the same result as before.&lt;br /&gt;
&lt;br /&gt;
The Dungeon Master (DM) in this case [[356: Nerd Sniping|has to]] map that probability into rolling multiple dice, whose sums are also not evenly distributed: i.e. if rolling 3d6 (3 six-sided dice) and a d4 (1 four-sided die), the sums can range from 4 to 22. It's pretty hard to do this in one's head, but it does happen that the odds of rolling 16 or more with this combination is 2/9, matching the probability that we want to simulate. Here's a table of all the 6*6*6*4=864 possible outcomes -&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ All possible combinations of rolls for 3d6 + 1d4&lt;br /&gt;
|-&lt;br /&gt;
!Total!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14!!15!!16!!17!!18!!19!!20!!21!!22&lt;br /&gt;
|-&lt;br /&gt;
|Ways to roll it||1||4||10||20||34||52||71||88||100||104||100||88&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 71&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 52&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 34&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 20&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 10&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
71+52+34+20+10+4+1 = 192&lt;br /&gt;
&lt;br /&gt;
192/864 = 2/9, which matches the desired probability from earlier. The table of outcomes can either be bruteforced with a program, or can be derived using generating functions.&lt;br /&gt;
&lt;br /&gt;
The caption elaborates that the DM has a degree in the relevant field, and is unable to resist applying this to the D&amp;amp;D game when the opportunity arises - opportunities that Cueball eagerly provides for this very reason.&lt;br /&gt;
&lt;br /&gt;
There are several much easier ways of implementing this operation. First, literally present 10 similar-looking arrows, or other objects that are taken to represent arrows (cards, for example), with the assigned information of whether each one is cursed hidden away from Cueball, and then let Cueball pick any two. Even just with D&amp;amp;D dice, the DM could ask Cueball to roll a 1d10 for the first arrow, and for the second, roll another 1d10 and reroll if Cueball gets the same number. If 1-5 represents the cursed arrows and 6-10 represents the non-cursed arrows, following the convention that lower rolls are bad in D&amp;amp;D, then this achieves the same result without coming up with a more complex solution. These two approaches work well without requiring understanding probabilities, but to achieve the required odds just using two d6 dice, a 2/9 probability can be found by saying Cueball would succeed with a 9, 11, or 12 (4/36, 2/36, and 1/36 probability, respectively, giving 8/36 = 2/9). Using a d100 with 89 or higher gives a 22% percent chance as an approximation to 2/9 = 22.222..%, which may be sufficient.&lt;br /&gt;
&lt;br /&gt;
One could argue that the above solutions do not have the &amp;quot;polished&amp;quot; D&amp;amp;D feel of rolling a certain number of dice, adding them up, and seeing if the result is greater than or equal to a given required numer. This is a commonly used mechanic for difficulty checks, hit calculations, and other such chance-based events in D&amp;amp;D. The DM may feel that this dice format is a requirement, but this approach is far too clunky for most DMs to be practical. It may be inferred that as the DM's mind tends towards more combinatorial solutions, she is either unable or unwilling to consider more straightforward and less time-consuming solutions to this cursed arrow problem.&lt;br /&gt;
&lt;br /&gt;
The title text claims that Randall only started doing this to the DM after she herself insisted on forcing another combinatorial puzzle on the players several times, involving a bunch of locked treasure chests and a multitude of keys to unlock them with. This might be a reference to an M-of-N encryption system, where a system has ''n'' valid passwords (instead of just one) but requires ''m'' of those passwords to be given before it will open; it is assumed m is greater than 1 but less than n. While this is easy enough to implement in a computer system, it would be extremely cumbersome to build for a physical lock with keys, and spreading the mechanism across multiple separate treasure chests would be impossible without literal magic (luckily, magic is in plentiful supply in a typical Dungeons and Dragons game).{{cn}}&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:[Cueball, Megan, Ponytail, White Hat, and Knit Cap are sitting at a table. Everyone is looking at Cueball. Ponytail is facepalming. The table is covered in sheets of paper and assorted dice.]&amp;lt;br&amp;gt;&lt;br /&gt;
:Cueball: I grab 2 of the 10 arrows without looking and fire them, hoping I didn't grab one of the 5 cursed ones. Did I?&lt;br /&gt;
:Ponytail: Sigh. Umm. Okay.&lt;br /&gt;
:Ponytail: Roll... Uh... Hang on...&lt;br /&gt;
:Ponytail: Roll 3d6 and a d4. You need... 16 or better to avoid the cursed arrows.&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:I got '''''way''''' more annoying to play D&amp;amp;D with once I learned that our DM has a combinatorics degree and can't resist puzzles.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Comics featuring Megan]]&lt;br /&gt;
[[Category:Comics featuring Ponytail]]&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Knit Cap]]&lt;br /&gt;
[[Category:Games]]&lt;br /&gt;
[[Category:Math]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357760</id>
		<title>3015: D&amp;D Combinatorics</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357760"/>
				<updated>2024-11-24T12:40:46Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3015&lt;br /&gt;
| date      = November 22, 2024&lt;br /&gt;
| title     = D&amp;amp;D Combinatorics&lt;br /&gt;
| image     = dnd_combinatorics_2x.png&lt;br /&gt;
| imagesize = 328x446px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = Look, you can't complain about this after giving us so many scenarios involving N locked chests and M unlabeled keys.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created by a BOT THAT GRABBED A CURSED ARROW - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
Dungeons and Dragons (D&amp;amp;D) is a role-playing game that usually has a &amp;quot;Dungeon Master&amp;quot; (narrator) that takes a team of players through scenarios where they attack monsters and go on quests.&lt;br /&gt;
&lt;br /&gt;
Often, there will be semi-random events: e.g., when attacking a monster, often a player will roll a die and deal damage based on the result. D&amp;amp;D uses a variety of dice, from regular d6 (6-sided, cubic dice) to other polyhedral dice, with the number of faces denoted by dX (e.g., d10 is a 10-sided die, with numbers from 1 to 10 on it). Common sets include: d4, d6, d8, d10, d12, d20, and occasionally d100 (typically not, however, the [[2626:_d65536|d65536]]).{{cn}}&lt;br /&gt;
&lt;br /&gt;
With these, you can simulate events with a wide variety of denominators. In this case, Cueball gives a {{w|combinatorics|combinatorial}} problem:&lt;br /&gt;
&lt;br /&gt;
* There are 10 arrows.&lt;br /&gt;
* 5 arrows are cursed.&lt;br /&gt;
* You randomly take two.&lt;br /&gt;
* What are the odds that neither of them are cursed?&lt;br /&gt;
&lt;br /&gt;
Calculating using {{w|binomial coefficients}}, there are “10 choose 2” (45) ways to choose two arrows, of which there are “5 choose 2” (10) ways to choose 2 arrows that are non-cursed. As a result, the odds of taking all non-cursed arrows is 10/45, which simplifies to 2/9. &lt;br /&gt;
&lt;br /&gt;
To see this in a different way, the probability of choosing one non-cursed arrow is 5/10, which then must be multiplied by the probability of choosing the second non-cursed arrow, which is now 4/9, giving 20/90 or 2/9, the same result as before.&lt;br /&gt;
&lt;br /&gt;
The Dungeon Master (DM) in this case [[356: Nerd Sniping|has to]] map that probability into rolling multiple dice, whose sums are also not evenly distributed: i.e. if rolling 3d6 (3 six-sided dice) and a d4 (1 four-sided die), the sums can range from 4 to 22. It's pretty hard to do this in one's head, but it does happen that the odds of rolling 16 or more with this combination is 2/9, matching the probability that we want to simulate. Here's a table of all the 6*6*6*4=864 possible outcomes -&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ All possible combinations of rolls for 3d6 + 1d4&lt;br /&gt;
|-&lt;br /&gt;
!Total!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14!!15!!16!!17!!18!!19!!20!!21!!22&lt;br /&gt;
|-&lt;br /&gt;
|Ways to roll it||1||4||10||20||34||52||71||88||100||104||100||88&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 71&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 52&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 34&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 20&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 10&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
71+52+34+20+10+4+1 = 192&lt;br /&gt;
&lt;br /&gt;
192/864 = 2/9, which matches the desired probability from earlier. The table of outcomes can either be bruteforced with a program, or can be derived using generating functions.&lt;br /&gt;
&lt;br /&gt;
The caption elaborates that the DM has a degree in the relevant field, and is unable to resist applying this to the D&amp;amp;D game when the opportunity arises - opportunities that Cueball eagerly provides for this very reason.&lt;br /&gt;
&lt;br /&gt;
There are several much easier ways of implementing this operation. First, literally present 10 similar-looking arrows, or other objects that are taken to represent arrows (cards, for example), with the assigned information of whether each one is cursed hidden away from Cueball, and then let Cueball pick any two. Even just with D&amp;amp;D dice, the DM could ask Cueball to roll a 1d10 for the first arrow, and for the second, roll another 1d10 and reroll if Cueball gets the same number. If 1-5 represents the cursed arrows and 6-10 represents the non-cursed arrows, following the convention that lower rolls are bad in D&amp;amp;D, then this achieves the same result without coming up with a more complex solution. These two approaches work well without requiring understanding probabilities, but to achieve the required odds just using two d6 dice, a 2/9 probability can be found by saying Cueball would succeed with a 9, 11, or 12 (4/36, 2/36, and 1/36 probability, respectively, giving 8/36 = 2/9). Using a d100 with 89 or higher gives 22% percent chance as an approximation to 2/9 = 22.222..%.&lt;br /&gt;
&lt;br /&gt;
One could argue that the above solutions do not have the &amp;quot;polished&amp;quot; D&amp;amp;D feel of rolling a certain number of dice, adding them up, and seeing if the result is greater than or equal to a given required numer. This is a commonly used mechanic for difficulty checks, hit calculations, and other such chance-based events in D&amp;amp;D. The DM may feel that this dice format is a requirement, but this approach is far too clunky for most DMs to be practical. It may be inferred that as the DM's mind tends towards more combinatorial solutions, she is either unable or unwilling to consider more straightforward and less time-consuming solutions to this cursed arrow problem.&lt;br /&gt;
&lt;br /&gt;
The title text claims that Randall only started doing this to the DM after she herself insisted on forcing another combinatorial puzzle on the players several times, involving a bunch of locked treasure chests and a multitude of keys to unlock them with. This might be a reference to an M-of-N encryption system, where a system has ''n'' valid passwords (instead of just one) but requires ''m'' of those passwords to be given before it will open; it is assumed m is greater than 1 but less than n. While this is easy enough to implement in a computer system, it would be extremely cumbersome to build for a physical lock with keys, and spreading the mechanism across multiple separate treasure chests would be impossible without literal magic (luckily, magic is in plentiful supply in a typical Dungeons and Dragons game).{{cn}}&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:[Cueball, Megan, Ponytail, White Hat, and Knit Cap are sitting at a table. Everyone is looking at Cueball. Ponytail is facepalming. The table is covered in sheets of paper and assorted dice.]&amp;lt;br&amp;gt;&lt;br /&gt;
:Cueball: I grab 2 of the 10 arrows without looking and fire them, hoping I didn't grab one of the 5 cursed ones. Did I?&lt;br /&gt;
:Ponytail: Sigh. Umm. Okay.&lt;br /&gt;
:Ponytail: Roll... Uh... Hang on...&lt;br /&gt;
:Ponytail: Roll 3d6 and a d4. You need... 16 or better to avoid the cursed arrows.&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:I got '''''way''''' more annoying to play D&amp;amp;D with once I learned that our DM has a combinatorics degree and can't resist puzzles.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Comics featuring Megan]]&lt;br /&gt;
[[Category:Comics featuring Ponytail]]&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Knit Cap]]&lt;br /&gt;
[[Category:Games]]&lt;br /&gt;
[[Category:Math]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357759</id>
		<title>3015: D&amp;D Combinatorics</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357759"/>
				<updated>2024-11-24T12:39:19Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3015&lt;br /&gt;
| date      = November 22, 2024&lt;br /&gt;
| title     = D&amp;amp;D Combinatorics&lt;br /&gt;
| image     = dnd_combinatorics_2x.png&lt;br /&gt;
| imagesize = 328x446px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = Look, you can't complain about this after giving us so many scenarios involving N locked chests and M unlabeled keys.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created by a BOT THAT GRABBED A CURSED ARROW - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
Dungeons and Dragons (D&amp;amp;D) is a role-playing game that usually has a &amp;quot;Dungeon Master&amp;quot; (narrator) that takes a team of players through scenarios where they attack monsters and go on quests.&lt;br /&gt;
&lt;br /&gt;
Often, there will be semi-random events: e.g., when attacking a monster, often a player will roll a die and deal damage based on the result. D&amp;amp;D uses a variety of dice, from regular d6 (6-sided, cubic dice) to other polyhedral dice, with the number of faces denoted by dX (e.g., d10 is a 10-sided die, with numbers from 1 to 10 on it). Common sets include: d4, d6, d8, d10, d12, d20, and occasionally d100 (typically not, however, the [[2626:_d65536|d65536]]).{{cn}}&lt;br /&gt;
&lt;br /&gt;
With these, you can simulate events with a wide variety of denominators. In this case, Cueball gives a {{w|combinatorics|combinatorial}} problem:&lt;br /&gt;
&lt;br /&gt;
* There are 10 arrows.&lt;br /&gt;
* 5 arrows are cursed.&lt;br /&gt;
* You randomly take two.&lt;br /&gt;
* What are the odds that neither of them are cursed?&lt;br /&gt;
&lt;br /&gt;
Calculating using {{w|binomial coefficients}}, there are “10 choose 2” (45) ways to choose two arrows, of which there are “5 choose 2” (10) ways to choose 2 arrows that are non-cursed. As a result, the odds of taking all non-cursed arrows is 10/45, which simplifies to 2/9. &lt;br /&gt;
&lt;br /&gt;
To see this in a different way, the probability of choosing one non-cursed arrow is 5/10, which then must be multiplied by the probability of choosing the second non-cursed arrow, which is now 4/9, giving 20/90 or 2/9, the same result as before.&lt;br /&gt;
&lt;br /&gt;
The Dungeon Master (DM) in this case [[356: Nerd Sniping|has to]] map that probability into rolling multiple dice, whose sums are also not evenly distributed: i.e. if rolling 3d6 (3 six-sided dice) and a d4 (1 four-sided die), the sums can range from 4 to 22. It's pretty hard to do this in one's head, but it does happen that the odds of rolling 16 or more with this combination is 2/9, matching the probability that we want to simulate. Here's a table of all the 6*6*6*4=864 possible outcomes -&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ All possible combinations of rolls for 3d6 + 1d4&lt;br /&gt;
|-&lt;br /&gt;
!Total!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14!!15!!16!!17!!18!!19!!20!!21!!22&lt;br /&gt;
|-&lt;br /&gt;
|Ways to roll it||1||4||10||20||34||52||71||88||100||104||100||88&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 71&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 52&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 34&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 20&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 10&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
71+52+34+20+10+4+1 = 192&lt;br /&gt;
&lt;br /&gt;
192/864 = 2/9, which matches the desired probability from earlier. The table of outcomes can either be bruteforced with a program, or can be derived using generating functions.&lt;br /&gt;
&lt;br /&gt;
The caption elaborates that the DM has a degree in the relevant field, and is unable to resist applying this to the D&amp;amp;D game when the opportunity arises - opportunities that Cueball eagerly provides for this very reason.&lt;br /&gt;
&lt;br /&gt;
There are several much easier ways of implementing this operation. First, literally present 10 similar-looking arrows, or other objects that are taken to represent arrows (cards, for example), with the assigned information of whether each one is cursed hidden away from Cueball, and then let Cueball pick any two. Even just with D&amp;amp;D dice, the DM could ask Cueball to roll a 1d10 for the first arrow, and for the second, roll another 1d10 and reroll if Cueball gets the same number. If 1-5 represents the cursed arrows and 6-10 represents the non-cursed arrows, following the convention that lower rolls are bad in D&amp;amp;D, then this achieves the same result without coming up with a more complex solution. These two approaches work well without requiring understanding probabilities, but to achieve the required odds just using two d6 dice, a 2/9 probability can be found by saying Cueball would succeed with a 9, 11, or 12 (4/36, 2/36, and 1/36 probability, respectively, giving 8/36 = 2/9). Using a d100 with 89 or higher gives 22% percent chance as an approximation to 2/9 = 22.222..%..&lt;br /&gt;
&lt;br /&gt;
One could argue that the above solutions do not have the &amp;quot;polished&amp;quot; D&amp;amp;D feel of rolling a certain number of dice, adding them up, and seeing if the result is greater than or equal to a given required numer. This is a commonly used mechanic for difficulty checks, hit calculations, and other such chance-based events in D&amp;amp;D. The DM may feel that this dice format is a requirement, but this approach is far too clunky for most DMs to be practical. It may be inferred that as the DM's mind tends towards more combinatorial solutions, she is either unable or unwilling to consider more straightforward and less time-consuming solutions to this cursed arrow problem.&lt;br /&gt;
&lt;br /&gt;
The title text claims that Randall only started doing this to the DM after she herself insisted on forcing another combinatorial puzzle on the players several times, involving a bunch of locked treasure chests and a multitude of keys to unlock them with. This might be a reference to an M-of-N encryption system, where a system has ''n'' valid passwords (instead of just one) but requires ''m'' of those passwords to be given before it will open; it is assumed m is greater than 1 but less than n. While this is easy enough to implement in a computer system, it would be extremely cumbersome to build for a physical lock with keys, and spreading the mechanism across multiple separate treasure chests would be impossible without literal magic (luckily, magic is in plentiful supply in a typical Dungeons and Dragons game).{{cn}}&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:[Cueball, Megan, Ponytail, White Hat, and Knit Cap are sitting at a table. Everyone is looking at Cueball. Ponytail is facepalming. The table is covered in sheets of paper and assorted dice.]&amp;lt;br&amp;gt;&lt;br /&gt;
:Cueball: I grab 2 of the 10 arrows without looking and fire them, hoping I didn't grab one of the 5 cursed ones. Did I?&lt;br /&gt;
:Ponytail: Sigh. Umm. Okay.&lt;br /&gt;
:Ponytail: Roll... Uh... Hang on...&lt;br /&gt;
:Ponytail: Roll 3d6 and a d4. You need... 16 or better to avoid the cursed arrows.&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:I got '''''way''''' more annoying to play D&amp;amp;D with once I learned that our DM has a combinatorics degree and can't resist puzzles.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Comics featuring Megan]]&lt;br /&gt;
[[Category:Comics featuring Ponytail]]&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Knit Cap]]&lt;br /&gt;
[[Category:Games]]&lt;br /&gt;
[[Category:Math]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357758</id>
		<title>3015: D&amp;D Combinatorics</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357758"/>
				<updated>2024-11-24T12:16:03Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3015&lt;br /&gt;
| date      = November 22, 2024&lt;br /&gt;
| title     = D&amp;amp;D Combinatorics&lt;br /&gt;
| image     = dnd_combinatorics_2x.png&lt;br /&gt;
| imagesize = 328x446px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = Look, you can't complain about this after giving us so many scenarios involving N locked chests and M unlabeled keys.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created by a BOT THAT GRABBED A CURSED ARROW - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
Dungeons and Dragons (D&amp;amp;D) is a role-playing game that usually has a &amp;quot;Dungeon Master&amp;quot; (narrator) that takes a team of players through scenarios where they attack monsters and go on quests.&lt;br /&gt;
&lt;br /&gt;
Often, there will be semi-random events: e.g., when attacking a monster, often a player will roll a die and deal damage based on the result. D&amp;amp;D uses a variety of dice, from regular d6 (6-sided, cubic dice) to other polyhedral dice, with the number of faces denoted by dX (e.g., d10 is a 10-sided die, with numbers from 1 to 10 on it). Common sets include: d4, d6, d8, d10, d12, d20, and occasionally d100 (typically not, however, the [[2626:_d65536|d65536]]).{{cn}}&lt;br /&gt;
&lt;br /&gt;
With these, you can simulate events with a wide variety of denominators. In this case, Cueball gives a {{w|combinatorics|combinatorial}} problem:&lt;br /&gt;
&lt;br /&gt;
* There are 10 arrows.&lt;br /&gt;
* 5 arrows are cursed.&lt;br /&gt;
* You randomly take two.&lt;br /&gt;
* What are the odds that neither of them are cursed?&lt;br /&gt;
&lt;br /&gt;
Calculating using {{w|binomial coefficients}}, there are “10 choose 2” (45) ways to choose two arrows, of which there are “5 choose 2” (10) ways to choose 2 arrows that are non-cursed. As a result, the odds of taking all non-cursed arrows is 10/45, which simplifies to 2/9. &lt;br /&gt;
&lt;br /&gt;
To see this in a different way, the probability of choosing one non-cursed arrow is 5/10, which then must be multiplied by the probability of choosing the second non-cursed arrow, which is now 4/9, giving 20/90 or 2/9, the same result as before.&lt;br /&gt;
&lt;br /&gt;
The Dungeon Master (DM) in this case [[356: Nerd Sniping|has to]] map that probability into rolling multiple dice, whose sums are also not evenly distributed: i.e. if rolling 3d6 (3 six-sided dice) and a d4 (1 four-sided die), the sums can range from 4 to 22. It's pretty hard to do this in one's head, but it does happen that the odds of rolling 16 or more with this combination is 2/9, matching the probability that we want to simulate. Here's a table of all the 6*6*6*4=864 possible outcomes -&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ All possible combinations of rolls for 3d6 + 1d4&lt;br /&gt;
|-&lt;br /&gt;
!Total!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14!!15!!16!!17!!18!!19!!20!!21!!22&lt;br /&gt;
|-&lt;br /&gt;
|Ways to roll it||1||4||10||20||34||52||71||88||100||104||100||88&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 71&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 52&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 34&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 20&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 10&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
71+52+34+20+10+4+1 = 192&lt;br /&gt;
&lt;br /&gt;
192/864 = 2/9, which matches the desired probability from earlier. The table of outcomes can either be bruteforced with a program, or can be derived using generating functions.&lt;br /&gt;
&lt;br /&gt;
The caption elaborates that the DM has a degree in the relevant field, and is unable to resist applying this to the D&amp;amp;D game when the opportunity arises - opportunities that Cueball eagerly provides for this very reason.&lt;br /&gt;
&lt;br /&gt;
There are several much easier ways of implementing this operation. First, literally present 10 similar-looking arrows, or other objects that are taken to represent arrows (cards, for example), with the assigned information of whether each one is cursed hidden away from Cueball, and then let Cueball pick any two. Even just with D&amp;amp;D dice, the DM could ask Cueball to roll a 1d10 for the first arrow, and for the second, roll another 1d10 and reroll if Cueball gets the same number. If 1-5 represents the cursed arrows and 6-10 represents the non-cursed arrows, following the convention that lower rolls are bad in D&amp;amp;D, then this achieves the same result without coming up with a more complex solution. Even just using two d6 dice, a 2/9 probability is easily achieved by saying Cueball would succeed with a 9, 11, or 12 (4/36, 2/36, and 1/36 probability, respectively, giving 8/36 = 2/9 probability).&lt;br /&gt;
&lt;br /&gt;
One could argue that the above solutions do not have the &amp;quot;polished&amp;quot; D&amp;amp;D feel of rolling a certain number of dice, adding them up, and seeing if the result is greater than or equal to a given required numer. This is a commonly used mechanic for difficulty checks, hit calculations, and other such chance-based events in D&amp;amp;D. The DM may feel that this dice format is a requirement, but this approach is far too clunky for most DMs to be practical. It may be inferred that as the DM's mind tends towards more combinatorial solutions, she is either unable or unwilling to consider more straightforward and less time-consuming solutions to this cursed arrow problem.&lt;br /&gt;
&lt;br /&gt;
The title text claims that Randall only started doing this to the DM after she herself insisted on forcing another combinatorial puzzle on the players several times, involving a bunch of locked treasure chests and a multitude of keys to unlock them with. This might be a reference to an M-of-N encryption system, where a system has ''n'' valid passwords (instead of just one) but requires ''m'' of those passwords to be given before it will open; it is assumed m is greater than 1 but less than n. While this is easy enough to implement in a computer system, it would be extremely cumbersome to build for a physical lock with keys, and spreading the mechanism across multiple separate treasure chests would be impossible without literal magic (luckily, magic is in plentiful supply in a typical Dungeons and Dragons game).{{cn}}&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:[Cueball, Megan, Ponytail, White Hat, and Knit Cap are sitting at a table. Everyone is looking at Cueball. Ponytail is facepalming. The table is covered in sheets of paper and assorted dice.]&amp;lt;br&amp;gt;&lt;br /&gt;
:Cueball: I grab 2 of the 10 arrows without looking and fire them, hoping I didn't grab one of the 5 cursed ones. Did I?&lt;br /&gt;
:Ponytail: Sigh. Umm. Okay.&lt;br /&gt;
:Ponytail: Roll... Uh... Hang on...&lt;br /&gt;
:Ponytail: Roll 3d6 and a d4. You need... 16 or better to avoid the cursed arrows.&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:I got '''''way''''' more annoying to play D&amp;amp;D with once I learned that our DM has a combinatorics degree and can't resist puzzles.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Comics featuring Megan]]&lt;br /&gt;
[[Category:Comics featuring Ponytail]]&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Knit Cap]]&lt;br /&gt;
[[Category:Games]]&lt;br /&gt;
[[Category:Math]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357757</id>
		<title>3015: D&amp;D Combinatorics</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357757"/>
				<updated>2024-11-24T12:14:32Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3015&lt;br /&gt;
| date      = November 22, 2024&lt;br /&gt;
| title     = D&amp;amp;D Combinatorics&lt;br /&gt;
| image     = dnd_combinatorics_2x.png&lt;br /&gt;
| imagesize = 328x446px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = Look, you can't complain about this after giving us so many scenarios involving N locked chests and M unlabeled keys.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created by a BOT THAT GRABBED A CURSED ARROW - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
Dungeons and Dragons (D&amp;amp;D) is a role-playing game that usually has a &amp;quot;Dungeon Master&amp;quot; (narrator) that takes a team of players through scenarios where they attack monsters and go on quests.&lt;br /&gt;
&lt;br /&gt;
Often, there will be semi-random events: e.g., when attacking a monster, often a player will roll a die and deal damage based on the result. D&amp;amp;D uses a variety of dice, from regular d6 (6-sided, cubic dice) to other polyhedral dice, with the number of faces denoted by dX (e.g., d10 is a 10-sided die, with numbers from 1 to 10 on it). Common sets include: d4, d6, d8, d10, d12, d20, and occasionally d100 (typically not, however, the [[2626:_d65536|d65536]]).{{cn}}&lt;br /&gt;
&lt;br /&gt;
With these, you can simulate events with a wide variety of denominators. In this case, Cueball gives a {{w|combinatorics|combinatorial}} problem:&lt;br /&gt;
&lt;br /&gt;
* There are 10 arrows.&lt;br /&gt;
* 5 arrows are cursed.&lt;br /&gt;
* You randomly take two.&lt;br /&gt;
* What are the odds that neither of them are cursed?&lt;br /&gt;
&lt;br /&gt;
Calculating using {{w|binomial coefficients}}, there are “10 choose 2” (45) ways to choose two arrows, of which there are “5 choose 2” (10) ways to choose 2 arrows that are non-cursed. As a result, the odds of taking all non-cursed arrows is 10/45, which simplifies to 2/9. &lt;br /&gt;
&lt;br /&gt;
To see this in a different way, the probability of choosing one non-cursed arrow is 5/10, which then must be multiplied by the probability of choosing the second non-cursed arrow, which is now 4/9, giving 20/90 or 2/9, the same result as before.&lt;br /&gt;
&lt;br /&gt;
The Dungeon Master (DM) in this case [[356: Nerd Sniping|has to]] map that probability into rolling multiple dice, whose sums are also not evenly distributed: i.e. if rolling 3d6 (3 six-sided dice) and a d4 (1 four-sided die), the sums can range from 4 to 22. It's pretty hard to do this in one's head, but it does happen that the odds of rolling 16 or more with this combination is 2/9, matching the probability that we want to simulate. Here's a table of all the 6*6*6*4=864 possible outcomes -&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ All possible combinations of rolls for 3d6 + 1d4&lt;br /&gt;
|-&lt;br /&gt;
!Total!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14!!15!!16!!17!!18!!19!!20!!21!!22&lt;br /&gt;
|-&lt;br /&gt;
|Ways to roll it||1||4||10||20||34||52||71||88||100||104||100||88&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 71&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 52&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 34&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 20&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 10&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
71+52+34+20+10+4+1 = 192&lt;br /&gt;
&lt;br /&gt;
192/864 = 2/9, which matches the desired probability from earlier. The table of outcomes can either be bruteforced with a program, or can be derived using generating functions.&lt;br /&gt;
&lt;br /&gt;
The caption elaborates that the DM has a degree in the relevant field, and is unable to resist applying this to the D&amp;amp;D game when the opportunity arises - opportunities that Cueball eagerly provides for this very reason.&lt;br /&gt;
&lt;br /&gt;
There are several much easier ways of implementing this operation. First, literally present 10 similar-looking arrows, or other objects that are taken to represent arrows (cards, for example), with the assigned information of whether each one is cursed hidden away from Cueball, and then let Cueball pick any two. Even just with D&amp;amp;D dice, the DM could ask Cueball to roll a 1d10 for the first arrow, and for the second, roll another 1d10 and reroll if Cueball gets the same number. If 1-5 represents the cursed arrows and 6-10 represents the non-cursed arrows, following the convention that lower rolls are bad in D&amp;amp;D, then this achieves the same result without coming up with a more complex solution. Even just using two d6 dice, achieving a 2/9 probability is easily achieved by saying Cueball would succeed with a 9, 11, or 12 (4/36, 2/36, and 1/36 probability, respectively, giving 8/36 = 2/9 probability).&lt;br /&gt;
&lt;br /&gt;
One could argue that the above solutions do not have the &amp;quot;polished&amp;quot; D&amp;amp;D feel of rolling a certain number of dice, adding them up, and seeing if the result is greater than or equal to a given required numer. This is a commonly used mechanic for difficulty checks, hit calculations, and other such chance-based events in D&amp;amp;D. The DM may feel that this dice format is a requirement, but this approach is far too clunky for most DMs to be practical. It may be inferred that as the DM's mind tends towards more combinatorial solutions, she is either unable or unwilling to consider more straightforward and less time-consuming solutions to this cursed arrow problem.&lt;br /&gt;
&lt;br /&gt;
The title text claims that Randall only started doing this to the DM after she herself insisted on forcing another combinatorial puzzle on the players several times, involving a bunch of locked treasure chests and a multitude of keys to unlock them with. This might be a reference to an M-of-N encryption system, where a system has ''n'' valid passwords (instead of just one) but requires ''m'' of those passwords to be given before it will open; it is assumed m is greater than 1 but less than n. While this is easy enough to implement in a computer system, it would be extremely cumbersome to build for a physical lock with keys, and spreading the mechanism across multiple separate treasure chests would be impossible without literal magic (luckily, magic is in plentiful supply in a typical Dungeons and Dragons game).{{cn}}&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:[Cueball, Megan, Ponytail, White Hat, and Knit Cap are sitting at a table. Everyone is looking at Cueball. Ponytail is facepalming. The table is covered in sheets of paper and assorted dice.]&amp;lt;br&amp;gt;&lt;br /&gt;
:Cueball: I grab 2 of the 10 arrows without looking and fire them, hoping I didn't grab one of the 5 cursed ones. Did I?&lt;br /&gt;
:Ponytail: Sigh. Umm. Okay.&lt;br /&gt;
:Ponytail: Roll... Uh... Hang on...&lt;br /&gt;
:Ponytail: Roll 3d6 and a d4. You need... 16 or better to avoid the cursed arrows.&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:I got '''''way''''' more annoying to play D&amp;amp;D with once I learned that our DM has a combinatorics degree and can't resist puzzles.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Comics featuring Megan]]&lt;br /&gt;
[[Category:Comics featuring Ponytail]]&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Knit Cap]]&lt;br /&gt;
[[Category:Games]]&lt;br /&gt;
[[Category:Math]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357756</id>
		<title>3015: D&amp;D Combinatorics</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357756"/>
				<updated>2024-11-24T12:07:43Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3015&lt;br /&gt;
| date      = November 22, 2024&lt;br /&gt;
| title     = D&amp;amp;D Combinatorics&lt;br /&gt;
| image     = dnd_combinatorics_2x.png&lt;br /&gt;
| imagesize = 328x446px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = Look, you can't complain about this after giving us so many scenarios involving N locked chests and M unlabeled keys.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created by a BOT THAT GRABBED A CURSED ARROW - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
Dungeons and Dragons (D&amp;amp;D) is a role-playing game that usually has a &amp;quot;Dungeon Master&amp;quot; (narrator) that takes a team of players through scenarios where they attack monsters and go on quests.&lt;br /&gt;
&lt;br /&gt;
Often, there will be semi-random events: e.g., when attacking a monster, often a player will roll a die and deal damage based on the result. D&amp;amp;D uses a variety of dice, from regular d6 (6-sided, cubic dice) to other polyhedral dice, with the number of faces denoted by dX (e.g., d10 is a 10-sided die, with numbers from 1 to 10 on it). Common sets include: d4, d6, d8, d10, d12, d20, and occasionally d100 (typically not, however, the [[2626:_d65536|d65536]]).{{cn}}&lt;br /&gt;
&lt;br /&gt;
With these, you can simulate events with a wide variety of denominators. In this case, Cueball gives a {{w|combinatorics|combinatorial}} problem:&lt;br /&gt;
&lt;br /&gt;
* There are 10 arrows.&lt;br /&gt;
* 5 arrows are cursed.&lt;br /&gt;
* You randomly take two.&lt;br /&gt;
* What are the odds that neither of them are cursed?&lt;br /&gt;
&lt;br /&gt;
Calculating using {{w|binomial coefficients}}, there are “10 choose 2” (45) ways to choose two arrows, of which there are “5 choose 2” (10) ways to choose 2 arrows that are non-cursed. As a result, the odds of taking all non-cursed arrows is 10/45, which simplifies to 2/9. &lt;br /&gt;
&lt;br /&gt;
To see this in a different way, the probability of choosing one non-cursed arrow is 5/10, which then must be multiplied by the probability of choosing the second non-cursed arrow, which is now 4/9, giving 20/90 or 2/9, the same result as before.&lt;br /&gt;
&lt;br /&gt;
The Dungeon Master (DM) in this case [[356: Nerd Sniping|has to]] map that probability into rolling multiple dice, whose sums are also not evenly distributed: i.e. if rolling 3d6 (3 six-sided dice) and a d4 (1 four-sided die), the sums can range from 4 to 22. It's pretty hard to do this in one's head, but it does happen that the odds of rolling 16 or more with this combination is 2/9, matching the probability that we want to simulate. Here's a table of all the 6*6*6*4=864 possible outcomes -&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ All possible combinations of rolls for 3d6 + 1d4&lt;br /&gt;
|-&lt;br /&gt;
!Total!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14!!15!!16!!17!!18!!19!!20!!21!!22&lt;br /&gt;
|-&lt;br /&gt;
|Ways to roll it||1||4||10||20||34||52||71||88||100||104||100||88&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 71&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 52&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 34&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 20&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 10&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
71+52+34+20+10+4+1 = 192&lt;br /&gt;
&lt;br /&gt;
192/864 = 2/9, which matches the desired probability from earlier. The table of outcomes can either be bruteforced with a program, or can be derived using generating functions.&lt;br /&gt;
&lt;br /&gt;
The caption elaborates that the DM has a degree in the relevant field, and is unable to resist applying this to the D&amp;amp;D game when the opportunity arises - opportunities that Cueball eagerly provides for this very reason.&lt;br /&gt;
&lt;br /&gt;
There are several much easier ways of implementing this operation. First, literally present 10 similar-looking arrows, or other objects that are taken to represent arrows (cards, for example), with the assigned information of whether each one is cursed hidden away from Cueball, and then let Cueball pick any two. Even just with D&amp;amp;D dice, the DM could ask Cueball to roll a 1d10 for the first arrow, and for the second, roll another 1d10 and reroll if Cueball gets the same number. If 1-5 represents the cursed arrows and 6-10 represents the non-cursed arrows, following the convention that lower rolls are bad in D&amp;amp;D, then this achieves the same result without coming up with a more complex solution. Even just using two d6 dice, achieving a 2/9 probability is easily achieved by saying Cueball would succeed with a 9, 11, or 12 (4/36, 2/36, and 1/36 probability, respectively, giving 8/36 = 2/9 probability).&lt;br /&gt;
&lt;br /&gt;
One could argue that the above solutions do not have the &amp;quot;polished&amp;quot; D&amp;amp;D feel of rolling a certain number of dice, adding them up, and seeing if the result is greater than or equal to a given required numer. This is a commonly used mechanic for difficulty checks, hit calculations, and other such chance-based events in D&amp;amp;D. The DM may feel that this dice format is a requirement, but this approach is far too clunky for most DMs to.be practical. It may be inferred that as the DM's mind tends towards more combinatorial solutions, she is either unable or unwilling to consider more straightforward and less time-consuming solutions to this cursed arrow problem.&lt;br /&gt;
&lt;br /&gt;
The title text claims that Randall only started doing this to the DM after she herself insisted on forcing another combinatorial puzzle on the players several times, involving a bunch of locked treasure chests and a multitude of keys to unlock them with. This might be a reference to an M-of-N encryption system, where a system has ''n'' valid passwords (instead of just one) but requires ''m'' of those passwords to be given before it will open; it is assumed m is greater than 1 but less than n. While this is easy enough to implement in a computer system, it would be extremely cumbersome to build for a physical lock with keys, and spreading the mechanism across multiple separate treasure chests would be impossible without literal magic (luckily, magic is in plentiful supply in a typical Dungeons and Dragons game).{{cn}}&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:[Cueball, Megan, Ponytail, White Hat, and Knit Cap are sitting at a table. Everyone is looking at Cueball. Ponytail is facepalming. The table is covered in sheets of paper and assorted dice.]&amp;lt;br&amp;gt;&lt;br /&gt;
:Cueball: I grab 2 of the 10 arrows without looking and fire them, hoping I didn't grab one of the 5 cursed ones. Did I?&lt;br /&gt;
:Ponytail: Sigh. Umm. Okay.&lt;br /&gt;
:Ponytail: Roll... Uh... Hang on...&lt;br /&gt;
:Ponytail: Roll 3d6 and a d4. You need... 16 or better to avoid the cursed arrows.&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:I got '''''way''''' more annoying to play D&amp;amp;D with once I learned that our DM has a combinatorics degree and can't resist puzzles.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Comics featuring Megan]]&lt;br /&gt;
[[Category:Comics featuring Ponytail]]&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Knit Cap]]&lt;br /&gt;
[[Category:Games]]&lt;br /&gt;
[[Category:Math]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357755</id>
		<title>3015: D&amp;D Combinatorics</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357755"/>
				<updated>2024-11-24T12:05:43Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */ several methods&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3015&lt;br /&gt;
| date      = November 22, 2024&lt;br /&gt;
| title     = D&amp;amp;D Combinatorics&lt;br /&gt;
| image     = dnd_combinatorics_2x.png&lt;br /&gt;
| imagesize = 328x446px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = Look, you can't complain about this after giving us so many scenarios involving N locked chests and M unlabeled keys.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created by a BOT THAT GRABBED A CURSED ARROW - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
Dungeons and Dragons (D&amp;amp;D) is a role-playing game that usually has a &amp;quot;Dungeon Master&amp;quot; (narrator) that takes a team of players through scenarios where they attack monsters and go on quests.&lt;br /&gt;
&lt;br /&gt;
Often, there will be semi-random events: e.g., when attacking a monster, often a player will roll a die and deal damage based on the result. D&amp;amp;D uses a variety of dice, from regular d6 (6-sided, cubic dice) to other polyhedral dice, with the number of faces denoted by dX (e.g., d10 is a 10-sided die, with numbers from 1 to 10 on it). Common sets include: d4, d6, d8, d10, d12, d20, and occasionally d100 (typically not, however, the [[2626:_d65536|d65536]]).{{cn}}&lt;br /&gt;
&lt;br /&gt;
With these, you can simulate events with a wide variety of denominators. In this case, Cueball gives a {{w|combinatorics|combinatorial}} problem:&lt;br /&gt;
&lt;br /&gt;
* There are 10 arrows.&lt;br /&gt;
* 5 arrows are cursed.&lt;br /&gt;
* You randomly take two.&lt;br /&gt;
* What are the odds that neither of them are cursed?&lt;br /&gt;
&lt;br /&gt;
Calculating using {{w|binomial coefficients}}, there are “10 choose 2” (45) ways to choose two arrows, of which there are “5 choose 2” (10) ways to choose 2 arrows that are non-cursed. As a result, the odds of taking all non-cursed arrows is 10/45, which simplifies to 2/9. &lt;br /&gt;
&lt;br /&gt;
To see this in a different way, the probability of choosing one non-cursed arrow is 5/10, which then must be multiplied by the probability of choosing the second non-cursed arrow, which is now 4/9, giving 20/90 or 2/9, the same result as before.&lt;br /&gt;
&lt;br /&gt;
The Dungeon Master (DM) in this case [[356: Nerd Sniping|has to]] map that probability into rolling multiple dice, whose sums are also not evenly distributed: i.e. if rolling 3d6 (3 six-sided dice) and a d4 (1 four-sided die), the sums can range from 4 to 22. It's pretty hard to do this in one's head, but it does happen that the odds of rolling 16 or more with this combination is 2/9, matching the probability that we want to simulate. Here's a table of all the 6*6*6*4=864 possible outcomes -&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ All possible combinations of rolls for 3d6 + 1d4&lt;br /&gt;
|-&lt;br /&gt;
!Total!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14!!15!!16!!17!!18!!19!!20!!21!!22&lt;br /&gt;
|-&lt;br /&gt;
|Ways to roll it||1||4||10||20||34||52||71||88||100||104||100||88&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 71&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 52&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 34&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 20&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 10&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
71+52+34+20+10+4+1 = 192&lt;br /&gt;
&lt;br /&gt;
192/864 = 2/9, which matches the desired probability from earlier. The table of outcomes can either be bruteforced with a program, or can be derived using generating functions.&lt;br /&gt;
&lt;br /&gt;
The caption elaborates that the DM has a degree in the relevant field, and is unable to resist applying this to the D&amp;amp;D game when the opportunity arises - opportunities that Cueball eagerly provides for this very reason.&lt;br /&gt;
&lt;br /&gt;
There are several much easier ways of implementing this operation: literally present 10 similar-looking arrows, or other objects that are taken to represent arrows (cards, for example), with the assigned information of whether each one is cursed hidden away from Cueball, and then let Cueball pick any two. Even just with D&amp;amp;D dice, the DM could ask Cueball to roll a 1d10 for the first arrow, and for the second, roll another 1d10 and reroll if Cueball gets the same number. If 1-5 represents the cursed arrows and 6-10 represents the non-cursed arrows, following the convention that lower rolls are bad in D&amp;amp;D, then this achieves the same result without coming up with a more complex solution. Even just using two d6 dice, achieving a 2/9 probability is easily achieved by saying Cueball would succeed with a 9, 11, or 12 (4/36, 2/36, and 1/36 probability, respectively, giving 8/36=2/9 probability).&lt;br /&gt;
&lt;br /&gt;
One could argue that the above solutions do not have the &amp;quot;polished&amp;quot; D&amp;amp;D feel of rolling a certain number of dice, adding them up, and seeing if the result is greater than or equal to a given required numer. This is a commonly used mechanic for difficulty checks, hit calculations, and other such chance-based events in D&amp;amp;D. The DM may feel that this dice format is a requirement, but this approach is far too clunky for most DMs to.be practical. It may be inferred that as the DM's mind tends towards more combinatorial solutions, she is either unable or unwilling to consider more straightforward and less time-consuming solutions to this cursed arrow problem.&lt;br /&gt;
&lt;br /&gt;
The title text claims that Randall only started doing this to the DM after she herself insisted on forcing another combinatorial puzzle on the players several times, involving a bunch of locked treasure chests and a multitude of keys to unlock them with. This might be a reference to an M-of-N encryption system, where a system has ''n'' valid passwords (instead of just one) but requires ''m'' of those passwords to be given before it will open; it is assumed m is greater than 1 but less than n. While this is easy enough to implement in a computer system, it would be extremely cumbersome to build for a physical lock with keys, and spreading the mechanism across multiple separate treasure chests would be impossible without literal magic (luckily, magic is in plentiful supply in a typical Dungeons and Dragons game).{{cn}}&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:[Cueball, Megan, Ponytail, White Hat, and Knit Cap are sitting at a table. Everyone is looking at Cueball. Ponytail is facepalming. The table is covered in sheets of paper and assorted dice.]&amp;lt;br&amp;gt;&lt;br /&gt;
:Cueball: I grab 2 of the 10 arrows without looking and fire them, hoping I didn't grab one of the 5 cursed ones. Did I?&lt;br /&gt;
:Ponytail: Sigh. Umm. Okay.&lt;br /&gt;
:Ponytail: Roll... Uh... Hang on...&lt;br /&gt;
:Ponytail: Roll 3d6 and a d4. You need... 16 or better to avoid the cursed arrows.&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:I got '''''way''''' more annoying to play D&amp;amp;D with once I learned that our DM has a combinatorics degree and can't resist puzzles.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Comics featuring Megan]]&lt;br /&gt;
[[Category:Comics featuring Ponytail]]&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Knit Cap]]&lt;br /&gt;
[[Category:Games]]&lt;br /&gt;
[[Category:Math]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357754</id>
		<title>3015: D&amp;D Combinatorics</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357754"/>
				<updated>2024-11-24T12:04:14Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */ Adding &amp;quot;polished&amp;quot; D&amp;amp;D feel argument&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3015&lt;br /&gt;
| date      = November 22, 2024&lt;br /&gt;
| title     = D&amp;amp;D Combinatorics&lt;br /&gt;
| image     = dnd_combinatorics_2x.png&lt;br /&gt;
| imagesize = 328x446px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = Look, you can't complain about this after giving us so many scenarios involving N locked chests and M unlabeled keys.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created by a BOT THAT GRABBED A CURSED ARROW - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
Dungeons and Dragons (D&amp;amp;D) is a role-playing game that usually has a &amp;quot;Dungeon Master&amp;quot; (narrator) that takes a team of players through scenarios where they attack monsters and go on quests.&lt;br /&gt;
&lt;br /&gt;
Often, there will be semi-random events: e.g., when attacking a monster, often a player will roll a die and deal damage based on the result. D&amp;amp;D uses a variety of dice, from regular d6 (6-sided, cubic dice) to other polyhedral dice, with the number of faces denoted by dX (e.g., d10 is a 10-sided die, with numbers from 1 to 10 on it). Common sets include: d4, d6, d8, d10, d12, d20, and occasionally d100 (typically not, however, the [[2626:_d65536|d65536]]).{{cn}}&lt;br /&gt;
&lt;br /&gt;
With these, you can simulate events with a wide variety of denominators. In this case, Cueball gives a {{w|combinatorics|combinatorial}} problem:&lt;br /&gt;
&lt;br /&gt;
* There are 10 arrows.&lt;br /&gt;
* 5 arrows are cursed.&lt;br /&gt;
* You randomly take two.&lt;br /&gt;
* What are the odds that neither of them are cursed?&lt;br /&gt;
&lt;br /&gt;
Calculating using {{w|binomial coefficients}}, there are “10 choose 2” (45) ways to choose two arrows, of which there are “5 choose 2” (10) ways to choose 2 arrows that are non-cursed. As a result, the odds of taking all non-cursed arrows is 10/45, which simplifies to 2/9. &lt;br /&gt;
&lt;br /&gt;
To see this in a different way, the probability of choosing one non-cursed arrow is 5/10, which then must be multiplied by the probability of choosing the second non-cursed arrow, which is now 4/9, giving 20/90 or 2/9, the same result as before.&lt;br /&gt;
&lt;br /&gt;
The Dungeon Master (DM) in this case [[356: Nerd Sniping|has to]] map that probability into rolling multiple dice, whose sums are also not evenly distributed: i.e. if rolling 3d6 (3 six-sided dice) and a d4 (1 four-sided die), the sums can range from 4 to 22. It's pretty hard to do this in one's head, but it does happen that the odds of rolling 16 or more with this combination is 2/9, matching the probability that we want to simulate. Here's a table of all the 6*6*6*4=864 possible outcomes -&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ All possible combinations of rolls for 3d6 + 1d4&lt;br /&gt;
|-&lt;br /&gt;
!Total!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14!!15!!16!!17!!18!!19!!20!!21!!22&lt;br /&gt;
|-&lt;br /&gt;
|Ways to roll it||1||4||10||20||34||52||71||88||100||104||100||88&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 71&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 52&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 34&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 20&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 10&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
71+52+34+20+10+4+1 = 192&lt;br /&gt;
&lt;br /&gt;
192/864 = 2/9, which matches the desired probability from earlier. The table of outcomes can either be bruteforced with a program, or can be derived using generating functions.&lt;br /&gt;
&lt;br /&gt;
The caption elaborates that the DM has a degree in the relevant field, and is unable to resist applying this to the D&amp;amp;D game when the opportunity arises - opportunities that Cueball eagerly provides for this very reason.&lt;br /&gt;
&lt;br /&gt;
There is a much easier way of implementing the operation: literally present 10 similar-looking arrows, or other objects that are taken to represent arrows (cards, for example), with the assigned information of whether each one is cursed hidden away from Cueball, and then let Cueball pick any two. Even just with D&amp;amp;D dice, the DM could ask Cueball to roll a 1d10 for the first arrow, and for the second, roll another 1d10 and reroll if Cueball gets the same number. If 1-5 represents the cursed arrows and 6-10 represents the non-cursed arrows, following the convention that lower rolls are bad in D&amp;amp;D, then this achieves the same result without coming up with a more complex solution. Even just using two d6 dice, achieving a 2/9 probability is easily achieved by saying Cueball would succeed with a 9, 11, or 12 (4/36, 2/36, and 1/36 probability, respectively, giving 8/36=2/9 probability).&lt;br /&gt;
&lt;br /&gt;
One could argue that the above solutions do not have the &amp;quot;polished&amp;quot; D&amp;amp;D feel of rolling a certain number of dice, adding them up, and seeing if the result is greater than or equal to a given required numer. This is a commonly used mechanic for difficulty checks, hit calculations, and other such chance-based events in D&amp;amp;D. The DM may feel that this dice format is a requirement, but this approach is far too clunky for most DMs to.be practical. It may be inferred that as the DM's mind tends towards more combinatorial solutions, she is either unable or unwilling to consider more straightforward and less time-consuming solutions to this cursed arrow problem.&lt;br /&gt;
&lt;br /&gt;
The title text claims that Randall only started doing this to the DM after she herself insisted on forcing another combinatorial puzzle on the players several times, involving a bunch of locked treasure chests and a multitude of keys to unlock them with. This might be a reference to an M-of-N encryption system, where a system has ''n'' valid passwords (instead of just one) but requires ''m'' of those passwords to be given before it will open; it is assumed m is greater than 1 but less than n. While this is easy enough to implement in a computer system, it would be extremely cumbersome to build for a physical lock with keys, and spreading the mechanism across multiple separate treasure chests would be impossible without literal magic (luckily, magic is in plentiful supply in a typical Dungeons and Dragons game).{{cn}}&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:[Cueball, Megan, Ponytail, White Hat, and Knit Cap are sitting at a table. Everyone is looking at Cueball. Ponytail is facepalming. The table is covered in sheets of paper and assorted dice.]&amp;lt;br&amp;gt;&lt;br /&gt;
:Cueball: I grab 2 of the 10 arrows without looking and fire them, hoping I didn't grab one of the 5 cursed ones. Did I?&lt;br /&gt;
:Ponytail: Sigh. Umm. Okay.&lt;br /&gt;
:Ponytail: Roll... Uh... Hang on...&lt;br /&gt;
:Ponytail: Roll 3d6 and a d4. You need... 16 or better to avoid the cursed arrows.&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:I got '''''way''''' more annoying to play D&amp;amp;D with once I learned that our DM has a combinatorics degree and can't resist puzzles.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Comics featuring Megan]]&lt;br /&gt;
[[Category:Comics featuring Ponytail]]&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Knit Cap]]&lt;br /&gt;
[[Category:Games]]&lt;br /&gt;
[[Category:Math]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357753</id>
		<title>3015: D&amp;D Combinatorics</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=3015:_D%26D_Combinatorics&amp;diff=357753"/>
				<updated>2024-11-24T11:31:24Z</updated>
		
		<summary type="html">&lt;p&gt;Lgstarn: /* Explanation */ improving explanation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 3015&lt;br /&gt;
| date      = November 22, 2024&lt;br /&gt;
| title     = D&amp;amp;D Combinatorics&lt;br /&gt;
| image     = dnd_combinatorics_2x.png&lt;br /&gt;
| imagesize = 328x446px&lt;br /&gt;
| noexpand  = true&lt;br /&gt;
| titletext = Look, you can't complain about this after giving us so many scenarios involving N locked chests and M unlabeled keys.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|Created by a BOT THAT GRABBED A CURSED ARROW - Please change this comment when editing this page. Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
Dungeons and Dragons (D&amp;amp;D) is a role-playing game that usually has a &amp;quot;Dungeon Master&amp;quot; (narrator) that takes a team of players through scenarios where they attack monsters and go on quests.&lt;br /&gt;
&lt;br /&gt;
Often, there will be semi-random events: e.g., when attacking a monster, often a player will roll a die and deal damage based on the result. D&amp;amp;D uses a variety of dice, from regular d6 (6-sided, cubic dice) to other polyhedral dice, with the number of faces denoted by dX (e.g., d10 is a 10-sided die, with numbers from 1 to 10 on it). Common sets include: d4, d6, d8, d10, d12, d20, and occasionally d100 (typically not, however, the [[2626:_d65536|d65536]]).{{cn}}&lt;br /&gt;
&lt;br /&gt;
With these, you can simulate events with a wide variety of denominators. In this case, Cueball gives a {{w|combinatorics|combinatorial}} problem:&lt;br /&gt;
&lt;br /&gt;
* There are 10 arrows.&lt;br /&gt;
* 5 arrows are cursed.&lt;br /&gt;
* You randomly take two.&lt;br /&gt;
* What are the odds that neither of them are cursed?&lt;br /&gt;
&lt;br /&gt;
Calculating using {{w|binomial coefficients}}, there are “10 choose 2” (45) ways to choose two arrows, of which there are “5 choose 2” (10) ways to choose 2 arrows that are non-cursed. As a result, the odds of taking all non-cursed arrows is 10/45, which simplifies to 2/9. &lt;br /&gt;
&lt;br /&gt;
To see this in a different way, the probability of choosing one non-cursed arrow is 5/10, which then must be multiplied by the probability of choosing the second non-cursed arrow, which is now 4/9, giving 20/90 or 2/9, the same result as before.&lt;br /&gt;
&lt;br /&gt;
The Dungeon Master (DM) in this case [[356: Nerd Sniping|has to]] map that probability into rolling multiple dice, whose sums are also not evenly distributed: i.e. if rolling 3d6 (3 six-sided dice) and a d4 (1 four-sided die), the sums can range from 4 to 22. It's pretty hard to do this in one's head, but it does happen that the odds of rolling 16 or more with this combination is 2/9, matching the probability that we want to simulate. Here's a table of all the 6*6*6*4=864 possible outcomes -&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ All possible combinations of rolls for 3d6 + 1d4&lt;br /&gt;
|-&lt;br /&gt;
!Total!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14!!15!!16!!17!!18!!19!!20!!21!!22&lt;br /&gt;
|-&lt;br /&gt;
|Ways to roll it||1||4||10||20||34||52||71||88||100||104||100||88&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 71&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 52&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 34&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 20&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 10&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;background:#ffffcc;&amp;quot; | 1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
71+52+34+20+10+4+1 = 192&lt;br /&gt;
&lt;br /&gt;
192/864 = 2/9, which matches the desired probability from earlier. The table of outcomes can either be bruteforced with a program, or can be derived using generating functions.&lt;br /&gt;
&lt;br /&gt;
The caption elaborates that the DM has a degree in the relevant field, and is unable to resist applying this to the D&amp;amp;D game when the opportunity arises - opportunities that Cueball eagerly provides for this very reason.&lt;br /&gt;
&lt;br /&gt;
There is a much easier way of implementing the operation: literally present 10 similar-looking arrows, or other objects that are taken to represent arrows (cards, for example), with the assigned information of whether each one is cursed hidden away from Cueball, and then let Cueball pick any two. Even just with D&amp;amp;D dice, the DM could ask Cueball to roll a 1d10 for the first arrow, and for the second, roll another 1d10 and reroll if Cueball gets the same number. If 1-5 represents the cursed arrows and 6-10 represents the non-cursed arrows, following the convention that lower rolls are bad in D&amp;amp;D, then this achieves the same result without coming up with a more complex solution.&lt;br /&gt;
&lt;br /&gt;
It may be inferred that as the DM's mind tends towards more combinatorial solutions, she is either unable or unwilling to consider more straightforward solutions to the problem.&lt;br /&gt;
&lt;br /&gt;
The title text claims that Randall only started doing this to the DM after she herself insisted on forcing another combinatorial puzzle on the players several times, involving a bunch of locked treasure chests and a multitude of keys to unlock them with. This might be a reference to an M-of-N encryption system, where a system has ''n'' valid passwords (instead of just one) but requires ''m'' of those passwords to be given before it will open; it is assumed m is greater than 1 but less than n. While this is easy enough to implement in a computer system, it would be extremely cumbersome to build for a physical lock with keys, and spreading the mechanism across multiple separate treasure chests would be impossible without literal magic (luckily, magic is in plentiful supply in a typical Dungeons and Dragons game).{{cn}}&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
:[Cueball, Megan, Ponytail, White Hat, and Knit Cap are sitting at a table. Everyone is looking at Cueball. Ponytail is facepalming. The table is covered in sheets of paper and assorted dice.]&amp;lt;br&amp;gt;&lt;br /&gt;
:Cueball: I grab 2 of the 10 arrows without looking and fire them, hoping I didn't grab one of the 5 cursed ones. Did I?&lt;br /&gt;
:Ponytail: Sigh. Umm. Okay.&lt;br /&gt;
:Ponytail: Roll... Uh... Hang on...&lt;br /&gt;
:Ponytail: Roll 3d6 and a d4. You need... 16 or better to avoid the cursed arrows.&lt;br /&gt;
&lt;br /&gt;
:[Caption below the panel:]&lt;br /&gt;
:I got '''''way''''' more annoying to play D&amp;amp;D with once I learned that our DM has a combinatorics degree and can't resist puzzles.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Comics featuring Megan]]&lt;br /&gt;
[[Category:Comics featuring Ponytail]]&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Knit Cap]]&lt;br /&gt;
[[Category:Games]]&lt;br /&gt;
[[Category:Math]]&lt;/div&gt;</summary>
		<author><name>Lgstarn</name></author>	</entry>

	</feed>