## Task 1, CJam, 7 bytes

    q~,:+_*

I just wanted to get the (presumably) optimal CJam solution for this in. It makes use of the fact that the sum of the first *n* cubes is the square of the *nth* triangular number, which is itself the sum of the first *n* integers.

[Test it here.][1]

---

## Task 4, Fission, <s>173</s> <s>88</s> <s>78</s> <s>69</s> 68 bytes

[GitHub repository for Fission.](https://github.com/C0deH4cker/Fission/)

     /@\O/S@+>\
    ^{ }[<X/ @/;
    ,\?/@\J^X\
    'M~\$ $
    UK/W%@]  /
    D
    ?\{\/
    0'A Y

My second reasonably complicated Fission program. :)

The input format is a bit weird. To support negative inputs, the first character is expected to be either `+` or `-` to indicate the sign. The second character's byte value is then the magnitude of the input (since Fission can't natively read decimal integers). So if you want `111` you'd pass it `+o` on STDIN. And if you want `-56` you pass it `-8`. In place of `+` and `-` you can use any character with a lower or higher character code, respectively. This can be helpful to pass in something like `-n` (which your `echo` might treat as an argument) as, e.g., `0n`.

Let's look at how we can find the negabinary representation of a positive number. We want to compute the number from least to most significant bit (we'll push those bits on a stack and print them all at the end to get them in the right order). The first digit is then just the parity of the number, and we integer-divide the number by 2 to continue processing. The next digit is now negative (with value -2) - but it should be noted that this bit will be set whenever the 2-bit would be set in a normal binary number. The only difference is that we need to counter the -2 with positive higher valued digits. So what we do is this:

- We determine the parity again - this is the next negabit - and divide by 2 as before.
- If that digit was a `1`, we increment the remaining number by 1 in order to counter-act the negative bit (the difference between a negabit and a bit is *once* the value of the next more-significant bit).

A great simplification of the code results from noticing that conditionally adding one here is equivalent to rounding the number *up* when integer dividing (if the discarded bit was 1, we increment the integer-divided result by 1).

Then, the next bit is just a positive value again so we can determine it normally. That means we want a loop that computes two bits at a time, alternating between rounding up and rounding down for the remaining number, but we want to enter the loop in the middle so we start with rounding down.

How can we handle negative integers? The problem is that Fission can't really do arbitrary arithmetic on negative integers, because masses are always non-negative. So one would have to do something really complicated like working with the magnitude and keeping track of the sign somewhere else. However, the negabinary representation of a negative number can be computed based on a related positive number:

If *n* is negative, compute the negabinary representation of *n/2* (rounded *up*) and append the parity of *n*.

This is exactly the first step of our two-bit loop. So all we need to do is start the loop at a different point if the sign is negative.

Most of the savings from the 173 original bytes came from these insights which allowed me to compress three parity checks and a two-section loop into a single loop with a single parity check.

This post will get too long if I explain all the code in detail, but I'll point out a few sections to give the rough layout of the control flow, and you can puzzle out the details with the Fission reference.

     /@\
    ^{ }[
    ,\?/
    '
    U
    D
    ?

Starting from the `D`, this reads a sign bit into the energy and the magnitude into the mass of an atom that ends up in the `[` (going right). This sign bit will alternate after each pass through the parity check and will determine whether we retain the rounded down or rounded up half of the loop input.

         /S@+>\
        [<X/ @/
     \  @\J^X\
     M  $ $
     K  %@]  /

This is the loop which computes the individual bits and feeds the correct half into the next iteration. The `S` and the `J` are used to create a copy of the right half based on the current sign bit, the `X`s do the copying. The `>` in the top right corner computes the actual bit which is then sent to the stack `K` to be retrieved later. I think the layout of the top right corner is pretty nifty and definitely worth studying in detail if you're interested in Fission.

The `%` is a switch which feeds the number back into the loop as long as it's greater than 0.

        O


     M~\
     K/W%
     
     \{\/
    0'A Y

Once the number reaches 0 it's reflected down instead. This starts another loop which retrieves the bits from the stack, adds them to the character code of `0` and prints them with `O`. The program terminates once the stack is empty, because the control atom will end up being pushed on the stack (and afterwards there are no more moving atoms left).

---

## Task 5, Prelude, 219 bytes

[Esolangs page for Prelude.](http://esolangs.org/wiki/Prelude)

    66+(1-)^9-!^2+!^6+!v5-6-!v2v#+!v4+!v3-! ^6-!^3+!v v7+!6-!^  !v1- !v !  v!
    4   9+ !^7+!^1+!^3-!^6+!^8+!^6+!v ^# !^3+  !v v!6+!v3-! ^2-!v   !v v#4+!
    2   9+ !v1-!v2+!v5+!v1+ !^9+8+!^9-3-!^6-!v  !^6-!v^ ^!1- 1+ !6-!^6-!^  !

A rather standard hand-crafted fixed-output Prelude program. I'm sure this could be shortened considerably but I haven't yet figured out any good techniques to golf programs like this.

---

## Task 8, Mathematica, 28 bytes

    LongestCommonSequence@##==#&

Yay for built-ins. (Mathematica's naming is a bit weird here... `LongestCommonSubsequence` finds the longest common *substring* while `LongestCommonSequence` finds the longest common *subsequence*.)

---

## Task 9, J, 1 byte

    *

Same as the APL and K answers, but it seems no one has taken J yet.

---

## Task 10, Retina, <s>67</s> 60 bytes

[GitHub repository for Retina.](https://github.com/mbuettner/retina)

    (.*).
     ______  $1<LF>|      | $1<LF> ()--() ~$1
    +`(.{9})1
    $1$1
    ~$
    <empty>

Each line goes in a separate file, and `<LF>` should be replaced with a newline character and `<empty>` should be an empty file. You could also put all of this in a single file, and use the `-s` option, but that does not allow embedding of newline characters in place of `<LF>` yet. You could emulate that by doing something like

    echo -n "111" | ./Retina -s train.ret | ./Retina -e "<LF>" -e "\n"

As the above example shows, input is expected to be unary. The idea of the code is to create three copies of the unary input (minus 1), each with a copy of the corresponding line. Then we repeatedly duplicate the last nine characters in front of a `1` until all the `1`s are gone, thereby repeating the lines as necessary. Finally, we remove the extraneous trailing `~`.

 [1]: http://cjam.aditsu.net/#code=q~%2C%3A%2B_*&input=6