Masking UIImage in ios

Question: I'am trying to create profile picture image with custom shape pattern with using masking in ios. Here is what i've used to create masked image :
<code>- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {

    CGImageRef maskRef = maskImage.CGImage;

    CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
                                        CGImageGetHeight(maskRef),
                                        CGImageGetBitsPerComponent(maskRef),
                                        CGImageGetBitsPerPixel(maskRef),
                                        CGImageGetBytesPerRow(maskRef),
                                        CGImageGetDataProvider(maskRef), NULL, false);

    CGImageRef maskedImageRef = CGImageCreateWithMask([image CGImage], mask);
    UIImage *maskedImage = [UIImage imageWithCGImage:maskedImageRef];

    CGImageRelease(mask);
    CGImageRelease(maskedImageRef);

    // returns new image with mask applied
    return maskedImage;
}
</code>
After implementing instance , i am calling : *(_profileImage is global UIImage)
<code>UIImage *maskImage = [UIImage imageNamed:@"maskProfilePicture.png"];

UIImage *maskedImage = [self maskImage:_profileImage withMask:maskImage];
</code>
and result (Image should be added in subview of mask. But it seems , mask image overlap on Image that need to be masked ):

The mask image  : (Maybe mask image properties are wrong that i created in photoshop :)
Comment: naive comment: shouldn't the mask be black?
Comment: The Core Graphics calls look correct. Can you post the mask image you are using? According to the docs, it must be in the DeviceGray color space, and must not have an alpha component.
Comment: I've added mask image but it's white , that's why it seems there's nothing :)))
Comment: @GabrielePetronella not naïve at all. :-)
Comment: Can someone explain me , why these borders appear ? :( - http://prntscr.com/1z5nxw
Answer: The Core Graphics calls look correct.
Change the mask image to be have a black where you want the image to show through, and white elsewhere.
Comment: Thank you for your help , it works fine except giving white border to mask image :/
Comment: @JasonHarwig, how can I add mask to `UIView` that will be rotated, but make this mask tied to bottom of that `UIView` and won't rotate with UIView? I asked question about that but nobody answered, maybe you know the answer? Thanks.
Comment: Any idea about the reverse masking.(Reverse of above process).Means I want to remove the fill area(make it transparent) and Transparent area with fill.
Comment: @Milanpatel, Invert colors of the mask image. `convert mask.png -negate inverted.png`
Comment: @JasonHarwig,please see my question on stack overflow.   ..   http://stackoverflow.com/questions/28122370/masking-and-reverse-masking-in-imageview-ios
Answer: You can use CALayer's mask property to achieve the result.
CALayer Apple Documentation
Your masking layer should be transparent in places where you want to cut out the image.

Masking UIImage in ios


Sample size needed to prove equal proportions

Question: We are trying to prove that three groups have the same proportion of some effect. We are struggling with formulating the null hypothesis, and whether or not the sample size is big enough. The proportions are 37/213, 55/344 and 32/210. This seems like a very common scenario, but naive google search was not that helpful.
Comment: A very similar Q:  https://stats.stackexchange.com/questions/77965/sample-size-calculation-for-comparison-of-3-proportions
Answer: Now you have data, and it is somewhat late for a power analysis, if not for a future confirmation experiment. The hypothesis of equal proportions in three groups is the hypothesis of homogeneity in a contingency table. You data is (I am using R):
       yourtable
       G1  G2  G3
x      37  55  32
total 213 344 210

The proportions are
sapply(as.data.frame(yourtable), function(x) x[1]/x[2])
       G1        G2        G3
0.1737089 0.1598837 0.1523810

For the homogeneity test we need this in the form of a contingency table:
con.table <- yourtable
con.table[2, ] <- con.table[2, ]-con.table[1, ]
row.names(con.table) <- c("x", "n-x")

chisq.test(con.table)

    Pearson's Chi-squared test

data:  con.table
X-squared = 0.36957, df = 2, p-value = 0.8313

so there is no evidence against homogeneity, but you need evidence for homogeneity. I would first go for confidence intervals, which can be calculated via logistic regression:
my.df <- as.data.frame(t(con.table))
 my.df$G <- rownames(my.df)

> logmod <- glm( cbind(x, `n-x`) ~ 0+G, family=binomial, data=my.df)
> logmod

Call:  glm(formula = cbind(x, `n-x`) ~ 0 + G, family = binomial, data = my.df)

Coefficients:
   GG1     GG2     GG3
-1.560  -1.659  -1.716

Degrees of Freedom: 3 Total (i.e. Null);  0 Residual
Null Deviance:      385
Residual Deviance: -3.553e-14   AIC: 22.08
> confint(logmod)
Waiting for profiling to be done...
        2.5 %    97.5 %
GG1 -1.928812 -1.217750
GG2 -1.957458 -1.379635
GG3 -2.110139 -1.354896

You could backtransform that confidence interval to probability scale, and see if it is close enough for your purposes. Else you would need to collect more data,sample size calculations could be based on simulations from this model, or look at ideas from Experimental Design on Testing Proportions  or  Sample size for logistic regression?
For experiments with the code, here is a textual representation of yourtable:
 dput(yourtable)
structure(c(37, 213, 55, 344, 32, 210), .Dim = 2:3, .Dimnames = list(
    c("x", "total"), c("G1", "G2", "G3")))

Comment: We used the overlap of CI as a measure of equality, but I'm starting to think this is actually wrong ... could you explain how to "back-transform CI to probability scale", and can this be translated to a minimal sample size needed? thanks!


ets() in R returns a flat forecast for intermittent demand

Question: In my attempt to forecast sales demand by month utilizing the last 3 years of history to predict balance of the year, ets() from forecast() package yields an answer for some time series but not others. I'm following Dr Hyndman's presentation on best fist ets() function.
I understand while the flat forecast (average of the intermittent/volatile inputs) might be the best based on the intermittent history.  My question is more of whether the process below has any validity or if it's tottay wonky.  For the ones where ets() provides a flat forecast I tried the procedure outlined below to fix it, please let me know if I'm totally lost in my way of thinking:

ETS() flat forecast when there are too many 0's (or volatile)
I increase every observation of the time series by 100
ETS() forecast a curve
Can I just now reduce everything by 100 to get my forecast?
Comment: What makes you think a flat forecast function is incorrect? The forecasts are the conditional means of the future demand, and when demand is intermittent, the future demand often has constant mean.
Comment: We're going to need a lot more information about your data & what you're doing to answer this question. You may also want to look at the [free online forecasting textbook](http://otexts.com/fpp/) written by the author of the `forecast` package in R.
Comment: In particular, we cannot do anything without knowing the package where to find `ets()`.
Answer: If you have an additive model, then your proposed method will do nothing. You will get the same forecasts as when applied to the original data.
If you have a multiplicative model, or a mixed model, then you could get different forecasts. But then you need to think about the meaning of your model, and I'm not sure how it can be interpreted. For example, suppose you have an ETS(M,M,N) model --- the simplest multiplicative model with non-constant forecasts. Your model is then
$$y_t -c = \ell_{t-1}b_{t-1}(1+\varepsilon_t)$$
where $\ell_t$ is a local level, $b_t$ is a local growth factor and $\varepsilon_t$ is an iid noise term. The value $c$ is what you've added to your data ($c=100$ in your question). What does this mean? $\ell_t$ and $b_t$ no longer function as the level and growth of the data, but for the shifted data. It is hard to see that this is interpretable.
Comment: Thank you.  This is what I was looking for is that it's not appropriate to do this.

For the ETS() best fit forecasting by months, is there a minimum number of historical months that I should feed it for optimal/interpretable output?
Comment: Use as much data as you have got unless there has been a major structural break.


how to generate wave functions of different instruments?

Question: Sadly i don't have a harmonica or acoustic guitar i could easily access.
But i was playing around with a sinusoidal wave function and managed to build a really basic oscillator using software.
I'm looking to mathematically express functions of various instruments.
First however, i need to understand what corresponding sound waves of acoustic guitars and harmonicas look like. Those are the 2 i like the most.
Comment: You are looking for an introduction to musical  instrument synthesis. There are whole books on the subject, so it's way too broad to answer here.
Comment: not only are there whole books on the subject, but nobody's really managed it yet. there are some extremely expensive solutions that are getting very close -- but, those solutions are very expensive because it turns out that the answer is "it's very difficult"
Comment: This is so broad it would require books - this site is useful if you have a query about one particular part of it that we can then provide an answer to.
Comment: This is like asking, how to generate wave functions for spoken languages. I'd like to generate sound waves for Portuguese and Zulu.
Comment: You're not going to build this out of regular analogue oscillators. Investigate FM synthesis or physical modelling for how it needs to be calculated.
Comment: This might be of interest: https://music.stackexchange.com/q/16980/9198
Comment: BTW, historically, Yamaha did really well out of the FM market, not because they invented it [which they didn't] or even because they bought/licensed the patents [which they did] but most of all because they had the facilities to build the [in those days] **hugely**-complex VLSI chips to be able to calculate it in real time. They were actually, at that time, the biggest VLSI manufacturer in the world.
Comment: VLSI == very large scale integrated circuit
Comment: For anyone following this far… they also at the other end of the scale made chips for things like washing machines… which we used to complain they put in some of their keyboards [they once actually did that]. The chips were, of course, non-specific until programmed…. (though maybe they were responsible for getting some of those clean sounds whiter than white ;))
Comment: Related [question](https://music.stackexchange.com/q/8214/2600) extending that already broad problem to ALL instruments.
Comment: I am surprise this was closed!  I think the question, though short, was clear.  What does the waveform of a real instrument look like.  I voted to reopen.  Perhaps some suggestions on how to clarify it would be helpful.
Answer: Sadly, manufacturers have spent millions trying to do what you'd like to do. And the success rate is close to none. A sine wave alone may get close (but not very) to one or two instruments, but each instrument's sound is soooo much more complex than just a sine wave - and that in itself changes with volume, pitch and several other aspects.
Other waves produce other sounds too - square, saw, for example. And most instruments' sounds will have combinations.
For not much money, you could buy a harmonica - or even a pre-loved guitar, which would actually give the sounds you love. And be able to play several notes simultaneously - something I doubt your set-up would.
For those and many other reasons, synths and keyboards have gone down the sample route. Each of the 88 piano notes are sampled, or recorded, if you like, in many different ways, and that's what gets heard when a key is pressed on an electronic keyboard, for instance.
If you're interested in synthesis, you could do worse than source something like an Arturia Minibrute, which gives you the opportunity to synthesise many different sounds using its many different parameters. But a guitar would be cheaper - a harmonica cheaper still - and give the sounds you require!
Comment: @ggcg FM can achieve "good" results, but they usually are very *synthish*. It's almost the same as CGI (at least, as it was until ~5-10 years ago), where you can achieve good levels of realism, but when dealing with more "human" aspects there's always the "uncanny valley" issue.
Comment: TG33 is a stripped-down DX7 [FM synthesis] + simple samples of more complex waves
Comment: Well, physical modelling has reached *very good* results at least for certain types of instruments that rely more on mechanical aspects for the production of sound: [Modartt](https://www.modartt.com/) is probably the most known and successful, with very realistic results of pianos as much as other pitched percussions (with PianoTeq) and organs (with Organteq).
Comment: This surprises me.  Perhaps I'm missing something but I've modeled waveforms using physics and nothing else and the results were nice, maybe not perfect, but nice.  I recall in the 90s a device called the TG33 (forget the manufacturer) that allowed you to manually edit the attack, sustain, and decay portions of the wave form.  A group of us consisting of physics and music students spent months playing with it and we were impressed with the resulting sounds.  Maybe we were just pleased with ourselves.
Answer: This is a great question.
What you are interested in is understanding the time dependent behavior of the spectrum of these instruments.
There is a lot of physics involved in this, so what you get here may be quite watered down.
First there is a set of natural harmonics related to the vibrating components of system.  For the guitar each note created by the string under tension will have a fundamental tone (the actual letter name of the note assuming it is in tune) and a sequence (theoretically infinite) of harmonics that obey fn = n*f1, n = 1, 2, 3, ..., infinity.  These are the natural resonant frequencies supported by the vibrator.
The human attack of the instrument determines how much of each harmonic is initially present in the waveform.  This is a "simple" application of initial conditions to the shape profile or velocity profile of the string or reed, etc.
As an example, if you pull a string at the center point and release it from rest the initial shape would be close to an isosceles triangle.  Any harmonic with a node at the mid point will be missing from the spectrum (n = even).  Pluck it somewhere else and you will get a different set of harmonics.
If you can get a list of the harmonics and their relative strength and relative phase in a book you will be in good shape to start modeling sounds.
But... Over time damping will cause the higher harmonics to decay leaving a different spectrum over time.  This is, in my opinion, where a lot of sound engineers neglect physics.  You need to model the evolution of the spectrum over time with the correct physics to get a sound that really sounds like the instrument.
There are a lot of books out there that provide a nice starting point.  Physics and the Sound of Music by Rigden, any book on sound waves and vibration, several on musical instrument construction and analysis by Fletcher and Rossing.
I have modeled musical instrument sounds using software and imo they are pretty accurate, despite what has been said about the state of the art.  Perhaps I should market my tone generators.
If modeling the physics is beyond the scope of your project you could sample the instrument, do a spectral analysis on it and get the info right from the data.  It may not ever sound perfect but it may sound good enough.
Comment: Even if OP (or anyone!) manages to produce a recognisable sound from the oscillator, it's only one sound. Given that OP prefers guitar and harmonica - both of which are capable of playing multi-notes - he's going to need several oscillators to emulate. A lot of the existing synths are monophonic, so it'll be like pushing water uphill.
Comment: Without knowing the specific "oscillator" he has I would not guess that it is not capable of multiple tones.  I've used multi channel function generators.  It will not likely allow for time dependent waveform changes.  I was venturing away from the OPs set up.  I'd suggest using s/w to do this (which the OP also mentions).
Answer: It may be a simple question, but the answer is far from simple.
Musical instruments don't produce simple sine waves.  Instead, they produce a fundamental, plus a series of harmonics at multiples of the frequency of the fundamental. (Actually, some percussion instruments produce harmonics that aren't exact multiples of the fundamental)
So if you play an A at 440Hz, your instrument will also produce 880Hz, 1320Hz, 1760Hz, 2200Hz, and so on.
Each instrument produces the harmonics at different amplitudes.  That's why they all sound different.  To get an accurate reproduction of an instrument, you have to record it, perform a Fourier analysis of the recording, and determine the amplitudes of each of the harmonics.
But it's worse than that.  An open guitar string doesn't sound like one played at a fret.  A harmonica blown hard doesn't produce the same sound as one played soft.  You need to make recordings of every note, in every way you can play the instrument, and measure the harmonics of each.
That's why many synthesisers these days are actually playing recordings of real instruments, rather than trying to generate them synthetically.
Comment: String instruments produce harmonics that aren't exact multiples of the fundamental. Some percussion instruments produce harmonics that aren't anywhere near a multiple of the fundamental.


Para que serve um submodule no git?

Question: Certo dia fui clonar uma biblioteca no github e lá tinha uma instrução para utilizarmos o comando git submodule update.
Trabalho há algum tempo com o git e até então não tinha conhecimento desse comando.
Para que serve esse comando submodule?
Answer: Este comando é útil quando você quer inserir um outro repositório git dentro do seu projeto principal (uma biblioteca, por exemplo).
Para o git o submodulo será um projeto totalmente independente. Você pode editar o conteúdo abaixo da pasta do submódulo, comitar, fazer push, etc. Desde que tenha permissão para isso :)
Existem alternativas, como gerenciadores de pacote, que organizam as dependências de outras formas mais eficientes e seguras.
Comment: Nesse último parágrafo, então teríamos como exemplo o `composer`, `npm` e o `gem`.
Comment: Exatamente! Esses gerenciadores geralmente analisam as dependências do projeto, baixam os arquivos em uma pasta específica e esta fica fora do controle de versões do git no seu projeto (.gitignore). Em geral você pode atualizar tudo com uma simples linha de comando.

Gosto de usar submodulos quando também estou fazendo modificações no próprio submodulo também. Caso contrário, não recomendo.
Answer: Submodule serve para você gerenciar os módulos do seu repositório!
O que isso quer dizer?!
Digamos que você está criando um programa e precisa adicionar uma biblioteca que você encontrou no github para facilitar o desenvolvimento. Você pode adicionar essa biblioteca como um sub módulo da sua aplicação.
Qual a vantagem de usar isso ao invés de somente copiar o código?
Se você simplesmente copiar o código:

Pode ter problemas com a licença do código que está utilizando
Perde o histórico da biblioteca que está usando
Se houver alguma mudança no código da biblioteca você não saberá disso a menos que fique copiando constantemente o código

Se você usar o submodule:

Se houver uma atualização na biblioteca você poderá facilmente atualizá-la
Provavelmente não terá problema com licenciamento de código
Diminui o tamanho do seu repositório

Como o submodule funciona na prática?
De maneira simplificada pode-se dizer que ele mantém um ponteiro para o repositório
Para mais detalhes veja https://git-scm.com/docs/git-submodule
Comment: Só faltou dizer que um gerenciador de pacotes (npm, composer, etc) é ainda mais simples/vantajoso que um submodule
Comment: Sim! Mas nem todas as linguagens têm gerenciadores de pacotes, por exemplo linguagem C (pelo menos eu desconheço um)
Answer: Na verdade, o comando git submodule update diz ao Git que você deseja que seus submódulos façam check-out do commit já especificado no índice do superprojeto. Se você deseja atualizar seus submódulos para a confirmação mais recente disponível a partir do controle remoto, será necessário fazer isso diretamente nos submódulos.
Resuminto:
# Get the submodule initially
git submodule add ssh://bla submodule_dir
git submodule init

# Time passes, submodule upstream is updated
# and you now want to update

# Change to the submodule directory
cd submodule_dir

# Checkout desired branch
git checkout master

# Update
git pull

# Get back to your project root
cd ..

# Now the submodules are in the state you want, so
git commit -am "Pulled down update to submodule_dir"

No caso se você for preguiçoso ( kkk )
git submodule foreach git pull origin master

Para que serve um submodule no git?


How to get executable phar command from the PHP source working?

Question: I want to be able to work with phar command line tool (on Debian Linux) like described on this manpage.
What I've done so far:

downloaded the PHP PHAR source folder;
moved it to /usr/share/;
altered the first line of the phar.php from #!/usr/local/bin/php to #!/usr/bin/php (path to the PHP symlink -> to the PHP executable file);
created a symlink phar to /usr/share/phar/phar.php.

Now phar help returns an error:
# phar help
PHP Fatal error:  Uncaught exception 'PharException' with message 'manifest cannot be larger than 100 MB in phar "/usr/share/phar/phar.php"' in /usr/share/phar/phar.php:48
Stack trace:
#0 /usr/share/phar/phar.php(48): Phar::mapPhar()
#1 {main}
  thrown in /usr/share/phar/phar.php on line 48

What am I doing wrong? How to get it working?
Thx
Comment: It works! S. [this comment](http://stackoverflow.com/questions/15373638/how-to-get-where-to-obtain-the-php-phar-command-line-tool#comment21793827_15373638) to the question "[How to get / where to obtain the PHP phar command line tool?](http://stackoverflow.com/questions/15373638/how-to-get-where-to-obtain-the-php-phar-command-line-tool)".
Answer: Probably a corrupted phar file.  Try download it again.


Find five positive integers whose reciprocals sum to $1$

Question: Find a positive integer solution $(x,y,z,a,b)$ for which
$$\frac{1}{x}+ \frac{1}{y} + \frac{1}{z} + \frac{1}{a} + \frac{1}{b} = 1\;.$$
Is your answer the only solution? If so, show why.
I was surprised that a teacher would assign this kind of problem to a 5th grade child. (I'm a college student tutor) This girl goes to a private school in a wealthy neighborhood.
Please avoid the trivial $x=y=z=a=b=5$. Try looking for a solution where $ x \neq y \neq z \neq a \neq b$ or if not, look for one where one variable equals to another, but explain your reasoning. The girl was covering "unit fractions" in her class.
Comment: $x\neq y\neq z\neq a\neq b$ is not the same as saying that $x, y, z, a,$ and $b$ are all distinct. For example $1\neq 2\neq 1\neq 2\neq 1$, but they are not distinct.
Comment: I wouldn't be surprised if a bright fifth grader came up with the trivial x=y=z=a=b=5. Then answer the next question with "No": x=y=z=a=6, b=3. That seems do-able for bright grade fives.
Comment: Is there a reason why 1/5 + 1/5 + 1/5 + 1/5 + 1/5 = 1 is a bad answer?  Especially if this is grade school math.  For a generic fifth grader is seems that this would be a rather logical introduction to fractions.  I know you're looking for 'x≠y≠z≠a≠b' but is there some outside reason as to why?  The question, as stated, doesn't seem to have that restriction.  Occam's Razor and all that.
Comment: $(2, 4, 8, 16, 16)$ is another solution.
Comment: A $5$-tuple is hardly a 'pair'!
Comment: How old is a 5th grader in your country?
Comment: Don't have enough rep here (I come from other stackexchange sites) to answer but I came up with another brute force method I didn't see here. Pick the largest fraction with a non-repeating decimal equivalent that's less than your total (1/2) and keep going (1/2 + 1/4 = .75; 1/2 + 1/4 + 1/5 = .95; 1/2 + 1/4 + 1/5 + 1/25 = .99; 1/2 + 1/4 + 1/5 + 1/25 + 1/100 = 1)
Comment: What about $a = b = 3$, $x = 6$, $y = 9$ and $z = 18$? Or simpler still $x=y=z=a=8$, $b=2$?
Comment: http://www.jstor.org/stable/2299023
Comment: @Michael, I agree.   Low: Why the surprise?  We easily found two different solutions, and that answers the question.
Comment: When I was in 5th grade, I was still learning long division. Crazy that they start algebra so young now.
Comment: If they find any solution other than all=5, then they can just swap which number is assigned to which variable - that works for the "is it the only solution?" part.  Sorta.
Comment: From the question it seems clear that the distinct requirement was not given to the 5th graders. Fractions and equations with multiple unknowns is part of the 4-6th grade plan so the problem seems appropriate (though maybe not required for a passing grade). I would expect somewhere between 70-90% to figure out the trivial solution and maybe 20-30% to figure out another solution, thus proving it's not the only one. Less than 1% of 5th graders would probably find a distinct solution.
Comment: More context is needed to judge appropriateness of the difficulty.  eg Regular vs honors math, and if it's something that all students are expected to be able to do or a stretch problem.  It appears similar in difficulty to weekly challenge/puzzle solving sets that I was regularly given in my honors math class around that grade level; but the typical expectation was that we'd only be able to figure out how to solve 2 or 3 out of 5 of them (and the 'easier' half were generally solvable both via brute force using just pencil and paper and by a more elegant method if you could figure it out).
Comment: related: http://math.stackexchange.com/questions/109655/how-to-prove-that-sum-n-12012-frac1x-n-1-has-finitely-many-solut
Comment: A generalized version of the question has received some good answers at http://mathoverflow.net/questions/229514/how-many-solutions-does-frac1x-1-frac1x-2-cdots-frac1x-n-1-ha
Comment: Indeed, is the constraint that the solution consist of distinct integers part of the original fifth grade problem, or is that an embellishment added by you?
Comment: @grauwulf I think the point was that s/he assumed a 5th grader 'could' figure that out and was focusing on finding out whether a 5th grader really should be able to figure out another answer.
Comment: Interestingly enough, the number of distinct solutions is an upper bound for the number of (isomorphism classes of) groups with exactly 5 conjugacy classes!
Comment: The actual content of the class would be relevant to the ease of finding examples -- e.g. if the class had recently talked about Egyptian fractions, they might have been taught some ways to find equations like this.
Answer: The perfect number $28=1+2+4+7+14$ provides a solution:
$$\frac1{28}+\frac1{14}+\frac17+\frac14+\frac12=\frac{1+2+4+7+14}{28}=1\;.$$
If they've been doing unit (or 'Egyptian') fractions, I'd expect some to see that since $\frac16+\frac13=\frac12$, $$\frac16+\frac16+\frac16+\frac16+\frac13=1$$ is a solution, though not a much more interesting one than the trivial solution. The choice of letters might well suggest the solution
$$\frac16+\frac16+\frac16+\frac14+\frac14\;.$$
A little playing around would show that $\frac14+\frac15=\frac9{20}$, which differs from $\frac12$ by just $\frac1{20}$; that yields the solution
$$\frac1{20}+\frac15+\frac14+\frac14+\frac14\;.$$
If I were the teacher, I'd hope that some kids would realize that since the average of the fractions is $\frac15$, in any non-trivial solution at least one denominator must be less than $5$, and at least one must be greater than $5$. Say that $x\le y\le z\le a\le b$. Clearly $x\ge 2$, so let's try $x=2$. Then we need to solve
$$\frac1y+\frac1z+\frac1a+\frac1b=\frac12\;.$$
Now $y\ge 3$. Suppose that $y=3$; then $$\frac1z+\frac1a+\frac1b=\frac16\;.$$
Now $1,2$, and $3$ all divide $36$, and $\frac16=\frac6{36}$, so we can write
$$\frac1{36}+\frac1{18}+\frac1{12}=\frac{1+2+3}{36}=\frac6{36}=\frac16\;,$$
and we get another 'nice' solution,
$$\frac12+\frac13+\frac1{12}+\frac1{18}+\frac1{36}\;.$$
Comment: @LowScores: I realized immediately that a perfect number would work **if** it had exactly $5$ proper divisors. $6$ is too small, and I knew that the next perfect number is $28$, so I tried it, and it worked.
Comment: I love that we have real professors on here.
Comment: Oh my gosh Brian. How did you figure that out? It took 5 adults in the room and 50 minutes yet no one got as close as Michael or Karolis! There was a woman in the room who had her B.A. in math from a prestigious university and she couldn't figure this out. Amazing. Is it possible for you to show your reasoning or is this something that "popped" into your head ...like magic?
Comment: Your answer is the most fitting for lines of reasoning to this problem as a fifth-grader might see it. It's approximately the same approach I used the problem when I first saw it.
Comment: Your solution to try x = 2 ... etc is good.  Solving by iteratively eliminating variables is a good technique for 5th graders to learn.
Comment: Think he meant 1/3 for the last term based on the line above.
Comment: Fixed it because 7/6 isn't 1.
Comment: @AAron: I've taken only a quick look, but it appears that you could do a lot worse than to start [here](http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fractions/egyptian.html) and [here](http://www.ics.uci.edu/~eppstein/numth/egypt/).
Comment: Do the sum of the reciprocals of the factors of all perfect numbers =1?
Comment: @AAron: The sum of the reciprocals of the factors that are greater than $1$ is always $1$, yes; this follows from the definition of *perfect number*. If you put those fractions over the common denominator $n$, the numerators will be all of the divisors of $n$ except $n$ itself, and a number is perfect precisely when the sum of those divisors is $n$.
Comment: Oh ok, but I am guessing that there are other numbers that fit the bill for this case, right? Or do these numbers have any other significance?
Comment: @AAron: According to [this answer](http://math.stackexchange.com/a/290575/12042) by **Joe Z.** there are $147$ solutions altogether; the one using the perfect number $28$ was just the first one that occurred to me that had all of the denominators distinct.
Comment: Are there any recommended sites other than Wikipedia where I could study Egyptian fractions?
Comment: Thank you very much. Ill have a look at them. Also, I have a problem related to this coming out tomorrow midday so do you mind taking a look at it for me?
Comment: @AAron: You're welcome. Once you've posted it, leave a note under any of my answers, including a link to the question, and I'll take a look.
Answer: You could connect it to geometry. Cut the square into equally-sized pieces, then take some of those pieces and cut them into even-smaller ones until you get five pieces. e.g.

After that, you could try some different-sized pieces and have a good chance of getting something like this:
Comment: There aren't infinitely many solutions, though. There are 147, as shown in Joe Zeng's answer
Comment: I think this solution is the most impressive, because it seems like the only one that instantly and accessibly conveys to almost everybody that there is an infinite amount of solutions.
Comment: @gmline This wasn't supposed to be a method for enumerating all the answers or anything like that; just a way to approach it visually that might help for some kids.
Comment: An excellent idea. Cutting out fractions of a unit circle and passing them to the class to put back together in different ways would work really well!
Comment: This is genius. If I were the teacher, I'd hope for this kind of thinking!
Comment: This is awesome. I thought of so many numerous attempts and thoughts, but this one is the high-five kicker!!!
Comment: I feel this answer is the purpose/intention of asking such question to 5th grade students.
Comment: I agree. However, I feel 'cakes' are more appropriate a representation for a 5th grader than squares. Most fractions are taught using 'pieces of cakes'. It really IS digestable by halflings :)
Comment: The simple geometric visual is what makes this solution genius.
Answer: This solution may be too advanced for a fifth-grader, but you can do this problem algorithmically - simply by searching all the possible fractions.
The gist of it is to use a greedy algorithm - start with the biggest fraction, and continue iterating small fractions until you can't anymore. For example, $\displaystyle \frac 1 2 + \frac 1 3 + \frac 1 7 + \frac 1 {43} + \frac 1 {1806}$ would be the first one you find. The next one would be $\displaystyle \frac 1 2 + \frac 1 3 + \frac 1 7 + \frac 1 {44} + \frac 1 {924}$, then $\displaystyle \frac 1 2 + \frac 1 3 + \frac 1 7 + \frac 1 {45} + \frac 1 {630}$, and so on.
Here's the algorithm in more detail:

For the first number, start with $\displaystyle \frac 12$, eventually working your way down to $\displaystyle \frac15$ (which is the smallest that the largest fraction can be, so you can stop there).
Subtract this fraction from 1, and use the remaining part to determine what the next few numbers will iterate through.
For each of the subsequent fractions, start with the largest unit fraction smaller than both the "remaining part" that's left and the fraction before it, and work down until you reach the smallest unit fraction larger than $\displaystyle \frac1n$ the "remaining part", where your fraction is the $n$th last fraction, and do the same as above, subtracting the unit fraction from the "remaining part" for the next fraction to use.
Once you have four fractions, if the "remaining part" for the last fraction can be expressed as a unit fraction, you have a solution. Otherwise, you don't, and continue onwards.

This algorithm will eventually return all the possible unit fraction combinations, starting from $\displaystyle \frac 1 2 + \frac 1 3 + \frac 1 7 + \frac 1 {43} + \frac 1 {1806}$ and ending with $\displaystyle \frac 15 + \frac 15 + \frac 15 + \frac 15 + \frac 15$.

http://joezeng.com/code/fractions/fractions.html $\leftarrow$ This is a list of all of the fractions, dynamically generated using some recursive Javascript that implements the algorithm above. You can view the source code here, which I have MIT-licensed for demonstration purposes.
According to the generator, there are a total of 147 solutions for 5 fractions, and the "minimum unique solution" such that all denominators are distinct and their sum is the lowest possible is $\displaystyle \frac 13 + \frac 14 + \frac 15 + \frac 16 + \frac 1 {20}$. There is another "minimum unique solution", such that the largest denominator is the lowest, which is $\displaystyle \frac 12 + \frac 14 + \frac 1{10} + \frac 1{12} + \frac 1{15}$.
You can also use the generator to generate fraction lists of arbitrary sizes by modifying the initial function call to use 6 levels (or 2, 3, or 4) instead of 5, as well as generate Egyptian fraction expansions for arbitrary fractions (by modifying the first two terms 1, 1 to be other things).
Comment: Brian had already presented the best solution; I was simply presenting a more comprehensive, less appropriate one.
Comment: "Brian had already presented the best solution; I was simply presenting a more comprehensive, less appropriate one."  +1 for this charming analysis of your work!
Comment: I'm very glad that someone took the trouble to do the exhaustive analysis!
Comment: There are 3462 solutions for six terms, 2320 with all unique terms (72 solutions for five unique terms).  There are 294326 solutions with seven terms (245767 unique); the least solution is 3 4 9 10 12 15 18.  Beyond seven I'd want a cleverer search strategy (breadth-first for small values would be fine).
Comment: Also, this solution would be to the benefit of that one girl with a B.A. in math who couldn't solve it, as mentioned by @LowScores in one comment on Brian's answer.
Comment: @JoeZeng We'd probably need assistance from SO staff to get an answer; but I'd be curious if your answer has a disproportionately high share of up votes from people whose network profiles indicate they're primarily programmers not mathematicians.
Comment: It's certainly flooding my reputation count. I've hit the daily limit three days in a row now, and this is the first time I've ever hit the daily limit even once.
Comment: The link does not work anymore.
Comment: Yeah, I restructured my site a bit and the code disappeared. I'll put it up on pastebin or something.
Comment: For 6 terms, the minimum unique solution is 1/3 + 1/4 + 1/6 + 1/10 + 1/12 + 1/15, and my computer lagged out on 7 terms.
Comment: the Question is one for a specific set of instructions, @Brian showed how simple the question really was.  if you look at the fractions Graphically it would seem so simple.  you have a pie cut it into 5 pieces that aren't the same.  they didn't want the 5th graders to create algorithms they wanted them to "see" the fractions.
Comment: I think beyond seven the actual *number* of solutions gets unwieldy. If we're doing a search for the least unique solution, you're right that we could probably employ some sort of BFS strategy.
Comment: Alternatively, we could try doing the iteration in reverse. One way we can enforce a unique solution is to disallow fractions exactly equal to $\frac 1n$ the remaining part.
Comment: @RexKerr I strongly suspect the minimum unique solution for eight terms is 3 5 9 10 12 15 18 20.
Comment: @JoeZ. - I don't believe I can check right now, but I wouldn't be surprised given the form of the others.
Answer: Yet another method would be to start with $${1\over2}+{1\over3}+{1\over 6}=1$$
Divide by two and add $1\over 2$; this yields $${1\over 2}+{1\over 4}+{1\over 6}+{1\over 12}=1$$
Again, divide by two and add $1\over 2$; this yields $${1\over 2}+{1\over 4}+{1\over8}+{1\over 12}+{1\over 24}=1$$
Comment: I like this method a lot.
Comment: This is simple but effective. Very nice.
Comment: I like this method, too.  It may be worth noting that your first equation is the result of applying the recursive function to $${1\over3}+{2\over 3}=1$$
Comment: @DavidKaczynski 2/3 isn't a unit fraction, though.
Comment: one can reach your solution with a similarly simple reasoning: start with 1/2+1/4+1/4 then divide the 1/4 using 1/2+1/3+1/6.
Answer: The number of solutions of $$1={1\over x_1}+{1\over x_2}+\cdots+{1\over x_n},\ \ \ 0\lt x_1\le x_2\le\cdots\le x_n$$ is tabulated, as a function of $n$, at OEIS A002966 but only a few terms are given: $1, 1, 3, 14, 147, 3462, 294314, 159330691$. I don't know whether the number of solutions with all denominators distinct has been tabulated at that site.
Comment: [A006585](http://oeis.org/A006585) gives the number of distinct denominator solutions, or $n!$ times that if you can reorder
Comment: @asmeurer, Henry is writing about *distinct denominator* solutions, so I don't think $(1/2)+(1/2)$ is an issue.
Comment: I think it's less than $n!$ if you still consider $\frac{1}{2} + \frac{1}{2}$ and $\frac{1}{2} + \frac{1}{2}$ to be the same.
Comment: Ah, missed that.
Answer: A simple C++ code to find the a-b-c-x-y pairs for the first positive 100 integers.
const double MAX_NUM = 100.0;
const double EPSILON = 0.0000001;
double Sum;
for (double a=1; a<=MAX_NUM; a++)
{
    for (double b=1; b<=a; b++)
    {
        for (double c=1; c<=b; c++)
        {
            for (double x=1; x<=c; x++)
            {
                for (double y=1; y<=x; y++)
                {
                    Sum = 1.0/a + 1.0/b + 1.0/c + 1.0/x + 1.0/y;
                    if (abs(Sum - 1.0) < EPSILON)
                    {
                        std::cout << a << "\t" << b << "\t" << c
                            << "\t" << x << "\t" << y << std::endl;
                    }
                }
            }
        }
    }
}

Its output is:
5       5       5       5       5
6       6       6       4       4
6       6       6       6       3
8       8       4       4       4
8       8       6       4       3
8       8       8       8       2
9       9       9       3       3
9       9       9       6       2
10      5       5       4       4
10      6       5       5       3
10      10      10      5       2
12      6       4       4       4
12      6       6       4       3
12      8       8       3       3
12      8       8       6       2
12      12      4       4       3
12      12      6       3       3
12      12      6       6       2
12      12      12      4       2
14      7       7       7       2
15      5       5       5       3
15      10      4       4       3
15      10      6       3       3
15      10      6       6       2
15      12      10      4       2
15      15      5       3       3
15      15      6       5       2
16      16      8       4       2
18      9       4       4       3
18      9       6       3       3
18      9       6       6       2
18      12      9       4       2
18      18      18      3       2
20      5       4       4       4
20      6       5       4       3
20      8       8       5       2
20      10      10      4       2
20      12      5       3       3
20      12      6       5       2
20      20      5       5       2
20      20      15      3       2
21      7       7       3       3
21      7       7       6       2
21      21      14      3       2
24      8       4       4       3
24      8       6       3       3
24      8       6       6       2
24      12      8       4       2
24      16      16      3       2
24      24      4       3       3
24      24      6       4       2
24      24      12      3       2
28      14      7       4       2
28      21      4       3       3
28      21      6       4       2
28      21      12      3       2
30      10      5       3       3
30      10      6       5       2
30      15      5       5       2
30      15      15      3       2
30      20      4       3       3
30      20      6       4       2
30      20      12      3       2
30      30      10      3       2
33      22      11      3       2
35      14      5       5       2
35      15      14      3       2
36      9       9       4       2
36      18      4       3       3
36      18      6       4       2
36      18      12      3       2
36      36      9       3       2
40      10      8       4       2
40      24      10      3       2
40      40      5       4       2
42      7       4       4       3
42      7       6       3       3
42      7       6       6       2
42      12      7       4       2
42      14      14      3       2
45      9       5       3       3
45      9       6       5       2
45      30      9       3       2
45      36      5       4       2
48      16      4       3       3
48      16      6       4       2
48      16      12      3       2
48      48      8       3       2
54      27      9       3       2
56      42      8       3       2
60      5       5       4       3
60      12      5       5       2
60      15      4       3       3
60      15      6       4       2
60      15      12      3       2
60      20      10      3       2
60      30      5       4       2
60      40      8       3       2
70      7       7       5       2
70      28      5       4       2
72      9       8       4       2
72      24      9       3       2
72      36      8       3       2
78      13      13      3       2
84      14      4       3       3
84      14      6       4       2
84      14      12      3       2
84      84      7       3       2
88      33      8       3       2
90      18      10      3       2
91      78      7       3       2
96      32      8       3       2
99      22      9       3       2
100     25      5       4       2

Comment: This is not a programming community. I wrote the simplest code in shortest time to solve this problem numerically with least effort. I don't care about code efficiency in this particular case.
Comment: C++ for 5th graders!
Comment: This is like an algorithm that will be used as a bad example of not thinking.
Comment: Your code doesn't seem very efficient.
Comment: In addition, it won't find unit fraction combinations below a certain granularity, while there is a way to do the question using only integers.
Comment: @mezhang You mean a good example?
Comment: @JoeZeng: Your solution is using floating point maths too, you used JavaScript :P
Comment: Yes, but it doesn't use any actual floating-point numbers, and can be easily rewritten in the language of your choice that uses actual integer arithmetic, such as Python or C++ with GMP.
Answer: My first reaction to the question was $\frac12+\frac14+\frac18+\frac1{16}+\frac1{16}$. sorry, but it seems too natural to need explaining, but also not satisfactory because not all denominators are different.
Then other replies remind me of the "5th grade level" equation $1 = \frac12 + \frac13 + \frac16$.
Well, then the pupil will probably try to use the same equation to divide one of the three fractions and realize that the only one that will provide different denominators is the $\frac16$.
That is $1/6 = \frac{1/6}2 + \frac{1/6}3 + \frac{1/6}6 = \frac1{12} + \frac1{18} + \frac1{36}$
Thus building the solution $1 = \frac12 + \frac13 + \frac1{12} + \frac1{18} + \frac1{36}$

Thinking further about it, I assume that anybody confronted with fractions will easily agree with the simple statement: $1 = \frac1n + \frac{n-1}n$.
Dividing the equation by $n-1$ and arranging differently will produce $\frac1{n-1} = \frac1n + \frac1{n(n-1)}$, of which $\frac12 = \frac13 + \frac16$ is a special case.
once you have a couple of these equations spelled out, like:
$$\frac12 = \frac13 + \frac16 $$
$$\frac13 = \frac14 + \frac1{12} $$
$$\frac14 = \frac15 + \frac1{20} $$
$$\frac15 = \frac16 + \frac1{30} $$
it should be a kid's game to expand
$$1 = \frac12 + \frac14 + \frac14$$
into a solution of the given problem.
you might also want to include the case for $n=2$:
$$1 = \frac12 + \frac12$$
and start with the expansion of $1$.
Answer: First, without context, there is no way to tell if the problem is suitable for a given grade. It doesn't seem likely, but then maybe they did some work on the Egyptian representation of fractions, which is close enough that they might think of it. For me, that was my first thought, and I then came to:
$$\frac{1}{2}+\frac{1}{4}+\frac{1}{8}+\frac{1}{16}+\frac{1}{16}=1$$
Even with that hint, the question about uniqueness is not trivial. You can play with replacing only part of the expression, for example:
$$\frac{1}{8}+\frac{1}{16} = \frac{1}{6}+\frac{1}{48}$$
which yields:
$$\frac{1}{2}+\frac{1}{4}+\frac{1}{6}+\frac{1}{16}+\frac{1}{48}=1$$
but I don't see how 5th grade student can do that other than trial and error.
Other than that, I don't see what "typical fith-grade" reasoning can be used. Perfect numbers seem out of the question.
Comment: If the goal is simply to find any arbitrary solution, the problem should be solvable if someone starts with the three-number case; it shouldn't take long to find 1/2 + 1/3 + 1/6.  From there, one may try to decompose the 1/6 into two parts which are unit fractions.  A natural first effort would be to see what's left if one bumps 1/6 to the next smaller unit fraction (1/7).  That turns out to leave 1/42--a unit fraction (hooray!)  Subtract the next unit fraction smaller than that (1/43) to leave 1/1806.  I wouldn't expect students to enumerate the solutions, though.
Comment: @supercat: if you decompose the 1/6 in '''three''' parts that are unit fractions, then you get the five fractions you need. see my other answer. according to me easy enough for the fifth grade student.
Answer:
Please avoid the trivial $x=y=z=a=b=5$. Try looking for a solution where $x≠y≠z≠a≠b$ or if not, look for one where one variable equals to another, but explain your reasoning. The girl was covering "unit fractions" in her class.

Was this a requirement in the homework problem? The easiest way to prove that there is more than one solution to a problem is to find more than one solution to the problem, even if the additional solution is trivial. A starting point of any arbitrary number of unit fractions that sum to $1$ and that also can be combined into other unit fractions is a very valid starting point.
Case in point: I would propose that this be solved at the fifth-grade level by splitting fractions, with a little special knowledge to produce unique values. $1 = 1/2 + 1/2$. Now we need to come up with three more fractions and differentiate the two we have. We do this by continuing to split, with some clever knowledge of prime factors.
For instance, if a number in the denominator is divisible by both $2$ and $3$, then you can combine two or three of that unit fraction, and when reducing to lowest terms you will get a new unit fraction. $6$ is the simplest example; $1/6 + 1/6 = 1/3$ and $1/6 + 1/6 + 1/6 = 1/2$. This is useful to us: $1/6 + 1/3 = 1/2$, so $1/6 + 1/3 + 1/2 = 1$. Now we just need two more unique fractions. Well, let's split up the largest fraction, $1/2$, into more pieces than we tried before. If we divide it into 12 units, each of those will be $1/24$ of the whole. $2/24 = 1/12, 3/24 = 1/8$, and $6/24 = 1/4$. We can also combine $4$ and $8$ of these, but those two produce the fractions $1/6$ and $1/3$ which we already have. Now, by serendipity (or not), $1 + 2 + 3 + 6 = 12$. That would give us $1/24 + 1/12 + 1/8 + 1/4 = 1/2$. That's four of the five we need, and $1/2$ (the remaining fraction of the whole) isn't spoken for yet and can be produced by recombining $1/3$ and $1/6$, so $1/2 + 1/4 + 1/8 + 1/12 + 1/24 = 1$, and thus $\{2,4,8,12,24\}$ is a valid solution.
This generalizes into the following statement: find five numbers, $j,k,m,n$, and $p$, that are all factors of an arbitrary $z$, and that sum to $z$. Then $1/x=j/z$, $1/y=k/z$, and so on.
A good z-value to try in this case is $100$, which turns the fractions into simple integer percentages. $100$ has the following prime factorization: $2^2*5^2$. Each unique combination of those factors, plus the universal factor $1$, is a factor of $100$ and thus a possible value for the set of $5$ we need. There are 8 factors of $100$, not including $100$; $1, 2, 4, 5, 10, 20, 25$, and $50$. We can now apply a variation of the value-splitting; find numbers in this set that will sum to other numbers in the set. $100=50+50$. $50=25+25$. $25=20+5$, and $5=4+1$. Putting these identities together, $1+4+20+25+50 = 100$. Dividing everything by $100$ and finding lowest terms gives $1/100+1/25+1/5+1/4+1/2 = 1$, so $\{2,4,5,25,100\}$ is another valid solution.
Pretty much any number with $4$ or more factors other than $1$ and itself is a candidate z-value. It helps to have a few extra factors laying around, as was shown from the example above; a number with only $4$ unique factors, say $20$ $(2, 4, 5, 10)$, is unlikely to have those factors all sum to the original number as well (in this case the sum of those four factors is $21$; close but no cigar). It also helps if the prime factorization of the number (a graspable concept for a fifth grader, with multiplication, division and primes under her belt) includes more than one prime factor; this allows you to do the "divide by one, then multiply by the other" trick to produce unique denominators.
The are multiple, but not infinite, total solutions to this problem; the numbers involved are naturally bound by the two conditions; that natural numbers are used, and that only reciprocals of those natural numbers are allowed (no numerators other than 1). Other answers have empirically found all possible answers.
Answer: There are many ways to obtain many solutions. Here is one systematic way to obtain solutions.
First look at a class of solutions such that $x \leq y \leq z \leq a \leq b \leq 10$ (other solution can be obtained as permutation of these).
This implies that $2 \leq x \leq 5$. So now start with $x=2$. This now means that $3 \leq y \leq 8$. Choose $y=3$. This now means that $7 \leq z \leq 10$. You will quickly find that no solution exists such that $x \leq y \leq z \leq a \leq b \leq 10$. Then choose $y=4$. Again you will find that no solution exists such that $x \leq y \leq z \leq a \leq b \leq 10$.
Going through this you will find that if we want $x=2$, and $x \leq y \leq z \leq a \leq b \leq 10$, then $$[2, 5, 10, 10, 10];
[2, 6, 9, 9, 9];
[2, 8, 8, 8, 8]$$ are the only solutions with $x=2$ and $x \leq y \leq z \leq a \leq b \leq 10$.
Now set $x=3$ and get bounds for the remaining variables to see that $$
[3, 3, 9, 9, 9];
[3, 4, 6, 8, 8];
[3, 5, 5, 6, 10];
[3, 6, 6, 6, 6]; $$ are the only solutions with $x=3$ and $x \leq y \leq z \leq a \leq b \leq 10$.
Here are the solutions such that $x \leq y \leq z \leq a \leq b \leq 10$
$$[x,y,z,a,b] \in \{[2, 5, 10, 10, 10];
[2, 6, 9, 9, 9];
[2, 8, 8, 8, 8];
[3, 3, 9, 9, 9];
[3, 4, 6, 8, 8];
[3, 5, 5, 6, 10];\\
[3, 6, 6, 6, 6];
[4, 4, 4, 8, 8];
[4, 4, 5, 5, 10];
[4, 4, 6, 6, 6];
[5, 5, 5, 5, 5]; \}
$$
There are $114$ distinct solutions i.e. without permutations such that
$$x \leq y \leq z \leq a \leq b \leq 100$$ and can be found here.
Comment: You can edit the code in my answer to preclude answers that have numbers above a certain bound.
Answer: $$\frac{1}{2}+\frac{1}{3}+\frac{1}{8}+\frac{1}{30}+\frac{1}{120}=1$$
In  general, if you want $n$ distinct unit fractions to sum up to $1$ , you can use a formula
 (which I found almost by luck) and find a direct solution
$$\frac{1}{\frac{2!}{1}}+\frac{1}{\frac{3!}{2}}+\frac{1}{\frac{4!}{3}}+...+\frac{1}{\frac{n!}{n-1}}+\frac{1}{n!}=1$$
It is accepted at the Monthly and it will be published.
Comment: @Nilan here is the link https://www.jstor.org/stable/10.4169/amer.math.monthly.123.1.87?seq=1#page_scan_tab_contents
Answer: Surprised that no-one proposed $1,-1,1,-1,1$ and a whole bunch of variations around it.
Comment: Sorry, missed the "positive" in question...
Comment: Such as N, -N, M, -M, 1 - where N, M are any numbers. A whole infinity of answers.
Answer: Note that $1=\dfrac12+\dfrac12.$ Then we can use $\dfrac1n=\dfrac1{(n+1)}+\dfrac1{n(n+1)}$ to expand this up to five terms. In more general,

$$\color{Green}{\dfrac{1}{pqr}=\dfrac{1}{pr(p+q)}+\dfrac{1}{qr(p+q)}.}$$

For distinct 4-tuples, I got that $$1=\dfrac12+\dfrac14+\dfrac16+\dfrac1{12}$$
$$1=\dfrac12+\dfrac13+\dfrac17+\dfrac1{42}$$
$$1=\dfrac12+\dfrac13+\dfrac19+\dfrac1{18}$$
$$1=\dfrac12+\dfrac13+\dfrac1{10}+\dfrac1{15}.$$ Then continue inductively .....
Similarly, $1=\dfrac13+\dfrac13+\dfrac13$ is a special case of

$$\color{Blue}{\dfrac{1}{pqr}=\dfrac{1}{pq(p+q+r)}+\dfrac{1}{qr(p+q+r)}++\dfrac{1}{pr(p+q+r)}.}$$

For example, $\dfrac1{2n}=\dfrac1{2(n+3)}+\dfrac1{n(n+3)}+\dfrac1{2n(n+3)}$ for any positive integer $n.$
Answer: I am posting another solution since one of my students found this method.
(He is 16 years old but as you see he is gifted)
Start with $\frac{1}{2}+\frac{1}{3}+\frac{1}{6}$. No write $\frac{1}{6}=\frac{3}{18}=\frac{1}{18}+\frac{2}{18}=\frac{1}{9}+\frac{1}{18}$ and you get $\frac{1}{2}+\frac{1}{3}+\frac{1}{9}+\frac{1}{18}=1$. Proceed like this: Write the last fraction (which will have an even denominator) of the sum as $\frac{1}{2n}=\frac{1}{6n}+\frac{2}{6n}=\frac{1}{3n}+\frac{1}{6n}$ and so on!
Comment: Very nice solution on his part.
Answer: Here are ALL solutions (72 in total) for x<y<z<a<b

{2,3,7,43,1806},{2,3,7,44,924},{2,3,7,45,630},{2,3,7,46,483},{2,3,7,48,336},{2,3,7,49,294},{2,3,7,51,238},{2,3,7,54,189},{2,3,7,56,168},{2,3,7,60,140},{2,3,7,63,126},{2,3,7,70,105},{2,3,7,78,91},{2,3,8,25,600},{2,3,8,26,312},{2,3,8,27,216},{2,3,8,28,168},{2,3,8,30,120},{2,3,8,32,96},{2,3,8,33,88},{2,3,8,36,72},{2,3,8,40,60},{2,3,8,42,56},{2,3,9,19,342},{2,3,9,20,180},{2,3,9,21,126},{2,3,9,22,99},{2,3,9,24,72},{2,3,9,27,54},{2,3,9,30,45},{2,3,10,16,240},{2,3,10,18,90},{2,3,10,20,60},{2,3,10,24,40},{2,3,11,14,231},{2,3,11,15,110},{2,3,11,22,33},{2,3,12,13,156},{2,3,12,14,84},{2,3,12,15,60},{2,3,12,16,48},{2,3,12,18,36},{2,3,12,20,30},{2,3,12,21,28},{2,3,14,15,35},{2,4,5,21,420},{2,4,5,22,220},{2,4,5,24,120},{2,4,5,25,100},{2,4,5,28,70},{2,4,5,30,60},{2,4,5,36,45},{2,4,6,13,156},{2,4,6,14,84},{2,4,6,15,60},{2,4,6,16,48},{2,4,6,18,36},{2,4,6,20,30},{2,4,6,21,28},{2,4,7,10,140},{2,4,7,12,42},{2,4,7,14,28},{2,4,8,9,72},{2,4,8,10,40},{2,4,8,12,24},{2,4,9,12,18},{2,4,10,12,15},{2,5,6,8,120},{2,5,6,9,45},{2,5,6,10,30},{2,5,6,12,20},{3,4,5,6,20}
Answer: $$1={1\over 3}+{1\over 2}+{1\over 6}={1\over 3}+\left({1\over 4}+{1\over 4}\right)+{1\over 6}+\left({1\over5}-{1\over 5}\right)={1\over3}+{1\over4}+{1\over5}+{1\over6}+{1\over 20}$$
So we have
$${1\over3}+{1\over4}+{1\over5}+{1\over6}+{1\over20}=1$$
Answer: You can try taking $x, y, z, a$ each with value larger than $5$ which may or may not be equal. Now find $b$ such a way that the given relation is satisfied. But this question is way beyond fifth grade student (my opinion).
Comment: As long as it's clearly understood to be a somewhat open-ended and challenging question, I think that it's a great question at the $5$-th grade level.
Answer: There are $147$ such $5$-tuples (see Gerry Myerson's answer).
There are $72$   $5$-tuples among them  with all distinct $x,y,z,a,b$ (see J42161217's answer).
And  Joe Z. had exhaustive list of solutions (see his answer).
Since his link doesn't work now, I'll post the list of solutions here for completeness.
Solutions are sorted by $x \leqslant y \leqslant z \leqslant a \leqslant b$ (and solutions with all distinct $x,y,z,a,b$ are marked as bold):
1) [2, 3, 7, 43, 1806]
2) [2, 3, 7, 44, 924]
3) [2, 3, 7, 45, 630]
4) [2, 3, 7, 46, 483]
5) [2, 3, 7, 48, 336]
6) [2, 3, 7, 49, 294]
7) [2, 3, 7, 51, 238]
8) [2, 3, 7, 54, 189]
9) [2, 3, 7, 56, 168]
10) [2, 3, 7, 60, 140]
11) [2, 3, 7, 63, 126]
12) [2, 3, 7, 70, 105]
13) [2, 3, 7, 78, 91]
14) [2, 3, 7, 84, 84]
15) [2, 3, 8, 25, 600]
16) [2, 3, 8, 26, 312]
17) [2, 3, 8, 27, 216]
18) [2, 3, 8, 28, 168]
19) [2, 3, 8, 30, 120]
20) [2, 3, 8, 32, 96]
21) [2, 3, 8, 33, 88]
22) [2, 3, 8, 36, 72]
23) [2, 3, 8, 40, 60]
24) [2, 3, 8, 42, 56]
25) [2, 3, 8, 48, 48]
26) [2, 3, 9, 19, 342]
27) [2, 3, 9, 20, 180]
28) [2, 3, 9, 21, 126]
29) [2, 3, 9, 22, 99]
30) [2, 3, 9, 24, 72]
31) [2, 3, 9, 27, 54]
32) [2, 3, 9, 30, 45]
33) [2, 3, 9, 36, 36]
34) [2, 3, 10, 16, 240]
35) [2, 3, 10, 18, 90]
36) [2, 3, 10, 20, 60]
37) [2, 3, 10, 24, 40]
38) [2, 3, 10, 30, 30]
39) [2, 3, 11, 14, 231]
40) [2, 3, 11, 15, 110]
41) [2, 3, 11, 22, 33]
42) [2, 3, 12, 13, 156]
43) [2, 3, 12, 14, 84]
44) [2, 3, 12, 15, 60]
45) [2, 3, 12, 16, 48]
46) [2, 3, 12, 18, 36]
47) [2, 3, 12, 20, 30]
48) [2, 3, 12, 21, 28]
49) [2, 3, 12, 24, 24]
50) [2, 3, 13, 13, 78]
51) [2, 3, 14, 14, 42]
52) [2, 3, 14, 15, 35]
53) [2, 3, 14, 21, 21]
54) [2, 3, 15, 15, 30]
55) [2, 3, 15, 20, 20]
56) [2, 3, 16, 16, 24]
57) [2, 3, 18, 18, 18]
58) [2, 4, 5, 21, 420]
59) [2, 4, 5, 22, 220]
60) [2, 4, 5, 24, 120]
61) [2, 4, 5, 25, 100]
62) [2, 4, 5, 28, 70]
63) [2, 4, 5, 30, 60]
64) [2, 4, 5, 36, 45]
65) [2, 4, 5, 40, 40]
66) [2, 4, 6, 13, 156]
67) [2, 4, 6, 14, 84]
68) [2, 4, 6, 15, 60]
69) [2, 4, 6, 16, 48]
70) [2, 4, 6, 18, 36]
71) [2, 4, 6, 20, 30]
72) [2, 4, 6, 21, 28]
73) [2, 4, 6, 24, 24]
74) [2, 4, 7, 10, 140]
75) [2, 4, 7, 12, 42]
76) [2, 4, 7, 14, 28]
77) [2, 4, 8, 9, 72]
78) [2, 4, 8, 10, 40]
79) [2, 4, 8, 12, 24]
80) [2, 4, 8, 16, 16]
81) [2, 4, 9, 9, 36]
82) [2, 4, 9, 12, 18]
83) [2, 4, 10, 10, 20]
84) [2, 4, 10, 12, 15]
85) [2, 4, 12, 12, 12]
86) [2, 5, 5, 11, 110]
87) [2, 5, 5, 12, 60]
88) [2, 5, 5, 14, 35]
89) [2, 5, 5, 15, 30]
90) [2, 5, 5, 20, 20]
91) [2, 5, 6, 8, 120]
92) [2, 5, 6, 9, 45]
93) [2, 5, 6, 10, 30]
94) [2, 5, 6, 12, 20]
95) [2, 5, 6, 15, 15]
96) [2, 5, 7, 7, 70]
97) [2, 5, 8, 8, 20]
98) [2, 5, 10, 10, 10]
99) [2, 6, 6, 7, 42]
100) [2, 6, 6, 8, 24]
101) [2, 6, 6, 9, 18]
102) [2, 6, 6, 10, 15]
103) [2, 6, 6, 12, 12]
104) [2, 6, 7, 7, 21]
105) [2, 6, 8, 8, 12]
106) [2, 6, 9, 9, 9]
107) [2, 7, 7, 7, 14]
108) [2, 8, 8, 8, 8]
109) [3, 3, 4, 13, 156]
110) [3, 3, 4, 14, 84]
111) [3, 3, 4, 15, 60]
112) [3, 3, 4, 16, 48]
113) [3, 3, 4, 18, 36]
114) [3, 3, 4, 20, 30]
115) [3, 3, 4, 21, 28]
116) [3, 3, 4, 24, 24]
117) [3, 3, 5, 8, 120]
118) [3, 3, 5, 9, 45]
119) [3, 3, 5, 10, 30]
120) [3, 3, 5, 12, 20]
121) [3, 3, 5, 15, 15]
122) [3, 3, 6, 7, 42]
123) [3, 3, 6, 8, 24]
124) [3, 3, 6, 9, 18]
125) [3, 3, 6, 10, 15]
126) [3, 3, 6, 12, 12]
127) [3, 3, 7, 7, 21]
128) [3, 3, 8, 8, 12]
129) [3, 3, 9, 9, 9]
130) [3, 4, 4, 7, 42]
131) [3, 4, 4, 8, 24]
132) [3, 4, 4, 9, 18]
133) [3, 4, 4, 10, 15]
134) [3, 4, 4, 12, 12]
135) [3, 4, 5, 5, 60]
136) [3, 4, 5, 6, 20]
137) [3, 4, 6, 6, 12]
138) [3, 4, 6, 8, 8]
139) [3, 5, 5, 5, 15]
140) [3, 5, 5, 6, 10]
141) [3, 6, 6, 6, 6]
142) [4, 4, 4, 5, 20]
143) [4, 4, 4, 6, 12]
144) [4, 4, 4, 8, 8]
145) [4, 4, 5, 5, 10]
146) [4, 4, 6, 6, 6]
147) [5, 5, 5, 5, 5]

To obtain these 5-tuples, one can use following steps:
 - for $x$: loop from $2$ to $5$;
 - for $y$: loop from $x$ to $\displaystyle\Biggl\lfloor{\frac{4}{1-\frac{1}{x}}}\Biggr\rfloor$;
 - for $z$: loop from $y$ to $\displaystyle\Biggl\lfloor\frac{3}{1-\frac{1}{x}-\frac{1}{y}}\Biggr\rfloor$;
 - for $a$: loop from $z$ to $\displaystyle\Biggl\lfloor\frac{2}{1-\frac{1}{x}-\frac{1}{y}-\frac{1}{z}}\Biggr\rfloor$;
 - check whether appropriate integer $b$ exists.
Answer: Note that $\frac{4!}{4!}=1$. Now write $4!=24$ as $1+2+3+6+12$ (basically the divisors of $24$) Then we have $$1=\frac{4!}{4!}=\frac{1+2+3+6+12}{24}=\frac{1}{24}+\frac{1}{12}+\frac{1}{8}+\frac{1}{4}+\frac{1}{2}$$
Answer: If you allow 2 fractions to be equal, as the question allowed, you can just use powers of $2$ to generate a solution for any number of fractions since:
$1/2 +1/2^2+...+1/2^n + 1/2^n = 1$
for all $n>1,$ containing $n+1$ fractions, so we need $n=4$
$1/2 + 1/4 + 1/8+ 1/16 + 1/16 =1$
This may be an easier solution to discover at school.
In addition with this idea you can easily create a solution with distinct fractions from the case of $1/2+1/3+1/6=1$ (which can easily be found by trial and error) using this idea by dividing by $4$ and using the $n=2$ case.
Thus $1/8+1/12+1/24=1/4$
and $1/2+1/4+1/4=1$ giving
$1/2+1/4+1/8+1/12+1/24=1.$


Solving $3 + \sqrt{3^2 + \sqrt{3^4 + \sqrt{3^8 + \sqrt{3^{16} + ...}}}}$

Question:
How to find the value of $3 + \sqrt{3^2 + \sqrt{3^4 + \sqrt{3^8 + \sqrt{3^{16} + ...}}}}$

I tried to solve it and found a relation that if I assume the given expression to be something say $x$, then following result holds true.
$$\boxed{x = 3 + \sqrt{3x}}\hspace{4cm}\bf ...(1.)$$
Can be proved as,
$$x = 3 + \sqrt{3(3 + \sqrt{3x})}$$
$$x = 3 + \sqrt{3^2 + \sqrt{3^3x}}$$
$$x = 3 + \sqrt{3^2 + \sqrt{3^3(3 + \sqrt{3x})}}$$
$$x = 3 + \sqrt{3^2 + \sqrt{3^4 + \sqrt{3^7x})}}$$
$$x = 3 + \sqrt{3^2 + \sqrt{3^4 + \sqrt{3^7(3 + \sqrt{3x})})}}$$
$$x = 3 + \sqrt{3^2 + \sqrt{3^4 + \sqrt{3^8 + \sqrt{3^{15}x}}}}$$
If I continue this process repeatedly,
$$x= 3 + \sqrt{3^2 + \sqrt{3^4 + \sqrt{3^{8} + \sqrt{3^{16} +\sqrt{...}}}}}$$
But how can I make sure that $(1.)$ is absolutely correct? Also how can I make sure that "If I continue this process repeatedly" I would get the same expression?
Comment: The important question here is how do you define this infinite expression, usually it is a limit of finite expressions. You just need to prove that the limit exists and formulate $x = 3 + \sqrt{3x}$ in the sense of limits.
Answer: Let
$$f(x)=x+\sqrt{x^2+\sqrt{x^4+\sqrt{ x^8+\cdots}}},$$
which is to be understood as $\lim_{n\to\infty}f_n(x)$, where
$$f_n(x)=x+\sqrt{x^2+\sqrt{x^4+\sqrt{ x^8+\cdots\sqrt{\cdots\sqrt{x^{2^n}}}}}},$$
or recursively (and thus finally in a sufficiently formal way),
$$\tag1f_0(x)=x,\qquad f_{n+1}(x)=x+\sqrt{f_n(x^2)}.$$
We want to find the limit (if it exists) $f(3)$.
Note that instead of your equation, $(1)$ rather gives us
$$\tag2 {f(x)=x+\sqrt{f(x^2)}}.$$
Your guess seems to have ignored the way the exponents of $x$ grow under the deeper radicals.
The above looks like we need to first find $f$ evaluated at larger arguments (hence with seemingly "worse" convergence), but we can easily get out of that trap:

 For $x>0$, let $g_n(x)=\frac1xf_n(x)$. Then $(1)$ becomes $$ g_0(x)=1,\qquad g_{n+1}(x)=1+\frac1x\sqrt{f_n(x^2)}=1+\sqrt{\frac1{x^2}f_n(x^2)}=1+\sqrt{g_n(x^2)}.$$

 In particular, we find by induction that all $g_n$ are constant, $g_n(x)=G_n$. What about convergence of this sequence of constants $$\tag3 G_0=1,\qquad G_{n+1}=1+\sqrt{G_n}?$$

 As $x\mapsto 1+\sqrt x$ is an increasing function on $[0,\infty)$ and as $G_1=2>1=G_0$, we see that $\{G_n\}_n$ is inceasing. On the other hand, we readily see by induction that $G_n<3$. Hence $G:=\lim_{n\to\infty}G_n$ exists, and certainlky $1<G\le 3$.

 From $(2)$, we know that $G$ must be a soution of $$ x=1+\sqrt{x}$$ or,

 $$ (x-1)^2=x.$$

 This quadratic has solutions $x_{1,2}=\frac{3\pm\sqrt{5}}2$, and as we know $G>1$, we have $G=\frac{3+\sqrt{5}}2$ and ultimately

$$f(3)= 3g(3)=3G=\frac32(3+\sqrt{5}).$$
Comment: @user983206 Intriguing. Then perhaps my judgement was too quick and your method works fine after all. However, I think that it gets into trouble because it has worse problems with convergence in the first place. In fact that is precisely the doubt about "If I continue this process repeatedly" that made you ask this question in the first place.
Comment: $x  = 3 + \sqrt{3x}$ also gives the same result $x = \dfrac{3}{2}(3 + \sqrt{5})$ ._.
Comment: You maintain the suspense up to the end, Mr  Hitchcock ! Cheers
Answer: I think that OP's guess was okay, here's a different approach.
Let $a_1 = 3$ and let $a_{n+1} = 3 + \sqrt{3a_n}$ for $n\geq 1$. Then the first few elements are
\begin{align*}
a_1 &= 3,\\
a_2 &= 3+ \sqrt{3^2},\\
a_3 &= 3+\sqrt{3^2 + \sqrt{3^4}},\\
a_4 &= 3+ \sqrt{3^2 + \sqrt{3^4 + \sqrt{3^8}}},
\end{align*}
so it is reasonable to define
\begin{align*}
3+ \sqrt{3^2 + \sqrt{3^4 + \sqrt{3^8+\ldots}}} := \lim\limits_{n\to\infty} a_n.
\end{align*}
We first need to make sure that the limit exists. We will use the theorem saying that any monotone and bounded sequence is convergent, it is often useful for recursive sequences such as $a_n$.
Monotonicity: we will prove it by induction. First note that $a_2 \geq a_1$. Now assume that for some $n\geq 1$ we have $a_{n+1}\geq a_n$. Then
\begin{align*}
a_{n+2} - a_{n+1} = 3 + \sqrt{3a_{n+1}} - (3 + \sqrt{3a_{n}}) = \sqrt{3}(\sqrt{a_{n+1}} - \sqrt{a_n}) \geq 0,
\end{align*}
where the last inequality follows from the induction hypothesis and the fact that the square root is increasing. Thus, by induction we get that $a_{n+1}\geq a_n$ for all $n\geq 1$, so the sequence is increasing.
Boundedness: obviously the sequence is bounded from below by 0. To find a reasonable upper bound let us first compute what we think the limit should be (if a sequence is increasing, then its limit is also its upper bound). Note that
\begin{align*}
\lim\limits_{n\to \infty} a_{n} = \lim\limits_{n\to \infty} a_{n+1} = 3 +3\lim\limits_{n\to\infty}\sqrt{a_n},
\end{align*}
so if we let $x = \lim\limits_{n\to \infty} a_{n}$, we get that $x = \frac 32(3 + \sqrt{5}).$
To make the computations easier, we will show that $a_n \leq 27$ by induction ($27\geq x$ and it works nicely if we plug it into $\sqrt{3\cdot a_n}$). It is of course true for $a_1$. If $a_n\leq 27$ , then
\begin{align*}
a_{n+1} = 3 + \sqrt{3a_n} \leq 3 + \sqrt{3\cdot 27} = 3+9 = 12 \leq 27.
\end{align*}
Thus we get that $a_n$ is bounded and increases, so it has a finite limit. By the above computation, the limit is equal to $x$.
Answer: If we have
$$a_{n+1}=x \sqrt{x\,a_n} \qquad \text{with}\qquad a_0=x$$
$$a_n=x^{b_n} \implies  x^{b_{n+1}}=x \sqrt{x^{b_n+1}} \implies b_{n+1}=\frac 12 b_n+\frac 32$$
$$b_n=c_n+3\implies c_{n+1}=\frac 12 c_n$$
Finishing and back to $a_n$
$$a_n=x^{3-2^{1-n}}\quad \to \quad x^3$$


C program array takes more input than it should

Question: I was just playing around and i created a two D array in C of 3 rows and three columns and set a nested for loops to scan the elements.
Now, a three by three matrix has Nine elements but this code is taking 10 inputs(even the for loop is running only 9 times) How is it happening???
#include <stdio.h>

int main(){
int array[3][3];
int i,j;
for(i = 0; i < 3; ++i){
    for(j = 0; j < 3; ++j){
        printf("i = %d j = %d\n",i,j);
        scanf(" %d ",&array[i][j]);
        printf("i = %d j = %d\n",i,j);
    }
}

Comment: `scanf(" %d "` --> `scanf("%d"`
Comment: space after `%d` wait for not white-spaces(space, tab and newline, etc).
Comment: There's probably someone who knows more, but I think the space you have there makes it not take accept the input until you have whitespace before the number. It's not that it's getting 10 inputs, but rather `1` isn't a valid input while `1\n2` is for that string.
Comment: Note that the space _before_ `"%d"` is not the issue - it is simply not needed as `"%d` consumes leading white-space even without the leading `" "`.
Comment: Why do i have to do that?
Comment: Where is it taking the extra input? What do the `printf`s show?
Comment: before entering anything it shows i = 0 j = 0 but after entering an input it does not show anything then after that it works normally.
Comment: i = 0 j = 0
1
2
i = 0 j = 0
i = 0 j = 1
3
i = 0 j = 1
i = 0 j = 2
4
i = 0 j = 2
i = 1 j = 0
5
i = 1 j = 0
i = 1 j = 1
6
i = 1 j = 1
i = 1 j = 2
7
i = 1 j = 2
i = 2 j = 0
8
i = 2 j = 0
i = 2 j = 1
9
i = 2 j = 1
i = 2 j = 2
10
i = 2 j = 2
Comment: Thanks lluvatar and BLUEPIXY you are right the whitespace is causing the problem i'll look it up why it is happening       Thanks again it was a valuable thing to learn
Comment: Robust code also checks the result of input functions like `scanf()`.  `if scanf(" %d ",&array[i][j] != 1) Handle_Error();`
Answer: scanf(" %d " --> scanf("%d"

Probably , the space after %d results in scanf waiting for another input. So, remove the space and it should work fine.
Answer: scanf("%d ",&array[i][j]) ----> scanf("%d",&array[i][j])

this might help resolving it


How to use ViewModel

Question: Ok, after some research I was unable to understand the "viewmodel thing".
I didn't find any article that explains me what are the steps to work with ViewModels compared to simply passing the Entity as a Model to the View.
When using the pure Entity it is pretty straight-forward:
If creating a new entry, just show the view. If is post, validate, do Add(x) and voilá! When editting, populate an object and send it to the View. When posting, validate, change the state and save. No secret here.
But I am unable to create and edit ViewModels. Can someone help me on this?
To be short, I have this POCOs :
public class Vessel
{
    public int Id { get; set; }

    [Required]
    public string Name { get; set; }

    public int ShipownerId { get; set; }
    public virtual Shipowner Shipowner { get; set; }
}

public class Shipowner
{
    public int Id { get; set; }

    public string Name { get; set; }

    public virtual ICollection<Vessel> Vessels { get; set; }
}

And this View:
@model INTREPWEB.Models.VesselCreateViewModel
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
    <fieldset>
        <legend>Vessel</legend>

            @Html.LabelFor(model => model.Vessel.Name)

            @Html.EditorFor(model => model.Vessel.Name)
            @Html.ValidationMessageFor(model => model.Vessel.Name)

            @Html.DropDownListFor(model => model.Vessel.ShipownerId, Model.Shipowners, String.Empty)
            @Html.ValidationMessageFor(model => model.Vessel.Name)

            <input type="submit" value="Create" />

    </fieldset>
}

I've created this ViewModel:
public class VesselCreateViewModel
{
    public Vessel Vessel { get; set; }

    public SelectList Shipowners { get; set; }

    public VesselCreateViewModel()
    {
        using (INTREPDB db = new INTREPDB())
        {
            var list = db.Shipowners.ToList()
                .Select(x => new SelectListItem
                {
                    Text = x.Name,
                    Value = x.Id.ToString()
                });
            Shipowners = new SelectList(list, "Value", "Text");
        }
    }

    public VesselCreateViewModel(int id)
    {
        using (INTREPDB db = new INTREPDB())
        {

            Vessel = db.Vessels.Find(id);

            var list = db.Shipowners.ToList()
                .Select(x => new SelectListItem
                {
                    Text = x.Name,
                    Value = x.Id.ToString()
                });
            Shipowners = new SelectList(list, "Value", "Text");
        }
    }
}

As you can see, it auto populates a collection for the View to show a DropDown menu. I was able to create new Vessels by doing the same way I do with only Models. But can't figure out what I'm doing wrong when editting this thing.
This is the wrong POST Edit method:
    [HttpPost]
    public ActionResult Edit(VesselCreateViewModel vm)
    {
        if (ModelState.IsValid)
        {
            db.Entry(vm.Vessel).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(vm);
    }

What should I do to save this little monster?
Answer: as you can see you are only using the Model-part of your ViewModel in this code. This is IMHO typical so you pass the ViewModel to the View but only bind the Model in your Edit-Postback.
Then you can easily recreate the viewmodel based on the changed model if you have to.
BTW: IMO ViewModel is a bad name in this case. If I hear ViewModel I think of MVVM but this case the viewmodel is only some kind of static-typed View-Helper and should have no behavior.
Answer: Viewmodel little excerpt from Steve senderson book
MVC also uses the term view model, but refers to a simple model class that is used only to pass data from
a controller to a view. We differentiate between view models and domain models, which are sophisticated
representations of data, operations, and rules.

If you want to save view model you may use automapper
Answer: I'm guessing you should wrap around the db calls in a Using block just like in the VesselCreateViewModel constructors.
You could eventually use commands in your ViewModel to save, edit or delete your data and bind this command to Buttons or other Controls on the view.
I would recommend you two great books about MVVM, you find good examples, easy to understand them too.

Building Enterprise Applications with Windows® Presentation Foundation
  and the Model View ViewModel Pattern
Pro WPF and Silverlight MVVM - Effective Application Development with
  Model-View-ViewModel
Comment: I think that viewmodel has different context in mvc
Comment: Yes i'm sure you are right i don't know much about mvc and i only just started MVVM. And i see only now that it is asp.net-mvc question. :) But then shouldn't he use a controller?
Comment: his actionresult method is in controller
Comment: See told you i don't know much about MVC pattern. :(
Comment: I think that is not a big problem , would be hard to know everything and a developer would have to learn 20-30 years until he know something from everything but he wouldn't know anything good enough to find a job. :D

How to use ViewModel


Entity reference widget

Question: I know that in Drupal 8 the taxonomy term reference is deprecated and it's implemented by an entity reference in Drupal 8 Core.
Is there any widget to select items by checkbox list instead of the default autocomplete entity reference widget?
Answer: Yes!!

Go to Manage form display of the content type
Go to the entity reference field and there you can find a list of options including checkbox .
Comment: Still I think I am in Drupal 7 :D.tnx
Comment: If you tag the question with [tag:8] users will think it is about Drupal 8.
Comment: @kiamlaluno sorry, it was miss typing.
Answer: Drupal 8
Go to the Manage form display tab.

Drupal 7
Go to Manage fields tab, and click on the blue widget link.

It takes you a new page, where you can change the widget to Check boxes/radio buttons.

Entity reference widget


Uniform Bound, Dominance, and Convergence Theorems

Question: Consider a sequence of measurable functions $\{f_n\}\rightarrow f,$ almost everywhere $x$ on a finite measurable set $E$.
My questions:

When we say the sequence is uniformly bounded, does this mean:

$$\exists M\in\mathbb{N},f_n(x)\leq M\space\forall n,x$$

To check (1), we fix $x_0$, see if $f_n$ is bounded by $M$. Do this for all $x\in E$. Is this correct?
When we say $f$ dominates the sequence, does this mean:

$$\forall n,x\space f_n(x)\leq f(x)$$

Also to check (3), we fix $x_0$, see if the entire sequence is bounded by the value $f(x_0).$ Do this for all $x\in E$. Is this procedure correct?
I am studying these concepts in the context of Fatou's Lemma, Monotone and Dominated Convergence Theorem. Why is this boundedness important in converence theorems? The way I understand is through the Dirac delta function. This function behaves in the limit such a way when the function takes a materially large value, the domain on which such this happens is a negligible set. So does the boundedness or dominance take care of this issue? Is this the correct intuition?
Answer:
There is no particular reason to require $M \in \Bbb N$. Any $M \in \Bbb R$ will do. Of course, that make no change in the functions meeting the condition, since if you have a negative or non-integer bound, any higher positive integer bound will also work. Also, the condition you give is for a uniform upper bound. In general, uniformly bounded means bounded above and below: $f_n$ is uniformly bounded if $$\exists M \in \Bbb R, \forall x\in E, \forall n \in\Bbb N, |f_n(x)| \le M$$
In measure theory, one generally isn't worried about the behavior of the functions on sets of measure $0$, so there is also the notion of "uniformly bounded almost everywhere":
$$\exists E_0 \subset E, \mu(E \setminus E_0) = 0 \text{ and }\exists M \in \Bbb R, \forall x\in E_0, \forall n \in\Bbb N, |f_n(x)| \le M$$
If you have an uncountably infinite amount of time and paper, sure, you can do it that way. More practical approaches use the defining properties of the sequence $f_n$ to show that the condition holds on larger subsets of $E$ than single points.
When $f_n$ consists of positive functions, that is true, but generally it means that $\forall x, |f_n(x)| \le f(x)$. Note that the dominating function need not be the limit of the sequence $f$. If $|f_n| \le g$ for any integrable function $g$, then the Dominated Convergence Theorem applies.
See 2.
The "Dirac delta function" is not a function as described in these theorems. The theorems do not apply to the various sequences that "converge" to it. In fact, those sequences converge to the $0$ function except for a single point, where they converge to $+\infty$. The integral of that function, of any other function multiplied by it, will always be $0$. The sequences are not bounded, nor dominated by any integrable function.

To properly discuss the Dirac delta function in mathematics, there are two approaches:

Consider the "function" to be nothing more than a notational device, so $\int f(x)\delta(x - a)\, dx$ is just a really funky way of writing $f(a)$.
Generalize the concept of "function" to be more than just maps from a set into $\Bbb R$. When you do this, you must also generalize the concept of integration to cover these new functions (as well as every other operation one wishes to apply to these new "functions"). And you must prove new theorems to deal with them. You cannot simply apply old results such as the DCT, MCT, or Fatou's lemma to them.

Which a particular author uses depends on how deeply they want to get into the subject.


Proper Windows Forms multi screen program

Question: I'm trying to build a rather simple Windows Application for the employees that process our payroll (currently it's a vbscript/terminal combination).  The logic is mostly worked out, but I'm trying to find out what the best way build a Windows Forms application that has multiple screens (login/etc).  I've been using the TabControl container for this, but just wasn't sure if this was correct...or 'common'.
If this is what is normally done are the contents of the tabs generally made up of User Control object or are they just filled with different layouts on the tab?
I doubt I need much in the way of help on the coding side, but more the "how a gui" is normally laid out in the visual designer.
EDIT: Just to provide a basis of the screens that I'm needing to build.  I'm currently planning on having a Login Screen and the three screens that guide the user through processing two different types of payroll and then certain accounts receivables work.  Primarily I will have two user types.  The ones that process payroll and the ones that do accounts receivable work.  I'm wanting to make this easily expandable so that as I build in more functionality it's not a major pain to add screens and limit who can see them.
Comment: possible duplicate of [Resources for windows form design and increased usability](http://stackoverflow.com/questions/189286/resources-for-windows-form-design-and-increased-usability). Besides that, this question is too broad to even begin answering it.
Comment: @GertArnold it's broad due to no current base to have a specific code related question.  My question is how are the UI's generally built.  Not a question of how the UI should look/function.  I can finagle my way through doing that now.  I'm just trying to make sure I'm doing it properly (if there is a current convention to current control usage).  If there is some more information that I can provide to make the question to your liking please let me know.  I have no problem doing the work needed to help get a question answered. I guess I just don't know what to provide at the moment.
Comment: It depends, simply layout the controls on the tab if that makes sense. If you find you are reusing controls on tab pages then user User Controls.
Comment: I think, for your needs, you should use MDI forms instead of tabcontrols. But maybe I'm misunderstanding your needs.
Comment: @trippino I will actually update the question with an answer.  I ended up integrating with our AD Server to add tabs based on what group a user is in.  Each tab simply has a `UserControl` on it that I've made that contains the logic and layout.  While this may not be 100% correct it does remove any of the responsibilities from the primary "form" other then to add the different `UserControls` that are displayed through the use of a `TabControl`
Answer: What I ended up doing is removing the "Login Screen" as hinted to in the question.  Instead of a Login Screen and the corresponding logic being required I ended up doing integration with our Active Directory Server.
Once this integration was done I simply design the Screens as UserControl elements and then add each one to a tab based on if the user is in a specific group or not.
Doing this solved my main concern of having a heavy main form containing logic.  Now the only logic in the main form is whether or not to add a tab based on Active Directory groups.


Access to container view controller

Question: I have simple ViewController which have one container view with TableViewController.
At ViewController I loading data from external API and one part of that data, I need to pass into TableViewController in container.
Is there any way how to do that?
Thank you!
Answer: The controllers contained in a container view can be accessed by self.childViewControllers from the parent controller. If you only have one, then it will be at self.childViewControllers[0].

Note: regarding RD's excellent technique explained in the comment below; here's a typical example, tested and working: this simply goes in the VC of the overall scene. Just click on the segue itself (ie, the small symbol in the middle of the connecting arrow) to set the text identifier.
<code>-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
    if ([segue.identifier isEqualToString:@"containerLogin"])
        self.vcLogin = (LoginVC *)segue.destinationViewController;

    if ([segue.identifier isEqualToString:@"containerStartNew"])
        self.vcStartNew = (StartNewVC *)segue.destinationViewController;

    }
</code>
Here's just how to do it in Swift: (you have to be careful with the unwrappers)
<code>override func prepareForSegue(segue:(UIStoryboardSegue!), sender:AnyObject!)
    {
    if (segue.identifier == "feedContainer")
        {
        feed = segue!.destinationViewController as! Feed
        feed.someFunction()
        }
    }
</code>
Comment: @JoeBlow, You can check the class of the controller you get back to determine which is which. You can also assign the controllers in prepareForSegue instead of doing it like I said in my answer (the embedded controller will be the segue.destinationViewController). That method is called for embedded controllers, so you can implement that, and check the segue's identifier to know which controller is which. That's probably the better way to do it, particularly if you have more than one child.
Comment: RD, what the hell to do if there's more than one? How do you know which is which??  Any ideas??
Comment: I tested it and that works perfectly.  Brilliant.  Amazing that is not more commonly known.
Comment: I asked a question about the array order on the "other" method .. http://stackoverflow.com/questions/23597123/in-fact-is-destinationviewcontroller-in-storyboard-order
Comment: @rdelmar I know this is an old question, but I'll try. How can I do the opposite? Meaning, how can I access the `viewController` from the `container view`?
Comment: @Horray If you mean from the view controller embedded in the container view,  you can use self.parentViewController.
Comment: @Horray Where did log it? I think it's still nil in viewDidLoad.
Comment: I assigned it like this: self.theMainViewController = (theMainViewController *)self.parentViewController; then in another method (already called) I nsloged it, and it gave me a nil
Comment: @Horray In what method did you do the assignment? Did you do that in viewDidLoad?
Comment: I assigned it in viewDidLoad
Comment: @Horray As I said, that's too early. Try it in viewDidAppear.
Comment: Oh!! My bad! I thought you meant I shouldn't call it in `viewDidLoad`. Sorry. Thanks!!
Comment: This answer is amazing. Much cleaner than iterating the parent's child view controllers.

Access to container view controller


Store image to use in all resolutions

Question: I want to use PNG image with fixed pixels on my application. I don't want to add the same image into all folders (ldpi, mdpi, hdpi, xhdpi, xxhdpi and xxxhdpi). Image will get blurred if I just add it into one folder. How do I do it?
Answer: You can use drawable-nodpi directory, if I understood your intent correctly. Images in there will be displayed as is on the device, no scaling will be used. That means that it might be really small on some device and/or really large on other devices.
More info in Table 2 here
Answer: You can use drawable folder to put your PNG. To prevent from image blurring, use high resolution images(xxxhdpi), and create different layout for each dpi and set size on each image you are using. Hope this trick can help.
Answer: Add your 640 dpi image to the drawable-xxxhdpi folder.
It will be scaled DOWN (that is, no blur due to stretch up will occur).
It's always better to scale DOWN rather than UP.

Store image to use in all resolutions


Conditioning on independent random variables

Question: I am in a situation where I have to compute:
$$E(u(x_1)|\bar{X},S^2)$$
where $X_1$ is a normally distributed random variable and $u(.)$ some function. I know that by the student's theorem the sample mean and the sample variance are independent and moreover that $\frac{(n-1)S^2}{\sigma^2}\sim \chi^2 (n-1)$.
Can I simplify the expectation with the information I possess? Is perhaps the bivariate normal distribution of use here?
Thanks.
EDIT: Yes, an iid sample on $X$ is assumed here, hence the subscript $1$ on $u(x_1)$. If the expectation cannot be simplified, what is the conditional distribution of $X_1$ given $\bar{X}$ and $S^2$?
Comment: @Glen_b You can consult Hogg and Craig, 7th edition, page 193.
Comment: How is $X_1$ related to $\overline{X}$ and $S^2$?  Your comment about wanting to understand $E(u(\overline{X})|\overline{X},S^2)$ is confusing.  That is just $u(\overline{X})$ unless you meant two different samples of the mean.
Comment: I assume there is an i.i.d sample somewhere in the back. Try a 2nd order Taylor Expansion around the sample mean.
Comment: Also, treat $X_1$ and $\bar X$ as two correlated normal rv's, calculate their correlation, etc
Comment: @AlecosPapadopoulos  $u(x_1)=u(\bar{x})+u\prime (\bar{x}) (x_1-\bar{x})+u\prime \prime (c)(x_1-\bar{x})^2 /2$. But what will I get out of that? Are you perhaps suggesting replacing $u(x_1)$ with its taylor expansion? If so, what would be the benefit? Sorry I am completely stuck here.
Comment: But what you want is the _expected value_ of the Taylor expansion, _conditional_ on...
Comment: @AlecosPapadopoulos It's still a conditional expectation which I do not know how to handle. For example, how would I take the expectation $E(u(\bar{x})|\bar{X},S^2)$?
Comment: @Glen_b Hello Glen. This is a corollary of the t-distribution and simply says that the sample mean and the sample variance are independent. Student refers to William Gosset who published it under that pseudonym.
Comment: He did? Where and when?
Comment: @Glen_b In the early 20th century http://en.wikipedia.org/wiki/William_Gossett. Recall that the t-distribution is defined by $t=\frac{W}{\sqrt{V/r}}$ with $W\sim N(0,1)$ and $V \sim \chi^2 (r)$ , $W$ and $V$ independent! His contribution is an example of how beer moves the world.
Comment: I've managed to find reference to it in some documents online (e.g. [here](http://www.math.nyu.edu/faculty/goodman/teaching/RPME/notes/Section2.pdf)) but at that link what they call 'Student's theorem' is this: "Student noticed that the probability density of $t$ depends on $n$ but not on the parameters $\mu$ and $\sigma$."
Comment: @Glen_b There are several aspects to the student's theorem, as presented in Hogg and Craig. One is that the sample mean and the sample variance are independent. Another is that the sample mean of a normal population is normally distributed and then, because of these implications, the quotient $T=\frac{\bar{X}-\mu}{S/\sqrt{n}}$ has a t-distribution with $n-1$ df. So although, it is not the exact same phrasing the other authors use, I do not see any contradiction.
Comment: @MathEE I do not understand your point. There is only one sample.
Comment: I mean the probability of $A=c$ given $A=a$ and $B=b$ is either zero or one depending on whether or not $a=c$.
Comment: @MathEE If you have a solution, please post it then.
Answer: Given the information in the question, we have a sample of $n$ i.i.d normals (which also means that their joint distribution is also normal), each following $N(\mu, \sigma^2)$. Therefore $\bar X \sim N(\mu, \sigma^2/n)$.
One can easily calculate that $\operatorname{Cov}(X_1, \bar X) = \sigma^2/n$. So their correlation coefficient is $\rho = 1/\sqrt{n}$. Then, since their joint distribution is bi-variate normal, the conditional expected value of $X_1\mid \bar X$ is
$$E(X_1\mid \bar X) = \mu + \rho \frac{\sigma}{\sigma/\sqrt n}(\bar X - \mu)= \bar X$$.
...as should be expected
Now the reason I mentioned in the comments a 2nd-order Taylor expansion, is the completely arbitrary nature of $u(\cdot)$, which does not really permit us to do anything much. But with the Taylor expansion around the sample mean, we have (write $M$ for $\{\bar X, S^2\}$)
$$E(u(X_1)\mid M)\approx E\Big(u(\bar{X})+u^{\prime} (\bar{X}) (X_1-\bar{X})+\frac 12u^{\prime \prime} (\bar X)(X_1-\bar{X})^2\mid M\Big)$$
Since when we condition a function of a random variable on the random variable, we have $E(u(Y)\mid Y) = u(Y)$, $E(Y \mid Y) = Y$, $E(ZY\mid Y) = YE(Z\mid Y)$ in our case this implies
$$E(u(X_1)\mid M) \approx u(\bar{X})+u^{\prime} (\bar{X}) (E(X_1\mid M)-E(\bar{X}\mid M))+\frac 12u^{\prime \prime}(\bar X)E\Big[(X_1-\bar{X})^2\mid M\Big]$$
and using the previous results, the second term is zero, and so we obtain
$$E(u(X_1)\mid M) \approx u(\bar{X})+\frac 12u^{\prime \prime}(\bar X)E\Big[(X_1-\bar{X})^2\mid M\Big]$$
But
$$E\Big[(X_1-\bar{X})^2\mid M\Big] = \text{Var}(X_1\mid M) = S^2$$ so
$$E(u(X_1)\mid M) \approx u(\bar{X})+\frac 12u^{\prime \prime}(\bar X)S^2 \qquad [1]$$
Of course, one should deal also with the Remainder (the expected value of it). The "Peano form" of the Remainder is the most convenient here, meaning that we need to consider
$$E[R_2(X_1;\bar X) \mid M]=E\left[h_2(X_1)\cdot \left(X_1-\bar X\right)^2 \mid M\right] \qquad [2]$$
where $h_2()$ is some function with the property that $h_2(X_1) \rightarrow 0$ as $X_1 \rightarrow \bar X$.
Then, take the full Taylor expansion of $h_2()$ around $\bar X$ using again the peano form to write this Remainder too:
$$h_2(X_1) = h_2(\bar X) + h_2'(\bar X)(X_1-\bar X) + g_1(X_1)\cdot (X_1-\bar X)$$
$h_2(\bar X) = 0$. Insert the rest into eq. $[2]$ to obtain:
$$E[R_2(X_1;\bar X) \mid M]=E\left[\Big(h_2'(\bar X)+ g_1(X_1)\Big)\cdot\left(X_1-\bar X\right)^3 \mid M\right]$$
$$=h_2'(\bar X)E\left[\left(X_1-\bar X\right)^3 \mid M\right] + E\left[g_1(X_1)\cdot\left(X_1-\bar X\right)^3 \mid M\right]$$
The conditional on $M$ distribution of $X_1$ will also be normal, and has mean $\bar X$ as we have seen. So the third central moment, being odd, will be zero. Then the 1st term in the above expression is zero and we are left with
$$E[R_2(X_1;\bar X) \mid M]= E\left[g_1(X_1)\cdot\left(X_1-\bar X\right)^3 \mid M\right] \qquad [3]$$
which I would say, will be a rather small amount, since $g_1$ belongs to the Remainder of the Remainder.
Note that if we can say that $u'''(X_1)$ is bounded above and below in a neighborhood of $\bar X$ and belongs to the interval, say $[a, A]$ then the expected value of the Remainder is sandwiched to zero, because we have
$$a\frac {(X_1-\bar X)^3}{3!} \le R_2(X_1;\bar X) \le A\frac {(X_1-\bar X)^3}{3!}$$
$$\Rightarrow E\left (a\frac {(X_1-\bar X)^3}{3!} \mid M\right) \le E[R_2(X_1;\bar X) \mid M] \le E\left (a\frac {(X_1-\bar X)^3}{3!} \mid M\right)$$
$$\Rightarrow 0 \le E[R_2(X_1;\bar X) \mid M] \le 0 \Rightarrow E[R_2(X_1;\bar X) \mid M]=0$$
If we cannot say anything about $u()$ then we are left with the approximation $[1]$ and the approximation error $[3]$.
Comment: Your answer, covers my question and provides isnightful hints as well. I will keep the question open until bounty expires in case anyone else wants to contribute.


Apache 2.2.21 upgrade from 2.2.8, what is the best way to do this on a production system?

Question: I have little experience in being a web application administrator however I am a software developer.  I inherited support for a legacy application that jkMount's a JBoss application server farm and the front end are two Apache 2.2.8 with OpenSSL servers preconfigured and running on Windows Server 2003.
The recent publicized security flaw triggered a response from my manager that I need to upgrade the Apache servers to the most secure version, 2.2.21.
I believe I know what I need to do in theory but I have never personally installed or upgraded Apache before so I am a little nervous.  My plan was to:

Backup the existing installation location completely
Stop the Apache Servers
Install to the same location via the MSI installer I downloaded
Replace the installed contents of the /conf/ directory with the backed up contents of the pre-configured /conf/ directory (including SSL certs).
Restart the servers and pray to God/Allah/Spaghetti Monster.

Do you see anything that I may be missing?  I imagine the only differences between 2.2.8 and 2.2.21 are just security updates and that configuration files should be interchangeable?
Comment: FYI, I updgraded Apache on my local test server following roughly these steps and it was a lot easier than I thought.  The uninstaller for the old version left all of my configurations and third party modules untouched.  I just installed the new version and everything is working fine, including SSL on test.
Answer: Yup, you have it down fine, I was going to suggest testing it on another server first if you could, then I read your comment.
Comment: Thanks!  I feel more confident now.  I was hoping to get a quick and easy answer.  I will do this tonight, if all goes well I will award you the points.