I've done the MergeSort algorithm, but I don't know how to count the swaps.  My code is:  def mergesortInv(list):     if len(list) &lt; 2:         return list     else:         middle = len(list) // 2         left = mergesortInv(list[:middle])   #definim les dues meitats         right = mergesortInv(list[middle:])         swaps=???            return mergeInv(left, right,swaps)  def mergeInv(left, right,swaps):     if len(left) &lt; 1:         return right     if len(right) &lt; 1:         return left     if left[0] &lt;= right[0]:         return [left[0]] + mergeInv(left[1:],right,swaps)     else:         return [right[0]] + mergeInv(left,right[1:],swaps)   The output of this algorithm would be the sorted list(the algorithm works in this part) and the  number of swaps: mergesortInv(list) == ([1, 2, 3, 4, 5, 7, 8], 6) 6 is the number of swaps.
I'm designing an algorithm to do the following: Given array A[1... n], for every i &lt; j, find all inversion pairs such that A[i] &gt; A[j]. I'm using merge sort and copying array A to array B and then comparing the two arrays, but I'm having a difficult time seeing how I can use this to find the number of inversions. Any hints or help would be greatly appreciated.
Show $4x^2+6x+3$ is a unit in $\mathbb{Z}_8[x]$ (inverting unit + nilpotent) Show that $4x^2+6x+3$ is a unit in $\mathbb{Z}_8[x]$.  Once you have found the inverse like , the verification is trivial. But how do you come up with such an inverse. Do I just try with general polynomials of all degrees and see what restrictions RHS = $1$ imposes on the coefficients until I get lucky? Also is there a general method to show an element in a ring is a unit? Skynet - were AI's actions evidence of Intelligence? I ran into the problem that my primary key sequence is not in sync with my table rows.   That is, when I insert a new row I get a duplicate key error because the sequence implied in the serial datatype returns a number that already exists.  It seems to be caused by import/restores not maintaining the sequence properly. Associativity of symmetric difference of sets By $A\oplus B$ we denote the symmectric difference of two sets. The definition is $A\oplus B =(A\setminus B) \cup (B\setminus A)$. Now I hope to show that $A\oplus (B\oplus C) = (A\oplus B)\oplus C$. I remember that there's an elegant proof, but I forget its detail. (The first step is to show $A\oplus (A\oplus B) = B$, and maybe applying this formula, we can obtain associativity.) Is there an emulator or wine type environment that would allow use of android apps on linux? Is it poor form to switch accepted answers? I had a question of the form "does something like X exist?" Someone wrote a response to say that, No, X does not exist, but I could write it if I liked. I had suspected as much, so I marked his answer as the accepted answer. Today someone actually posted the code to do X for me, and I feel that the new poster deserves the "Accepted Answer" checkmark.  Is it poor form for me to pick a new Accepted answer? Does the original answerer get penalized in terms of reputation?  While the original responder's answer was accepted at the time, I feel this new answer is really more helpful.  Edit: Which of these responses should I accept? What does the notion of a single accepted answer mean with a question that is subjective that could have multiple "right" answers? Is there a difference between single and double quotes in Java? Is there a difference between single and double quotes in Java? I am trying to create a map in both Leaflet and OpenLayers 3 which displays the  layer EMAP8 from the WMS http://wms.nlsc.gov.tw/wms. I can't get it to work. I can open the layer in QGIS, but when I try to use it in Leaflet like this:  var overlay_taiwanemapen0 = L.tileLayer.wms('http://wms.nlsc.gov.tw/wms', {     layers: 'EMAP8',     format: 'image/png',     transparent: true,     continuousWorld : true, });   or in OpenLayers 3 like this:  var lyr_taiwanemapen = new ol.layer.Tile({     source: new ol.source.TileWMS(({         url: "http://wms.nlsc.gov.tw/wms",         params: {"LAYERS": "EMAP8", "TILED": "true"},     })),     title: "taiwane-map(en)", });   I get nothing displayed. I can see layers being requested, and data being transferred, but nothing on the map.  What am I doing wrong? I see a lot of interesting programs out there that can only be obtained by adding a "PPA" to the system but, if I'm understanding correctly, we should stay within the official "repositories" for adding software to our system.   Is there any way for a novice to know if a "PPA" is safe or if it should be avoided? What tips should the user know about when dealing with a PPA?. Compactness of $A:=${$f \in C[0,1], |f|_\infty \le K, |f'|_\infty \le M$} Here we use infinity norm as metrics for $C[0,1]$. The professor claims that this set is compact. I can show this set is relative compact by Arzela Ascoli, i.e., for each subsequence there is a further sub-subsequence that uniformly converges to a continuous function on $[0,1]$. But it is not intuitive to me why this set is compact, i.e. the limiting function also satisfies $|f'|_\infty \le M$. Is it true that $A$ is close and therefore compact? Bibliography style elsarticle-num-names with DOI and hyperlinks but no explicit url I prepared my article with elsarticle, using \citep &amp; \citet throughout. I originally used apalike bibliographystyle but now need to change it to elsarticle-num-names for citation formatting requirements (see point #2 below).  Now, I am attempting to make 2 changes:     add DOIs to the bibliography change reference style to [1] for \citep and Author et al. [1] for \citet.   I want to keep hyperref and do not want explicit URLs (only DOIs) but cannot make this work!  Thank you for any help you might have!  MWE:  \documentclass[preprint,12pt]{elsarticle} %\usepackage{hyperref}  \journal{Test Journal} \begin{document} \begin{frontmatter} \title{The Title} \author{Prof. Big Ol' Wanker} \address{123 Happy Lane} \begin{abstract} TEXT \end{abstract} \begin{keyword} keyword 1 \sep keyword 2 \sep keyword 3 \end{keyword} \end{frontmatter}  \section{SECTION1TEST} \noindent cite: \cite{Richards1931} \\ citep: \citep{Richards1931} \\ citet: \citet{Richards1931} \\  \bibliography{library} \bibliographystyle{elsarticle-num-names}  \end{document}   Here is the reference for Richards1931 from my library.bib file:    @article{Richards1931, author = {Richards, LA}, doi = {10.1063/1.1745010}, file = {:D$\backslash$:/Papers/Richards - 1931 - Capillary Conduction of Liquids Through Porous Mediums - Journal of Applied Physics.pdf:pdf}, issn = {01486349}, journal = {Journal of Applied Physics}, pages = {318}, title = {{Capillary Conduction of Liquids Through Porous Mediums}}, url = {http://scitation.aip.org/content/aip/journal/jap/1/5/10.1063/1.1745010}, volume = {1}, year = {1931} }   without hyperref (wanted hyperlinks present, DOI displays correctly, but unwanted URL is present):    with hyperref (hyperlinks not present, DOI displays incorrectly, and unwanted URL is present): Suppose $K \subset L$ is a finite field extension of degree $m$. Is it true that there exists some natural $n$ such that $L$ is isomorphic to a subfield of $M^{n\times n}(K)$, the ring of $n\times n$ matrices with entries in $K$? What is the smallest dimension (as a function of $m$) for which an isomorphism exists?  The example I had in mind was the 2-dimensional extension $\mathbb{R} \subset \mathbb{C}$ with $\mathbb{C}$ being isomorphic to $\{ \begin{pmatrix}a&amp;-b\\b&amp;a\end{pmatrix} : a, b \in \mathbb{R}\}$. Virtualbox Kernel driver not installed I tried to use my Virtual Box and this is the error I received - (I just updated to the new Ubuntu also) and I am VERY new at this Linux OS.     Kernel driver not installed (rc=-1908)      The VirtualBox Linux kernel driver (vboxdrv) is either not loaded or   there is a permission problem with /dev/vboxdrv. Please reinstall the   kernel module by executing      '/etc/init.d/vboxdrv setup'      as root. Users of Ubuntu, Fedora or Mandriva should install the DKMS   package first. This package keeps track of Linux kernel changes and   recompiles the vboxdrv kernel module if necessary. Almost every time I turn my XBox on and start up Fallout 4, I am unable to use the "Continue" option because the most recent save is corrupt.  I instead use the "Load" option. Here, I can see that the last save I manually performed is perfectly fine, and load it with no problem. However, there is an additional, corrupt save with the same time stamp immediately after it.  This doesn't happen quite every time, but often enough that I'm surprised when there's no corrupt save waiting for me to delete it.  I've tried a few things to solve this, including exiting to the game's main menu before turning the XBox off, going out to the guide before turning the XBox off, turning it off immediately after saving, and waiting a while after saving.  Why do I get all these corrupt saves? Do others have this problem? How do I fix it? How can I disable landscape mode in Android? Find the number of natural solutions of $5^x+7^x+11^x=6^x+8^x+9^x$   It's easy to see that $x=0$ and $x=1$ are solutions but are these the only one? How do I demonstrate that?  I've tried to write them either:  $$5^x+7^x+11^x=2^x*3^x+2^{3x}+3^{2x}$$  or  $$5^x+7^x+11^x=(5+1)^x+(7+1)^x+(11-2)^x$$  and tried to think of some AM-GM mean inequality or to divide everything by $11^x$, but those don't seem like the way to go. Any hints? Calculating Mean for Multiple Rows in ArcGIS for Desktop? I am trying to calculate a mean across a multiple number of attribute rows and have this value added to a new field that I have entered in the attribute table. I have an attribute table which has a number of different ecoregion types associated with them.  For example:  If I select "Arid Canyonlands" there are 3 attribute rows that are selected, each with their own "mean". I am trying to add a new field to the attribute table which will take the "mean" of these three and populate that value in the new field created. I could manually do it through an editing session and using a calculator but just wanted to know if there is an easier way to actually do it through field calculator? What is the effect where some objects are a single bright color but the rest is black and white? There is an option to filter only one color (R,G,B,Y) in my camera. What I want to know is can this effect be achieved in photoshop? And what is this called? I tried googling monochrome and came up with nothing. My camera calls it part color. Ubuntu: Resize the root LVM(2?) partition A borderline between on-topic questions and questions about library recommendation? I have a consideration about new off-topic close reason:     Questions asking us to recommend a tool, library or favorite off-site   resource are off-topic for Stack Overflow as they tend to attract   opinionated answers and spam. Instead, describe the problem and what   has been done so far to solve it.   For example take that question:   It has a close vote with the reason above. But if it would be formed     How to zoom image in an absolute position div to the side?   The answer would be probably also a jQuery plugin or javascript library, but it would follow the patter of most questions about jQuery.  Take that question:   This is the good question about real-life problem. The answer is to use a maven plugin. It is correct, there's no need to reinvent the wheel or rediscover the America.   But  I'm afraid the off-topic text could be misleading and could be misused to close such a questions as that about maven simply because a tool, library or plugin is the answer.   Is it a new guideline that the questions such as cited above should be banned, no matter how they are formed (this would make most how-to-do-in-maven/jquery) questions illegal? Or the close reason should be changed to make more clear what the guidelines are (it's not clear to me now)?