[Question]
      [
Given a non-flat list of integers, output a list of lists containing the integers in each nesting level, starting with the least-nested level, with the values in their original order in the input list when read left-to-right. If two or more lists are at the same nesting level in the input list, they should be combined into a single list in the output. The output should not contain any empty lists - nesting levels that contain only lists should be skipped entirely.
You may assume that the integers are all in the (inclusive) range `[-100, 100]`. There is no maximum length or nesting depth for the lists. There will be no empty lists in the input - every nesting level will contain at least one integer or list.
The input and output must be in your language's native list/array/enumerable/iterable/etc. format, or in any reasonable, unambiguous format if your language lacks a sequence type.
## Examples
```
[1, 2, [3, [4, 5], 6, [7, [8], 9]]] => [[1, 2], [3, 6], [4, 5, 7, 9], [8]]
[3, 1, [12, [14, [18], 2], 1], [[4]], 5] => [[3, 1, 5], [12, 1], [14, 2, 4], [18]]
[2, 1, [[5]], 6] => [[2, 1, 6], [5]]
[[54, [43, 76, [[[-19]]]], 20], 12] => [[12], [54, 20], [43, 76], [-19]]
[[[50]], [[50]]] => [[50, 50]]
```

[Answer]
# Pyth, 17
```
 us-GeaYsI#GQ)S#Y
```
The leading space is important. This filters the list on whether the values are invariant on the `s` function, then removes these values from the list and flatten it one level. The values are also stored in `Y` and when we print we remove the empty values by filtering if the sorted value of the list is truthy.
[Test Suite](https://pyth.herokuapp.com/?code=+us-GeaYsI%23GQ%29S%23Y&input=%5B1%2C+2%2C+%5B3%2C+%5B4%2C+5%5D%2C+6%2C+%5B7%2C+%5B8%5D%2C+9%5D%5D%5D&test_suite=1&test_suite_input=%5B1%2C+2%2C+%5B3%2C+%5B4%2C+5%5D%2C+6%2C+%5B7%2C+%5B8%5D%2C+9%5D%5D%5D%0A%5B3%2C+1%2C+%5B12%2C+%5B14%2C+%5B18%5D%2C+2%5D%2C+1%5D%2C+%5B%5B4%5D%5D%2C+5%5D%0A%5B2%2C+1%2C+%5B%5B5%5D%5D%2C+6%5D%0A%5B%5B54%2C+%5B43%2C+76%2C+%5B%5B%5B-19%5D%5D%5D%5D%2C+20%5D%2C+12%5D%0A%5B%5B%5B50%5D%5D%2C+%5B%5B50%5D%5D%5D&debug=0)
Alternatively, a 15 byte answer with a dubious output format:
```
 us-GpWJsI#GJQ)
```
[Test Suite](https://pyth.herokuapp.com/?code=%20us-GpWJsI%23GJQ%29&input=%5B1%2C%202%2C%20%5B3%2C%20%5B4%2C%205%5D%2C%206%2C%20%5B7%2C%20%5B8%5D%2C%209%5D%5D%5D&test_suite=1&test_suite_input=%5B1%2C%202%2C%20%5B3%2C%20%5B4%2C%205%5D%2C%206%2C%20%5B7%2C%20%5B8%5D%2C%209%5D%5D%5D%0A%5B3%2C%201%2C%20%5B12%2C%20%5B14%2C%20%5B18%5D%2C%202%5D%2C%201%5D%2C%20%5B%5B4%5D%5D%2C%205%5D%0A%5B2%2C%201%2C%20%5B%5B5%5D%5D%2C%206%5D%0A%5B%5B54%2C%20%5B43%2C%2076%2C%20%5B%5B%5B-19%5D%5D%5D%5D%2C%2020%5D%2C%2012%5D%0A%5B%5B%5B50%5D%5D%2C%20%5B%5B50%5D%5D%5D&debug=0)
### Expansion:
```
 us-GeaYsI#GQ)S#Y     ##   Q = eval(input)
 u          Q)        ##   reduce to fixed point, starting with G = Q
        sI#G          ##   get the values that are not lists from G
                      ##   this works because s<int> = <int> but s<list> = flatter list
      aY              ##   append the list of these values to Y
     e                ##   flatten the list
   -G                 ##   remove the values in the list from G
              S#Y     ##   remove empty lists from Y
```
[Answer]
# Mathematica, ~~56~~ ~~54~~ 52 bytes
*-2 bytes due to [Alephalpha](https://codegolf.stackexchange.com/users/9288).*
*-2 bytes due to [CatsAreFluffy](https://codegolf.stackexchange.com/users/51443).*
```
Cases[#,_?AtomQ,{i}]~Table~{i,Depth@#}/.{}->Nothing&
```
Actually deletes empty levels.
[Answer]
# Python 2, 78 bytes
```
f=lambda l:l and zip(*[[x]for x in l if[]>x])+f(sum([x for x in l if[]<x],[]))
```
[Answer]
# [Retina](http://github.com/mbuettner/retina), 79
I *know* the Retina experts will golf this more, but here's a start:
```
{([^{}]+)}(,?)([^{}]*)
$3$2<$1>
)`[>}],?[<{]
,
(\d),+[<{]+
$1},{
<+
{
,*[>}]+
}
```
[Try it online.](http://retina.tryitonline.net/#code=K2B7LD99CgooYHsoW157fV0rKX0oLD8pKFtee31dKikKJDMkMjwkMT4KKWBbPn1dLD9bPHtdCiwKKFxkKSwrWzx7XSsKJDF9LHsKPCsKewosKls-fV0rCn0&input=e3s1NCx7NDMsNzYse3t7LTE5LHt7fSx7e319fX19fX0sMjB9LDEyLHt7fX19)
[Answer]
# Mathematica ~~55 64~~ 62 bytes
```
#~Select~AtomQ/.{}->Nothing&/@Table[Level[#,{k}],{k,Depth@#}]&
```
---
```
%&[{1, 2, {3, {4, 5}, 6, {7, {8}, 9}}}]
```
>
> {{1, 2}, {3, 6}, {4, 5, 7, 9}, {8}}
>
>
>
[Answer]
# JavaScript, ~~112~~ 80 bytes
```
F=(a,b=[],c=0)=>a.map(d=>d!==+d?F(d,b,c+1):b[c]=[...b[c]||[],d])&&b.filter(d=>d)
```
Thanks Neil for helping shave off 32 bytes.
[Answer]
# Jelly, 24 bytes
```
fFW®;©ṛ¹ḟF;/µŒḊ’$¡W®Tị¤;
```
[Try it online!](http://jelly.tryitonline.net/#code=ZkZXwq47wqnhuZvCueG4n0Y7L8K1xZLhuIrigJkkwqFXwq5U4buLwqQ7&input=&args=W1s1NCwgWzQzLCA3NiwgW1tbLTE5XV1dXSwgMjBdLCAxMl0)
If newline-separated lists were allowed, this could be golfed down to **14 bytes**.
```
fFṄ¹¹?ḟ@¹;/µ¹¿
```
[Try it online!](http://jelly.tryitonline.net/#code=ZkbhuYTCucK5P-G4n0DCuTsvwrXCucK_&input=&args=W1s1NCwgWzQzLCA3NiwgW1tbLTE5XV1dXSwgMjBdLCAxMl0)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
ŒJẈĠịF
```
[Try it online!](https://tio.run/##y0rNyan8///oJK@HuzqOLHi4u9vt/@H2R01rjk56uHMGkI78/z/aUEfBSEch2hiITXQUTGN1FMyATHMgtgCyLWNjYyGyQHXRhiCVhiYgAiRpBMSGIOloE5AqkN5oI4jKaFOQiBlY0hSkwQRohDnI5OhoXUOQqSD9BiADjMCKok0NYiGqgXQsAA "Jelly – Try It Online")
Jelly has [substantially improved](https://codegolf.stackexchange.com/a/73659/66833) in the past 5 years
## How it works
```
ŒJẈĠịF - Main link. Takes a list L on the left
ŒJ     - Multi-dimensional indices
  Ẉ    - Get the length of each element
         This yields the depth (starting at 1 for flat elements) of each element
   Ġ   - Group the indices of this list by the values
     F - Flatten L
    ị  - Index into
```
Huh? The way that `ŒJẈĠ` works is kinda confusing without an example. Let's take `L = [3, 1, [12, [14, [18], 2], 1], [[4]], 5]` and work through it
`ŒJ` is one of a series of multi-dimensional commands that reflect the behaviour of their one-dimensional versions. Specifically, this is the "multi-dimensional indices" command, a multi-dimensional version of `J`, the "indices" command.
Picture `L` arranged like this:
```
3 1 12 14 18 2 1 4 5
    12 14 18 2 1 4
       14 18 2   4
          18
```
That is, each element is repeated down a number of times equal to it's depth. `ŒJ` doesn't quite leave the elements like this (it changes the specific values, not the shape), but it's enough. `Ẉ` then calculates the length of each i.e. how many rows each element goes down:
```
1 1 2 3 4 3 2 3 1
```
`Ġ` the takes this list as it's argument. First, it's generates this list's indices: `[1, 2, 3, 4, 5, 6, 7, 8, 9]`. We then group these indices by the values of the argument. So because the values at indices `3` and `7` are equal (they're both `2`), `[3, 7]` is grouped. The final result of this is `[[1, 2, 9], [3, 7], [4, 6, 8], [5]]` as the groups are sorted by the values they're grouped by.
Finally, we index into the flattened `L` using this list of groups, which yields the intended output
[Answer]
# Python, ~~108~~ 99 bytes
This seems a bit long to me, but I couldn't make a one-liner shorter, and if I try using `or` instead of `if`, I get empty lists in the results.
```
def f(L):
    o=[];i=[];j=[]
    for x in L:[i,j][[]<x]+=[x]
    if i:o+=[i]
    if j:o+=f(sum(j,[]))
    return o
```
[**Try it online**](http://ideone.com/FhIvyM)
Edit: [Saved 9 bytes thanks to Stack Overflow](https://stackoverflow.com/a/12135169/2415524)
[Answer]
## Python 3, 109 bytes
As ever, stupid Python 2 features like comparing `int`s and `list`s mean that Python 3 comes out behind. Oh well...
```
def d(s):
 o=[]
 while s:
  l,*n=[],
  for i in s:
   try:n+=i
   except:l+=[i]
  if l:o+=[l]
  s=n
 return o
```
[Answer]
# Perl, 63 bytes
```
{$o[$x++]=[@t]if@t=grep{!ref}@i;(@i=map{@$_}grep{ref}@i)&&redo}
```
Input is expected in `@i`, output produced in `@o`. (I hope this is acceptable).
Example:
```
@i=[[54, [43, 76, [[[-19]]]], 20], 12];                              # input
{$o[$x++]=[@t]if@t=grep{!ref}@i;(@i=map{@$_}grep{ref}@i)&&redo}      # the snippet
use Data::Dumper;                                                    # print output
$Data::Dumper::Indent=0;  # keep everything on one line
$Data::Dumper::Terse=1;   # don't print $VAR =
print Dumper(\@o);
```
Output:
```
[[12],[54,20],[43,76],[-19]]
```
[Answer]
## Clojure, 119 bytes
**(116 with seq? and input as lists, a trivial modification)**
```
(defn f([v](vals(apply merge-with concat(sorted-map)(flatten(f 0 v)))))([l v](map #(if(number? %){l[%]}(f(inc l)%))v)))
```
Better intended:
```
(defn f([v]  (vals(apply merge-with concat(sorted-map)(flatten(f 0 v)))))
       ([l v](map #(if(number? %){l[%]}(f(inc l)%))v)))
```
When called with two arguments (the current level and a collection) it either creates an one-element unordered-map like `{level: value}`, or calls `f` recursively if a non-number (presumambly a collection) is seen.
These mini-maps are then merged into a single `sorted-map` and key collisions are handled by `concat` function. `vals` returns map's values from first level to the last.
If a number is the only one at its level then it remains a `vec`, others are converted to lists by `concat`.
```
(f [[54, [43, 76, [[[-19]]]], 20], 12])
([12] (54 20) (43 76) [-19])
```
If input was a `list` instead of `vec` then `number?` could be replaced by `seq?`, oddly vector isn't `seq?` but it is `sequential?`. But I'm too lazy to implement that version, re-do examples etc.
[Answer]
## Racket 259 bytes
```
(let((ol'())(m 0))(let p((l l)(n 0))(cond[(empty? l)][(list?(car l))(set! m(+ 1 n))
(p(car l)(+ 1 n))(p(cdr l)n)][(set! ol(cons(list n(car l))ol))(p(cdr l)n )]))
(for/list((i(+ 1 m)))(flatten(map(λ(x)(cdr x))(filter(λ(x)(= i(list-ref x 0)))(reverse ol))))))
```
Ungolfed:
```
(define (f l)
  (define ol '())
  (define maxn 0)
  (let loop ((l l)              ; in this loop each item is added with its level
             (n 0))
    (cond
      [(empty? l)]
      [(list? (first l))
       (set! maxn (add1 n))
       (loop (first l) (add1 n))
       (loop (rest l) n)]
      [else
       (set! ol (cons (list n (first l)) ol))
       (loop (rest l) n )]))
  ; now ol is '((0 1) (0 2) (1 3) (2 4) (2 5) (1 6) (2 7) (3 8) (2 9))
  (for/list ((i (add1 maxn)))   ; here similar levels are combined
    (flatten
     (map (λ (x) (rest x))      ; level numbers are removed
          (filter (λ (x) (= i(list-ref x 0)))
                  (reverse ol))))))
```
Testing:
```
(f '[1 2 [3 [4 5] 6 [7 [8] 9]]])
```
Output:
```
'((1 2) (3 6) (4 5 7 9) (8))
```
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 37 bytes
```
j']['!=dYsXKu"GK@=)'[\[\],]'32YXUn?1M
```
[**Try it online!**](http://matl.tryitonline.net/#code=aiddWychPWRZc1hLdSJHS0A9KSdbXFtcXSxdJzMyWVhVbj8xTQ&input=W1s1NCwgWzQzLCA3NiwgW1tbLTE5XV1dXSwgMjBdLCAxMl0)
Works with [current release (13.0.0)](https://github.com/lmendo/MATL/releases/tag/13.0.0) of the language/compiler.
This produces the output as lines of space-separated values, where each line corresponds to the same nesting level, and different nesting levels are separated by newlines.
```
j            % read input as string (row array of chars)
']['!        % 2x1 array containing ']'  and '['
=            % test for equality, all combinations
d            % row array obtained as first row minus second row
Ys           % cumulative sum. Each number is a nesting level
XK           % copy to clibdoard K
u            % unique values: all existing nesting levels
"            % for each nesting level
  G          %   push input
  K          %   push array that indicates nesting level of each input character
  @          %   push level corresponding to this iteration
  =          %   true for characters corresponding to that nesting level
  )          %   pick those characters
  '[\[\],]'  %   characters to be replaced
  32         %   space
  YX         %   regexp replacement
  U          %   only numbers and spaces remain: convert string to array of numbers
  n?         %   if non-empty
    1M       %     push that array of numbers again
             %   end if implicitly
             % end for each implicitly
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 18 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
é╔óó)₧ú↔u.≤∟╦Ç╟·○`
```
[Run and debug it](https://staxlang.xyz/#p=82c9a2a2299ea31d752ef31ccb80c7fa0960&i=%5B1,+2,+%5B3,+%5B4,+5%5D,+6,+%5B7,+%5B8%5D,+9%5D%5D%5D%0A%5B3,+1,+%5B12,+%5B14,+%5B18%5D,+2%5D,+1%5D,+%5B%5B4%5D%5D,+5%5D%0A%5B2,+1,+%5B%5B5%5D%5D,+6%5D%0A%5B%5B54,+%5B43,+76,+%5B%5B%5B-19%5D%5D%5D%5D,+20%5D,+12%5D%0A%5B%5B%5B50%5D%5D,+%5B%5B50%5D%5D%5D&m=2)
I rhought I'd be able to beat pyth, but ¯\\_(○-○)\_/¯
]


[Question]
      [
## Background
Most everyone is familiar with the *Fibonacci numbers* \$F(n)\$:
>
> \$0, 1, 1, 2, 3, 5, 8, 13, 21, ...\$
>
>
>
These are formed by the recursion function \$F(n) = F(n-1) + F(n-2)\$ with \$F(0)=0\$ and \$F(1)=1\$. [A000045](https://oeis.org/A000045)
A closely related sequence is the *Lucas numbers* \$L(m)\$:
>
> \$2, 1, 3, 4, 7, 11, 18, 29, ...\$
>
>
>
These are formed by the recursion function \$L(m) = L(m-1) + L(m-2)\$ with \$L(0)=2\$ and \$L(1)=1\$. [A000032](https://oeis.org/A000032)
We can alternate between the two sequences based on even/odd indices, with the construction
$$A(x) = \begin{cases}
F(x) & x \equiv 0 \pmod 2 \\
L(x) & x \equiv 1 \pmod 2 \\
\end{cases}$$
For example, \$A(4)\$ is equal to \$F(4)\$ since \$4 \bmod 2 \equiv 0\$. We'll call this sequence the *Lucas-nacci Numbers*, \$A(x)\$:
>
> 0, 1, 1, 4, 3, 11, 8, 29, 21, 76 ...
>
>
>
This can be formed by the recursion function \$A(x) = 3A(x-2) - A(x-4)\$ with \$A(0)=0, A(1)=1, A(2)=1\$, and \$A(3)=4\$. [A005013](http://oeis.org/A005013)
## Challenge
Given input \$n\$, output the sequence of \$n+1\$ numbers up to and including \$A(n)\$ as described above. Fewest bytes (or byte-equivalents, such as for [LabVIEW](https://codegolf.meta.stackexchange.com/a/7589/42963), as determined individually on Meta) wins.
## Input
A single non-negative integer \$n\$.
## Output
A list of numbers that correspond to the subsequence of Lucas-nacci numbers from \$A(0)\$ to \$A(n)\$. The list must be in sequential order as described above.
## Rules
* Standard code-golf rules and [loophole restrictions](https://codegolf.meta.stackexchange.com/q/1061/42963) apply.
* [Standard input/output rules](https://codegolf.meta.stackexchange.com/a/1326/42963) apply.
* Input number can be in any suitable format: unary or decimal, read from STDIN, function or command-line argument, etc. - your choice.
* Output can be printed to STDOUT or returned as a result of the function call. If printed, suitable delimiters to differentiate the numbers must be included (space-separated, comma-separated, etc.).
* Additionally, if output to STDOUT, surrounding whitespace, trailing newline, etc. are all optional.
* If the input is a non-integer or a negative integer, the program can do anything or nothing, as behavior is undefined.
## Examples
```
Input -> Output
0 -> 0
5 -> 0, 1, 1, 4, 3, 11
18 -> 0, 1, 1, 4, 3, 11, 8, 29, 21, 76, 55, 199, 144, 521, 377, 1364, 987, 3571, 2584
```

[Answer]
# Jelly, 12 bytes
```
;2U+¥Ð¡-,1ZḢ
```
[Try it online!](http://jelly.tryitonline.net/#code=OzJVK8Klw5DCoS0sMVrhuKI&input=MTg)
### Background
We can extend F and L to -1 by defining F(-1) = 1 and L(-1) = -1. This is consistent with the recursive function.
Our program starts with
```
-1  1
 0  2
```
In each step, to form the next pair, we reverse the last pair and add it to the penultimate pair. For example:
```
[0, 2] U+¥ [-1, 1] -> [2, 0] + [-1, 1] -> [1, 1]
```
If we continue this process for a few more steps, we get
```
-1  1
 0  2
 1  1
 1  3
 4  2
 3  7
11  5
```
The Lucas-nacci sequence is simply the left column.
### How it works
```
;2U+¥Ð¡-,1ZḢ  Niladic link. No implicit input.
              Since the link doesn't start with a nilad, the argument 0 is used.
;2            Concatenate the argument with 2, yielding [0, 2].
       -,1    Yield [-1, 1]. This is [L(-1), F(-1)].
    ¥         Create a dyadic chain of the two atoms to the left:
  U             Reverse the left argument.
   +            Add the reversed left argument and the right one, element-wise.
     Ð¡       For reasons‡, read a number n from STDIN.
              Repeatedly call the dyadic link U+¥, updating the right argument with
              the value of the left one, and the left one with the return value.
              Collect all intermediate results.
          Z   Zip the list of results, grouping the first and seconds coordinates.
           Ḣ  Head; select the list of first coordinates.
```
‡ `Ð¡` peeks at the two links to the left: `2` and `U+¥`. Since the leftmost one is a nilad, it cannot be the body of the loop. Therefore, `U+¥` is used as body and a number is read from input. Since there are no command-line arguments, that number is read from STDIN.
[Answer]
## CJam, ~~21~~ 20 bytes
*Thanks to Sp3000 for saving 1 byte.*
```
TXX4ri{1$3*4$-}*?;]p
```
[Test it here.](http://cjam.aditsu.net/#code=TXX4ri%7B1%243*4%24-%7D*%3F%3B%5Dp&input=18)
### Explanation
Simply uses the recurrence given in the challenge spec.
```
TXX4 e# Push 0 1 1 4 as base cases.
ri   e# Read input and convert to integer N.
{    e# Run this N times...
  1$ e#   Copy a(n-2).
  3* e#   Multiply by 3.
  4$ e#   Copy a(n-4).
  -  e#   Subtract.
}*
?;   e# Discard the last three values, using a ternary operation and popping the result.
]p   e# Wrap the rest in an array and pretty-print it.
```
[Answer]
# Perl 6, 42 bytes
```
{(0,1,1,4,{$^b;$^d;3*$^c-$^a}...*)[0..$_]}
```
**usage**
```
> my &f = {(0,1,1,4,{$^b;$^d;3*$^c-$^a}...*)[0..$_]}
-> ;; $_? is raw { #`(Block|184122176) ... }
> f(0)
(0)
> f(5)
(0 1 1 4 3 11)
> f(18)
(0 1 1 4 3 11 8 29 21 76 55 199 144 521 377 1364 987 3571 2584)
```
[Answer]
# Haskell, ~~59~~, ~~57~~, ~~56~~, ~~52~~, 51 bytes
```
l a=2*mod a 2:scanl(+)1(l a)
f n=[l i!!i|i<-[0..n]]
```
Series definition adapted from [this answer](https://codegolf.stackexchange.com/a/89/48962).
Less golfed:
```
fibLike start = start : scanl (+) 1 (fibLike start)
whichStart i = (2*mod i 2)
lucasNacci i = fibLike (whichStart i) !! i
firstN n = [ lucasNacci i | i <- [0..n]]
```
`fibLike start` gives an infinite list, defined: `f(0)=start, f(1)=1, f(n)=f(n-1) + f(n-2)`.
`whichStart i` returns 2 for odd input (Lucas series) or 0 for even (Fibonacci series).
`lucasNacci i` gives the ith Lucas-nacci number.
`firstN n` maps over the list.
One byte saved by Boomerang.
[Answer]
## ES6, 65 bytes
```
n=>[...Array(n)].map(_=>a.shift(a.push(a[2]*3-a[0])),a=[0,1,1,4])
```
Uses the recurrence relation given in the question.
[Answer]
## [Retina](https://github.com/mbuettner/retina), ~~70~~ ~~62~~ 59 bytes
```
1
¶$`1
m`^(11)*1$
$&ff
m`$
 f
+`1(f*) (f*)
$2 $2$1
 f*
f
1
```
[Try it online](http://retina.tryitonline.net/#code=MQrCtiRgMQptYF4oMTEpKjEkCiQmZmYKbWAkCiBmCitgMShmKikgKGYqKQokMiAkMiQxCiBmKgoKZgox&input=MTExMTExMTExMQ)
* Input is in unary base, *n* 1s.
* `1?` `$`¶` - Create a line for each number from 0 to *n*: `, 1, 11, 111, 1111, ...`
* `m`^(11)*1$` `$&ff` - Append `ff` to odd lines. This will seed the function with L(0)=2.
* `m`$` `f` - Append `f` to all lines (note the space). This seeds the function with 0 and 1 for Fibonacci numbers, and 2 and 1 for Lucas numbers.
* `+`1(f*) (f*)` `$2 $2$1` - Loop: calculate F(n+1) = F(n) + F(n-1) while there are still 1s.
* `f*`    - Remove F(n+1) from the end of each line.
* Replace `f`s back to 1s. If this isn't needed and we can stay with `f`s, the length is just 55 bytes.
[Answer]
# Oracle SQL 11.2, ~~218~~ ~~216~~ 201 bytes
```
WITH v(a,b,c,d,i)AS(SELECT 0,1,1,4,3 FROM DUAL UNION ALL SELECT b,c,d,3*c-a,i+1 FROM v WHERE i<:1)SELECT SIGN(LEVEL-1) FROM DUAL WHERE LEVEL-1<=:1 CONNECT BY LEVEL<4UNION ALL SELECT d FROM v WHERE:1>2;
```
Un-golfed
```
WITH v(a,b,c,d,i) AS
(
  SELECT 0,1,1,4,3 FROM DUAL
  UNION ALL
  SELECT b,c,d,3*c-a,i+1 FROM v WHERE i<:1
)
SELECT SIGN(LEVEL-1) FROM DUAL WHERE LEVEL-1<=:1 CONNECT BY LEVEL<4
UNION ALL SELECT d FROM v WHERE:1>2;
```
I managed to gain a few bytes by using (abusing ?) the SIGN function to generate the first 3 elements of the sequence.
[Answer]
# Japt, ~~25~~ ~~22~~ 21 bytes
```
Uò £MgXf2)+X%2*Mg°X)r
```
[Test it online!](http://ethproductions.github.io/japt?v=master&code=VfIgo01nWGYyKStYJTIqTWewWCly&input=MTg=)
### Background
It's somewhat difficult to create a Fibonacci sequence in Japt, but we have a built-in `Mg` to do it for us. However, this only gives us the Fibonacci sequence, not the Lucas sequence. We can accomplish the Lucas sequence fairly easily using this trick:
```
N    F(N-1)  F(N+1)  F(N-1)+F(N+1)
0    1       1       2
1    0       1       1
2    1       2       3
3    1       3       4
4    2       5       7
5    3       8       11
6    5       13      18
7    8       21      29
```
As you can see, `F(N-1) + F(N+1)` is equal to `L(N)` for all `N`. However, since we only need Lucas numbers on the odd indices, we can combine the two formulas into one:
```
N    N-N%2  N+N%2    F(N-N%2)  F(N+N%2)*(N%2)  F(N-N%2)+F(N+N%2)*(N%2)
0    0      0        0         0               0
1    0      2        0         1               1
2    2      2        1         0               1
3    2      4        1         3               4
4    4      4        3         0               3
5    4      6        3         8               11
6    6      6        8         0               8
7    6      8        8         21              29
```
### How it works
```
Uò £  MgX-1 +X%2*Mg° X)r
Uò mX{MgX-1 +X%2*Mg++X)r
             // Implicit: U = input integer
Uò mX{       // Create the inclusive range [0..U], and map each item X to:
MgXf2)+      //  Floor X to a multiple of 2, calculate this Fibonacci number, and add:
+X%2*Mg++X)  //  Calculate the (X+1)th Fibonacci number and multiply by X%2.
)r           //  Round the result. (The built-in Fibonacci function returns
             //  a decimal number on higher inputs.)
```
[Answer]
# Mathematica, ~~52~~ 51 bytes
```
If[#>2,3#0[#-2]-#0[#-4],#-If[#>1,1,0]]&/@0~Range~#&
```
Very similar idea to Martin's above, I spent some time trying to find a shorter way of defining the "base cases" for the function. Polynomial interpolation was a bust, so I went for this, using the extension into negatives to yield a fairly short definition.
[Answer]
## Mathematica, 56 bytes
```
f@0=0
f@1=f@2=1
f@3=4
f@n_:=3f[n-2]-f[n-4];
f/@0~Range~#&
```
Very straightforward implementation. Defines a helper-function `f` and then evaluates to an unnamed function which applies `f` to a range to get all the results. This feels unnecessarily cumbersome.
A single unnamed function seems to be one byte longer though:
```
Switch[#,0,0,1,1,2,1,3,4,_,3#0[#-2]-#0[#-4]]&/@0~Range~#&
```
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 17 ~~18~~ bytes
```
0ll4i:"y3*5$y-](x
```
Almost direct translation of [Martin's CJam answer](https://codegolf.stackexchange.com/a/71439/36398).
[**Try it online!**](http://matl.tryitonline.net/#code=MGxsNGk6InkzKjUkeS1dKHg&input=MTg)
```
0ll4       % push first four numbers: 0,1,1,4
i:         % input n and generate array [1,2,...,n]
"          % for loop. Repeat n times
  y        % copy second-top element from stack
  3*       % multiply by 3
  5$y      % copy fifth-top element from stack
  -        % subtract. This is the next number in the sequence
]          % end loop
(x         % indexing operation and delete. This gets rid of top three numbers
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 51 bytes
```
:0re{:4<:[0:1:1:4]rm!.|-4=:1&I,?-2=:1&*3-I=.}w,@Sw\
```
This takes a number as input and prints to STDOUT the list, with spaces separating each number.
### Explanation
```
§ Main predicate
:0re{...}               § Enumerate integers between 0 and the Input, pass the integer
                        § as input to sub-predicate 1
         w,@Sw          § Write sub-predicate 1's output, then write a space
              \         § Backtrack (i.e. take the next integer in the enumeration)
§ Sub-predicate 1
:4<                     § If the input is less than 4
   :[0:1:1:4]rm!.       § Then return the integer in the list [0,1,1,4] at index Input
|                       § Else
-4=:1&I,                § I = sub_predicate_1(Input - 4)
        ?-2=:1&*3-I=.   § Output = sub_predicate_1(Input - 2) * 3 - I
```
The cut `!` in the first rule of sub-predicate 1 is necessary so that when we backtrack (`\`), we don't end up in an infinite loop where the interpreter will try the second rule for an input less than 4.
[Answer]
# Mathematica, 41 bytes
```
LinearRecurrence[{0,3,0,-1},{0,1,1,4},#]&
```
[Answer]
# Groovy, 50 Bytes
```
x={a,b=0,c=1,d=1,e=4->a<0?:[b,x(a-1,c,d,e,3*d-b)]}
```
This defines the function x, which takes in n as it's first argument and has the base case of the first four numbers in the Fibocas sequence as default arguments for the rest of the function.
a here is n. b, c, d, and e are the next four elements in the sequence.
It decrements n and recurses until n is less than zero-- when it recurses, it adds on to the ultimate return value the first element in its current sequence. The new values for the next four elements in the sequence are given to the recursive call-- the last three elements are shifted over to be the first three, and a new fourth element is generated from two of the previous elements using 3\*d-b.
It delimits new values with list nestings, as groovy can return multiple values by stuffing them into a list-- so each call returns the current first element and the result of recursion, which will be its own list.
[Answer]
# C++ Template Meta Programming, 130 bytes
```
template<int X>struct L{enum{v=3*L<X-2>::v-L<X-4>::v};};
#define D(X,A) template<>struct L<X>{enum{v=A};};
D(0,0)D(1,1)D(2,1)D(3,4)
```
Recursive definitions somehow cry for C++TMP, usage:
```
L<x>::v
```
with `x` being the `A(x)` you like.
[Answer]
# [R](https://www.r-project.org/), 55 bytes
```
A=c(0,1,1,4);for(x in 4:scan()+1)A[x]=3*A[x-2]-A[x-4];A
```
[Try it online!](https://tio.run/##K/r/39E2WcNAxxAITTSt0/KLNCoUMvMUTKyKkxPzNDS1DTUdoytibY21gJSuUawuiDKJtXb8b2jxHwA "R – Try It Online")
* -24 bytes thanks to JayCe
[Answer]
# [Pylons](https://github.com/morganthrapp/Pylons-lang), 19
This is a pretty direct translation of Martin's approach.
```
0114{@-4@-33*-,i}=4
```
How it works:
```
0114    # Push 0, 1, 1, 4 to the stack.
{       # Start a for loop.
 @-4    # Get the stack element at index -4
 @-3    # Get the stack element at index -3
 3      # Push 3 to the stack.
 *      # Multiply the top two elements of the stack.
 -      # Subtract the top two elements of the stack.
  ,     # Switch to loop iterations.
 i      # Get command line args.
}       # End for loop.
=4      # Discard the top 4 elements of the stack.
```
[Answer]
# [DUP](https://esolangs.org/wiki/DUP), 32 bytes
```
[a:0 1$4[a;1-$a:][1ø3*4ø-]#%%]
```
`[Try it here!](http://www.quirkster.com/iano/js/dup.html)`
An anonymous lambda that leaves a sequence of numbers on the stack. Usage:
```
8[a:0 1$4[a;1-$a:][1ø3*4ø-]#%%]!
```
# Explanation
```
[                              {start lambda}
 a:                            {save input number to a}
   0 1$4                       {base cases to get us started}
        [       ][       ]#    {while loop}
         a;1-$a:               {a--, check if a>0}
                  1ø3*4ø-      {3*stack[n-2]-stack[n-4]}
                           %%  {discard top 2 stack items}
                             ] {end lambda}
```
[Answer]
## Python 2, 71 bytes
```
def a(n,x=0,y=1,z=2,w=1,p=0):
 if~n:print[x,z][p];a(n-1,y,x+y,w,z+w,~p)
```
This definitely seems too long. However, I was pleased that I got to use the bitwise `not` operator...twice. Once as kind of a parity flip back and forth, and once to terminate the recursion when `n` reaches `-1`.
The variable `p` will always be either `0` or `-1`, so it will alternate between entries `0` or `-1` of the list. (Choosing entry `-1` of a Python list means choosing the last element.)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
ŻÆĿÆḞḂ?€
```
[Try it online!](https://tio.run/##AS0A0v9qZWxsef//xbvDhsS/w4bhuJ7huII/4oKs/8OHxZLhuZgpWf//MCwgNSwgMTg "Jelly – Try It Online")
Close to a literal interpretation of the spec
## How it works
```
ŻÆĿÆḞḂ?€ - Main link. Takes N on the left
Ż        - Range from 0 to N
       € - Over each integer k:
      ?  -   If:
     Ḃ   -     Condition: k mod 2
 ÆĿ      -     Truthy: kth Lucas number
   ÆḞ    -     Falsey: kth Fibonacii number
```
]


[Question]
      [
Given a string with a multiple people's investment data, find out how much profit/loss they recorded.
The string only contains capital and lowercase letters, like this:
```
AABaBbba
```
Each letter represents a person - a capital letter means buy, a lowercase letter means sell. The price of the stock they are investing in (CGLF) starts at $50. After someone buys, the price goes up 5%. After someone sells the price goes down 5%. You need to figure out how much money each person who participated made/lost.
## Notes:
* The string will always be valid, no selling without first buying. Also, everyone who buys a stock will sell it eventually.
* Your calculations should be accurate to at least 6 decimal places. However, final answers should be rounded to two decimals.
## Test Cases:
**Input:** `AABaBbba`
>
> * A: Buy - $50
> * A: Buy - $52.50
> * B: Buy - $55.125
> * a: Sell - $57.88125
> * B: Buy - $54.9871875
> * b: Sell - $57.736546875
> * b: Sell - $54.8497195313
> * a: Sell - $52.1072335547
>
>
>
* Person A profit: `57.88125+52.1072335547-50-52.50=`7.4884835547
* Person B profit: `57.736546875+54.8497195313-55.125-54.9871875=`2.4740789063
**Output:** `A:7.49,B:2.47` (order doesn't matter, separators not required)
---
**Input:** `DGdg`
>
> * D: Buy - $50
> * G: Buy - $52.50
> * d: Sell - $55.125
> * g: Sell - $52.36875
>
>
>
* Person D profit: `55.125-50=`5.125
* Person G profit: `52.36875-52.50=`-0.13125
**Output:** `D:5.13,G:-.13`
---
**Input:** `ADJdja`
>
> * A: Buy - $50
> * D: Buy - $52.50
> * J: Buy - $55.125
> * d: Sell - $57.88125
> * j: Sell - $54.9871875
> * a: Sell - $52.237828125
>
>
>
* Person A profit: `52.237828125-50=`2.237828125
* Person D profit: `57.88125-52.50=`5.38125
* Person J profit: `54.9871875-55.125=`-0.1378125
**Output:** `A:2.24,D:5.38,J:-.14`

[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), ~~34~~ 32 bytes
```
‚åä{‚ç∫,2‚çï+/-‚çµ}‚å∏√ó√ó50√ó¬Ø1√ó\‚ç§‚Üì1,1+.05√ó√ó
```
```
Monadic √ó in Dyalog extended for letters corresponds to the casing
¬Ø1 1 ‚â° √ó'aA'
1+.05√ó√ó - 1 + 0.05 times the sign (either 1.05 or 0.95)
1,      - concat 1 to the front
¬Ø1√ó\‚ç§‚Üì  - cumulative product and drop the last element
50√ó     - multiply by 50
√ó√ó50... - the sign times that
‚åä{‚ç∫,2‚çï+/-‚çµ}‚å∏ - group (dyadic ‚å∏) by the lowercased input (‚åä)
 {‚ç∫,2‚çï+/-‚çµ}  - return the left item (the person) concat their rounded total
```
-2 thanks to Ad√°m
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn//1FPV/Wj3l06Ro96p2rr6z7q3Vr7qGfH4emHp5saHJ5@aL3h4ekxj3qXPGqbbKhjqK1nYAqS@u/2qG3Co96@R13Nj3rXPOrdcmi98aO2iY/6pgYHOQPJEA/PYIVH3S0KaUB11UABIOWmADQbLAjhq6vXAkXmKhSnFiQWJZakKpRkpOYq5OYXpSrkJ5Vl5pcW51T@T1NQd3R0SnRKSkpU5wJyXNxT0sEMRxevlKxEdQA "APL (Dyalog Extended) ‚Äì Try It Online")
[Answer]
## Java, 277 bytes
```
class c{public static void main(String[]a){double[]m=new double[26];double s=50;for(byte b:a[0].getBytes()){if(b>=97){m[b-97]+=s;s*=.95;}else{m[b-65]-=s;s*=1.05;}}char g=65;for(double k:m){if(k!=0){System.out.println(g+String.format(java.util.Locale.ENGLISH,"%.2f",k));}g++;}}}
```
Ungolfed:
```
class c {
    public static void main(String[]a) {
        double[] m = new double[26];
        double s = 50;
        for(byte b : a[0].getBytes()) {
            if(b>=97) {
                m[b-97]+=s;
                s*=.95;
            } else {
                m[b-65]-=s;
                s*=1.05;
            }
        }
        char g=65;
        for(double k:m) {
            if(k!=0) {
                System.out.println(g+String.format(java.util.Locale.ENGLISH,"%.2f",k));
            }
            g++;
        }
    }
}
```
[Answer]
# JavaScript (ES7), ~~145~~ 142 bytes
I can't find a shorter way to round out the results...
```
x=>[for(c of(i=50,a={},x))(a[d=c.toUpperCase()]=a[d]||0,c<"["?(a[d]-=i,i*=1.05):(a[d]+=i,i*=.95))]&&Object.keys(a).map(k=>[k,a[k].toFixed(2)])
```
Fun fact: this would only be 101 bytes if not for the rounding requirement:
```
x=>[for(c of(i=50,a={},x))(a[d=c.toUpperCase()]=a[d]||0,c<"["?(a[d]-=i,i*=1.05):(a[d]+=i,i*=.95))]&&a
```
[Answer]
# Python 3, 116 bytes
```
P=50
M={}
for c in input():C=c.upper();u=c>C;u+=~-u;M[C]=M.get(C,0)+P*u;P*=1-u*.05
for k in M:print(k,round(M[k],2))
```
### Ungolfed
```
price = 50
profits = {}
for char in input():
    upper = char.upper()
    direction = 2 * (char > upper) - 1
    profits[upper] = profits.get(upper, 0) + price * direction
    price *= 1 - direction * .05
for key in profits:
    print(key, round(profits[key], 2))
```
[Answer]
# ARM Thumb-2 (VFP + `printf`, softfp ABI), ~~109~~ 104 bytes
Uses the softfp ABI (default on Android). It won't work on `armhf` Linux. `f7ff fffe` is a 4 byte linker placeholder for `printf`.
Both of these examples must be placed at an address that is **not** a multiple of 4 (but even), and must be in a W+X section because we modify an inline `printf` string in place.
```
b5f8 2100 2234 3a01 b402 d8fc f2c4 0249
ec42 1b10 ed9f 1b11 f810 2b01 b192 3a61
bf48 3220 eb0d 02c2 ed92 5b00 bf47 ee35
5b40 ee00 0b01 ee35 5b00 ee00 0b41 ed82
5b00 e7e9 2641 bc0c b11b a005 7006 f7ff
fffe 3601 2e5a ddf6 bdf8 999a 9999 9999
3fa9 2558 322e 0066
```
Assembly:
```
        .syntax unified
        .arch armv6t2
        // We need VFPv2 for this.
        .fpu vfpv2
        // We modify an inline string in place, so we need W+X.
        .section ".writeable_text","awx",%progbits
        .thumb
        .globl silly_stocks
        .thumb_func
        // Must NOT be 4 byte aligned.
        // .align 4
        // nop
        // void silly_stocks(const char *input);
        // Follows AAPCS convention.
        // input is a null-terminated string in r0.
silly_stocks:
        push          {r3-r7, lr}
        // double buf[26] = {0}
        movs          r1, #0
        movs          r2, #26*2
.Lclear_loop:
        subs          r2, #1
        push          {r1}
        bhi           .Lclear_loop
.Lclear_loop_end:
        // note: r1 and r2 are zero at this point
        // r1:r2 = 0x4049000000000000 = 50.0 double
        movt           r2, #0x4049
        vmov           d0, r1, r2
        vldr           d1, .Lfloat_pool
.Lprocess_loop:
        // Loop until the null terminator.
        // while (r2 = *input++)
        ldrb          r2, [r0], #1
        cbz           r2, .Lprocess_loop_end
        // tolower(r2) - 'a'
        //
        // Specifically, we subtract 'a', and if the char was uppercase,
        // it would be negative, triggering the N flag, which is why we
        // check the mi condition in the following IT blocks.
        subs          r2, #'a'
        it            mi
        // if (isupper(r2))
          addmi       r2, #'a' - 'A'
        // Yucky. We can't use proper offsetting with VFP and we need to
        // keep the flags for the IT block.
        add.w         r2, sp, r2, lsl #3
        // Behold, the beautiful syntax of VFP/NEON.
        // Combine it with a an IT block and you get a 10 letter mnemonic. OwO
        vldr.64       d5, [r2]
        ittee         mi
        // if (isupper(r2)) {    // Buy
          vsubmi.f64  d5, d5, d0 //   profit[i]   -= d0
          vmlami.f64  d0, d0, d1 //   stock_price += stock_price * 0.05
        // } else {              // Sell
          vaddpl.f64  d5, d5, d0 //   profit[i]   += stock_price
          vmlspl.f64  d0, d0, d1 //   stock_price -= stock_price * 0.05
        // } endif
        vstr.64       d5, [r2]
        b             .Lprocess_loop
.Lprocess_loop_end:
        movs          r6, #'A'
.Lprint_loop:
        // Pop the double into r2 and r3. We are using the softfp abi, so
        // doubles are passed in integer registers.
        pop           {r2, r3}
        // Only check if the most signicant half of the double is zero.
        // Any non-zero double that is 0x00000000xxxxxxxx is denormal.
        cbz           r3, .Lprint_loop_skip
        // Set up an AEABI call to printf.
        adr           r0, .Lprintf_str
        // Instead of %c, store the char directly (that's why we need W+X)
        strb          r6, [r0]
        bl            printf
.Lprint_loop_skip:
        // Loop from A-Z.
        adds          r6, #1
        cmp           r6, #'Z'
        ble           .Lprint_loop
        pop           {r3-r7, pc}
        // At least for the softfp ABI, doubles are smaller than floats.
        // This is because printf takes doubles, not floats, and we need
        // to pass them in a register pair.
        // So we would need something like this, which is 12 bytes.
        //  vpop         {d0}
        //  vcvt.f64.f32 d0, s0
        //  vmov         r2, r3, d0
        .align 2
.Lfloat_pool:
        .double       0.05
.Lprintf_str:
        // Our printf string. We modify X directly.
        .asciz        "X%.2f"
        .section ".testsuite_unscored","ax",%progbits
.macro $TEST str
        adr           r0, 1f
        bl            puts
        adr           r0, 1f
        bl            silly_stocks
        movs          r0, #'\n'
        bl            putchar
        b             2f
        .align 2
1:
        .asciz        "\str"
.align 2
2:
.endm
        .align 2
        .globl main
        .thumb_func
main:
        push          {r4, lr}
        $TEST         "AABaBbba"
        $TEST         "DGdg"
        $TEST         "ADJdja"
        pop           {r4, pc}
```
Decided to take a shot at VFP code in ARM assembly instead of doing something easy (and basically identical to the Java entry) like C or C++.
One of the things I realized the hard way was that ARM actually needs the stack to be 8 byte aligned, or else subtle bugs will occur. Two hours of debugging I am NEVER getting back. üò´
Oddly enough, using doubles is smaller than floats, despite the larger literal pool. This is because the C calling convention mandates that `float`s be promoted to `double` in variadic functions, so we would have to convert to `double` anyways, and that is larger than the 8 bytes for the larger pool.
Output isn't pretty. But the question says "**separators not required**" so I took that in the most literal sense. üòè
```
AABaBbba
A7.49B2.47
DGdg
D5.12G-0.13
ADJdja
A2.24D5.38J-0.14
```
But aside from the `5.12` which is the same rounding error that was mentioned in Python, the results are correct.
# ARM Thumb-2 (VFP + `printf`, softfp ABI, very imprecise), ~~99~~ 96 bytes
This version uses 32-bit x 16-bit fixed point arithmetic.
It lacks the required 6 digits of precision, but for the test cases it products the same results. Interpret it as you wish.
Must be loaded at an address that is not a multiple of 4 for constant pool alignment.
Machine code:
```
b5f8 2100 2534 3d01 b402 d8fc f2c0 0132
4d11 f810 2b01 b172 3a61 bf48 3220 f85d
3032 fb51 f605 bf47 1a5b 4431 440b 1b89
f84d 3032 e7ed 2641 ecbd 0b02 eeba 0bc8
ec53 2b10 b11b a004 7006 f7ff fffe 3601
2e5a ddf1 bdf8 cccc 0ccc 2558 322e 0066
```
Assembly:
```
        .syntax unified
        .arch armv6t2
        // We need VFPv2 for this.
        .fpu vfpv2
        // We modify an inline string in place, so we need W+X.
        .section ".writeable_text_fixed","awx",%progbits
        .thumb
        .globl silly_stocks_fixed
        .thumb_func
        // Must not be 4 byte aligned.
        // .align 4
        // nop
        // void silly_stocks_fixed(const char *input);
        // Follows AAPCS convention.
        // input is a null-terminated string in r0.
silly_stocks_fixed:
        push          {r3-r7, lr}
        // We use double the width because we need to keep alignment.
        // int64_t buf[26] = {0}
        movs          r1, #0
        movs          r5, #26*2
.Lclear_loop_fixed:
        subs          r5, #1
        push          {r1}
        bhi           .Lclear_loop_fixed
.Lclear_loop_end_fixed:
        // Load our float constants from the pool.
        movt          r1, #0x32       // 0x00320000 = 50.0 in 16-bit fixed point
        ldr           r5, .L.05.fix32 // 0x0ccccccc = 0.05 in 32-bit fixed point
.Lprocess_loop_fixed:
        // Loop until the null terminator.
        // while (r2 = *input++)
        ldrb          r2, [r0], #1
        cbz           r2, .Lprocess_loop_end_fixed
        // tolower(r2) - 'a'
        //
        // Specifically, we subtract 'a', and if the char was uppercase,
        // it would be negative, triggering the N flag, which is why we
        // check the mi condition in the following IT blocks.
        subs          r2, #'a'
        it            mi
        // if (isupper(r2))
          addmi       r2, #'a' - 'A'
        ldr           r3, [sp, r2, lsl #3]
        // fixed point multiply:
        // x<fixA> = (y<fixB> * z<fixC>) >> (B + C - A)
        // tmp<fix16> = (stock_price<fix16> * 0.05<fix32>) >> 32
        smmul         r6, r1, r5  // r6 = stock_price * 0.05
        ittee         mi
        // if (isupper(r2)) {     // Buy
          submi       r3, r1      //   profit[i]   -= stock_price
          addmi       r1, r6      //   stock_price += stock_price * 0.05
        // } else {               // Sell
          addpl       r3, r1      //   profit[i]   += stock_price
          subpl       r1, r6      //   stock_price -= stock_price * 0.05
        // } endif
        str           r3, [sp, r2, lsl #3]
        b             .Lprocess_loop_fixed
.Lprocess_loop_end_fixed:
        movs          r6, #'A'
.Lprint_loop_fixed:
        // Pop the result into d0 (also cleaning the stack)
        vpop          {d0}
        // Convert from fix16 to double
        vcvt.f64.s32  d0, d0, #16
        // Move the double result into r2 and r3. This is for the softfp ABI
        // which passes floating point values in registers.
        vmov          r2, r3, d0
        // Only check if the most signicant half of the double is zero.
        // Any non-zero double that is 0x00000000xxxxxxxx is denormal.
        cbz           r3, .Lprint_loop_skip_fixed
        // Set up an AEABI call to printf.
        adr           r0, .Lprintf_str_fixed
        // Instead of %c, store the char directly (that's why we need W+X)
        strb          r6, [r0]
        bl            printf
.Lprint_loop_skip_fixed:
        // Loop from A-Z.
        adds          r6, #1
        cmp           r6, #'Z'
        ble           .Lprint_loop_fixed
        pop           {r3-r7, pc}
        // 0.05 in fix32.
.L.05.fix32:
        .word         0x0ccccccc
        // Our printf string. We replace the X when we use it.
.Lprintf_str_fixed:
        .asciz        "X%.2f"
        .section ".testsuite_unscored","ax",%progbits
.macro $TEST str
        adr           r0, 1f
        bl            puts
        adr           r0, 1f
        bl            silly_stocks_fixed
        movs          r0, #'\n'
        bl            putchar
        b             2f
        .align 2
1:
        .asciz        "\str"
.align 2
2:
.endm
        .align 2
        .globl main
        .thumb_func
main:
        push          {r4, lr}
        $TEST         "AABaBbba"
        $TEST         "DGdg"
        $TEST         "ADJdja"
        pop           {r4, pc}
```
For the reference, here is the results for float vs fixed point at 6 digits of precision.
```
AABaBbba
float: A:7.488484,B:2.474079,
fixed: A:7.488434,B:2.474060,
DGdg
float: D:5.125000,G:-0.131250,
fixed: D:5.124969,G:-0.131256,
ADJdja
float: A:2.237828,D:5.381250,J:-0.137812,
fixed: A:2.237808,D:5.381226,J:-0.137817,
```
[Answer]
# [Perl 5](https://www.perl.org/) `-MList::Util=pairmap -F`, 80 bytes
```
$p=50;map{$k{uc$_}+=$q=95>ord?-$p:$p;$p-=$q/20}@F;pairmap{printf"$a:%.2f ",$b}%k
```
[Try it online!](https://tio.run/##LY1BC4IwGEDv/oqITyxKW8IObaxSxCDq2DlmZixNv@Y6iX@9ZdHpwePBw6uuqLWAghL@kNhB2b0ucO5nAp5iRdeNzjc@IAPkgP4gFyHptylHqfS3R61qU4xBMjcIi9F4Dlnvlpb/vOdxtxSTKbdRFMs4y6ST7PKbEyX7/C7fDRrV1K31jzQgSzLwoFrD2MmoSvwH1q/SDw "Perl 5 ‚Äì Try It Online")
[Answer]
# Javascript (ES6, Node.js), 136 bytes
## Source
```
s=>(m=50,a={},[...s].map(p=>(u=p.toUpperCase(),n=p==u?1:-1,a[u]=(a[u]||0)-m*n,m*=1+n/20)),Object.keys(a).map(k=>a[k]=a[k].toFixed(2)),a)
```
## Explanation
```
f=s=>( // (s)tring
    m=50, // stock value (m)oney
    a={}, // (a)ll people
    [...s].map(
        p=>(
            u=p.toUpperCase(), // (u)ppercase: used to group buys and sells for each person
            n=p==u?1:-1, // sig(n): 1 for buy, -1 for sell
            a[u]=(a[u]||0)-m*n, // adjust balance with stock value and sign
            m*=1+n/20 // adjust stock value
        )
    ),
    Object.keys(a).map(k=>a[k]=a[k].toFixed(2)), // round profits
    a // return profits
)
```
## Proof
```
f=s=>(m=50,a={},[...s].map(p=>(u=p.toUpperCase(),n=p==u?1:-1,a[u]=(a[u]||0)-m*n,m*=1+n/20)),Object.keys(a).map(k=>a[k]=a[k].toFixed(2)),a)
const TESTS = [
    ['AABaBbba',{A:'7.49',B:'2.47'}],
    ['DGdg',{D:'5.13',G:'-0.13'}],
    ['ADJdja',{A:'2.24',D:'5.38',J:'-0.14'}]
]
TESTS.forEach(([input,expected])=>{
    console.log(input);
    console.log(expected);
    console.log(f(input))
});
```
[Answer]
# Japt, ~~91~~ 84 bytes
```
A=[]J=50¬°AhD=Xc %H(X<'_?[AgD ¬™0 -JJ*=1.05]:[AgD +JJ*=.95] g};A¬£X¬©[Y+I d X*L r /L]} f
```
Based on my JS answer. [Try it online!](http://ethproductions.github.io/japt?v=master&code=QT1bXUo9NTChQWhEPVhjICVIKFg8J18/W0FnRCCqMCAtSkoqPTEuMDVdOltBZ0QgK0pKKj0uOTVdIGd9O0GjWKlbWStJIGQgWCpMIHIgL0xdfSBm&input=IkFBQmFCYmJhIg==)
[Answer]
# [J](http://jsoftware.com/), 64 bytes
```
tolower(~.@[,.(0j2":_50*+/)/.)](]*1*/\@}:@,1+0.05*])_1+2*91>3&u:
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/S/Jz8stTizTq9ByidfQ0DLKMlKziTQ20tPU19fU0YzVitQy19GMcaq0cdAy1DfQMTLViNeMNtY20LA3tjNVKrf5rcqUmZ@QrpCmoOzo6JTolJSWqg0XU1eESLu4p6RiCji5eKVlAtVz/AQ "J ‚Äì Try It Online")
]


[Question]
      [
*Inspired by [this](http://chat.stackexchange.com/transcript/240?m=26561376#26561376) conversation in chat.*
Your goal in this challenge is to emulate a ninja and count how many deaths he has left.
## Specs
You ninja starts out with 9 deaths left. He also gets an integral starting health as an input.
Then, he takes as input a list of events in his life that alter his health. These can be negative, positive, or zero integers.
At any point, if his health reaches at or below zero, he loses a life and his health goes back to the starting health.
Your program should report the number of deaths he has left. If he has zero or less left, you should output `dead` instead.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code in **bytes** wins!
## Test Cases
```
3, [] -> 9
100, [-20, 5, -50, 15, -30, -30, 10] -> 8
10, [-10, -10, -10, -10] -> 5
10, [-10, -10, -10, -10, -10, -10, -10, -10, -10] -> dead
0, [] -> dead
0, [1] -> dead
100, [10, -100] -> 9
```

[Answer]
# [Jelly](http://github.com/DennisMitchell/jelly), ~~30~~ ~~28~~ 26 [bytes](https://github.com/DennisMitchell/jelly/blob/master/docs/code-page.md)
```
»0o⁴+
;@ñ\<1S_9«0N“dead”×?
```
[Try it online!](http://jelly.tryitonline.net/#code=wrswb-KBtCsKO0DDsVw8MVNfOcKrME7igJxkZWFk4oCdw5c_&input=&args=Wy0yMCwgNSwgLTUwLCAxNSwgLTMwLCAtMzAsIDEwXQ+MTAw)
### How it works
```
;@ñ\<1S_9«0N“dead”×?  Main link. Input: e (events), h (initial health)
;@                    Prepend h to e.
  ñ\                  Reduce the resulting array by the next, dyadic link.
                      This returns the array of intermediate results.
    <1                Check each intermediate value for non-positivity.
      S               Sum. This calculates the number of event deaths.
       _9             Subtract 9 from the result.
         «0           Take the minimum of the result and 0. This yields 0 if no
                      lives are left, the negated amount of lives otherwise.
                   ?  Conditional:
                  ×     If the product of the minimum and h is non-zero:
           N              Return the negated minimum.
            “dead”      Else, return "dead".
»0o⁴+                 Dyadic helper link. Arguments: x, y
»0                    Take the maximum of x and 0.
                      This yields x if x > 0 and 0 otherwise.
  o⁴                  Take the logical OR of the result and the second input (h).
    +                 Take the sum of the result and y.
```
[Answer]
# Japt, ~~40~~ ~~39~~ 32 bytes
```
U¬©(9-Vf@T=X+(T¬²ªU)<1} l)¬²ª`Ü%
```
[Try it online!](http://ethproductions.github.io/japt?v=master&code=VaypKDktVmZAVD1YKyhUrLKqVSk8MX0gbCmssqpg3CU=&input=MTAsIFstMTAsIC0xMCwgLTEwLCAtMTAsIC0xMCwgLTEwLCAtMTAsIC0xMCwgLTEwXQ==)
### How it works
While trying to golf this last night (away from a computer, no less), I ran across an interesting replacement for `>0`: `¬`. On numbers, this takes the square root, which returns `NaN` for negative numbers. `NaN` is falsy, so this returns exactly the same truthily/falsily as `>0`.
Extending this trick a little further, we can reset T to U iff it's `>=0` in only five bytes: `T¬²ªU`. How does this work? Let's take a look:
```
T    ¬      ²       ªU
     sqrt   square  if falsy, set to U (JS's || operator)
4    2      4       4
7   ~2.646  7       7
0    0      0       U
-4   NaN    NaN     U
-7   NaN    NaN     U
```
As you can see, `T¬²` returns `NaN` if `T` is negative; otherwise, it returns `T`. Since `NaN` and `0` are both falsy, this provides an easy way to reset the ninja's health with `ªU`. This trick is also used to return the ninja's lives left if that number is positive, or `"dead"` if negative.
Putting this all together:
```
           // Implicit: U = starting health, V = events, T = 0
U¬©        // If U is positive,
Vf@     }  // Filter out the items X in V that return truthily from this function:
 T=X+      //  Set T to X plus
 (T¬²ªU)   //   If T is positive, T; otherwise, U.
           //  This keeps a running total of the ninja's health, resetting upon death.
 <1        //  Return (T < 1).
9-    l)   // Take the length of the resulting array and subtract from 9.
           // This returns the number of lives the ninja has left.
¬²         // If the result is negative, set it to NaN.
ª`Ü%       // If the result of EITHER of the two parts above is falsy, return "dead".
           //  (`Ü%` is "dead" compressed.)
           // Otherwise, return the result of the middle part (lives left).
           // Implicit: output last expression
```
If the input is guaranteed to be non-negative, or even positive, we can golf of 1 or 4 bytes:
```
U©(9-Vf@T=X+(T¬²ªU)<1} l)¬²ª`Ü%  // U is non-negative
9-Vf@T=X+(T¬²ªU)<1} l)¬²ª`Ü%     // U is positive
```
[Answer]
## JavaScript ES6, ~~62 60~~ 58 bytes
*Saved 4 bytes thanks to @ETHproductions*
```
(a,b,d=9,l=a)=>b.map(i=>l=l+i<1?d--&&a:l+i,a)|d<1?"dead":d
```
[Try it online](http://vihanserver.tk/p/esfiddle/?code=f%3D%20(a%2Cb%2Cd%3D9)%3D%3E(b.reduce((l%2Ci)%3D%3El%2Bi%3C1%3F(d--%2Ca)%3Al%2Bi%2Ca)%2Cd%3C1%3F%22dead%22%3Ad)%3B%0A%0Af(%20100%2C%20%5B-20%2C%205%2C%20-50%2C%2015%2C%20-30%2C%20-30%2C%2010%5D%20)) (All browsers work)
## Explanation
```
(a,b,    // a = 1st input, b = 2nd input
 d=9)=>  // Lives counter
  (b.reduce((l,i)=>     // Loop through all the health changes
    l+i<1                 // If (health + health change) < 1
    ?(d--,a)              // Decrease life, reset health
    :l+i                  // Return new health
  ,a)                   // Sets starting health to `a`
  ,d<1?        // Lives is less than 1
   "dead":d);  // Output "dead" otherwise lives left
```
[Answer]
# CJam, 35 bytes
```
q~_@{+_1<{W$}&}/](\,_A<@*A@-"dead"?
```
[Try it online!](http://cjam.tryitonline.net/#code=cX5fQHsrXzE8e1ckfSZ9L10oXCxfQTxAKkFALSJkZWFkIj8&input=Wy0yMCA1IC01MCAxNSAtMzAgLTMwIDEwXSAxMDA)
[Answer]
## Haskell, ~~81~~ ~~77~~ 75 bytes
```
p l i h a|l<1="dead"|i<1=p(l-1)h h a|[]<-a=show l|x:y<-a=p l(i+x)h y
p 10 0
```
Usage example: `p 10 0 100 [-20, 5, -50, 15, -30, -30, 10]` -> `"8"`
[Answer]
# Pyth, 32
```
 u+?>GZG&=hZQH+E0Q?&Q<Z9-9Z"dead
```
Note that there is a leading space. This probably isn't the best approach, but it was the first thing that came to mind. It reduces over input by adding the values to the ninja's health, and incrementing a counter and resetting the health when it drops below zero. We add a zero to the end of the list to count if the last change kills the ninja, and then just do some checking to see if the ninja is dead. The zero starting health case is hard coded.
[Test Suite](https://pyth.herokuapp.com/?code=%20u%2B%3F%3EGZG%26%3DhZQH%2BE0Q%3F%26Q%3CZ9-9Z%22dead&input=3%0A%5B%5D&test_suite=1&test_suite_input=3%0A%5B%5D%0A100%0A%5B-20%2C%205%2C%20-50%2C%2015%2C%20-30%2C%20-30%2C%2010%5D%0A10%0A%5B-10%2C%20-10%2C%20-10%2C%20-10%5D%0A10%0A%5B-10%2C%20-10%2C%20-10%2C%20-10%2C%20-10%2C%20-10%2C%20-10%2C%20-10%2C%20-10%5D%0A0%0A%5B%5D%0A0%0A%5B1%5D%0A100%0A%5B10%2C%20-100%5D&debug=0&input_size=2)
[Answer]
# MATL, 32
```
9yi"@+t0>~?x1-y]]g*wxt0>~?x'dead'
```
## Explanation
```
9        # push 9
y        # duplicate 2nd value to top (there is none -> get it from input first)
i        # get input and push it
```
The stack now looks like this (for input `100, [-20, 5, -50, 15, -30, -30, 10]`):
```
100        9        100        [-20, 5, -50, 15, -30, -30, 10]
reload   deaths    health
value    left
```
Pop the array and loop
```
"            ]    # loop
 @+               # add to health
   t0>~?    ]     # if health is zero or less
        x1-y      # delete health counter, decrement life counter, reload health
```
If the health is zero, set death counter to zero. Special case handling for `initial health = 0`.
```
g        # health to bool
*        # multiply with death counter
```
Delete the reload value from stack
```
wx
```
If the death counter is zero or less, delete it and print 'dead' instead.
```
t0>~?x'dead'
```
[Answer]
# [TeaScript](http://github.com/vihanb/teascript), ~~36 34~~ 31 bytes
```
yR#l+i<1?e─·x:l+i,x);e≥0?e:D`Ü%
```
Similar to my JavaScript answer. the last 4 characters are the decompression of the string "dead".
TeaScript's online interpreter doesn't support array input so you're going to need to open the console, and run this by typing:
```
TeaScript( `yR#l+i<1?(e─,x):l+i,x);─e>0?e:D\`Ü%` ,[
  10, [-10, -10, -10, -10]
],{},TEASCRIPT_PROPS);
```
### Explanation
```
      // Implicit: x = 1st input, y = 2nd input
yR#   // Reduce over 2nd input
  l+i<1?  // If pending health is less then 1
  (e─,x): // then, decrease life counter, reset health
  l+i     // else, modify health
,x);  // Set starting health
─e>0? // Ninja is alive?
e:    // Output lives left
D`Ü%  // Decompress and output "dead"
```
[Answer]
## Python 2.7, 82 66 55 106 bytes
*Thanks to @RikerW for -16 bytes.:(*
*Thanks to @Maltysen for -11 bytes. :(*
```
i=input;h=[i()]*9;d=i()
if 0==h[0]:print'dead';exit()
for x in d:
 h[0]+=x
 if h[0]<=0:h=h[1:]
y=len(h)
print['dead',y][y!=0]
```
First type health, then enter, then events in list form.
[Answer]
## C# 207
```
class P{static void Main(string[]a){int h=int.Parse(a[0]),H=h,l=9,i=1;if(a.Length!=1){for(;i<a.Length;i++){H+=int.Parse(a[i]);if(H<=0){l--;H=h;}}}System.Console.Write(h==0?"dead":l<=0?"dead":l.ToString());}}
```
Takes the input through argument stream. The first argument is the amount of health and all the rest is the list of events.
Readable / ungolfed version
```
class Program
{
    static void Main(string[]a)
    {
        int health = int.Parse(a[0]);
        int Health = health;
        int lives = 9;
        if(a.Length!=1)
        {
            for (int i = 1;i < a.Length;i++)
            {
                Health += int.Parse(a[i]);
                if (Health <= 0)
                {
                    lives--;
                    Health = health;
                }
            }
        }
        System.Console.Write(health == 0 ? "dead" : lives <= 0 ? "dead" : lives.ToString());
    }
}
```
Examples:
* CSharp.exe 3 => 9
* CSharp.exe 100 -20 5 -50 15 -30 -30 10 => 8
(Psst.) CSharp.exe is name used as an example. You have to call like this in reality: [program\_name.exe] arguments, without the square parentheses.
]


[Question]
      [
The [Cheela](http://aliens.wikia.com/wiki/Cheela) (from the book [*Dragon's Egg*](https://en.wikipedia.org/wiki/Dragon%27s_Egg) by Robert L. Forward) are creatures that live on the surface of a neutron star. Their body is flat and circular with twelve eyes on the perimeter, so they naturally use a base-12 numbering system.
Among the Cheela, care of the hatchlings and education of the young are tasks carried out by the Old Ones. Since young Cheela need to be taught how to multiply, the Old Ones could use a multiplication table.
Your task is to produce a `12`x`12` multiplication table in base `12`, like the following. Uppercase letters `A` and `B` are used for digits corresponding to decimal `10` and `11` respectively.
```
  1   2   3   4   5   6   7   8   9   A   B  10
  2   4   6   8   A  10  12  14  16  18  1A  20
  3   6   9  10  13  16  19  20  23  26  29  30
  4   8  10  14  18  20  24  28  30  34  38  40
  5   A  13  18  21  26  2B  34  39  42  47  50
  6  10  16  20  26  30  36  40  46  50  56  60
  7  12  19  24  2B  36  41  48  53  5A  65  70
  8  14  20  28  34  40  48  54  60  68  74  80
  9  16  23  30  39  46  53  60  69  76  83  90
  A  18  26  34  42  50  5A  68  76  84  92  A0
  B  1A  29  38  47  56  65  74  83  92  A1  B0
 10  20  30  40  50  60  70  80  90  A0  B0 100
```
The output shoud be printed on screen. The format should be as follows:
1. Numbers should be aligned to the right within each column.
2. Leading spaces before the first column, trailing spaces after the last column, or a trailing new line after the last row are allowed.
3. Separation between columns can be one space (as shown above) or more than one space, but the number of spaces should be consistent between columns. To measure column separation, consider that displayed numbers include any leading spaces that may have been necessary fo fulfill requirement 1 (so each number occupies three characters, the first of which may be spaces). For example, the table with two-space separation would be as follows:
```
  1    2    3    4    5    6    7    8    9    A    B   10
  2    4    6    8    A   10   12   14   16   18   1A   20
  3    6    9   10   13   16   19   20   23   26   29   30
  4    8   10   14   18   20   24   28   30   34   38   40
  5    A   13   18   21   26   2B   34   39   42   47   50
  6   10   16   20   26   30   36   40   46   50   56   60
  7   12   19   24   2B   36   41   48   53   5A   65   70
  8   14   20   28   34   40   48   54   60   68   74   80
  9   16   23   30   39   46   53   60   69   76   83   90
  A   18   26   34   42   50   5A   68   76   84   92   A0
  B   1A   29   38   47   56   65   74   83   92   A1   B0
 10   20   30   40   50   60   70   80   90   A0   B0  100
```
Computer storage on a neutron star is really expensive, so your code should use as few bytes as possible.
## Extended challenge and bonus
Ideally your code should be reused in other parts of the universe, where other numbering systems may be in use. To that end, the challenge is optionally extended as follows: Your code accepts a number `N` as input and generates an `N`x`N` multiplication table in base `N`, with the above format.
Input may be from keyboard or as a function argument. The program or function should work for `2` ‚â§ `N` ‚â§ `36`, using as digits the first `N` characters of the sequence `0`, `1`, ..., `9`, `A`, `B`, ..., `Z` (uppercase letters)
This extended challenge is optional. If you follow this route, take 20% off your byte count (no need to round to an integer number).

[Answer]
# Pyth, 27 \* 0.8 = 21.6
```
VSQsm.[\ 4jkXj*dNQrT99rG1SQ
```
Try it online: [Demonstration](https://pyth.herokuapp.com/?code=VSQsm.%5B%5C%204jkXj%2AdNQrT99rG1SQ&input=12&debug=0)
### Explanation:
```
VSQsm.[\ 4jkXj*dNQrT99rG1SQ   implicit: Q = input number
VSQ                           for N in [1, 2, ..., Q]:
    m                    SQ      map each number d in [1, 2, ..., Q] to:
              *dN                   N * d
             j   Q                  in base Q
            X     rT99rG1           replace the numbers [10, 11, ..., 98] with "A...Z"
          jk                        join to a string
     .[\ 4                          prepend spaces, so that the string has a length of 4
   s                             join all strings and print
```
[Answer]
## CJam, 33 \* 0.8 = 26.4 bytes
```
ri:C,:)_ff{*Cb{_9>{'7+}&}%4Se[}N*
```
[Test it here.](http://cjam.aditsu.net/#code=ri%3AC%2C%3A)_ff%7B*Cb%7B_9%3E%7B'7%2B%7D%26%7D%254Se%5B%7DN*&input=32)
This uses the minimum required separation.
### Explanation
```
ri:C        e# Read input, convert to integer, store in C.
,:)         e# Get range [1 2 ... C].
_ff{        e# 2D-map over all repeated pairs from that range...
  *Cb       e#   Multiply, convert to base C.
  {         e#   Map over the digits...
    _9>     e#     Check if the digit is greater than 9.
    {'7+}&  e#     If so, add the digit to the character "7", to get "A" to "Z".
  }%
  4Se[      e#   Pad the digits with spaces from the left, to 4 elements.
}
N*          e# Join with linefeeds.
```
Table for input `22` (the largest that fits in the post without a horizontal scrollbar):
```
   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F   G   H   I   J   K   L  10
   2   4   6   8   A   C   E   G   I   K  10  12  14  16  18  1A  1C  1E  1G  1I  1K  20
   3   6   9   C   F   I   L  12  15  18  1B  1E  1H  1K  21  24  27  2A  2D  2G  2J  30
   4   8   C   G   K  12  16  1A  1E  1I  20  24  28  2C  2G  2K  32  36  3A  3E  3I  40
   5   A   F   K  13  18  1D  1I  21  26  2B  2G  2L  34  39  3E  3J  42  47  4C  4H  50
   6   C   I  12  18  1E  1K  24  2A  2G  30  36  3C  3I  42  48  4E  4K  54  5A  5G  60
   7   E   L  16  1D  1K  25  2C  2J  34  3B  3I  43  4A  4H  52  59  5G  61  68  6F  70
   8   G  12  1A  1I  24  2C  2K  36  3E  40  48  4G  52  5A  5I  64  6C  6K  76  7E  80
   9   I  15  1E  21  2A  2J  36  3F  42  4B  4K  57  5G  63  6C  6L  78  7H  84  8D  90
   A   K  18  1I  26  2G  34  3E  42  4C  50  5A  5K  68  6I  76  7G  84  8E  92  9C  A0
   B  10  1B  20  2B  30  3B  40  4B  50  5B  60  6B  70  7B  80  8B  90  9B  A0  AB  B0
   C  12  1E  24  2G  36  3I  48  4K  5A  60  6C  72  7E  84  8G  96  9I  A8  AK  BA  C0
   D  14  1H  28  2L  3C  43  4G  57  5K  6B  72  7F  86  8J  9A  A1  AE  B5  BI  C9  D0
   E  16  1K  2C  34  3I  4A  52  5G  68  70  7E  86  8K  9C  A4  AI  BA  C2  CG  D8  E0
   F  18  21  2G  39  42  4H  5A  63  6I  7B  84  8J  9C  A5  AK  BD  C6  CL  DE  E7  F0
   G  1A  24  2K  3E  48  52  5I  6C  76  80  8G  9A  A4  AK  BE  C8  D2  DI  EC  F6  G0
   H  1C  27  32  3J  4E  59  64  6L  7G  8B  96  A1  AI  BD  C8  D3  DK  EF  FA  G5  H0
   I  1E  2A  36  42  4K  5G  6C  78  84  90  9I  AE  BA  C6  D2  DK  EG  FC  G8  H4  I0
   J  1G  2D  3A  47  54  61  6K  7H  8E  9B  A8  B5  C2  CL  DI  EF  FC  G9  H6  I3  J0
   K  1I  2G  3E  4C  5A  68  76  84  92  A0  AK  BI  CG  DE  EC  FA  G8  H6  I4  J2  K0
   L  1K  2J  3I  4H  5G  6F  7E  8D  9C  AB  BA  C9  D8  E7  F6  G5  H4  I3  J2  K1  L0
  10  20  30  40  50  60  70  80  90  A0  B0  C0  D0  E0  F0  G0  H0  I0  J0  K0  L0 100
```
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 42\*.8 = 33.6
### Disclaimer
*Since the creator of the language and the author of the challenge are the same, this answer is not eligible for winning*.
*For a discussion on whether this restriction is necessary or not, see [this meta question](http://meta.codegolf.stackexchange.com/questions/7760/can-you-post-a-challenge-and-answer-in-a-language-you-designed).*
### Code
```
iXK:t!*Y)KYAZ{'(?<=^0*)0'32cYXZc32hK4*[]e!
```
This uses the minimum separation.
### Example
Octal multiplication table
```
>> matl
 > iXK:t!*Y)KYAZ{'(?<=^0*)0'32cYXZc32chK4*[]e!
 >
> 8
  1   2   3   4   5   6   7  10
  2   4   6  10  12  14  16  20
  3   6  11  14  17  22  25  30
  4  10  14  20  24  30  34  40
  5  12  17  24  31  36  43  50
  6  14  22  30  36  44  52  60
  7  16  25  34  43  52  61  70
 10  20  30  40  50  60  70 100
```
### Explanation
```
i              % input number, say n
XK             % copy to clipboard K
:              % vector 1, 2, ... n
t!*            % generate table: duplicate, transpose and multiply with broadcasting
Y)             % linearize into column array
KYA            % paste n from clipboard K. Convert to that base
Z{             % cell array of rows from array
'(?<=^0*)0'    % string literal for regexp replacement: find leading zeros
32c            % space character (for regexp replacement)
YX             % regexp replacement
Zc             % join cell array of strings into single string
32             % code for space character. Conversion to char happens automatically
h              % concatenate horizontally
K4*[]e!        % paste n and multiply by 4. Reshape into 2D char array with 4*n columns
```
### Edit: [Try it online!](http://matl.tryitonline.net/#code=aVhLOnQhKlg6S1lBWnsnKD88PV4wKikwJzMyY1lYWmMzMmhLNCplIQ&input=MTI)
To run in the online compiler (as of February 19, 2016), change `Y)` to `X:`, and remove `[]`. This is to adapt to changes that have been made to the language since this challenge was posted.
[Answer]
# Bash + BSD utilities, 36
```
echo Co{1..12}d{1..12}*p|dc|rs -j 12
```
Works out-of-the-box on OS X. `rs` may need to be installed on Linux systems.
* Bash expands `Co{1..12}d{1..12}*p` to `Co1d1*p Co1d2*p Co1d3*p ... Co1d12*p ... Co12d12*p`.
* This is a `dc` expression that generates the required terms. `Co` sets output base to 12. `d` is used as a separator between numbers instead of a space, so no escape is required in the brace expansion. `d` actually duplicates the top of stack, but this is effectively ignored and discarded.
* The output from `dc` is a single space-separated line. `rs` reshapes this to a 12x12 array. `-j` right-justifies each term.
[Answer]
# Pyth, 36 bytes
```
Km+1dUJ12rjbmjkm.[\ 4j""m.Hbj*dkJKK1
```
[Try it here.](http://pyth.herokuapp.com/?code=Km%2B1dUJ12rjbmjkm.%5B+4j%22%22m.Hbj*dkJKK1&debug=0)
[Answer]
## Python, ~~153~~ ~~147~~ 132 bytes \* 0.8 = 105.6
```
def p(b):
 f=lambda n:(n>=b and f(n/b)or'')+chr((48,55)[n%b>9]+n%b)
 for i in range(b*b):print'%4s\n'[:3+(~i%b<1)]%f(~(i%b)*~(i/b)),
```
Down to 132 bytes thanks to the advice of Tim Pederick! :)
[Answer]
# CJam, ~~38~~ ~~33~~ ~~32~~ 38 \* (.8) = 30.4 bytes
```
qi:D,:):L{Lf*{Db{_9>{55+c}&}%4Se[}%N}%
```
[Try it here.](http://cjam.aditsu.net/#code=qi%3AD%2C%3A)%3AL%7BLf*%7BDb%7B_9%3E%7B55%2Bc%7D%26%7D%254Se%5B%7D%25N%7D%25&input=12)
(Looks pretty similar to Martin's now.)
```
qi:D,:):L          e# Generate list of [1...input]
{Lf*               e# Take each number in that list and multiply it by the same list ([[1,2,3,..,input][2,4,6,...,input],...})
{Db{_9>{55+c}&}%   e# Convert each product to base input. If a digit value is >= 10 add 55 and convert to char, to make it a letter.
4Se[}%N}%          e# Pad each number with spaces to length 4. Put a newline after each row.
```
[Answer]
# [Perl 6](http://perl6.org), 60 bytes -20% = 48 bytes
```
{.put for (1..$_ X*1..$_)¬ª.base($_)¬ª.fmt('%3s').rotor($_)} # 60-20% = 48
#          ^-----------^ produce a list of two cross multiplied lists
#                        ^--------^ convert each to base N
#          format each to 3 spaces ^----------^
#         split the list into N element chunks ^--------^
#^-------^ print each of those on their own line with spaces between elements
```
( This is almost exactly how I would write it even if I wasn't trying to get it as short as I could )
Usage:
```
{...}(2)
  1  10
 10 100
```
```
my &code = {...}
code 2;
  1  10
 10 100
```
```
{...}(12);
  1   2   3   4   5   6   7   8   9   A   B  10
  2   4   6   8   A  10  12  14  16  18  1A  20
  3   6   9  10  13  16  19  20  23  26  29  30
  4   8  10  14  18  20  24  28  30  34  38  40
  5   A  13  18  21  26  2B  34  39  42  47  50
  6  10  16  20  26  30  36  40  46  50  56  60
  7  12  19  24  2B  36  41  48  53  5A  65  70
  8  14  20  28  34  40  48  54  60  68  74  80
  9  16  23  30  39  46  53  60  69  76  83  90
  A  18  26  34  42  50  5A  68  76  84  92  A0
  B  1A  29  38  47  56  65  74  83  92  A1  B0
 10  20  30  40  50  60  70  80  90  A0  B0 100
```
```
{...}(18);
  1   2   3   4   5   6   7   8   9   A   B   C   D   E   F   G   H  10
  2   4   6   8   A   C   E   G  10  12  14  16  18  1A  1C  1E  1G  20
  3   6   9   C   F  10  13  16  19  1C  1F  20  23  26  29  2C  2F  30
  4   8   C   G  12  16  1A  1E  20  24  28  2C  2G  32  36  3A  3E  40
  5   A   F  12  17  1C  1H  24  29  2E  31  36  3B  3G  43  48  4D  50
  6   C  10  16  1C  20  26  2C  30  36  3C  40  46  4C  50  56  5C  60
  7   E  13  1A  1H  26  2D  32  39  3G  45  4C  51  58  5F  64  6B  70
  8   G  16  1E  24  2C  32  3A  40  48  4G  56  5E  64  6C  72  7A  80
  9  10  19  20  29  30  39  40  49  50  59  60  69  70  79  80  89  90
  A  12  1C  24  2E  36  3G  48  50  5A  62  6C  74  7E  86  8G  98  A0
  B  14  1F  28  31  3C  45  4G  59  62  6D  76  7H  8A  93  9E  A7  B0
  C  16  20  2C  36  40  4C  56  60  6C  76  80  8C  96  A0  AC  B6  C0
  D  18  23  2G  3B  46  51  5E  69  74  7H  8C  97  A2  AF  BA  C5  D0
  E  1A  26  32  3G  4C  58  64  70  7E  8A  96  A2  AG  BC  C8  D4  E0
  F  1C  29  36  43  50  5F  6C  79  86  93  A0  AF  BC  C9  D6  E3  F0
  G  1E  2C  3A  48  56  64  72  80  8G  9E  AC  BA  C8  D6  E4  F2  G0
  H  1G  2F  3E  4D  5C  6B  7A  89  98  A7  B6  C5  D4  E3  F2  G1  H0
 10  20  30  40  50  60  70  80  90  A0  B0  C0  D0  E0  F0  G0  H0 100
```
[Answer]
# JavaScript (ES6) 84 (105-20%)
The obvious way, to begin with.
```
n=>{for(o=i=``;i++<n;o+=`
`)for(j=0;j++<n;)o+=(`   `+(i*j).toString(n)).slice(-4).toUpperCase();alert(o)}
```
Notes
* It's a pity js toString produce lowercase letters
* `alert` is not the best way to output the table, but it's the shorter, as there is an explicit request to "display on screen"
* Just returning the value would be a couple bytes shorter.
**Less golfed**
```
n=>{
  for(o='', i=0; i++<n; o+='\n')
    for(j=0;j++<n;)
       o+=('   '+(i*j).toString(n)).slice(-4).toUpperCase()
  alert(o)
}
```
[Answer]
## Python 3, 126 - 20% = 100.8 bytes
The outer function, `t`, is the one that actually prints the multiplication table. The inner function, `i`, does the conversion of a number to a base from 2 to 36.
```
def t(b):
 i=lambda n:(n>=b and i(n//b)or'')+chr(n%b+[48,55][n%b>9]);R=range(b)
 for r in R:print(*('%3s'%i(~r*~c)for c in R))
```
Hat tip to Boomerang for [their solution](https://codegolf.stackexchange.com/a/67191/13959), and for a golfing tip. I avoided copying anything from Boomerang's solution, but I did allow myself glances at it to see where I could trim more out. And even before that, I found that the more I golfed it, the more mine started to look like Boomerang's!
[Answer]
# Javascript (ES6) 96.8 93.6 Bytes (20% of 117)
```
n=>{b='';for(i=0;i++<n;b+=`\n`)for(j=0;j++<n;)a=(i*j).toString(n).toUpperCase(),b+=' '.repeat(4-a.length)+a;alert(b)}
```
## Explanation
```
n=>
    {
      b='';                                    //clear table var at each run
      for(i=0;i++<n;b+=`\n`)                   //iterate through rows
        for(j=0;j++<n;)                        //iterate through cols
          a=(i*j).toString(n).toUpperCase(),   //get desired number
          b+=' '.repeat(4-a.length)+a";        //pad to right
    alert(b)                                   //display result
}
```
-*saved 4 bytes thanks to @edc65*
[Answer]
## MATLAB, 111\*0.8=88.8 110\*0.8=88 bytes
My debut here:
```
@(N)disp(reshape(strrep(strrep([' ',strjoin(cellstr(dec2base([1:N]'*[1:N],N)))],' 0','  '),' 0','  '),4*N,N)')
```
Explanation:
`[1:N]'*[1:N]` make multiplication table in base 10
`dec2base([1:N]'*[1:N],N)` convert to base 12. The output is char array with leading 0-s
`strjoin(cellstr(dec2base(___)))` convert to cell and back to char joining strings with space yielding 1x575 string
`[' ',strjoin(___)]` append space to have 576 elements
`strrep(___,' 0',' ')` remove one leading zero. We do it twice because we have strings with two leading zeros
`reshape(___,4*N,N)'` convert 1x576 char array into 48x12 char array
`disp(___)` display the result without `ans =`
Output:
```
 1   2   3   4   5   6   7   8   9   A   B  10
 2   4   6   8   A  10  12  14  16  18  1A  20
 3   6   9  10  13  16  19  20  23  26  29  30
 4   8  10  14  18  20  24  28  30  34  38  40
 5   A  13  18  21  26  2B  34  39  42  47  50
 6  10  16  20  26  30  36  40  46  50  56  60
 7  12  19  24  2B  36  41  48  53  5A  65  70
 8  14  20  28  34  40  48  54  60  68  74  80
 9  16  23  30  39  46  53  60  69  76  83  90
 A  18  26  34  42  50  5A  68  76  84  92  A0
 B  1A  29  38  47  56  65  74  83  92  A1  B0
10  20  30  40  50  60  70  80  90  A0  B0 100
```
If we don't count statement `N=12;`, `5*.8=4` bytes are saved. Also, if `ans =` output is tolerated, then we can remove `disp()` saving another `6*0.8=4.8` bytes. Of course, there may be other ways to save bytes :)
[Answer]
# Python 3: ~~166~~ ~~161~~ 152 - 20% = 121.6 bytes
I know it's inferior to the existing Python answers but I figured to give it a shot. It's my first time posting on this site‚Ä¶
```
def t(b):
 r=range(1,b+1);f=lambda x:x and f(x//b)+chr((55,48)[x%b>9]+x%b)or''
 print('\n'.join(''.join(B)for B in(('%4s'%f(i*j)for j in r)for i in r)))
```
[Answer]
## APL, ~~32~~ 31√ó0.8=24.8 [bytes](http://meta.codegolf.stackexchange.com/a/9429/43319)
```
{¬Ø4‚Üë¬®‚äÉ‚àò(‚éïD,‚éïA)¬®¬®‚çµ‚ä•‚ç£¬Ø1¬®‚àò.√ó‚ç®1+‚ç≥‚çµ}
```
In origin 0.
In English:
* `‚àò.√ó‚ç®1+‚ç≥‚çµ`: multiplication table
* `‚çµ‚ä•‚ç£¬Ø1¬®`: express in base ‚çµ each element of the multiplication table
* `‚äÉ‚àò(‚éïD,‚éïA)¬®¬®`: convert the table of vector of numbers into a table of vectors of chars
* `¬Ø4‚Üë¬®`: right align to length 4 each element of the result
The default APL print routine does the right thing.
```
      {¬Ø4‚Üë¬®(‚çµ‚ä•‚ç£¬Ø1¬®‚àò.√ó‚ç®1+‚ç≥‚çµ)‚äÉ¬®¬®‚äÇ‚äÇ‚éïD,‚éïA}13
    1     2     3     4     5     6     7     8     9     A     B     C    10
    2     4     6     8     A     C    11    13    15    17    19    1B    20
    3     6     9     C    12    15    18    1B    21    24    27    2A    30
    4     8     C    13    17    1B    22    26    2A    31    35    39    40
    5     A    12    17    1C    24    29    31    36    3B    43    48    50
    6     C    15    1B    24    2A    33    39    42    48    51    57    60
    7    11    18    22    29    33    3A    44    4B    55    5C    66    70
    8    13    1B    26    31    39    44    4C    57    62    6A    75    80
    9    15    21    2A    36    42    4B    57    63    6C    78    84    90
    A    17    24    31    3B    48    55    62    6C    79    86    93    A0
    B    19    27    35    43    51    5C    6A    78    86    94    A2    B0
    C    1B    2A    39    48    57    66    75    84    93    A2    B1    C0
   10    20    30    40    50    60    70    80    90    A0    B0    C0   100
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 20 \$\times\$ 0.8 = 16 bytes
```
…æ:v*$œÑkdkAJƒ∞·πÖ:f√ûGL‚Ü≥‚Åã
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLJvjp2KiTPhGtka0FKxLDhuYU6ZsOeR0zihrPigYsiLCIiLCIxMiJd)
This could actually be 9\*0.8=7.2 bytes if Vyxal had a gridify builtin and a buitlin to convert to a base as a string (with letters).
[Answer]
# Ruby, ~~69~~ 66 characters - 20% = 52.8
```
->n{(r=1..n).map{|a|puts r.map{|b|"%4s"%(a*b).to_s(n).upcase}*''}}
```
Sample run:
```
2.1.5 :001 > ->n{(r=1..n).map{|a|puts r.map{|b|"%4s"%(a*b).to_s(n).upcase}*''}}[4]
   1   2   3  10
   2  10  12  20
   3  12  21  30
  10  20  30 100
```
[Answer]
# ksh93, 51 \* 0.8 == 40.8 bytes
```
eval echo "'
' {"{1..$1}'..$((++n*$1))..$n%3..$1d}'
```
This should work up to base 64 (the largest radix supported by ksh). Examples:
```
 $ n= ksh -s 12 <<\EOF
eval echo "'
' {"{1..$1}'..$((++n*$1))..$n%3..$1d}'
EOF
   1   2   3   4   5   6   7   8   9   a   b  10
   2   4   6   8   a  10  12  14  16  18  1a  20
   3   6   9  10  13  16  19  20  23  26  29  30
   4   8  10  14  18  20  24  28  30  34  38  40
   5   a  13  18  21  26  2b  34  39  42  47  50
   6  10  16  20  26  30  36  40  46  50  56  60
   7  12  19  24  2b  36  41  48  53  5a  65  70
   8  14  20  28  34  40  48  54  60  68  74  80
   9  16  23  30  39  46  53  60  69  76  83  90
   a  18  26  34  42  50  5a  68  76  84  92  a0
   b  1a  29  38  47  56  65  74  83  92  a1  b0
  10  20  30  40  50  60  70  80  90  a0  b0 100
 $ n= ksh -s 22 <<\EOF
eval echo "'
' {"{1..$1}'..$((++n*$1))..$n%3..$1d}'
EOF
   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f   g   h   i   j   k   l  10
   2   4   6   8   a   c   e   g   i   k  10  12  14  16  18  1a  1c  1e  1g  1i  1k  20
   3   6   9   c   f   i   l  12  15  18  1b  1e  1h  1k  21  24  27  2a  2d  2g  2j  30
   4   8   c   g   k  12  16  1a  1e  1i  20  24  28  2c  2g  2k  32  36  3a  3e  3i  40
   5   a   f   k  13  18  1d  1i  21  26  2b  2g  2l  34  39  3e  3j  42  47  4c  4h  50
   6   c   i  12  18  1e  1k  24  2a  2g  30  36  3c  3i  42  48  4e  4k  54  5a  5g  60
   7   e   l  16  1d  1k  25  2c  2j  34  3b  3i  43  4a  4h  52  59  5g  61  68  6f  70
   8   g  12  1a  1i  24  2c  2k  36  3e  40  48  4g  52  5a  5i  64  6c  6k  76  7e  80
   9   i  15  1e  21  2a  2j  36  3f  42  4b  4k  57  5g  63  6c  6l  78  7h  84  8d  90
   a   k  18  1i  26  2g  34  3e  42  4c  50  5a  5k  68  6i  76  7g  84  8e  92  9c  a0
   b  10  1b  20  2b  30  3b  40  4b  50  5b  60  6b  70  7b  80  8b  90  9b  a0  ab  b0
   c  12  1e  24  2g  36  3i  48  4k  5a  60  6c  72  7e  84  8g  96  9i  a8  ak  ba  c0
   d  14  1h  28  2l  3c  43  4g  57  5k  6b  72  7f  86  8j  9a  a1  ae  b5  bi  c9  d0
   e  16  1k  2c  34  3i  4a  52  5g  68  70  7e  86  8k  9c  a4  ai  ba  c2  cg  d8  e0
   f  18  21  2g  39  42  4h  5a  63  6i  7b  84  8j  9c  a5  ak  bd  c6  cl  de  e7  f0
   g  1a  24  2k  3e  48  52  5i  6c  76  80  8g  9a  a4  ak  be  c8  d2  di  ec  f6  g0
   h  1c  27  32  3j  4e  59  64  6l  7g  8b  96  a1  ai  bd  c8  d3  dk  ef  fa  g5  h0
   i  1e  2a  36  42  4k  5g  6c  78  84  90  9i  ae  ba  c6  d2  dk  eg  fc  g8  h4  i0
   j  1g  2d  3a  47  54  61  6k  7h  8e  9b  a8  b5  c2  cl  di  ef  fc  g9  h6  i3  j0
   k  1i  2g  3e  4c  5a  68  76  84  92  a0  ak  bi  cg  de  ec  fa  g8  h6  i4  j2  k0
   l  1k  2j  3i  4h  5g  6f  7e  8d  9c  ab  ba  c9  d8  e7  f6  g5  h4  i3  j2  k1  l0
  10  20  30  40  50  60  70  80  90  a0  b0  c0  d0  e0  f0  g0  h0  i0  j0  k0  l0 100
```
[Answer]
## Pyke, 14 bytes \* 0.8 = 11.2 bytes, noncompetitive
```
QhD]UA*MbQMl2P
```
[Try it here!](http://pyke.catbus.co.uk/?code=QhD%5DUA%2aMbQMl2P&input=12)
Explanation:
```
            - autoassign Q = eval_or_not_input()
QhD]        - [Q+1, Q+1]
    U       - nd_range(^)
     A*     - apply(*, ^)
       MbQ  - map(base(Q), ^)
          Ml2 - map(lower, ^)
          P - print_grid(^)
```
Or 12 bytes without the bonus
```
13D]UA*Mb12P
```
]