text:
Creating Distinct Sums
You should write a program or function which receives an integers as input and outputs or returns two integers whose sum is the first one.
There is one further requirement: no number can be part of the output for two different inputs.
Details

You should be able to handle inputs for at least the range -32768 .. 32767 (inclusive).
If your datatype can't handle arbitrary whole numbers, that is fine but your algorithm should work for arbitrary large and small numbers in theory.

Examples
Each block shows a part of a correct or incorrect solution in the format of input => output.
1 => 6 -5
2 => -2 4
15 => 20 -5

Incorrect, as `-5` is used in two outputs.

-5 => -15 10
0 => 0 0
1 => 5 6
2 => -5 7

Incorrect, as `5 + 6` isn't `1`.

-1 => -1 0
0 => 6 -6
2 => 1 1

Can be correct if other outputs doesn't collide.

This is code golf so the shortest entry wins.

Can you restrict the input range to -32768 .. 32767 so we don't have to use 17 bit integers?

@FUZxxl My bad, that was the intention. Fixed.

Can the output be a list/array/tuple/set/etc containing two integers? (  For example, f(1) => [2, -1]  )

There seem to be several solutions which fundamentally rely on a restricted integer size--for example, by multiplying the input by a large positive and a large negative number.  It seems to me that such solutions are failing the requirement that "your algorithm should work for arbitrary large and small numbers in theory".  Am I misreading the question?

Pyth, 8 bytes
_J^Q3+QJ

Demonstration. Equivalent to the Python 2 code:
Q=input()
J=Q**3
print -J
print Q+J

So, the output has form (-n**3, n+n**3)
Some outputs:
-5 (125, -130)
-4 (64, -68)
-3 (27, -30)
-2 (8, -10)
-1 (1, -2)
 0 (0, 0)
 1 (-1, 2)
 2 (-8, 10)
 3 (-27, 30)
 4 (-64, 68)
 5 (-125, 130)

These are distinct because cubes are far enough spaced that adding n to n**3 is not enough to cross the gap to the next cube :n**3 < n+n**3 < (n+1)**3 for positive n, and symmetrically for negative n.

You don't need the , at the beginning, two lines appears to be allowed.

@Maltysen I tried removing it, but only the second number prints. Maybe the J assignment suppresses printing?

Oh yeah you're right, sorry.

- in pyth is not the unary negation operator, its _, so _J^Q3+QJ works as expected.

@Maltysen Actually, that works, I just need the J to not be on the outside.  Thanks for poking me about this.

Snowman 0.1.0, 101 chars
}vg0aa@@*45,eQ.:?}0AaG0`NdE`;:?}1;bI%10sB%nM2np`*`%.*#NaBna!*+#@~%@0nG\]:.;:;bI~0-NdEnMtSsP" "sP.tSsP

Input on STDIN, space-separated output on STDOUT.
This uses the same method as isaacg's answer.
Commented version with newlines, for "readability":
}vg0aa          // get input, take the first char
@@*45,eQ.       // check if it's a 45 (ASCII for -) (we also discard the 0 here)
// this is an if-else
:               // (if)
  ?}0AaG        // remove first char of input (the negative sign)
  0`NdE`        // store a -1 in variable e, set active vars to beg
;
:               // (else)
  ?}1           // store a 1 in variable e, set active vars to beg
;bI             // active variables are now guaranteed to be beg
%10sB           // parse input as number (from-base with base 10)
%nM             // multiply by either 1 or -1, as stored in var e earlier
2np`*`          // raise to the power of 2 (and discard the 2)
%.              // now we have the original number in b, its square in d, and
                //   active vars are bdg
*#NaBna!*+#     // add abs(input number) to the square (without modifying the
                //   input variable, by juggling around permavars)
@~%@0nG\]       // active vars are now abcfh, and we have (0>n) in c (where n is
                //   the input number)
:.;:;bI         // if n is negative, swap d (n^2) and g (n^2+n)
~0-NdEnM        // multiply d by -1 (d is n^2 if n is positive, n^2+n otherwise)
tSsP            // print d
" "sP           // print a space
.tSsP           // print g

Commentary on the very first Snowman solution on PPCG: I think my design goal of making my language as confusing as possible has been achieved.
This actually could have been a lot shorter, but I'm an idiot and forgot to implement negative numbers for string -> number parsing. So I had to manually check whether there was a - as the first character and remove it if so.

Way better than Brainfuck.

How does Ostrich feel about this? ;)

Pyth, 15 11 bytes
4 bytes thanks to @Jakube
*RQ,hJ.aQ_J

Demonstration.
This maps as follows:
0  -> 0, 0
1  -> 2, -1
-1 -> -2, 1
2  -> 6, -4
-2 -> -6, 4

And so, on, always involving n^2 and n^2 + n, plus or minus.

APL, 15 bytes
{(-⍵*3)(⍵+⍵*3)}

This creates an unnamed monadic function that returns the pair -n^3 (-⍵*3), n+n^3 (⍵+⍵*3).
You can try it online.

O, 17 15 9 bytes
Uses some new features of O.
Q3^.Q+p_p
Older Version
[i#.Z3^*\Z3^)_*]o

I'm starting to enjoy these O answers, though I would like it more if the interpreter wasn't written in Java... ;)

@kirbyfan64sos It's not as small as Pyth, but it can beat CJam & GolfScript in some instances. It defiantly can beat anything having to do with arrays, as they're so powerful.

Pyth - 11 10 bytes
Just multiplies by 10e10 and -10e10+1 Thanks to @xnor for showing me that I could use CG for the number.
*CGQ_*tCGQ

Try it online here.

You can make a suitably huge number as CG.

@xnor adding to tips list.

Python 3, 29 27
Edit: doesn't meet the requirement in the 2nd "Details" bullet point
Bonus: it works from -99998 to 99998 inclusive

lambda n:[99999*n,-99998*n]

This creates an anonymous function*, which you can use by enclosing in brackets and then placing the argument in brackets afterwards like this:
(lambda n:[99999*n,-99998*n])(arg)

*Thanks to @vioz- for suggesting this.

Example input / output:
>>> (lambda n:[99999*n,-99998*n])(1)
[99999, -99998]
>>> (lambda n:[99999*n,-99998*n])(2)
[199998, -199996]
>>> (lambda n:[99999*n,-99998*n])(0)
[0, 0]
>>> (lambda n:[99999*n,-99998*n])(-1)
[-99999, 99998]
>>> (lambda n:[99999*n,-99998*n])(-2)
[-199998, 199996]
>>> (lambda n:[99999*n,-99998*n])(65536)
[6553534464, -6553468928]

Nice post! Just so you know, you can remove the f= and leave it as an anonymous function, which is still a valid answer. Then you can take down your byte count to 27 :)

"...your algorithm should work for arbitrary large and small numbers in theory."  Obviously (lambda n:[99999*n,-99998*n])(99999) and (lambda n:[99999*n,-99998*n])(-99998) will collide in theory (and in practice).

@mathmandan You're right, I'll edit my post to make it clear that it doesn't meet the requirements. I would try to write & test new code but I'm on mobile away from my computer.

Haskell, 16 bytes
I shamelessly copied @xnor's method. There probably isn't much better than this.
f x=(-x^3,x^3+x)


text:
Transit all day every day
In addition to contributing to Stack Overflow and other SE sites, I like to ride public transit during my free time. I'd be spending a fortune on cash fare and/or bus tickets every month if I didn't have a bus pass. But for the average passenger, how much would you need to ride to make it worthwhile to buy a pass?
Input
Two parameters: Passenger age and transit usage report.
Standard loopholes apply. You can read input from CLI arguments, function arguments, or a file (whichever works best for your language).
Transit usage log format
Each line represents a trip:
<date> <time> <route number> <start> à <destination>
<date> <time> <route number> <start> à <destination> // comments, if any

Date is in ISO 8601 format. Time is 24 hour format (hours and minutes, both with leading zeros). The remaining information on the line is irrelevant for this question.
Fare structure
Tickets are $1.60 each.
            Child (0-5)    Child (6-12)  Student (13-19)   Adult (20+)
Cash           Free           1.90            3.55            3.55
Tickets        Free              1               2               2
DayPass        Free           8.30            8.30            8.30
Monthly pass   Free            n/A           82.25          103.25

Transfers
When paying with cash or tickets, a transfer (proof of payment) will be provided. The validity of the transfer is calculated as follows:

Until 04:30 the next day if time of boarding is after 22:00, else
105 minutes from time of boarding on weekends, else
90 minutes from time of boarding

If you have a valid transfer at the start of a trip, you do not have to pay anything.
For the purposes of this question, make the following assumptions:

All routes cost the same
You never lose your transfer or day pass
You do not have a transfer from the last day of the previous month.

Day pass
If more than $8.30 in cash is spent in a day, a day pass is cheaper.
A day pass is valid from 03:00 to 03:00 the next day. If a day pass is purchased at 02:30, it is only good for 30 minutes!
Output
Output may be in the form of a return value or written to STDOUT. A trailing newline is permitted.
Your program/function must output the cost of each option as follows (order does not matter):
C: $50.45
T: $44.1
J: $47.25
P: $100.75

J represents the calculation for a combination of cash with day passes where a day pass would have been cheaper.
Numbers must be truncated to at most two decimal places. Trailing zeros can be omitted.
For passengers age 6 through 12, passes are unavailable so any non-digit output for P is OK (whether it be false, empty string, nil, null, not a number, "Infinity", etc.)
Bonus
-5% if you indicate the least expensive valid option in the output by printing any printable character before method of payment. For example:
P: $NaN
C: $117.80
*T: $99.20
J: $117.80

Test cases
Input transit usage log

body {white-space: pre; font-family: monospace}
2015-04-01 02:28 95 Barrhaven Centre à Laurier
2015-04-01 06:31 98 Laurier à Tunney's Pasture
2015-04-01 06:51 176X Tunney's Pasture à Merivale/Rossdale
2015-04-01 08:06 176 Merivale/Family Brown à Laurier
2015-04-01 22:16 97 Campus à Lincoln Fields
2015-04-01 22:51 95 Lincoln Fields à Barrhaven Centre
2015-04-02 02:00 95 Barrhaven Centre à Laurier
2015-04-02 19:01 95 Campus à Barrhaven Centre
2015-04-02 22:31 170 Barrhaven Centre à Fallowfield
2015-04-02 23:22 95 Fallowfield à Trim
2015-04-02 00:41 95 Trim à Barrhaven Centre
2015-04-02 03:48 95 Barrhaven Centre à Laurier
2015-04-02 20:25 95X Laurier à Mackenzie King
2015-04-02 20:49 95 Mackenzie King à Barrhaven Centre
2015-04-02 23:58 95 Barrhaven Centre à Laurier
2015-04-04 21:26 96 Laurier à Lincoln Fields
2015-04-04 21:51 94 Lincoln Fields à Fallowfield
2015-04-04 22:10 95 Fallowfield à Barrhaven Centre
2015-04-04 22:38 95 Barrhaven Centre à Hurdman
2015-04-04 23:24 95 Hurdman à Mackenzie King
2015-04-05 00:03 1 Dalhousie/York à Johnston/Bank
2015-04-05 00:43 97 Greenboro à Lincoln Fields
2015-04-06 01:41 95 Lincoln Fields à Fallowfield
2015-04-06 02:11 95 Fallowfield à Barrhaven Centre
2015-04-06 05:21 95 Longfields à Laurier
2015-04-06 18:17 94 Laurier à Mackenzie King
2015-04-06 18:49 95 Mackenzie King à Barrhaven Centre
2015-04-06 23:18 95 Barrhaven Centre à Place d'Orléans
2015-04-06 00:41 95 Place d'Orléans à Barrhaven Centre
2015-04-06 02:01 95 Barrhaven Centre à Laurier
2015-04-06 19:15 94 Laurier à Mackenzie King
2015-04-06 19:49 95 Mackenzie King à Barrhaven Centre
2015-04-06 23:51 170 Strandherd à Fallowfield
2015-04-07 00:21 DH Fallowfield à Baseline
2015-04-07 00:39 95 Baseline à Laurier
2015-04-07 17:20 71 Mackenzie King à Berrigan/Edge
2015-04-07 23:18 95 Barrhaven Centre à Laurier
2015-04-09 00:40 95 Trim à Barrhaven Centre
2015-04-09 02:00 95 Barrhaven Centre à Laurier
2015-04-09 16:32 41 Campus à Hurdman
2015-04-09 16:37 94 Hurdman à St. Laurent
2015-04-09 17:41 95 St. Laurent à Campus
2015-04-10 01:06 95 Laurier à Barrhaven Centre
2015-04-10 02:01 95 Barrhaven Centre à Laurier
2015-04-10 17:15 66 Campus à Lincoln Fields
2015-04-10 17:44 95 Lincoln Fields à Barrhaven Centre
2015-04-10 23:38 95 Barrhaven Centre à Longfields
2015-04-11 00:05 95 Longfields à Laurier
2015-04-11 01:30 95 Laurier à Barrhaven Centre
2015-04-11 04:47 95 Barrhaven Centre à Fallowfield //stop engine
2015-04-11 05:17 95 Fallowfield à Laurier
2015-04-11 17:15 94 Laurier à Mackenzie King
2015-04-11 17:41 95 Mackenzie King à Barrhaven Centre
2015-04-11 23:30 170 Barrhaven Centre à Fallowfield
2015-04-12 00:21 95 Fallowfield à Laurier
2015-04-12 17:30 98 Laurier à Mackenzie King
2015-04-12 21:25 95 Laurier à Barrhaven Centre
2015-04-12 23:18 95 Barrhaven Centre à Laurier
2015-04-13 07:01 16 Laurier/Cumberland à Tunney's Pasture
2015-04-13 07:27 176X Tunney's Pasture à Merivale/Meadowlands
2015-04-13 09:12 176 Merivale/Baseline à LeBreton
2015-04-13 09:21 96 LeBreton à Blair
2015-04-14 00:34 95 Laurier à Barrhaven Centre
2015-04-14 02:30 95 Barrhaven Centre à Laurier
2015-04-14 07:06 86C Laurier à Tunney's Pasture
2015-04-14 07:21 176 Tunney's Pasture à Merivale/Meadowlands
2015-04-14 08:54 86 Meadowlands/Merivale à Laurier
2015-04-14 18:43 97X Laurier à Hurdman
2015-04-14 18:55 95 Hurdman à St. Laurent
2015-04-14 19:23 95 St. Laurent à Barrhaven Centre
2015-04-14 23:18 95 Barrhaven Centre à Trim
2015-04-15 00:38 95 Trim à Laurier
2015-04-15 08:00 35 Laurier à Mackenzie King
2015-04-15 08:35 94 Mackenzie King à Campus
2015-04-15 22:15 95 Laurier à Barrhaven Centre
2015-04-16 02:01 95 Barrhaven Centre à Laurier
2015-04-16 21:01 95 Laurier à Woodroffe/Tallwood
2015-04-16 21:34 86 Meadowlands/Woodroffe à Meadowlands/Merivale
2015-04-16 21:56 176 Merivale/Meadowlands à Barrhaven Centre
2015-04-17 02:00 95 Barrhaven Centre à Laurier
2015-04-17 11:52 96 Laurier à Bayshore
2015-04-17 13:21 96 Bayshore à Campus
2015-04-17 22:10 95X Campus à Baseline
2015-04-17 22:47 95 Baseline à Barrhaven Centre
2015-04-18 02:53 95 Barrhaven Centre à Laurier
2015-04-18 20:14 86X Laurier à Hurdman
2015-04-18 20:22 94 Hurdman à St. Laurent
2015-04-18 20:44 94 St. Laurent à Fallowfield
2015-04-18 21:43 95 Fallowfield à Barrhaven Centre
2015-04-19 00:58 95 Barrhaven Centre à Laurier
2015-04-19 15:16 95 Laurier à Mackenzie King
2015-04-19 16:22 94 Mackenzie King à Hurdman
2015-04-19 16:34 98 Hurdman à South Keys
2015-04-19 16:51 97 South Keys à Airport
2015-04-19 17:21 97 Airport à Laurier
2015-04-19 21:30 95 Laurier à Barrhaven Centre
2015-04-19 23:18 95 Barrhaven Centre à Laurier
2015-04-20 19:30 95 Laurier à Barrhaven Centre
2015-04-20 23:18 95 Barrhaven Centre à Trim
2015-04-21 00:38 95 Trim à Laurier
2015-04-21 19:30 95 Laurier à Barrhaven Centre
2015-04-22 02:00 95 Barrhaven Centre à Laurier
2015-04-22 19:30 95 Laurier à Barrhaven Centre
2015-04-23 01:28 95 Barrhaven Centre à Woodroffe/Medhurst
2015-04-23 02:11 95 Woodroffe/Medhurst à Laurier
2015-04-23 19:30 95 Laurier à Barrhaven Centre
2015-04-23 23:18 95 Barrhaven Centre à Trim
2015-04-24 00:38 95 Trim à Laurier
2015-04-24 23:15 95 Laurier à Barrhaven Centre
2015-04-25 00:23 95 Barrhaven Centre à Rideau St.
2015-04-25 01:44 96 Rideau St à Laurier
2015-04-25 16:58 86B Laurier à Albert/Bank
2015-04-25 17:44 87 Mackenzie King à Laurier
2015-04-26 01:25 95 Laurier à Barrhaven Centre
2015-04-27 01:04 95 Laurier à Rideau St
2015-04-27 01:31 95 Rideau St à Laurier
2015-04-27 17:25 41 Campus à Heron/Baycrest
2015-04-27 17:54 112 Baycrest/Heron à Elmvale
2015-04-27 18:30 114 Elmvale à Hurdman
2015-04-27 18:41 94 Hurdman à Laurier
2015-04-29 02:02 95 Barrhaven Centre à Laurier
2015-04-29 17:01 8 Campus à Heron
2015-04-29 17:37 118 Heron à Baseline
2015-04-29 18:01 95 Baseline à Barrhaven Centre
2015-04-29 20:32 95 Barrhaven Centre à Mackenzie King
2015-04-29 21:31 2 Rideau St à Bank/Queen
2015-04-29 21:35 95 Albert/Bank à Barrhaven Centre
2015-04-30 02:02 95 Barrhaven Centre à Laurier
2015-04-30 02:20 86C Campus à Mackenzie King
2015-04-30 02:44 96 Mackenzie King à Campus
2015-04-30 19:36 95 Laurier à Strandherd

Output
$ node --harmony golfed.js trips.txt 5 "Toddler"
P: $0.00
C: $0.00
T: $0.00
J: $0.00
$ node --harmony golfed.js trips.txt 10 "Child"
P: $NaN
C: $117.80
T: $99.20
J: $117.80
$ node --harmony golfed.js trips.txt 15 "Student"
P: $82.25
C: $220.10
T: $198.40
J: $194.20
$ node --harmony golfed.js trips.txt 61 "Adult"
P: $103.25
C: $220.10
T: $198.40
J: $194.20

I'm going to kick off my own question by providing my own golfed solutions in two languages. These functions write to STDOUT.
CoffeeScript, 438 bytes
F=(I,a)->f=[C=T=x=A=0,1.9,K=3.55,K,0,1,2,2];J=[];I.split('\n').map((r)->W=new Date w=r[..9];(y=+w[-2..]-((h=R.getUTCHours())<3);C+=f[A=a>19&&3||a>12&&2||a>5&&1||0];T+=f[A+4]*1.6;J[y]=J[y]||0;J[y]++;x=h>21&&+W+1026e5||h<3&&+W+162e5||+R+(R.getUTCDay()%6&&54e5||63e5))if x<R=new Date r=w+'T'+r[11..15]+':00');o={P:[0,NaN,Z=82.25,Z+21][A],C:C,T:T,J:J.reduce ((p,v)->v*f[A]>8.3&&p+8.3||p+v*f[A]),0};console.log(O+': $'+$.toFixed 2)for O,$ of o

JavaScript (ES6), 445 bytes
F=(I,a)=>{f=[C=T=x=0,1.9,K=3.55,K,0,1,2,2],J=[];I.split('\n').map(r=>{W=new Date(w=r[s='slice'](0,10));if((R=new Date(r=w+'T'+r[s](11,16)+':00'))>x){y=+w[s](-2)-(V=(h=R.getUTCHours())<3);C+=f[A=a>19?3:a>12?2:a>5?1:0];T+=f[A+4]*1.6;J[y]=J[y]||0;J[y]++;x=h>21?+W+1026e5:V?+W+162e5:+R+(R.getUTCDay()%6?54e5:63e5)}});for($ in(o={P:[0,NaN,Z=82.25,Z+21][A],C:C,T:T,J:J.reduce((p,v)=>v*f[A]>8.3?p+8.3:p+v*f[A],0)}))console.log($+': $'+o[$].toFixed(2))}

JavaScript (ES5), 474 bytes
There really wasn't much ES6 other than arrow functions.
F=function(I,a){f=[C=T=x=0,1.9,K=3.55,K,0,1,2,2],J=[];I.split('\n').map(function(r){W=new Date(w=r[s='slice'](0,10));if((R=new Date(r=w+'T'+r[s](11,16)+':00'))>x){y=+w[s](-2)-(V=(h=R.getUTCHours())<3);C+=f[A=a>19?3:a>12?2:a>5?1:0];T+=f[A+4]*1.6;J[y]=J[y]||0;J[y]++;x=h>21?+W+1026e5:V?+W+162e5:+R+(R.getUTCDay()%6?54e5:63e5)}});for($ in(o={P:[0,NaN,Z=82.25,Z+21][A],C:C,T:T,J:J.reduce(function(p,v){return v*f[A]>8.3?p+8.3:p+v*f[A]},0)}))console.log($+': $'+o[$].toFixed(2))}

Demo

F = function(I, a) {
  f = [C = T = x = 0, 1.9, K = 3.55, K, 0, 1, 2, 2], J = [];
  I.split('\n').map(function(r) {
    W = new Date(w = r[s = 'slice'](0, 10));
    if ((R = new Date(r = w + 'T' + r[s](11, 16) + ':00')) > x) {
      y = +w[s](-2) - (V = (h = R.getUTCHours()) < 3);
      C += f[A = a > 19 ? 3 : a > 12 ? 2 : a > 5 ? 1 : 0];
      T += f[A + 4] * 1.6;
      J[y] = J[y] || 0;
      J[y] ++;
      x = h > 21 ? +W + 1026e5 : V ? +W + 162e5 : +R + (R.getUTCDay() % 6 ? 54e5 : 63e5)
    }
  });
  for ($ in (o = {
    P: [0, NaN, Z = 82.25, Z + 21][A],
    C: C,
    T: T,
    J: J.reduce(function(p, v) {
      return v * f[A] > 8.3 ? p + 8.3 : p + v * f[A]
    }, 0)
  })) console.log($ + ': $' + o[$].toFixed(2))
}

// Demonstration stuff
console.log = function(x) {
  O.innerHTML += x + '\n'
}

F(D.innerHTML, 5);
console.log('
Child');
F(D.innerHTML, 10);
console.log('
Student');
F(D.innerHTML, 15);
console.log('
Adult');
F(D.innerHTML, 20);

2015-04-01 02:28 95 Barrhaven Centre à Laurier
2015-04-01 06:31 98 Laurier à Tunney's Pasture
2015-04-01 06:51 176X Tunney's Pasture à Merivale/Rossdale
2015-04-01 08:06 176 Merivale/Family Brown à Laurier
2015-04-01 22:16 97 Campus à Lincoln Fields
2015-04-01 22:51 95 Lincoln Fields à Barrhaven Centre
2015-04-02 02:00 95 Barrhaven Centre à Laurier
2015-04-02 19:01 95 Campus à Barrhaven Centre
2015-04-02 22:31 170 Barrhaven Centre à Fallowfield
2015-04-02 23:22 95 Fallowfield à Trim
2015-04-02 00:41 95 Trim à Barrhaven Centre
2015-04-02 03:48 95 Barrhaven Centre à Laurier
2015-04-02 20:25 95X Laurier à Mackenzie King
2015-04-02 20:49 95 Mackenzie King à Barrhaven Centre
2015-04-02 23:58 95 Barrhaven Centre à Laurier
2015-04-04 21:26 96 Laurier à Lincoln Fields
2015-04-04 21:51 94 Lincoln Fields à Fallowfield
2015-04-04 22:10 95 Fallowfield à Barrhaven Centre
2015-04-04 22:38 95 Barrhaven Centre à Hurdman
2015-04-04 23:24 95 Hurdman à Mackenzie King
2015-04-05 00:03 1 Dalhousie/York à Johnston/Bank
2015-04-05 00:43 97 Greenboro à Lincoln Fields
2015-04-06 01:41 95 Lincoln Fields à Fallowfield
2015-04-06 02:11 95 Fallowfield à Barrhaven Centre
2015-04-06 05:21 95 Longfields à Laurier
2015-04-06 18:17 94 Laurier à Mackenzie King
2015-04-06 18:49 95 Mackenzie King à Barrhaven Centre
2015-04-06 23:18 95 Barrhaven Centre à Place d'Orléans
2015-04-06 00:41 95 Place d'Orléans à Barrhaven Centre
2015-04-06 02:01 95 Barrhaven Centre à Laurier
2015-04-06 19:15 94 Laurier à Mackenzie King
2015-04-06 19:49 95 Mackenzie King à Barrhaven Centre
2015-04-06 23:51 170 Strandherd à Fallowfield
2015-04-07 00:21 DH Fallowfield à Baseline
2015-04-07 00:39 95 Baseline à Laurier
2015-04-07 17:20 71 Mackenzie King à Berrigan/Edge
2015-04-07 23:18 95 Barrhaven Centre à Laurier
2015-04-09 00:40 95 Trim à Barrhaven Centre
2015-04-09 02:00 95 Barrhaven Centre à Laurier
2015-04-09 16:32 41 Campus à Hurdman
2015-04-09 16:37 94 Hurdman à St. Laurent
2015-04-09 17:41 95 St. Laurent à Campus
2015-04-10 01:06 95 Laurier à Barrhaven Centre
2015-04-10 02:01 95 Barrhaven Centre à Laurier
2015-04-10 17:15 66 Campus à Lincoln Fields
2015-04-10 17:44 95 Lincoln Fields à Barrhaven Centre
2015-04-10 23:38 95 Barrhaven Centre à Longfields
2015-04-11 00:05 95 Longfields à Laurier
2015-04-11 01:30 95 Laurier à Barrhaven Centre
2015-04-11 04:47 95 Barrhaven Centre à Fallowfield //stop engine
2015-04-11 05:17 95 Fallowfield à Laurier
2015-04-11 17:15 94 Laurier à Mackenzie King
2015-04-11 17:41 95 Mackenzie King à Barrhaven Centre
2015-04-11 23:30 170 Barrhaven Centre à Fallowfield
2015-04-12 00:21 95 Fallowfield à Laurier
2015-04-12 17:30 98 Laurier à Mackenzie King
2015-04-12 21:25 95 Laurier à Barrhaven Centre
2015-04-12 23:18 95 Barrhaven Centre à Laurier
2015-04-13 07:01 16 Laurier/Cumberland à Tunney's Pasture
2015-04-13 07:27 176X Tunney's Pasture à Merivale/Meadowlands
2015-04-13 09:12 176 Merivale/Baseline à LeBreton
2015-04-13 09:21 96 LeBreton à Blair
2015-04-14 00:34 95 Laurier à Barrhaven Centre
2015-04-14 02:30 95 Barrhaven Centre à Laurier
2015-04-14 07:06 86C Laurier à Tunney's Pasture
2015-04-14 07:21 176 Tunney's Pasture à Merivale/Meadowlands
2015-04-14 08:54 86 Meadowlands/Merivale à Laurier
2015-04-14 18:43 97X Laurier à Hurdman
2015-04-14 18:55 95 Hurdman à St. Laurent
2015-04-14 19:23 95 St. Laurent à Barrhaven Centre
2015-04-14 23:18 95 Barrhaven Centre à Trim
2015-04-15 00:38 95 Trim à Laurier
2015-04-15 08:00 35 Laurier à Mackenzie King
2015-04-15 08:35 94 Mackenzie King à Campus
2015-04-15 22:15 95 Laurier à Barrhaven Centre
2015-04-16 02:01 95 Barrhaven Centre à Laurier
2015-04-16 21:01 95 Laurier à Woodroffe/Tallwood
2015-04-16 21:34 86 Meadowlands/Woodroffe à Meadowlands/Merivale
2015-04-16 21:56 176 Merivale/Meadowlands à Barrhaven Centre
2015-04-17 02:00 95 Barrhaven Centre à Laurier
2015-04-17 11:52 96 Laurier à Bayshore
2015-04-17 13:21 96 Bayshore à Campus
2015-04-17 22:10 95X Campus à Baseline
2015-04-17 22:47 95 Baseline à Barrhaven Centre
2015-04-18 02:53 95 Barrhaven Centre à Laurier
2015-04-18 20:14 86X Laurier à Hurdman
2015-04-18 20:22 94 Hurdman à St. Laurent
2015-04-18 20:44 94 St. Laurent à Fallowfield
2015-04-18 21:43 95 Fallowfield à Barrhaven Centre
2015-04-19 00:58 95 Barrhaven Centre à Laurier
2015-04-19 15:16 95 Laurier à Mackenzie King
2015-04-19 16:22 94 Mackenzie King à Hurdman
2015-04-19 16:34 98 Hurdman à South Keys
2015-04-19 16:51 97 South Keys à Airport
2015-04-19 17:21 97 Airport à Laurier
2015-04-19 21:30 95 Laurier à Barrhaven Centre
2015-04-19 23:18 95 Barrhaven Centre à Laurier
2015-04-20 19:30 95 Laurier à Barrhaven Centre
2015-04-20 23:18 95 Barrhaven Centre à Trim
2015-04-21 00:38 95 Trim à Laurier
2015-04-21 19:30 95 Laurier à Barrhaven Centre
2015-04-22 02:00 95 Barrhaven Centre à Laurier
2015-04-22 19:30 95 Laurier à Barrhaven Centre
2015-04-23 01:28 95 Barrhaven Centre à Woodroffe/Medhurst
2015-04-23 02:11 95 Woodroffe/Medhurst à Laurier
2015-04-23 19:30 95 Laurier à Barrhaven Centre
2015-04-23 23:18 95 Barrhaven Centre à Trim
2015-04-24 00:38 95 Trim à Laurier
2015-04-24 23:15 95 Laurier à Barrhaven Centre
2015-04-25 00:23 95 Barrhaven Centre à Rideau St.
2015-04-25 01:44 96 Rideau St à Laurier
2015-04-25 16:58 86B Laurier à Albert/Bank
2015-04-25 17:44 87 Mackenzie King à Laurier
2015-04-26 01:25 95 Laurier à Barrhaven Centre
2015-04-27 01:04 95 Laurier à Rideau St
2015-04-27 01:31 95 Rideau St à Laurier
2015-04-27 17:25 41 Campus à Heron/Baycrest
2015-04-27 17:54 112 Baycrest/Heron à Elmvale
2015-04-27 18:30 114 Elmvale à Hurdman
2015-04-27 18:41 94 Hurdman à Laurier
2015-04-29 02:02 95 Barrhaven Centre à Laurier
2015-04-29 17:01 8 Campus à Heron
2015-04-29 17:37 118 Heron à Baseline
2015-04-29 18:01 95 Baseline à Barrhaven Centre
2015-04-29 20:32 95 Barrhaven Centre à Mackenzie King
2015-04-29 21:31 2 Rideau St à Bank/Queen
2015-04-29 21:35 95 Albert/Bank à Barrhaven Centre
2015-04-30 02:02 95 Barrhaven Centre à Laurier
2015-04-30 02:20 86C Campus à Mackenzie King
2015-04-30 02:44 96 Mackenzie King à Campus
2015-04-30 19:36 95 Laurier à Strandherd

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Modular Fibonacci Cycles
The Fibonacci sequence is a well known and famous sequence, where each successive element is the sum of the previous two. A modular Fibonacci sequence is the same, except that the addition is performed over a finite field, or to put it another way, a modulo operation is performed after each addition.
For instance, the modular Fibonacci sequence with starting values 1, 1 and modulus 5 is:
1, 1, 2, 3, 0, 3, 3, 1, 4, 0, 4, 4, 3, 2, 0, 2, 2, 4, 1, 0, 1, 1, ...

At this point, the sequence is once again 1, 1, and so the sequence will repeat, cyclically, with a cycle length of 20.
Your challenge is to find the (minimal) cycle length for a specific starting pair and modulus, in the fewest bytes.
Details: The initial values will both be in the range 0 <= i,j < m, where m is the modulus. The initial values will not both be zero, and the modulus will be at least 2. You may take the input in any standard means or format, in any order, function, program or similar, and output via return or print. Standard loopholes apply.
Examples:
First element, second element, modulus:

1, 1, 5 => 20
1, 1, 4 => 6
2, 4, 6 => 8
3, 3, 6 => 3

This is code golf - shortest code in bytes wins. Good luck!

Is the cycle always formed by reaching the initial values again? Or is it possible that there's a cycle that does not include the initial values? If yes, it would be good to have a test example for this case. I haven't found one with a few random attempts, but I don't have the mathematical skills to prove that the values will always go back to the initial values.

@RetoKoradi Cycles must always include initial values, because there can't be any branching. Suppose that the first number in the cycle is A_i, and let the number behind A_i in the cycle be X. A_i+1 - A_i = A_i-1, but it also equals X, so A_i-1 equals X, a contradiction.

Possibly of interest: http://math.stackexchange.com/questions/1358310/how-to-prove-that-the-fibonacci-sequence-is-periodic-mod-5-without-using-inducti

Python, 56
g=lambda a,b,m,u=0:u!=(a,b)and-~g(b,(a+b)%m,m,u or(a,b))

It's a pity that the default argument of u=0 makes it a lot harder to replace a,b with *x and (a+b) with sum(*x)...

Great method for storing the initial values while iterating the current ones.

Retina, 69 61 bytes
This was great fun to write!
(1* )(1*).*
x$2$1$0
(1*)(?=.* \1$)

)`x(1* 1*) .* \1 .*
x
x
1

Each line should go to its own file but you can run the code as one file with the -s flag.
Takes input in unary, in format j i m and gives output in unary.
The four substitution pairs do the followings:

Add next element and increase step counter.
Take modulo of the new element.
If we reached the starting numbers delete everything except step counter. This will break the loop of the first three steps.
Convert step count to unary number.

The string has the following format during the computation (with (?#comments)):
x*(?#number of steps)(1* )+(?#sequence, reversed)1*(?#modulus)

The code makes use of some observations:

The modulus can be part of the sequence as it is bigger than any other number causing no false positive match.
There will always be a number between the two repeating pair. I.e.output will always be at least 3. (The 3rd number can be the same as the 1st if the sequence starts as x,0,x,x,...)
You have to subtract the modulo from the new number at most once.

Every substitution step shown in its own line for the example j=1, i=1, m=4:
1 1 1111
x11 1 1 1111
x11 1 1 1111
x11 1 1 1111
xx111 11 1 1 1111
xx111 11 1 1 1111
xx111 11 1 1 1111
xxx11111 111 11 1 1 1111
xxx1 111 11 1 1 1111
xxx1 111 11 1 1 1111
xxxx1111 1 111 11 1 1 1111
xxxx 1 111 11 1 1 1111
xxxx 1 111 11 1 1 1111
xxxxx1  1 111 11 1 1 1111
xxxxx1  1 111 11 1 1 1111
xxxxx1  1 111 11 1 1 1111
xxxxxx1 1  1 111 11 1 1 1111
xxxxxx1 1  1 111 11 1 1 1111
xxxxxx
xxxxxx
xxxxxx
xxxxxx
111111

This is nuts. Nice work!

Haskell, 76 71 bytes
p x y m=[i|(p,i)<-zip(x#y)[0..],(x,y)==p]!!1where x#y=(x,y):y#mod(x+y)m

Usage example: p 1 1 5 -> 20.
How it works: # builds an infinite list of (i,i+1) pairs of the modular Fibonacci sequence. e.g. with m==5: 1#1-> [(1,1),(1,2),(2,3),(3,0)...]. The list comprehension [i| ... ] returns a list of indices of the positions of (x,y) within x#y. From this list I take the second element (-> !!1), because the first (index 0) is always at the beginning of x#y.
Edit: replaced elemIndices from Data.List with my own version.

Pyth, 18 17 16 15 bytes
fqQu,eG%sGvzTQ1

Example input:
6
[2, 4]

Will output 8.
It works by outputting increasingly long Fibonacci sequences (in pairs), until the end is the same as the start.

C, 78 72 bytes
An essentially straightforward C solution. Perhaps there is a shorter solution by considering analytic expressions for Pisano periods of generalized Fibonacci numbers, though this thesis from 2013 makes it look like such expressions are not known.
g(o,t,m,N,M,i,v){N=o;M=t;for(i=1;v=N+M,N=M,M=v%m,N-o|M-t;i++);return i;}

Readable version, by way of explanation, is
int f(int one, int two, int mod) {
  int new_one, new_two, i, tmp;
  new_one = one;
  new_two = two;
  for(i = 1;
      tmp = new_one + new_two, new_one = new_two, new_two = tmp % mod,
      new_one - one | new_two - two;
      i++);
  return i;
}

And the examples
$ ./mod_fib 1 1 5
20
$ ./mod_fib 1 1 4
6
$ ./mod_fib 3 3 6
3
$ ./mod_fib 2 4 6
8

EDIT: returning the value instead of printing it is allowed in the spec and saves 6 bytes.

Prolog, 116 bytes
a(A,B,M,R):-f([B,A],A,B,M,1,R).
f([A,B|T],X,Y,M,Z,R):-Z=0,Y=A,X=B,length(T,R);C is(A+B)mod M,f([C,A,B|T],X,Y,M,0,R).

Example: a(1,1,5,R). outputs R = 20 .

CJam, 23 bytes
q~:MM*{_2$+M%}*]2ew(a#)

Reads whitspace-separated numbers from STDIN, in the same order as in the question.
Works by generating m2 more numbers, pairing all and searching the index of the first pair in the rest.
Try it online in the CJam interpreter.

Much shorter answers have been posted, but:
EcmaScript 6, 67 64 62  56  bytes
let f=(d,e,m,a=e,b=d+e)=>a^d||b^e?f(d,e,m,b,(a+b)%m)+1:1

Examples:
f(1,1,5) //20
f(1,1,4) // 6

Perl, 88 bytes
($v,$w,$m)=@ARGV;$x=$v;$y=$w;do{$c++;($x,$y)=($y,($x+$y)%$m)}while($x-$v||$y-$w);print$c

Arguments given on the command line, in the order as in the question.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Mini Golf Code Golf
This is a mini golf hole:

The outer boundary is a circle with radius 10 and center (0,0). The inner boundary is a circle with radius 3 and center (0,5). The tee is at (0,-8). Assume the ball is just a point with radius 0.
The dynamics of the ball are governed by the following rules:

The ball is initially hit with energy 50, and with a given angle.

The angle is in degress in the Cartesian coordinate system, so 0° means directly to the right, 90° is directly up, and so on.

When the ball hits the edge of the inner or outer circle, it bounces off the circle using the law of reflection.

The angle of collision with the circle at that point is equal to the angle of reflection. (Here angles are relative to the tangent line of the circle at the point of collision.)
For clarification, see this or this (in the notation of the second link, R_0 = 0 in this challenge.)

The ball loses energy as it moves.

For every unit of ground it covers, it loses 1 unit of energy.
Every time it bounces off a wall it loses 5 units of energy.

The ball stops either when it runs out of energy or when it falls into the hole.

If the ball hits a wall with <= 5 units of energy, it stops.
It falls into the hole if it has energy < 10 when it is within distance 1 of the hole, otherwise it keeps moving.

Challenge
Given the x-y coordinates of a hole, return an angle at which that you can hit the ball in order for the ball to fall into the hole (if such an angle exists).
Input
Take as input the x- and y-coordinates of the center of the hole in any convenient form. Input may be taken from STDIN (or closest alternative), command line parameters, or function arguments.
Output
Print or return an angle in degrees at which the ball can be hit from the tee such that the ball will fall into the hole. If such an angle exists, the output should be in the range [0, 360), otherwise the output should be -1.

You might want to specify how the x and y values should be read (standard input, function argument etc.).

What should be returned if no such angle exists?

Let's specify that the function will return a value in [0,360) if there is a solution, and return -1 otherwise.

I made a couple of edits. If it doesn't match your intent, please roll back the edit.

Also, could you provide at least one test case?

I'll provide one later today.

It seems to me that the simplest thing is just to aim the ball at the hole, avoiding all the rebound rules. Or am I missing something?

I think there are two complications with that: 1. some locations can't be accessed with a straight line (because of the barrier) and 2. if you haven't yet rebounded you almost certainly have too much energy

C, 415 430
EDIT: Like @Winny mentioned, exit values above 255 aren't possible, so I had to increase this code size in order to print values up to 360.
Assumes 2 (and only 2) command-line inputs (x y) as ints. Answer in degrees is printed or -1 if no degree exists.
#include <math.h>
#define E(z) {if((e-=5)<0)break;q=n/sqrt(n*n+pow(m-z,2));w=(m-z)/sqrt(n*n+pow(m-z,2));d=(t=d)*(1-2*q*q)-2*f*q*w;f=f*(1-2*w*w)-2*t*q*w;}
main(a,v)char**v;{float D=.01,e,d,f,n,m,p=.0174,q,t,w;a-=4;while(++a<360){n=0,m=-8,d=D*cos(a*p),f=D*sin(a*p),e=50;while(e>0){if((pow(n-atoi(v[1]),2)+pow(m-atoi(v[2]),2)<1)&(e<10)&&printf("%d",a))return;n+=d,m+=f,e-=D;if(n*n+m*m>100)E(0)if(n*n+pow(m-5,2)<9)E(5)}}puts("-1");}

Ex.
>./golfed 0 2; echo $?
90
>./golfed 0 10; echo $?
0
>./golfed -2 -7; echo $?
12

First time golfer; could probably be improved quite a bit. If we need to have more precision, I have a version that takes in x y and returns the angle with doubles working with .01 degree precision at 449 chars.
Readable version:
#include <math.h>
int main(int argc, char** argv)
{
    // p is roughly pi/180 and q, t, and w are temp vars
    float Delta=.01, energy, delta_x, f(delta_y), n(cur_x), m(cur_y), p=.0174, q, t, w;
    argc -= 4; /*using argc as int for angle*/
    // iterate through each degree
    while (++argc < 360)
    {
        n=0, m=-8, d=D*cos(a*p), f=D*sin(a*p), e=50;
        // then move in discrete .01 steps
        while (e > 0)
        {
            // check to see if we're inside the hole
            if ((pow(n-atoi(v[1]),2) + pow(m-atoi(v[2]),2) < 1)
                & (e<10) && printf("%d",a)) return;
            // move forward
            n += d, m += f, e -= D;
            // check if we've hit the outer wall
            if (n * n + m * m > 100)
            {
                // if too slow, finish this iteration
                // if not, find reflection vector
                if ((e -= 5) < 0) break;
                q = n / sqrt(n * n + pow(m,2));
                w = (m) / sqrt(n * n + pow(m,2));
                d = (t = d) * (1 - 2 * q * q) - 2 * f * q * w;
                f = f * (1 - 2 * w * w) - 2 * t * q * w;
            }
            // check inner wall collision
            if (n * n + pow(m - 5,2) < 9)
            {
                // if too slow, finish this iteration
                // if not, find reflection vector
                if ((e -= 5) < 0) break;
                q = n / sqrt(n * n + pow(m - 5,2));
                w = (m - 5) / sqrt(n * n + pow(m - 5,2));
                d = (t = d) * (1 - 2 * q * q) - 2 * f * q * w;
                f = f * (1 - 2 * w * w) - 2 * t * q * w;
            }
        }
    }
    // if an angle not found, return -1
    puts("-1");
}

I don't think you can return values larger than 255 via exit(code). Tested on Linux and FreeBSD via echo 'int main(){return 300;}' > test.c && cc test.c && ./a.out; echo $?.


text:
Knockout probabilities
Knockout is a basketball game where players take turns shooting. It is played as a sequence of two-player contests, each of which has the possibility of "knocking out" one of those players.
Suppose the players are A B C D and their chances of shooting and making a basket are 0.1 0.2 0.3 0.4 respectively, independently of the other player in the contest. The two players at the front of the line, A and B, "fight." Since A goes first, he is the defender, in danger of being eliminated, and B is the attacker, and not in danger of immediate elimination. A shoots first. If A makes it, A has successfully defended, and goes to the back of the line. The line would change to B C D A. If A doesn't make it, then B shoots. If B makes it, then A is out and B goes to the back of the line, so the line becomes C D B. If neither A nor B makes it, the process repeats, with A shooting again, until either A or B makes a basket.
Suppose the line changed to B C D A (A had successfully defended). Now, B and C "fight," with B being the defender, and C being the attacker. This process repeats until only one person is left over. That person is the winner.
Your task is to calculate the probabilities of each person winning given the chance that they will make a basket.
Input:
A list of numbers, such as 0.1 0.2 or 0.5 0.5 0.5 0.5, where the nth number is the chance that the nth player will make a basket. You can take this input in any format you like, including as the parameters to a function.
Output:
A list of numbers, where the nth number is the chance that the nth player will win the game. Your numbers must be accurate to at least two decimal places at least 90% of the time. This means that you can use a simulation-based approach. However, if your code is not simulation based (it is guaranteed to return a correct answer to at least 6 decimal places) then take away 30% from your score.
Example between 0.5 0.5: Call the players A and B. Let p be the probability of A winning. A has a 2/3 chance of successfully defending (since there's a 1/2 chance that A scores, a 1/4 chance that A misses and B scores, and a 1/4 chance that both miss and the process repeats). If A fails to defend, he is knocked out and B wins. If A defends, then the line becomes B A. Since the situation is symmetric, the probability of A winning is (1 - p). We get:
p = 2/3 * (1 - p) + 1/3 * 0. Solving, we get p = 2/5. The output should be 2/5 3/5 or 0.4 0.6.
I'm not good enough with probability to do more complex examples.
If you need more test cases, here are a few:
0.1 0.2 0.3 0.4 --> 0.01 0.12 0.25 0.62
0.99 0.99 --> 0.5 0.5 (it's not exact, but if you round to two decimal places, you get 0.5 and 0.5)

CJam (84 80 chars * 0.7 = 56)
{_,({_,,{_2$m<(;(+Q0\)\++m>\}%)_(+.{X2$-*_@+/}1\{1$*\1$-}%)1\-f/.f*:.+}{,da}?}:Q

Online demo. This is a recursive function which takes an array of doubles and returns an array of doubles. The online demo includes a tiny amount of scaffolding to execute the function and format the output for display.
Dissection
The basic principle is that if there are n > 1 players left, one of them must be the next one to be knocked out. Moreover, the order of the queue after that happens depends only on the initial order of the queue and on who gets knocked out. So we can make n recursive calls, calculate the winning probabilities for each player in each case, and then we just need to weight appropriately and add.
I'll label the input probabilities as [p_0 p_1 ... p_{n-1}]. Let f(a,b) denote the probability that a fails to defend against b. In any given round, the probability that a defends successfully is p_a, the probability that b knocks a out is (1-p_a)*p_b, and the probability that it goes to another round is (1-p_a)*(1-p_b). We can either do an explicit sum of a geometric progression or we can argue that the two geometric progressions are proportional to each other to reason that f(a,b) = (1-p_a)*p_b / (p_a + (1-p_a)*p_b).
Then we can step up a level to full rounds of the line. The probability that the first player is knocked out on is f(0,1); the probability that the second player is knocked out is (1-f(0,1)) * f(1,2); the third player is (1-f(0,1)) * (1-f(1,2)) * f(2,3); etc until the last one is knocked out with probability \prod_i (1-f(i,i+1)) * f(n-1,0). The same argument about geometric progressions allows us to use these probabilities as weights, with normalisation by a factor of 1 / \prod_i f(i, i+1 mod n).
{                   e# Define a recursive function Q
  _,({              e# If we have more than one person left in the line...
    _,,{            e#   Map each i from 0 to n-1...
      _2$m<         e#     Rotate a copy of the probabilities left i times to get [p_i p_{i+1} ... p_{n-1} p_0 ... p_{i-1}]
      (;(+          e#     i fails to defend, leaving the line as [p_{i+2} ... p_{n-1} p_0 ... p_{i-1} p_{i+1}]
      Q             e#     Recursive call
      0\)\++        e#     Insert 0 for the probability of i winning and fix up the order
      m>\           e#     Rotate right i times and push under the list of probabilities
    }%
    )               e#   Stack: [probs if 0 knocked out, probs if 1 knocked out, ...] [p_0 p_1 ...]
    _(+.{           e#   Duplicate probs, rotate 1, and pointwise map block which calculates f(a,b)
      X2$-*_@+/     e#     f(a,b) = (1-p_a)*p_b / (p_a + (1-p_a)*p_b)  TODO is the d necessary?
    }
    1\{1$*\1$-}%    e#   Lift over the list of f(a,b) a cumulative product to get the weights  TODO is the d necessary?
    )1\-f/          e#   Normalise the weights
    .f*             e#   Pointwise map a multiplication of the probabilities for each case with the corresponding weight
    :.+             e#   Add the weights across the cases
  }{,da}?           e# ...else only one left, so return [1.0]
}:Q


text:
Generate Probabilities around a Numpad
Inspired by this question earlier today, I'd like to see interesting ways various programming languages can turn a numpad into probabilities. Commonly, tile-based games will allow you to use a numpad to move in any direction based on where your character currently is. When making an AI for these games, Math.random() * 8 is not sufficient, so I had to get a little creative to make the movement look and feel somewhat natural.
A numpad is defined as such:
7 | 8 | 9
- - - - -
4 | x | 6
- - - - -
1 | 2 | 3

Please note, 5 is an invalid number, as you cannot move onto yourself.
All examples will use these probabilities: [50, 40, 30, 20, 10]
If I wanted to generate probabilities around 8, it would look like this:
40 | 50 | 40
-- | -- | --
30 | xx | 30
-- | -- | --
20 | 10 | 20

The output would be [20, 10, 20, 30, 30, 40, 50, 40] (with 5 omitted) or [20, 10, 20, 30, null, 30, 40, 50, 40] (with 5 present)
If I wanted to generate them around 1, it would look like this:
30 | 20 | 10
-- | -- | --
40 | xx | 20
-- | -- | --
50 | 40 | 30

The output would be [50, 40, 30, 40, 20, 30, 20, 10] (with 5 omitted) or [50, 40, 30, 40, null, 20, 30, 20, 10] (with 5 present)
You may write a full program that takes the input in any usual way (command line, stdin) and prints the output, or you may write a function with a number argument, that prints or returns the output. Your program or function should accept one number - the position to generate around. You should use these probabilities: [50, 40, 30, 20, 10] (they do not have to be hardcoded).
Shortest code in bytes wins. Standard loopholes are disallowed. Answers posted in the linked thread are disallowed. Trailing or leading spaces are allowed. You may treat position 4 as absent or empty, depending on your preference. I'm not too picky on output format - print it out as comma-separated strings or as an array.
(This is my first question, go easy on me!)

CJam, 27 bytes
12369874s_$\_r#m<f{#4-z)0S}

Try it online in the CJam interpreter.
Idea
If we go through the digits around 5 in counterclockwise fashion, we obtain the string 12369874 or any of its rotations (depending on the starting point).
After rotating this string so that the input digit n is at the leftmost position, the digits in the rotated string have the following probabilities:
50 40 30 20 10 20 30 40

If we consider the indexes of these digits, which are
 0  1  2  3  4  5  6  7

subtract 4 from each to yield
-4 -3 -2 -1  0  1  2  3

and take absolute values to get
 4  3  2  1  0  1  2  3

we only have to add 1 and append a 0 to get the desired probabilities.
Code
12369874s                   e# Push "12369874".
         _$                 e# Push a sorted copy, i.e., "12346789".
           \                e# Swap it with the unsorted original.
            _r#             e# Find the index of the input in an unsorted copy.
               m<           e# Rotate the unsorted original that many units left.
                 f{       } e# For each character C in "12346789":
                            e#   Push the rotated string.
                   #        e#   Find the index of C.
                    4-      e#   Subtract 4.
                      z     e#   Compute the absolute value.
                       )    e#   Add 1.
                        0S  e#   Push a 0 and a space.

Prolog, 166 bytes
a(A,R):-I:J:K:L:M=50:40:30:20:10,B is abs(5-A),member(B:S,[4:[I,J,K,J,L,K,L,M],3:[J,I,J,K,K,L,M,L],2:[K,J,I,L,J,M,L,K],1:[J,K,L,I,M,J,K,L]]),(A/5>1,reverse(S,R);S=R).

This uses the fact that the result for 9 is the reverse of the result for 1, same for 2 and 8, 3 and 7 and 4 and 6. There are recognizable patterns to go from the result of 1 to the results of 2,3 and 4 but I'm pretty sure it would be longer to code this than hardcoding the sequences for 1 to 4, which is what I did.
Example: a(7,R). outputs R = [30, 20, 10, 40, 20, 50, 40, 30].

A valid strategy, though I hope some languages make it easier to do algorithmically than it would be to hardcode it. I suppose we'll see.

@Seiyria I assume array-oriented languages will do just that. You unfortunately usually can't permute elements of lists in a short amount of bytes in Prolog.

Python - 115
a=[50,40,30,20,10,20,30,40]
b=[0,1,2,7,8,3,6,5,4]
def v(n):
 c=8-b[n-1]
 return[(a[c:]+a[:c])[e]for e in b if e-8]

a is an array with the values in order around the numpad (counter-clockwise from 1), and b maps numbers on the numpad to positions around it. Based on the number of spaces around the numpad for the input number (determined using b), it makes an array with that many elements moved from the front of a to the end, then uses b again to rearrange the elements to correspond with numpad numbers.

You can save a lot by making a /10 and then putting a *10 in your loop.

Isn't (a[c:]+a[:c])[e] that same is a[(c+e)%8] or a[c+e-8]? And then plugging in c simplifies the expression.

Pyth - 38 bytes
Uses kinda the same technique as the Python answer except with base compression for the two arrays.
J_jC"3ê"T*RTm@.<jC"<àR"T-8@JtQd.DJ4

Try it here online.

What are the ê and à doing?

@phase the aforementioned base compression: http://codegolf.stackexchange.com/questions/40039/tips-for-golfing-in-pyth/53383#53383

These short answers will never cease to amaze me.

@Seiyria I can really suggest to learn Pyth - these programs look a lot more complicated than they are :)

Java, 190
void g(int n){int i[]={8,0,1,2,7,8,3,6,5,4};String v="54321234",s="";n=i[n];if(n>0)v=v.substring(8-n)+v.substring(0,8-n);for(n=0;n++<9;s=", ")if(n!=5)System.out.print(s+v.charAt(i[n])+"0");}

String v holds the probabilities (divided by 10) in countrclockwise order with input = 1 being the default 50.
int[]i translates the input into an index into v. For example, v.charAt(i[1]) is 5. Inputs 0 and 5 are invalid so both i[0] and i[5] have a placeholder value of 8 which is the index for '\0' at the end of v.
I rotate the numbers in v to the right by the value i[n], and then print the probabilities as comma separated strings.


text:
Fibonacci Spiral
Your goal is to generate a Fibonacci spiral with numbers.

Example Input / Output
1 -> 1

2 -> 1 1

3 -> 1 1
     2 2
     2 2

6 -> 8 8 8 8 8 8 8 8 5 5 5 5 5
     8 8 8 8 8 8 8 8 5 5 5 5 5
     8 8 8 8 8 8 8 8 5 5 5 5 5
     8 8 8 8 8 8 8 8 5 5 5 5 5
     8 8 8 8 8 8 8 8 5 5 5 5 5
     8 8 8 8 8 8 8 8 1 1 3 3 3
     8 8 8 8 8 8 8 8 2 2 3 3 3
     8 8 8 8 8 8 8 8 2 2 3 3 3

Input of 9
Input
The input can be taken through STDIN or function argument. It will be a single number
Output
The output can be from STDOUT or a function's return value. It should be a single string.
Extra whitespace at the very end of the line is not allowed. The output can contain digits, linefeeds (newlines), and spaces.
Orientation does not matter, this means rotations and reflections. As long as it follows a valid Fibonacci spiral pattern.
Numbers with different amounts of digits (e.g. 1 and 13) should be right-aligned with each other. A space may need to be added to the very beginning of a line so everything can line up.
1   1                          1   1
100 100  should actually be  100 100

You can see an example here

This is code-golf so shortest code in bytes wins!

Related challenge (and a very cool clock)

Numbers with different amounts of digits (e.g. 1 and 13) should be aligned to the left side of the digit a space may need to be added to the very beginning of a line so everything can line up. This sounds like it might be clearer as two sentences.

It looks from the examples that you want the rightmost digit of each number to be aligned, but "aligned to the left side of the digit" sounds like the opposite.

Can you clarify "surrounding whitespace is not allowed"? In particular - is leading or trailing whitespace on the lines acceptable?

Matlab prints output to stdout by default. Is it acceptable to have numeric-type output (as opposed to string-type output) that gets automatically printed to stdout?

APL, 23
{a,⍴⍨2⍴⊃⍴a←⌽⍉⍵}⍣(⎕-1)⍪1

Explanation:
⍪1               this creates a 1x1 matrix containing just 1
{..}⍣(⎕-1)     the power operator (⍣) repeats the function {} user input - 1 times
a,⍴⍨2⍴⊃⍴a←⌽⍉⍵   the function being iterated rotates the matrix and appends the next matrix to it.

Try it on tryapl.org

If you search here, many had your doubt before. Here is for example @Tobia 's answer: * Dyalog APL supports a legacy charset which has the APL symbols mapped to the upper 128 byte values. Therefore an APL program that only uses ASCII characters and APL symbols can be considered to be bytes == chars.

Okay then, I'll retract my comment.

@MorisZucca Notice though, that some characters (like ⌸ or ⍤) are missing from that character set and cannot be used when you want to evoke that rule.

True, "key" and "rank" are newer implementations and exist in fact only in the Unicode version of the Dyalog interpreter I use. The Classic version has to use the ⎕command equivalent. The same applies to ⍠ (⎕OPT) too for example. Thus I usually think that if I can write it in the Dyalog Classic version, it's safe to say it's 1 byte per char. Correct me if I'm wrong. And thanks for the comment.

Matlab, 84 bytes
A function is used. Output is in stdout.
function f(N)
s=0;t=1;y=1;for n=2:N
u=s+t;s=t;t=u;y=[rot90(y) t*ones(t)];end;disp(y)

Examples:
>> f(1)
     1
>> f(2)
     1     1
>> f(3)
     1     2     2
     1     2     2
>> f(6)
     5     5     5     5     5     8     8     8     8     8     8     8     8
     5     5     5     5     5     8     8     8     8     8     8     8     8
     5     5     5     5     5     8     8     8     8     8     8     8     8
     5     5     5     5     5     8     8     8     8     8     8     8     8
     5     5     5     5     5     8     8     8     8     8     8     8     8
     3     3     3     1     1     8     8     8     8     8     8     8     8
     3     3     3     2     2     8     8     8     8     8     8     8     8
     3     3     3     2     2     8     8     8     8     8     8     8     8
>> f(7)
     8     8     8     8     8     8     8     8    13    13    13    13    13    13    13    13    13    13    13    13    13
     8     8     8     8     8     8     8     8    13    13    13    13    13    13    13    13    13    13    13    13    13
     8     8     8     8     8     8     8     8    13    13    13    13    13    13    13    13    13    13    13    13    13
     8     8     8     8     8     8     8     8    13    13    13    13    13    13    13    13    13    13    13    13    13
     8     8     8     8     8     8     8     8    13    13    13    13    13    13    13    13    13    13    13    13    13
     8     8     8     8     8     8     8     8    13    13    13    13    13    13    13    13    13    13    13    13    13
     8     8     8     8     8     8     8     8    13    13    13    13    13    13    13    13    13    13    13    13    13
     8     8     8     8     8     8     8     8    13    13    13    13    13    13    13    13    13    13    13    13    13
     5     5     5     5     5     1     2     2    13    13    13    13    13    13    13    13    13    13    13    13    13
     5     5     5     5     5     1     2     2    13    13    13    13    13    13    13    13    13    13    13    13    13
     5     5     5     5     5     3     3     3    13    13    13    13    13    13    13    13    13    13    13    13    13
     5     5     5     5     5     3     3     3    13    13    13    13    13    13    13    13    13    13    13    13    13
     5     5     5     5     5     3     3     3    13    13    13    13    13    13    13    13    13    13    13    13    13

Matlab, 78 bytes
function y=f(N)
s=0;t=1;y=1;for n=2:N
u=s+t;s=t;t=u;y=[rot90(y) t*ones(t)];end

Same as above except a Matlab's feature is exploited, namely, it automatically displays function output (as a string) in stdout. This avoids the conversion to string in the above approach.
f(6)
ans =
     5     5     5     5     5     8     8     8     8     8     8     8     8
     5     5     5     5     5     8     8     8     8     8     8     8     8
     5     5     5     5     5     8     8     8     8     8     8     8     8
     5     5     5     5     5     8     8     8     8     8     8     8     8
     5     5     5     5     5     8     8     8     8     8     8     8     8
     3     3     3     1     1     8     8     8     8     8     8     8     8
     3     3     3     2     2     8     8     8     8     8     8     8     8
     3     3     3     2     2     8     8     8     8     8     8     8     8

glad to see some Matlab solutions :-)

Ruby, 243 242 236 233 222 170 130 bytes
s,l,r=0,1,[]
gets.to_i.times{s+=l
l=s-l
s.times{r<<[s]*s}
r=r.transpose.reverse}
r.map{|w|puts w.map{|c|"%#{s.to_s.size}s"%c}*" "}

Nice golfing! You can save some chars on line 4, by converting t==value conditions to t>value. For example, (t=x%4)>2?s.times{r<<[s]*s}:t>1?s.times{r.map!{|w|w.unshift s}}:t>0?s.times{r.unshift [s]*s}:r.map!{|w|w+=[s]*s}}

Python 2, 121 bytes
a,b=0,1;L=[]
exec"a,b=b,a+b;L=zip(*L[::-1])+[[a]*a]*a;"*input()
for r in L:print" ".join("%*d"%(len(str(a)),x)for x in r)

The relaxed rules on rotations makes this a lot simpler.
I haven't used backticks in place of str(a) here because I'm not sure whether we're allowed more leading spaces than necessary, if we ever reach longs. Although, even if we were, using a itself would be shorter anyway.

Python - 189 179 174
n=int(input())
f=[1,1]
while len(f)<n:f+=[f[-1]+f[-2]]
o=[[]]
for i in f:o=(list(zip(*o)))[::-1]+[[i]*i]*i
for x in o:print(' '.join(str(y).rjust(len(str(f[-1])))for y in x))

Haskell, 183 176 171 163 bytes
import Data.List
s t=map((t>>[l t])++)t
e 1=[[1]];e n=s.reverse.transpose$e$n-1
f=g.e
g m=unlines$map(>>=((show$l m)#).show)m
a#b|l a<l b=b;a#b=a#(' ':b)
l=length

The function is f, which takes a number and returns a single string:
λ: putStr $ f 8
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21  5  5  5  5  5  8  8  8  8  8  8  8  8
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21  5  5  5  5  5  8  8  8  8  8  8  8  8
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21  5  5  5  5  5  8  8  8  8  8  8  8  8
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21  5  5  5  5  5  8  8  8  8  8  8  8  8
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21  5  5  5  5  5  8  8  8  8  8  8  8  8
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21  3  3  3  1  1  8  8  8  8  8  8  8  8
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21  3  3  3  2  2  8  8  8  8  8  8  8  8
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21  3  3  3  2  2  8  8  8  8  8  8  8  8
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13
 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 13 13 13 13 13 13 13 13 13 13 13 13 13

J, 36 bytes
1&(($~,~)@(1{$@]),.|:@|.@])&(,.1)@<:

Usage:
   (1&(($~,~)@(1{$@]),.|:@|.@])&(,.1)@<:) 6
8 8 8 8 8 8 8 8 5 5 5 5 5
8 8 8 8 8 8 8 8 5 5 5 5 5
8 8 8 8 8 8 8 8 5 5 5 5 5
8 8 8 8 8 8 8 8 5 5 5 5 5
8 8 8 8 8 8 8 8 5 5 5 5 5
8 8 8 8 8 8 8 8 1 1 3 3 3
8 8 8 8 8 8 8 8 2 2 3 3 3
8 8 8 8 8 8 8 8 2 2 3 3 3

Method:
The function rotates the current square and adds the new square to the current one input-1 times. Square size and element values are gathered from the size of the previous rectangle.
Code explanation:
1&(           loop
    ($~,~)      new square with size and elements
    @(1{$@])    with the size of the second dimension of the current rectangle
    ,.          attached to
    |:@|.@]     rotated current rectangle
)&(,.1)       starting the loop with matrix 1
@<:           looping input-1 times

Try it online here.

Pyth, 34 bytes
jbmsm.[hl`lhZ`k\ d=Zu+_CGmmlGGGQ]]

Surprisingly, more than half of the code is printing/padding, rather than generating the matrix.
The generation of the matrix is really simple however, it consists of a transpose and reversal, and adding N lines containing N copies of N, where N is the current number of lines.
Example output for 7:
  5  5  5  5  5  8  8  8  8  8  8  8  8
  5  5  5  5  5  8  8  8  8  8  8  8  8
  5  5  5  5  5  8  8  8  8  8  8  8  8
  5  5  5  5  5  8  8  8  8  8  8  8  8
  5  5  5  5  5  8  8  8  8  8  8  8  8
  3  3  3  1  1  8  8  8  8  8  8  8  8
  3  3  3  2  2  8  8  8  8  8  8  8  8
  3  3  3  2  2  8  8  8  8  8  8  8  8
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13
 13 13 13 13 13 13 13 13 13 13 13 13 13

Perl, 289 277 257 bytes
@f=(0,1);push@f,$f[-1]+$f[-2]while(@f<=$ARGV[0]);$d=1+length$f[-1];shift@f;map{$v=$f[$_];$t=sprintf("%${d}d",$v)x$v;$_%4||map{unshift@s,$t}1..$v;$_%4==3&&map{$_.=$t}@s;$_%4==2&&map{push@s,$t}1..$v;$_%4==1&&map{$_=$t.$_}@s;}0..$#f;$\=$/;for(@s){s/^ //;print}

K, 48 bytes
{{`0:1_',/'(1+#$|//x)$x}(x-1){+|x,\:t#t:#x}/,,1}

And in action:
  {{`0:1_',/'(1+#$|//x)$x}(x-1){+|x,\:t#t:#x}/,,1}7
 8  8  8  8  8  8  8  8  5  5  5  5  5
 8  8  8  8  8  8  8  8  5  5  5  5  5
 8  8  8  8  8  8  8  8  5  5  5  5  5
 8  8  8  8  8  8  8  8  5  5  5  5  5
 8  8  8  8  8  8  8  8  5  5  5  5  5
 8  8  8  8  8  8  8  8  1  1  3  3  3
 8  8  8  8  8  8  8  8  2  2  3  3  3
 8  8  8  8  8  8  8  8  2  2  3  3  3
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13 13 13 13 13 13 13

May still be some good opportunities for golfing.
The program basically consists of two parts- generating the concatenated matrix and formatting it for output. The former is fairly simple:
  {(x-1){+|x,\:t#t:#x}/,,1}5
(3 3 3 2 2
 3 3 3 2 2
 3 3 3 1 1
 5 5 5 5 5
 5 5 5 5 5
 5 5 5 5 5
 5 5 5 5 5
 5 5 5 5 5)

Beginning with a 1x1 matrix containing 1, build a T-length vector of T where T is the length of the starting matrix on the first dimension (t#t:#x) and attach that to each row of the original matrix (x,\:). Reversing and transposing the result (+|) rotates it 90 degrees. We do this N-1 times.
Formatting is pretty clunky, because K's natural approach to printing a matrix won't align number columns the way we need:
{`0:1_',/'(1+#$|//x)$x}

The basic idea is to take the maximum element of the matrix (|//x), convert it to a string (unary $), take its length plus one (1+#) and then format the elements of the matrix to right aligned strings of that size. Then to tidy up, join those strings (,/') and drop the resulting leading space (1_').

CJam, 48 bytes
1saali({z{W%}%_0=,__sa*a*+}*_W=W=,):U;{USe[}f%N*

Try it online
The core part of generating the pattern seems reasonably straightforward. Rotate the rectangle created so far, and add a square of values at the bottom.
The code for padding the result looks awful, though. I tried a bunch of combinations of f and : operators to apply the padding to the nested list, but nothing worked. If anybody has better suggestions, they are most welcome.
1s    First value. Using string for values so that we can pad them in the end.
aa    Wrap it twice. Data on stack will be a list of lists (list of lines).
li    Get input.
(     Decrement, since we seeded the list at n=1.
{     Loop over n.
  z     Transpose...
  {W%}% ... and reverse all lines, resulting in a 90 degree rotation.
  _0=,  Get length of line, which is the size of square we need to add.
  __    Create two copies of size.
  sa    Convert one size to string, and wrap it in array.
  *     Replicate it size times. This is one line.
  a     Wrap the line...
  *     ... and replicate it size times. The square of new values is done.
  +     Add the list of lines to the previous list of lines.
}*    End of loop over n.
_W=W= Get last value produced.
,)    Take its length, and increment it. This is the output field width.
:U;   Store the field width in variable, and pop it. This is ugly.
{     Start of block applied to all values.
  U     Field width stored in variable.
  S     Space.
  e[    Pad left.
}f%   End of block applied to all values.
N*    Join lines with newline.

Reversing all lines can be done with Wf%. Also, would you be able to do something like {Se[}ff% rather than :U;{USe[}f% for the padding? (That might not work as it is, I can't think through it right now.)

Ruby, 129 bytes
I edited the other ruby answer a bunch, but my most recent change is not being accepted or something, so here it is:
s,r=0,[[1]]
gets.to_i.times{s+=r[0][0]
r=(r+[[s]*s]*s).transpose.reverse}
r.map{|w|puts w.map{|c|"%#{r[0][s].to_s.size}s"%c}*' '}

Welcome to PPCG! Golfing improvements are usually rejected around here (if your other suggestions were accepted that must have been an oversight), because they are supposed to be posted in comments for the author to review. See this meta post for the reasoning behind this policy.

Thanks for the info, makes sense. Commenting is what I would have originally  done but I did not have enough reputation points to comment, but will do in the future. Happy golfing!

Pyth, 29 bytes
Vu+C_GmmlGGGQ\]Yjdm.\[l`lN`d\ N

Demonstration.
If padding was free/implicit, like in APL, or matrix output was allowed, this would be 14 bytes:
u+C_GmmlGGGQ]Y

ES6, 248 bytes
n=>(f=(n,o=n)=>Array(n).fill(o),g=n=>n<3?[f(n,1)]:(a=g(n-2)).reverse().concat(f(l=a[0].length,f(l))).map((e,i,a)=>f(a.length).concat(e.reverse())),a=g(n),s=' '.repeat(l=` ${a[0][0]}`.length),a.map(a=>a.map((e,i)=>(s+e).slice(!i-1)).join``).join`\n`)

Where \n represents a literal newline character.
Annoyingly the formatting takes up a large chunk of the code.
f is a helper function that makes a filled array. It's used mostly to create the filled squares but also handily doubles up to produce the base cases for the recursion.
g is the main gruntwork. It recursively generates the last but one solution, rotates it 180 degrees, then appends the next two squares.


text:
Count from 1 to n in Negabinary and Negaquaternary
Instead of normal binary, you must count from 1 to an input in negabinary concatenated to negaquaternary.
Here's an example, put in the form of an array:
[11, 1102, 1113, 100130, 101131, 11010132, 11011133, 11000120, 11001121, 11110122, 11111123, 11100110, 11101111, 10010112, 10011113, 10000100, 10001101, 10110102, 10111103, 10100230, 10101231, 1101010232, 1101011233, 1101000220, 1101001221, 1101110222, 1101111223, 1101100210, 1101101211, 1100010212, 1100011213, 1100000200, 1100001201, 1100110202, 1100111203, 1100100330, 1100101331, 1111010332, 1111011333, 1111000320, 1111001321, 1111110322, 1111111323, 1111100310, 1111101311, 1110010312, 1110011313, 1110000300, 1110001301, 1110110302, 1110111303, 111010013030, 111010113031, 100101013032, 100101113033, 100100013020, 100100113021, 100111013022, 100111113023, 100110013010, 100110113011, 100001013012, 100001113013, 100000013000, 100000113001, 100011013002, 100011113003, 100010013130, 100010113131, 101101013132, 101101113133, 101100013120, 101100113121, 101111013122, 101111113123, 101110013110, 101110113111, 101001013112, 101001113113, 101000013100, 101000113101, 101011013102, 101011113103, 101010013230, 101010113231, 11010101013232, 11010101113233, 11010100013220, 11010100113221, 11010111013222, 11010111113223, 11010110013210, 11010110113211, 11010001013212, 11010001113213, 11010000013200, 11010000113201, 11010011013202, 11010011113203, 11010010013330]
Your program must produce those numbers in any of these forms:

spaced apart
in an array
on new lines

How do I get those numbers?
Integer n will be used as an example of input.

for i := 1 to n
    print "i in base -2" + "i in base -4"

Rules:

You can submit a function or a whole program
You can go from 0 or 1 to the input
Builtins are allowed

O, 18 bytes
j){n.2_bo4_bo' o}d
Just my own take on this. Prints numbers with a space between them.
Try it online
Explanaiton:

j)                 Increment input by 1
  {             }d Do this (input+1) times
   n.2_bo          Convert n to base -2 and output
         4_bo      Convert n to base -4 and output
             ' o   Output a space

Python - 83 bytes
f=lambda i,k:i and f(-i/k,k)+`-i%k`or''
i=0;exec"i-=1;print f(i,2)+f(i,4);"*input()

f is a function that converts (the negation of) an integer i to a negative base 2 ≤ k ≤ 10. Input is taken from stdin.

Sample Usage
$ echo 30 | python nega2+4.py
11
1102
1113
100130
101131
11010132
11011133
11000120
11001121
11110122
11111123
11100110
11101111
10010112
10011113
10000100
10001101
10110102
10111103
10100230
10101231
1101010232
1101011233
1101000220
1101001221
1101110222
1101111223
1101100210
1101101211
1100010212

I love your for loop workaround :D

Julia, 124 81 73 bytes
n->(a=2863311530;b=3435973836;[base(2,(i+a)$a)*base(4,(i+b)$b)for i=1:n])

This creates an unnamed function that accepts an integer and returns an array. Each element of the array is a successive number between 1 and n in negabinary concatenated to itself in negaquaternary.
The negabinary representation of an integer can be computed using Schroppel's shortcut:
base(2, (i + 2863311530) $ 2863311530)

For an integer i, this is i + 2863311530, XOR 2863311530, encoded in base 2. The negaquaternary shortcut is similar:
base(4, (i + 3435973836) $ 3435973836)

as per this meta ruling, you can define globals with the constants outside: http://meta.codegolf.stackexchange.com/questions/5532/when-submitting-a-function-can-global-variables-be-declared-outside-the-functio

@Maltysen: Oh nice, I had forgotten about that. Thanks!

I don't think you can define globals unless the function is named.

@feersum: Okay, no problem. Made them local at the cost of 2 bytes.

Pyth - 31 30 29 27 bytes
Uses Forumla by D. Librik (Szudzik) (look at negabinary and quaternary sections). Can probably be golfed a bit.
VQjksjVmx+NKi*8d16K"AC",2 4

Prints from zero on separate lines.
VQ                   For i in 0-Q
 jk                  Join by empty string
  s                  Sum of two arrays
   jV                Vectorized base conversion
    m       "AC"     Map of A and C
     x               Bitwise xor
      +NK            Sum of loop var and constant inline assigned
       i  16         To base 10 from 16
        *8           String repetition times 8
         d           Map var
      K              Xnor of constant
   ,2 4              Bases 2 and 4

Try it here online.

@AlexA. "You can go from 0 or 1 to the input"

Wow, clearly I'm oblivious. Sorry, false alarm!

CJam, 34 33 32 bytes
I think this can be golfed further. Counts from 0.
li),{_[CA]{:Ba8*Gb_@+^B8-b\}/N}/

Try it online.

Jelly, 10 bytes
bF¥€Ø½ḤN¤Ḍ

Try it online!
How it works
bF¥€Ø½ḤN¤Ḍ - Main link. Takes an integer as left argument
    Ø½ḤN¤  - Yield the list [-2, -4]:
        ¤  -   Group the previous commands into a constant:
    Ø½     -     Start with [1, 2] (builtin constant)
      Ḥ    -     Double     [2, 4]
       N   -     Negate     [-2, -4]
  ¥€       - Generate the range 1...n and do the following to each:
b          -   Convert to bases -2 and -4
           -   For example, 5b[-2, -4] => [[1, 0, 1], [1, 3, 1]]
 F         -   Flatten the lists          [1, 0, 1, 1, 3, 1]
         Ḍ -   Convert to a number        101131

Japt, 12 bytes
Output is an array of digit arrays.
õìJÑ)ícUõì4n

Try it

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Conversion to Boolean satisfiability
Given a matrix M all of whose entries are 0 or 1, we want to known whether there exists a non-zero vector v with each element in {-1, 0, 1}, such that Mv = 0.
An easy way to do this is just to try all possible vectors v. The M is m by n then there are 3n - 1 such vectors.  But of course this is PPCG, so we don't want to do anything so simple!
Instead, this task is to convert the problem into an instance of  Boolean satisfiability problem.
Input
An m by n matrix M written out with one row per line each space separated. The first list has m and n on it, space separated. For example this 3 by 4 matrix M.
3 4
1 1 0 1
0 1 1 0
0 0 1 1

In this case there does not exist a non-zero vector v, all of whose entries are -1,0 or 1 such that Mv = 0.
Output
An instance of 3-SAT in simplified DIMACS format.
The instance of 3-SAT that you output should be satisfiable if and only if there exists a non-zero vector v, all of whose entries are -1,0 or 1 such that Mv = 0.
The file format will be in a simplified version of the DIMACS format using this specification taken from http://www.satcompetition.org/2009/format-benchmarks2009.html

c
c start with comments
c
c
p cnf 5 3
1 -5 4 0
-1 5 3 4 0
-3 -4 0

The file can start with comments, that is lines begining with the character c.
    Right after the comments, there is the line p cnf nbvar nbclauses indicating that the instance is in CNF format; nbvar is the exact number of variables appearing in the file; nbclauses is the exact number of clauses contained in the file.
    Then the clauses follow. Each clause is a sequence of distinct non-null numbers between -nbvar and nbvar ending with 0 on the same line; it cannot contain the opposite literals i and -i simultaneously. Positive numbers denote the corresponding variables. Negative numbers denote the negations of the corresponding variables.

Score
I will test your code on a 20 by 40 matrix and the score will be the total number of non-comment lines in your 3-SAT instance. Smaller is better.
Running time of your code
Your code should take less than 1 minute to run.  I don't want to restrict the languages used but I will attempt to test any code I can run otherwise I will just trust the timing you give.  For small instances you could of course just compute the answer but this won't work for matrices of the size I will test.
More examples
Your 3-SAT instances for the following matrices should be unsatisfiable.
1 1 0 1
0 1 1 0
0 0 1 1

1 1 0 1 0
0 1 1 0 1
0 0 1 1 0
0 0 0 1 1

1 0 0 1 0 1 1 0 0
1 1 0 0 1 0 1 1 0
0 1 1 0 0 1 0 1 1
0 0 1 1 0 0 1 0 1
0 0 0 1 1 0 0 1 0
0 0 0 0 1 1 0 0 1

1 1 0 1 0 0 1 1 1 0 0 1
1 1 1 0 1 0 0 1 1 1 0 0
0 1 1 1 0 1 0 0 1 1 1 0
0 0 1 1 1 0 1 0 0 1 1 1
0 0 0 1 1 1 0 1 0 0 1 1
0 0 0 0 1 1 1 0 1 0 0 1
0 0 0 0 0 1 1 1 0 1 0 0

Your 3-SAT instances for the following matrices should be satisfiable.
1 1 0 1 1 1 0
1 1 1 0 1 1 1
0 1 1 1 0 1 1
0 0 1 1 1 0 1
0 0 0 1 1 1 0

1 0 1 0 0 1 0 0 0
0 1 0 1 0 0 1 0 0
0 0 1 0 1 0 0 1 0
0 0 0 1 0 1 0 0 1
0 0 0 0 1 0 1 0 0
0 0 0 0 0 1 0 1 0

1 0 0 1 1 1 0 1 0 0 1 1
0 1 0 0 1 1 1 0 1 0 0 1
0 0 1 0 0 1 1 1 0 1 0 0
0 0 0 1 0 0 1 1 1 0 1 0
0 0 0 0 1 0 0 1 1 1 0 1
0 0 0 0 0 1 0 0 1 1 1 0
0 0 0 0 0 0 1 0 0 1 1 1

A possible short cut for the busy programmer
One possibly easier route to tacking this problem could be to output Pseudo-Boolean Constraints. See page 6 of http://www.cril.univ-artois.fr/PB12/format.pdf for example. There are then different open source tools and libraries which will convert that to 3-SAT.

I edited your question to say that v's entries can individually be {-1, 0, 1}. I'm not 100% sure you intended this, but it made no sense for all elements to be the same value, if you listed 0 as a possible value while disallowing zero vectors.

I'm starting to believe this is infeasible, unless I'm missing some smart mathematical shortcut. For example, simply consider the satisfiability of one simple mathematical expression with each variable in {0, 1}: a + b + c + d + e + f + g + h + j + i + k - l - m - n - o - p - q - r - s - t - u - v - w - x - z = 0. That's already a massive explosion in clauses, let alone doing it for every possible expansion of +, - or 0!

@orlp Thank you for the edit.  Could http://www.st.ewi.tudelft.nl/jsat/content/volume2/JSAT2_1_Een.pdf help?

If anything, that confirms my suspicion. Keep in mind the complexity of evaluating one such inequality as shown in the paper, and then doing that m*(3^n - 1) times, one for each expression. That's 2.199023e13 inequalities for your benchmark.

@orlp What about making a PBO instance and then calling a tool that converts it to 3-sat?

This probably counts as a loophole, but couldn't you just try all possible vectors and output any satisfiable formula like (x ∨ x ∨ x) iff there exists a non-zero vector v such that Mv = 0 and something like (x ∨ x ∨ x)  ∧ (¬x ∨ ¬x ∨ ¬x) otherwise to answer this question?

@vauge If you can do that in a 1 minute then please go ahead :)

The 6x9 matrix that is supposed to be unsatisfiable seems to be solved by [-1 1 1 1 0 0 -1 0 0].

After checking with brute force I believe the first and second matrices in the 'satisfiable' section are also classified incorrectly.

@feersum Sorry my examples were wrong due to a stupid copy and paste error. Should all be fixed now.

OCaml, ≤ 475318
After defining the basic logic gates (I ended up using only AND and OR), I compose them to make a variable for each of the possible partial sums of a row of M and v. A total of O(mn2) variables/clauses are used. This is an initial effort that doesn't make any attempt to simplify the formula. In the worst case (a matrix with no zeroes), it generates 475,318 clauses for a 20x40 matrix.
let rec genlist f n =
    match n with
    | 0 -> []
    | n -> let e = f() in e :: genlist f (n-1)
;;

let numvars = ref 0 ;;
type var = V of int | Const of bool;;
let mkv () = incr numvars; V !numvars;;
type clause = Cl1 of var | Cl2 of var*var | Cl3 of var*var*var ;;
let clauses = ref [] ;;
let req (x:clause) = if x <> Cl1(Const true) then clauses := x :: !clauses ;;
let deref = (!);;
let (!) = function
    | V x -> V (-x)
    | Const c -> Const (not c)
;;

let mkeq (a:var) (b:var) = match a,b with
    | Const true, b -> b
    | Const false, b -> !b
    | a, Const true -> a
    | a, Const false -> !a
    | a,b -> let v = mkv() in
    req@@Cl3 ( !v, a, !b ) ;
    req@@Cl3 ( !v, !b, a ) ;
    req@@Cl3 ( v, a, b ) ;
    req@@Cl3 ( v, !a, !b );
    v
;;

let mkxor a b = ! (mkeq a b) ;;

let mkor (a:var) (b:var) = match a,b with
    | Const false, b -> b
    | Const true, _ -> Const true
    | _, Const true -> Const true
    | a, Const false -> a
    | a,b -> let v = mkv() in
    req@@Cl2 ( v, !a ) ;
    req@@Cl2 ( v, !b ) ;
    req@@Cl3 ( !v, a, b ) ;
    v
;;

let mkand a b = ! (mkor !a !b) ;;

let mkorl l =
    let rec mkorl_ = function
        | a::b::tl -> mkor (mkor a b) (mkorl_ tl)
        | a::[] -> a
        | [] -> Const false
    in mkorl_ (List.filter (function | Const false -> false | _ -> true) l)
;;
let nextsums sums (minus1, zero, plus1) =
    let rec nextsums_ prev sums (minus1, zero, plus1) =
    match sums with
        | cur::next::tl ->
            ( mkorl [mkand minus1 next; mkand zero cur; mkand plus1 prev] ) ::
            ( nextsums_ cur (next::tl) (minus1, zero, plus1) )
        | cur::_ ->
            (mkor (mkand zero cur) (mkand plus1 prev)) ::
            ( nextsums_ cur [] (minus1, zero, plus1) )
        | _ -> [mkand plus1 prev]
    in
    (mkand minus1 (List.hd sums)) ::
    nextsums_ (Const false) sums (minus1, zero, plus1)
;;

let rec entry_zero row v sums maxsum =
    if row=[] then List.nth sums maxsum else
    if List.hd row = 0 then entry_zero (List.tl row) (List.tl v) sums maxsum else
    let (a,b,c) = List.hd v in
    let elemv = if List.hd row = -1 then (c,b,a) else (a,b,c) in
    entry_zero (List.tl row) (List.tl v) (nextsums sums elemv) (maxsum+1)
;;

let req1of3 (a,b,c) =
    req@@Cl2(!a, !b);
    req@@Cl2(!a, !c);
    req@@Cl2(!b, !c);
    req@@Cl3(a, b, c);;

let rdint () = Scanf.bscanf Scanf.Scanning.stdin " %d" (fun x -> x) ;;

let m = rdint();;
let n = rdint();;

let vec = genlist (fun () -> (mkv(), mkv(), mkv()) ) n;;
List.iter req1of3 vec;;

let mat = genlist (fun () -> genlist rdint n) m;;

List.iter (fun row -> req@@Cl1 (entry_zero row vec [Const true] 0) ) mat;;

let nonzeros = List.map (function _,z,_ -> !z) vec ;;
req@@Cl1 (mkorl nonzeros) ;;

exception Bug of string;;
let str_clause (cl:clause) = match cl with
    | Cl1(V a) -> Printf.sprintf "%d 0" a
    | Cl2(V a,V b) -> Printf.sprintf "%d %d 0" a b
    | Cl3(V a,V b,V c) -> Printf.sprintf "%d %d %d 0" a b c
    | _ -> raise @@ Bug "there seems to be";;
let (!) = deref;;

Printf.printf "p cnf %d %d\n" !numvars (List.length !clauses) ;;
List.iter (fun cl -> print_endline (str_clause cl)) !clauses ;;

This looks very impressive ! Did you get a chance to try it on my test cases?

Python, n/a
Not a full answer, but this turns matrices into PBS instances that can be transformed into 3-SAT instances by standard tools:
import fileinput

def pos_vec(i): return "x" + str(1 + 2*i)
def neg_vec(i): return "x" + str(1 + 2*i+1)

def print_pseudo(M):
    print(" ".join("1 x" + str(i) for i in range(1, len(M[0])*2 + 1)) + " > 0;")
    for v in range(len(M[0])):
        print("1 {} 1 {} < 2;".format(pos_vec(v), neg_vec(v)))

    for r in range(len(M)):
        terms = []
        for c in range(len(M[0])):
            if M[r][c]:
                terms.append("1 {}".format(pos_vec(c)))
                terms.append("-1 {}".format(neg_vec(c)))
        print(" ".join(terms) + " = 0;")

M = [[int(b) for b in line.split()] for line in fileinput.input()]
print_pseudo(M)

Thanks! The tools at http://tools.computational-logic.org/content/pblib.php seem appropriate and pbencoder in particular. (PBS == Pseudo Boolean Satisfaction .)