Deriving formula for time dilation Last week in class we derived the formula for time dilation using light clocks and got $$t=\gamma t_0\quad \gamma=\left(1+\left(\frac vc\right)^2\right)^{-1/2}$$
So far so good. However, after class I was thinking of an alternate proof, but for some reason I got another result and I can't tell why. 
Basically you have a train with an observer A inside who emits a beam of light to the left which is reflected off a wall at distance $d$ from A. The time it takes for the beam to get back to the observer is $t_0=\frac{2d}{c}$ which is the proper time. 
Now consider an observer B outside the train. The train is moving at a velocity $v$ to the right relative to B. Thus the time it take for the light to hit the wall is $\frac{d}{c+v}$ and the time it take for it to return to A is $\frac{d}{c-v}$. Thus the dilated time is 
$$t=\frac{d}{c+v}+\frac{d}{c-v}=\frac{2dc}{c^2-v^2}=\frac{2d/c}{1-\left(\frac vc\right)^2}=\frac{t_0}{1-\left(\frac vc\right)^2}=\gamma^2t_0$$
Where did I go wrong?
 A: Light always travels with $c$. That is why Michelson-Morley's experiment is so famous and groundbreaking.
If you send a beam of light from point A to point B, and it gets reflected and comes back to B than it doesn't matter, if A is moving relative to B with velocity v or not. You still get the same total velocity for the light: $c$.
Another thing, in SR you cannot change perspectives in the middle of experiments and treat measurements made by different observers as equal. Not only $t$ is affected by the difference in velocity. Your $d$ is also perceived differently from different frames of reference.
Incidentally, if I understand your set-up correctly, it looks like the light is traveling perpendicular to the direction of the movement of your train, and yet you simply add the values of $c$ and $v$ (regardless of the constancy of $c$).
A: 
Basically you have a train with an observer A inside who emits a beam of light to the left which is reflected off a wall 

... let's call that wall W, for reference below ...

at distance $d$ from A.

... let's call that distance $d := AW$
(anticipating that distances between certain other participants will have to be considered, and distinctly named, below).

The time it takes for the beam to get back to the observer is $t_0 = \frac{2 \, d}{c}$ which is the proper time.

... a.k.a. "ping duration" $\mathop{\Delta}\limits_{\text{ping}} \tau_A[ W ] = \frac{2 \, AW}{c}$. 
So far, so good.

Now consider an observer B outside the train. The train is moving at a velocity $v$ to the right relative to B. 

(Also:
B as well as everyone at rest wrt. B are moving at velocity $v$ relative to A and W; from A towards W.)

Thus the time it takes for the light to hit the wall is $\frac{d}{c + v}$

That's eventually incorrect.
Let's try to be more precise:     


*

*B and A were passing each other (which is supposed to be visible by everyone else; a.k.a. "emitting a light signal"),

*there exists some participant (let's call it P) who was and remained at rest wrt. B, who therefore of course was passed by W "sometime", and specificly: whose indication of being passed by W was simultaneous to B's indication of being passed by A, and  

*there exists some participant (let's call it Q) who was and remained at rest wrt. B (as well as P) and who was passed W just as Q and W observed (together, at their meeting) that B and A had passed each other.
Therefore $\frac{PQ}{BQ} = \frac{v}{c}$, and $\frac{BP}{BQ} = \frac{PQ}{BQ} + 1 = 1 + \frac{v}{c} = \frac{c + v}{c}$.
Of interest is then B's duration from the indication of being passed by A until the indication simultaneous to Q's indication of being passed by W (and observing that B and A had passed each other).
This is of course half of the ping duration $\mathop{\Delta}\limits_{\text{ping}} \tau_B[ Q ]$,
i.e. half of $\frac{2 \, BQ}{c}$; thus $\frac{BQ}{c}$ which is in turn equal to $\frac{BP}{c + v}$.

and the time it take for it to return to A is $\frac{d}{c - v}$. 

Arguing similarly to the above, this corrsponding duration of B is more precisely equal to $\frac{BP}{c - v}$.
Now, in order to compare A's ping duration $\mathop{\Delta}\limits_{\text{ping}} \tau_A[ W ] = \frac{2 \, AW}{c}$
with the sum of the corresponding durations of B, i.e. with $\frac{BP}{c + v} + \frac{BP}{c - v} = \frac{2 \, c \, BP}{c^2 - v^2} = \frac{2 \, BP}{c} \frac{1}{1 - \beta^2}$
we still need to establish value of the distance ratio $\frac{AW}{BP}$.
That means we're now left with having to derive "length contraction"!
But that's not difficult, given all of the explicit setup and named participants that were introduced above already: 
We should consider one more participant, J, who was and remained at rest wrt. A and W, and whose indication of being passed by B was simultaneous to W's indication of being passed by Q (and observing that B and A had passed each other).
Therefore $\frac{AJ}{AW} = \frac{v}{c}$, and $\frac{JW}{AW} = 1 - \frac{AJ}{AW} = 1 - \frac{v}{c} = \frac{c - v}{c}$.
Considering the two explicit requirements of simultaneity above, the corresponding ratios of distances should be equal:
$\frac{BP}{AW} = \frac{JW}{BQ}$.
Inserting expressions from above:
$\frac{BP}{AW} = \frac{JW}{AW} \frac{AW}{BP} \frac{BP}{BQ} = \frac{c - v}{c} \frac{AW}{BP} \frac{c + v}{c} = \frac{AW}{BP} \frac{c^2 - v^2}{c^2} = \frac{AW}{BP} (1 - \beta^2) = \sqrt{ 1 - \beta^2 }$.
Consequently:
$\mathop{\Delta}\limits_{\text{ping}} \tau_A[ W ] = \frac{2 \, AW}{c} = \frac{2 \, BP}{c} / \sqrt{ 1 - \beta^2 }$.
Calling B's corresponding duration $\frac{2 \, BP}{c} \frac{1}{1 - \beta^2} = \mathop{\Delta \, \tau_B}\limits_{\text{ping trip } A_W}$ therefore
$\mathop{\Delta}\limits_{\text{ping}} \tau_A[ W ] = \mathop{\Delta \, \tau_B}\limits_{\text{ping trip } A_W} \sqrt{ 1 - \beta^2 }$, as may have been expected.

Last week in class we derived the formula for time dilation using light clocks

Well, shouldn't that have been pretty much the derivation I just sketched?.
Edit
For completeness, and to emphasize a particular point in the following, here's also the derivitation involving light clocks "perpendicular to the direction of motion" (which seems to have been mentioned in passing in the OP's question):
Expanding on the setup described above, with the principal protagonists A and B and suitable auxiliary participants (W and J at rest wrt. A; P and Q at rest wrt. B), and all of them "sitting or moving in one line", we now also consider


*

*participant F (at rest wrt. A, J, W) with distance ratios $\left( \frac{AF}{FJ} \right)^2 + \left( \frac{AJ}{FJ} \right)^2 = 1$,
and (without loss of generality, but just to re-use setup relations from above) with $\frac{AW}{FJ} = 1$,
therefore $\frac{AF}{FJ} = \sqrt{ 1 - \left( \frac{AJ}{FJ} \right)^2 } = \sqrt{ 1 - \left( \frac{AJ}{AW} \right)^2 } = \sqrt{ 1 - \beta^2 }$; and

*participant G (at rest wrt. B, P, Q) with distance ratios $\left( \frac{BG}{GP} \right)^2 + \left( \frac{BP}{GP} \right)^2 = 1$,
and such that G and F met each other in passing.
Importantly, the entire region containing the setup is of course supposed to be flat. Therefore it can be demonstrated (what otherwise may be glanced over for seeming "too obvious to even point out"), that 


*

*F's indication of having been passed by G was simultaneous to A's indication of having been passed by B; and vice versa that

*G's indication of having been passed by F was simultaneous to B's indication of having been passed by A.
Then, by the same argument that was used above for comparison of distance ratios between pairs of participants who were not at rest to each other, we set:
$\frac{AF}{BG} = \frac{BG}{AF}$, and therefore $\frac{AF}{BG} = 1.$
With
$\mathop{\Delta , \tau_A}\limits_{\text{ping trip } B_G} = \frac{2 \, FJ}{c} = \frac{2 \, AF}{c} / \sqrt{ 1 - \beta^2 }$ and 
$\mathop{\Delta}\limits_{\text{ping}} \tau_B[ G ] = \frac{2 \, BG}{c}$ follows
$\mathop{\Delta}\limits_{\text{ping}} \tau_B[ G ] = \mathop{\Delta \, \tau_A}\limits_{\text{ping trip } B_G} \sqrt{ 1 - \beta^2 }$.
Finally, as can be shown explicitly, it holds symmetrically that
$\mathop{\Delta}\limits_{\text{ping}} \tau_A[ F ] = \mathop{\Delta \, \tau_B}\limits_{\text{ping trip } A_F} \sqrt{ 1 - \beta^2 }$.
