Today I wanted to propose to students a very short and stupid code as follows  # include &lt;iostream&gt;  int main()   {    int a[] {10, 20, 30, 40};     for(int k=0; k != 4; ++k) std::cout &lt;&lt; ++a[k] &lt;&lt; ' ';     std::cout &lt;&lt; std::endl;     }   in order to show how the ++ prefix operator acts in an expression.  I inadvertently mistyped the code, ending up with the following line, in place of the one shown above:  for(int k=0; k != 4; ++k) std::cout &lt;&lt; ++k[a] &lt;&lt; ' ';   shortly: swapping k and a in the operand of ++.  Well... not only this is compiled, but it gives also the correct results. How this could be understood? Is the index of the loop interpreted as an iterator over the array a? Or what else?
As Joel points out in , in  (aka: K &amp; R), there is mention of this property of arrays in C: a[5] == 5[a]  Joel says that it's because of pointer arithmetic but I still don't understand. Why does a[5] == 5[a]?
Copy/duplicate database without using mysqldump No cycle containing edges $e$ and $g$ implies there is a vertex $u$ so that every path sharing one end with $e$ and another with $g$ contains $u$ There is a proof in my textbook for the following claim, which doesn't make a whole lot of sense to me.  My annotations are in bold.  Could someone perhaps elaborate on what's going on?  Claim.  If there does not exist a cycle containing edges $e$ and $g$ then there exists a vertex $u \in V (G)$ such that every path in $G$ sharing one end with e and another with $g$ contains $u$.  Proof: The claim trivially holds if $e$ or $g$ is a loop OK, so we assume that neither is. Let $P$ with vertex set $v_1, v_2, . . . , v_k,$ in order, be a path with $e$ joining $v_1$ to $v_2$ and $g$ joining $v_{k−1}$ and $v_k$. Let $f_i \in E(P_i)$ be the edge with ends $v_i$ and $v_{i+1}$. Let $j$ be chosen minimum so that no cycle in $G$ contains $e$ and $f_j$ We can do this because we know that at least the edge $g$ will not create a cycle by assumption, right?. We will show that $u = v_j$ satisfies the claim.  Suppose not. Let $C$ be a cycle containing $e$ and $f_{j−1}$ What if $f_j = e$?  then what cycle? a single vertex? and let $P′$ be a path from an end of $e$ to an end of $f$ Not sure what the book meant by $f$ here, any guesses? avoiding $u$. Choose a subpath $Q$ of $P′$ with one end in $V (C)$ and another in ${v_{j+1}, v_{j+2}, . . . , v_k}$ as short as possible. Then $C \cup Q \cup P$ contains a cycle containing both $e$ and $f_j$, a contradiction. (The last statement requires some case checking.) This ending seems a bit abrupt and non-obvious to me  Thanks for the help How do Horcruxes work? A few questions regarding the Horcruxes.   Had Voldemort actually succeeded in using a Horcrux, would he come back the same age (biologically and/or aesthetically) he was when he made the Horcrux, or the age he would biologically be if he had never died (half died)? If Harry was a Horcrux, then in the graveyard, when Wormtail added Harry's blood to the potion to bring Voldemort back, didn't that technically use up the Horcrux inside of Harry? So in Deathly Hallows when Voldemort kills Harry, shouldn't Harry have actually died rather than just have the Horcrux inside him destroyed, seeing as it was technically used in the Goblet of Fire? The final state of 1000 light bulbs switched on/off by 1000 people passing by There are  1000  light bulbs and 1000 tutors. All light bulbs are off. Tutor 1 goes flipping light bulb 1,2,3,4... tutor 2 then flips 2,4,6,8... tutor 3 then 3,6,9...etc until all 1000 tutors have done this.  What is the status of light bulb 25? 93? 576?  Is there a general solution to find out the status of any light bulb?  How many light bulbs are on after all 1000 tutors have gone by?  Not homework but a UK university interview question. Please help. I would like to add my bibliography to my presentation in IEEE format. What should I add to my preamble and code.  \documentclass{beamer} \setbeamertemplate{footline}[page number]  \usepackage{graphicx} \usepackage{booktabs} \begin{document} \section{Reference} \begin{frame} \frametitle{Reference}  \end{frame}   I'm using the same bibTex which I use to make the IEEE paper. Moderncv adding date of birth to personal information I'm doing my cv with the moderncv package and I'm using the classic style. I would like to add a date of birth line directly above the adress. Does anyone know how to do this? I've tried various solutions but they all seem to be broken. How can I make an InputField with a proper newline/carriage return? Using biblatex and Biber, I want my bibliography to say "Ph.D. thesis" (with periods) rather than "PhD thesis" (without). MWE:  \documentclass{article} \usepackage{biblatex} \addbibresource{refs.bib} \begin{document} Hello \cite{testphd} \printbibliography \end{document}   and refs.bib:  @thesis{testphd,   title       = {Thesis Title},   author      = {Surname, Firstname},   date        = {2010},   institution = {Faculty of X, University of Y},   type        = {phdthesis},   location    = {Somewhere}, }   Output:    What's the easiest way to do this? I don't want to change the .bib file ideally. Prove every element of $G$ has finite order. Let $G$ be a group such that the intersection of all its subgroups which are different from $\{e\}$, is a subgroup different from $\{e\}$. Prove that every element of  $G$  has finite order.  Assume that $a$ has infinite order in $G$. Then let $y\neq e$ belong to the intersection of all subgroups of $G$ different from $\{e\}$. Then $y=a^n$ and $y$ will also belong to subgroup generted by $a^2$ hence  $y=a^{2m}$ for some integers $m$. This contradicts that $a$ has infinte order.  Is this correct? What is the reason that the value "47" is so popular in electrical engineering? Are the off-world colonies really a "golden land of opportunity"? In Blade Runner, there seems to be quite a  for emigration to the off-world colonies, e.g.,      "A new life awaits you in the off-world colonies, a chance to begin   again in a golden land of opportunity and adventure."   Is there any evidence that people emigrating are actually better off than staying on Earth?  The job descriptions of the replicants Deckard is tasked with "retiring" don't seem consistent with the colonies being wonderful places. If the colonies offered a good life, would they have to do so much advertising? To debug a JACK/Pulseaudio issue, I want to understand when and why the pulseaudio daemon is started by systemd (on Fedora).  Using:  $ ps -o'pid,ppid,args' `pgrep pulse`   I see that the pulseaudio daemon is being started by systemd (pid=1)   PID  PPID COMMAND 2738     1 /usr/bin/pulseaudio --start   However, I was unable to find any unit-file on my system containing pulseaudio or even just pulse.  My specific questions are:  A) Is there a way to determine the systemd unit that caused the creation of a specific process (in my example output, process 2738, the PA daemon)?  B) Are there alternative approaches to find out which unit-dependency chain or other settings of systemd resulted in the invocation of /usr/bin/pulseaudio --start? I'm experiencing a bug where when the machine comes back from standby a monitor connected via displayport (MST) does not come back on, however the windows are still in the area it cover if it did come on.  The only way to recover from this short of a restart is to disable and reenable the display now I can do that via the command line just fine but when the display is disabled all the windows get rearranged onto the remaining screen.  Is there a way to persist the window positions and restore them so my script could do this sequence:-   enumerate windows, store positions display off (messing up positions) display on (making the display work again, yay!)  restore position of the windows   I can do step 2 and 3 just fine but I'm lost for step 1 and 4  I know I can force a position per app but that's not what I want as I could be doing different things and have the same apps in different positions, I also have multiple terminals open, I need the current positions storing somehow and restoring.  Any help would be appreciated! I'm transitioning a Drupal 6 site to Drupal 8.1 so following the official instructions, I set up a new install in its own directory. Since this is only one site, I followed the instructions to put my database credentials in sites/default/default.settings.php after the declaration of the $databases array.  Running drush --status returns the following.  Drush version          :  8.1-dev                                           Drush temp directory   :  /tmp                                              Drush configuration    :                                                    Drush alias files      :                                                    Drupal root            :  /media/psf/Home/apps/newp                         Drupal Settings File   :  MISSING   Since this Drupal is 8.1-dev that must mean I need to upgrade it. Since this is a global install using Composer, I run composer global update.     Your requirements could not be resolved to an installable set of   packages drush/drush dev-master requires codegyre/robo ~1.0.0-beta1   Checking the drush-ops page on github doesn't show any anomalies like this nor my Google search.   What am I overlooking? Let $X_1$ and $X_2$ be two independent exponential random variables with the PDFs $f_{X_1}(x_1)=\lambda_1 \exp(-\lambda_1 x_1)$ and $f_{X_2}(x_2)=\lambda_2 \exp(-\lambda_2 x_2)$.   Let $X= \frac{X_1X_2}{X_1+X_2+a}$ be a r.v. for which I want to derive the CDF, where $a$ is a positive constant.  In other words, I need to calculate $\mathbb{P}\{X &lt;x \}$.  Any ideas or hints?  Edit (attempt):  Using a similar approach to that used , we have $X_1 \in [0, \infty)$ and  $X_2 \in [0, \frac{x(x_1+a)}{x_1-x})$. The latter interval results from: $\frac{x_1x_2}{x_1+x_2+a} &lt; x$, thus $x_2(x_1-x)&lt;x(x_1+a)$ which implies $x_2 &lt; \frac{x(x_1+a)}{x_1-x}$; but I am not sure if this is correct since $x_1-x$ can sometimes be negative (?). Based on the above, we can write: \begin{align}  \mathbb{P} \{ \frac{X_1X_2}{X_1+X_2+a} &lt; x \}  &amp; = \int_{x_1=0}^\infty \int_{x_2=0}^{ \frac{x(x_1+a)}{x_1-x}} \lambda_1 \exp(-\lambda_1 x_1) \lambda_2 \exp(-\lambda_2 x_2)  dx_2 dx_1  \\ &amp;= \int_{x_1=0}^\infty \left(1-\exp(-\lambda_2\frac{x(x_1+a)}{x_1-x}) \right) \lambda_1 \exp(-\lambda_1 x_1) dx_1  \\ &amp; = 1-\lambda_1 \int_{x_1=x}^\infty \exp(-\lambda_2\frac{x(x_1+a)}{x_1-x} ) \exp(-\lambda_1 x_1)   dx_1 \end{align} In the last equality: for the integral of $\lambda_1 \exp(-\lambda_1 x_1) dx_1$, I suppose that $x_1 \in [0,\infty)$, whereas for the second term I suppose that $x_1 \ge x$ (since $x_2$ should be positive) (?).  Is my approach correct ? About finding the function such that $f(xy)=f(x)f(y)-f(x+y)+1$ How do I convert my PhD dissertation so that it can be published as a book? General solution to the PDE $xU_x+yU_y=0$ Solve the equation $xU_x+yU_y=0$.   From Partial Differential Equations: An Introduction, 2nd Ed. (Strauss, pg. 10). There are no boundary conditions.  Solution: The PDE can be written $(x,y)\cdot\nabla U(x,y)=0$, implying that the vector $(x,y)$ is tangent to the PDE's characteristic equation. Then I can write $dy/dx=y/x$, and to solve this ODE,  $$\frac{dy}{dx}=\frac yx \\ \ln y=\ln x+c_1 \\ y=cx \\ y/x=c$$  Hence, the PDE is dependent on $c$ and I can write $U(x,y)=f(y/x)$ for some function $f$, solving the problem.  Question: Is this solution correct? The hint for the question (supplied by the professor) said I should use a substitution of variables, but this seems reasonably valid. Line-breaking widget layout for Android I'm trying to create an activity that presents some data to the user. The data is such that it can be divided into 'words', each being a widget, and sequence of 'words' would form the data ('sentence'?), the ViewGroup widget containing the words. As space required for all 'words' in a 'sentence' would exceed the available horizontal space on the display, I would like to wrap these 'sentences' as you would a normal piece of text.  The following code:  public class WrapTest extends Activity {     /** Called when the activity is first created. */     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         LinearLayout l = new LinearLayout(this);         LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(                 LinearLayout.LayoutParams.FILL_PARENT,                 LinearLayout.LayoutParams.WRAP_CONTENT);         LinearLayout.LayoutParams mlp = new LinearLayout.LayoutParams(                 new ViewGroup.MarginLayoutParams(                         LinearLayout.LayoutParams.WRAP_CONTENT,                         LinearLayout.LayoutParams.WRAP_CONTENT));         mlp.setMargins(0, 0, 2, 0);          for (int i = 0; i &lt; 10; i++) {             TextView t = new TextView(this);             t.setText("Hello");             t.setBackgroundColor(Color.RED);             t.setSingleLine(true);             l.addView(t, mlp);         }          setContentView(l, lp);     } }   yields something like the left picture, but I would want a layout presenting the same widgets like in the right one.        Is there such a layout or combination of layouts and parameters, or do I have to implement my own ViewGroup for this? Jumping in an elevator?