text:
Hexadecimal of a character
Given a unicode character C (or the first character of a string input), output that character's hex representation. Case does not matter. The output ranges from \u0000 to \u9999.
Test cases
A => 41  (65_10 === 41_16)
ʣ => 2A3 (675_10 === 2A3_16)
Ω => 3A9 (937_10 === 3A9_16)
7 => 37  (55_10 === 37_16)
(null byte) => 0 (0_10 === 0_16)

-50% byte bonus if you output the javascript escape character \uXXXX of the character C, e.g. g => \u0067 and ~ => \u007E

-1.  I think by the standards of this community this is a valid question and I don't see any grounds to close it.  However it is especially trivial as evidenced by all the very quick and very short answers.  IMO.  YMMV.

@DigitalTrauma IMO... YMMV... what!?

In My Opinion.  Your Mileage May Vary.  Knowing the things work around here, this question will end up hitting the HNQ and get lots of votes anyway.

@DigitalTrauma +3/-6?

Jolf, 3 bytes
Try it here!
~Ti

Compiles to var i=prompt("i = ");(i).charCodeAt().toString(16);
Bonus, 13 - 50% = 6.5 bytes
Try it here!
"\\u%"pq~Ti40
"\\u "        prefix
    %         interpolate with
        ~Ti    you know what this is
      pq   40  pad with 4 0's

It's rare to see a -50% bonus score be more than double the non-bonus version. :P

@El'endiaStarman Yes, that's a tidbit embarrassing ^^"

CJam, 5 20 18 bytes
{iGb{A,6,'Af++=}%}

i converts to integer, G pushes 16, b is base conversion.
... and CJam has no way to use 0-9A-Z instead of base-converting to numbers? That's not annoying at all.
{          }%   map over number-digits
 A,             generate the digits 0-9
   6,'Af+       generate the "digits" A-F
         +      concat
          =     array-index into the newly generated array

Thanks to @MartinBüttner for saving 2  bytes!

{iGb{A,6,'Af++=}%}

Julia, 14 bytes
Interestingly, this is 14 bytes with and without the bonus.
No bonus:
c->hex(Int(c))

Bonus:
c->"\\u"lpad(hex(Int(c)),4,0)

Both are lambda functions that accept Chars and return strings. To call a lambda, assign it to a variable.
We get the code point associated with the Char using Int(), then convert to hexadecimal using hex(). For the bonus, we left pad to 4 characters with zeros and prepend \\u. The backslash needs to be escaped in the string.

Julia has automatic string concatenation? o-O

@CᴏɴᴏʀO'Bʀɪᴇɴ Here it's actually a combination of two features: Julia uses multiplication to concatenate strings, and in some cases the * can be omitted for multiplication since Julia has coefficient literals (or whatever you want to call it when 2x means 2*x).

... I remember why I got Julia. Cool language! :D

CJam, 5.5 bytes
"\u%04X"qe%

The code is 11 bytes long and qualifies for the -50% bonus. Try it online in the CJam interpreter.
How it works
"\u%04X"     e# Push that format string, i.e., a literal "\u", followed by
             e# an integer in hexadecimal, 0-padded to 4 characters.
        q    e# Read all input.
         e%  e# Apply string formatting.

The online interpreter will happily treat the input string as the code point of its sole character. This does not work in the Java interpreter, so it might be a feature or a bug.

Pyth - 4 bytes
.HCz

Test Suite.
Pyth doesn't do unicode for string conversions, instead uses ISO-8859, so cost one more byte.
.H            Hex representation
 C            Unicode code point
  z           Input string

TeaScript, 5 bytes
xcT16

I'm very sure I have a unicode shortcut for 16
Try it online

Isn't m=16 from the docs?

@BlockCoder1392 yeah but I'd still have to replace 16 with (m which isn't any shorter

JavaScript ES6, 30 54 / 2 = 27 bytes
s=>"\\u"+("000"+s.charCodeAt().toString(16)).slice(-4)

The bonus helped a bit
Try it online at ESFiddle (all browsers work)

At least we know that this is the absolute hard minimum. I'm sure the bonus will help out here.

Mathematica, 50 - 50% = 25 bytes
"\u"<>IntegerString[First@ToCharacterCode@#,16,4]&

Ignore the error. Mathematica does not recognize the escape code \u, so just escapes the \ and gives a Syntax:stresc message.

Japt, 5 bytes
Uc sG

Very simple. Try it online!
How it works
Uc sG  // Implicit: U = input, G = 16
Uc     // Take the char code of U.
   sG  // Turn it into a base-16 string.
       // Implicit: output last expression

Bonus version, 20 bytes * 0.5 = 10
"\\u{'0³+Uc sG)t0-4

Not as simple. Try it online!
How it works
          // Implicit: U = input, G = 16
"\\u{     // Take the string "\u", and add:
 '0³+     //  Take 3 "0"s, plus
 Uc sG)   //  the hex char code of the input.
 t0-4     //  Take the last 4 chars.
          // Implicit: output last expression

Python 2, 27/2 = 13.5 bytes
lambda x:r'\u%04X'%(ord(x))

No online link because apparently ideone's Python 2 version doesn't support Unicode string literals.

, 3 chars / 8 bytes
ï⒞ⓧ

Try it here (Firefox only).
Superbly simple. Convert to charcode, then to hex.


text:
Make Bracket Squares
Every programmer knows that brackets []{}()<> are really fun.  To exacerbate this fun, groups of interwoven brackets can be transformed into cute and fuzzy diagrams.
Let's say that you have a string that contains balanced brackets, like [{][<(]})>(()).  Step one is to rotate the string 45 degrees clockwise. (In Mathematica, this can be almost done with Rotate[ur_string,-pi/4]). Here is the result of the first step:
[
 {
  ]
   [
    <
     (
      ]
       }
        )
         >
          (
           (
            )
             )

Next add a diagonal space between each character.
[

  {

    ]

      [

        <

          (

            ]

              }

                )

                  >

                    (

                      (

                        )

                          )

Next, start with the left-most bracket and draw a square between it and its partner in crime.
+---+
|   |
| { |
|   |
+---+

      [

        <

          (

            ]

              }

                )

                  >

                    (

                      (

                        )

                          )

Repeat this process with each pair of brackets, overwriting previous characters with +s if need be.
+---+
|   |
| +-+---------+
| | |         |
+-+-+         |
  |           |
  |   [       |
  |           |
  |     <     |
  |           |
  |       (   |
  |           |
  |         ] |
  |           |
  +-----------+

                )

                  >

                    (

                      (

                        )

                          )

Continue until you have made everything nice and square.
+---+
|   |
| +-+---------+
| | |         |
+-+-+         |
  |           |
  |   +-----+ |
  |   |     | |
  |   | +---+-+---+
  |   | |   | |   |
  |   | | +-+-+-+ |
  |   | | | | | | |
  |   +-+-+-+ | | |
  |     | |   | | |
  +-----+-+---+ | |
        | |     | |
        | +-----+ |
        |         |
        +---------+

                    +-----+
                    |     |
                    | +-+ |
                    | | | |
                    | +-+ |
                    |     |
                    +-----+

Input
Input will be a single line of balanced brackets and no other characters, with each bracket being one of []{}()<>.  Each type of bracket is balanced individually, though different types may overlap (this is what makes the squares look interesting).  A trailing newline is optional.
Output
Output will be the interlocking square pattern generated from the bracket string.  Trailing spaces and trailing newline are optional, but there mustn't be leading whitespace.
Goal
This is code-golf, fewest bytes wins.

Do we have to deal with nesting of the same type of bracket? e.g. for [[]] can we output two squares overlapping or do we have to output one square inside the other?

One square is inside of the other.  I will adjust my example.  Edit: done.

JavaScript (ES6), 269 274 278 296 261 bytes
Edit Saved 4 bytes thx @Neil
x=>[...x].map(c=>{g.push([],[]),z='<{[(>}])'.indexOf(c);if(z>3)for(j=a=o[z-4].pop();j<=b;j++)S(j,a,'|'),S(j,b,'|'),S(a),S(b);else o[z].push(b);b+=2},S=(y,x=j,c='-')=>g[y][x]=g[y][x]?'+':c,o=[[],[],[],[]],g=[],b=0)&&g.map(r=>[...r].map(c=>c||' ').join``).join`
`

TEST

F=x=>[...x].map(c=>{g.push([],[]),z='<{[(>}])'.indexOf(c);if(z>3)for(j=a=o[z-4].pop();j<=b;j++)S(j,a,'|'),S(j,b,'|'),S(a),S(b);else o[z].push(b);b+=2},S=(y,x=j,c='-')=>g[y][x]=g[y][x]?'+':c,o=[[],[],[],[]],g=[],b=0)&&g.map(r=>[...r].map(c=>c||' ').join``).join`
`

// Less golfed
U=x=>(
  S = (y,x=j,c='-')=>g[y][x]=g[y][x]?'+':c,
  o = [[],[],[],[]],
  g = [],
  b = 0,
  [...x].map(c=>
  {
    g.push([],[]),
    z='<{[(>}])'.indexOf(c);
    if(z>3)
      for(j = a =o[z-4].pop(); j <= b; j++)
        S(j,a,'|'),
        S(j,b,'|'),
        S(a),
        S(b)
    else
      o[z].push(b);
    b += 2
  }),
  g.map(r=>
    [...r].map(c=>c||' ').join``
  ).join`\n`
)

function test() {
  O.textContent=F(I.value)
}

test()
Input:<input id=I value='[{][<(]})>(())' oninput='test()'>

Why not [...r].map?

Better still, [...r].map(c=>c||' ').

@Neil I cannot use r.map because r is a sparse array and map skips missing elements. So I now use g, that is filled (and there are as many rows as columns in output)

I didn't say r.map, I said [...r].map, and [...r] is NOT a sparse array, as you mentioned yourself in http://codegolf.stackexchange.com/a/61505 comment 5.

@Neil I missed that ... it seems a nice hint, thanks

Python 3, 226
n,p,*t=0,[],0,[],[],[],[]
for b in input():
 r=t[ord(b)//30];r+=[n];n+=2
 if b in'])}>':p+=[r[-2:]];del r[-2:]
R=range(n-1)
for y in R:print(''.join(' -|+'[sum((y in q)+2*(x in q)for q in p if x>=q[0]<=y<=q[1]>=x)]for x in R))

Example. Explanation:
n,p,*t=0,[],0,[],[],[],[]   # n -> counter for input
                            # p -> bracket pairs
                            # t -> four stacks [unused, (), <>, [], {}]

for b in input():           # for each bracket b of input
  r=t[ord(b)//30];          # r -> alias for b's stack
  r+=[n];                   # push bracket's index
  n+=2                      # increase counter by 2 (to add diagonal gaps)

  if b in'])}>':            # if b is a closing bracket
    p+=[r[-2:]];            # pair the top 2 brackets on stack
    del r[-2:]              # pop them from stack

R=range(n-1)                # n-1 is now the width/height of output

for y in R:
  print(''.join(' -|+'[
    sum((y in{a,b})+2*(x in{a,b})for a,b in p if x>=a<=y<=b>=x)
  ]for x in R))

# three nested loops:
# 1) for each line y
#   2) for each character x
#     3) for each bracket pair (a, b)

if x>=a<=y<=b>=x
# if x or y isn't in the inclusive range [a, b], we can skip it

(y in{a,b})
# if y is a or b, then the character lies on a horizontal edge of that square
# so we add 1 to the sum

2*(x in{a,b})
# if x is a or b, then the character lies on a vertical edge of that square
# so we add 2 to the sum

' -|+'[sum()]
# if it lies on a single edge, the sum will be 1 or 2 -> '-' or '|'
# if it lies on two edges, the sum will be 1 + 2 == 3 -> '+'

You can save 2 bytes by not unpacking the bracket pairs in the last line.

pb - 449 bytes
^w[B!0]{w[B=40]{b[39]}t[B]w[B!0]{w[B=T]{^b[1]}w[B=T+1]{^b[1]}w[B=T+2]{^b[2]}^[Y]^>}<[X]^w[B!1]{>}t[1]b[0]w[T!0]{>w[B=1]{t[T+1]b[0]}w[B=2]{t[T-1]b[0]}}b[3]vw[B!0]{>}^w[B!3]{b[0]<}b[0]vb[1]>[X]vv[X]b[43]t[X]^[Y]^<[X]w[B=0]{>}>[X]vv[X]b[43]w[Y!T-1]{vw[B=45]{b[43]}w[B=0]{b[124]}}vb[43]t[1]>w[B!43]{t[T+1]w[B=124]{b[43]}w[B=0]{b[45]}>}w[T!0]{^t[T-1]w[B=45]{b[43]}w[B=0]{b[124]}}w[B!43]{w[B=124]{b[43]}w[B=0]{b[45]}<}<[X]^[Y]^w[B=0]{>}b[0]>w[B=1]{b[0]>}}

I was all excited when I read this because I have a language that prints directly to a position! This challenge about positioning outputs should be easy and short!
Then I remembered pb is longwinded anyway.
With comments:
^w[B!0]{
    w[B=40]{b[39]}                       # change ( to ' to make closing bracket calculation work
    t[B]

    # this used to just find the first matching bracket
    # but then op clarified we had to use depth
    # whoops
    # <fix>

    w[B!0]{
        w[B=T]{^b[1]}                        # put a 1 above opening brackets of this type
        w[B=T+1]{^b[1]}                      # same as before, but ugly hack to make ( work
        w[B=T+2]{^b[2]}                      # put a 2 above closing brackets of this type
        ^[Y]^                                # return to input line
    >}
    <[X]^w[B!1]{>}t[1]b[0]               # set T to 1 above the opening bracket
    w[T!0]{>                             # until T (depth) == 0:
        w[B=1]{t[T+1]b[0]}                   # add 1 to T if 1
        w[B=2]{t[T-1]b[0]}                   # subtract 1 from T if 2
    }
    b[3]                                 # when T is 0, we've found the right one
    vw[B!0]{>}                           # go to the end of the input
    ^w[B!3]{b[0]<}b[0]v                  # clean up the row above
    # </fix>

    b[1]                                 # replace it with 1 so it's not confusing later
    >[X]vv[X]b[43]t[X]                   # put a + at its output position and save coord
    ^[Y]^<[X]w[B=0]{>}>[X]vv[X]b[43]     # put a + at opening bracket's output position
    w[Y!T-1]{v
        w[B=45]{b[43]}                       # replace - with +
        w[B=0]{b[124]}                       # otherwise put |
    }
    vb[43]                               # put a + at lower left corner
    t[1]                                 # count side length + 1
    >w[B!43]{
        t[T+1]
        w[B=124]{b[43]}                      # replace | with +
        w[B=0]{b[45]}                        # otherwise put -
    >}
    w[T!0]{^                             # create right side
        t[T-1]
        w[B=45]{b[43]}
        w[B=0]{b[124]}
    }
    w[B!43]{                             # create top side
        w[B=124]{b[43]}                      # this replacement saves us from putting the last + explicitly
                                             # which is why we counted the side length + 1, to get that
                                             # extra char to replace
        w[B=0]{b[45]}
    <}
    <[X]^[Y]^w[B=0]{>}b[0]>w[B=1]{b[0]>}# Go to next character (skipping 1s)
}

I... Just... Can't...

CJam, 117 bytes
q_,2*:M2#0a*\:iee{1=K/}${~)4%1>{a+aL+:L;}*}/L{2f*__~,>m*5Zb\m*{~W2$#%Mb\}%\2m*Mfb3am*}%e_2/{~2$2$=+3e<t}/" |-+"f=M/N*

Try it here.

Ruby, 268
->z{a=(2..2*t=z.size).map{'  '*t}
g=->y,x{a[y][x]=(a[y][x-1]+a[y][x+1]).sum>64??+:?|}
2.times{|h|s=z*1
t.times{|i|c=s[i]
c>?$&&(j=s.index(c.tr('[]{}()<>','][}{)(><'))
(m=i*2).upto(n=j*2){|k|k%n>m ?g[k,m]+g[k,n]:h<1&&a[k][m..n]=?++?-*(n-m-1)+?+}
s[i]=s[j]=?!)}}
puts a}

ungolfed in test program
f=->z{
  a=(2..2*t=z.size).map{'  '*t}                       #make an array of strings of spaces
  g=->y,x{a[y][x]=(a[y][x-1]+a[y][x+1]).sum>64??+:?|} #function for printing verticals: | if adjacent cells spaces (32+32) otherwise +

  2.times{|h|                                         #run through the array twice
    s=z*1                                             #make a duplicate of the input (*1 is a dummy operation to avoid passing just pointer)
    t.times{|i|                                       #for each index in input
    c=s[i]                                            #take the character
    c>?$&&(                                           #if ascii value higher than for $
      j=s.index(c.tr('[]{}()<>','][}{)(><'))          #it must be a braket so find its match
      (m=i*2).upto(n=j*2){|k|                         #loop through the relevant rows of array
        k%n>m ?g[k,m]+g[k,n]:                         #if k!=n and k!m draw verticals
        h<1&&a[k][m..n]=?++?-*(n-m-1)+?+              #otherwise draw horizontals (but only on 1st pass)
      }
      s[i]=s[j]=?!)                                   #we are done with this set of brackets, replace them with ! so they will be ignored in next call of index
    }
  }
  puts a
}

z=gets.chop
f[z]

source: Stack Exchange

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

sort: votes


text:
Superstitious hotel elevator
Description
Here's a very superstitious hotel elevator in Shanghai:

It avoids the number 13, because thirteen is unlucky in the Western world, and it avoids the digit 4, because four is unlucky in parts of Asia. What if this hotel was taller?
Read a positive even integer n from STDIN, representing the number of floors, and print what the button layout would look like to STDOUT: -1, followed by the next n-1 positive integers that aren't equal to 13 and don't contain digit 4. Arrange these numbers in two columns such as in the above image: print two floor numbers per line, separated by a horizontal tab, so that reading the lines in reverse order from left-to-right yields the sequence in ascending order. (You may optionally print a trailing newline character, too.)
Test cases
For the input 14, output should be as in the above image:
15  16
11  12
9   10
7   8
5   6
2   3
-1  1

where the whitespace in each line is a single horizontal tab character.
For the input 2, you should print -1  1.
For the input 100, you should print:
120 121
118 119
116 117
113 115
111 112
109 110
107 108
105 106
102 103
100 101
98  99
96  97
93  95
91  92
89  90
87  88
85  86
82  83
80  81
78  79
76  77
73  75
71  72
69  70
67  68
65  66
62  63
60  61
58  59
56  57
53  55
51  52
39  50
37  38
35  36
32  33
30  31
28  29
26  27
23  25
21  22
19  20
17  18
15  16
11  12
9   10
7   8
5   6
2   3
-1  1

Goal
This is code-golf. Shortest answer in bytes wins.

Wouldn't they also avoid n13?

I don't think anyone considers e.g. 6138 an unlucky number over here. Either way, you should print integers that contain 13 but aren't equal to it.

Okay, cool! (filler)

@Mauris 6138, maybe not, but 113? I think the key would be whether you say "thirteen" when you read the number out loud.

Also, how tall can the hotel get? What about floor 666 (which occurs at 456 floors in the "standard" version, and 449 in the more aggressively 13-avoiding version)

@Random832 What you suggest are effectively arbitrary changes to the spec.  The PPCG etiquette discourages such changes after answers have been given, especially if existing answers are effectively invalidated, which they would be in this case

FWIW, 4 isn't unlucky. 4 just sounds very similar to "die" or "death" in the various chinese dialects/languages.

Is it acceptable if the numbers within each column are right-aligned? I guess yes, because the challenge doesn't say anything about it, but just to double check. Also, will the inohut number always be even? What if it's odd?

@Mauris is there a limit of the number of floors we have to be able to process? Are the chinese going to build a space elevator?

@Random832, I'm not changing the spec. Only avoid 13 or numbers containing 4.

@ThisNameBetterBeAvailable: If your program is limited by something like integer overflow, that's fine, but if your language of choice handles arbitrary-precision integer arithmetic, your code should theoretically work for any input size.

@LuisMendo I'm not sure what you mean: I assume you are working in some programming language that can format the output for you and print a nice two-column table. In the interest of fairness, I would like everyone's output to be exactly of the form 15\t16\n12\t11\n..., so what you write would not be allowed.

@slebetman: Well, yes, that's why 4 is unlucky. It's still superstition, whatever the origin is! But that's getting a bit off-topic.

@Mauris my submission can calculate just enough floors to get around the earth, but it can't reach the moon... yet. Time to bring out the ULL's

Wait! Counting the buttons I see that hotel has exactly 13 floors (excluding the basement.) There's no way I'm staying  there!

And apparently, zero is unlucky somewhere as well. USA, I think.

How should odd inputs be treated?

@BlackOwlKai The problem says, “Read a positive even integer n from STDIN”… Here on PPCG, that means you can assume the output is indeed a positive even integer. Your solution may handle invalid inputs (odd, negative, zero…) in whatever way it likes.

Pyth, 27 bytes
jjLC9_c+_1.f&!@\4`ZnZ13tQ)2

Try it online here.
Gets .first Q-1 numbers that match the filter !=13 and 4 isn't in the string representation of the number. Then it prepends -1 , chops in half, joins each by tabs(C9) and joins by newlines.

Bash + common utils, 51
seq 9$1|sed 13d\;/4/d\;1i-1|rs 0 2|sed $[$1/2]q|tac

seq generates ascending integers from 1 to N with an extra 9 digit in front - more than enough for 64bit integer input
sed filters out the unlucky floors and inserts -1 before line 1
rs reshapes into two tab-separated columns
sed stops after N/2 lines
tac reverses output line order

I can shave 5 bytes for you - replace the sed $[$1/2]q after rs with sed $1q before it.  I think that makes it POSIX-shell compatible, too.

Eventually, the preceding 1 won't be enough to compensate for passing only 0.9^n of the inputs through (numbers not containing 4 get sparser and sparser as the number of digits increases).  But once you have more than a few hundred million floors in your hotel, you probably have other problems, such as keeping the plumbing working, and organising staff rotas.

@TobySpeight you might have a space elevator too :)

@TobySpeight Even with the max signed 64bit integer as input (9223372036854775807), simply prefixing a 1 is (just about) enough - at least with my rudimentary base 9 calculation.  The rest of the answer is limited to this range anyway due to the shell $[] arithmetic.  I think this is a reasonable limitation in the absence of explicit mention of arbitrary precision arithmetic in the question.  Regardless, I'm now prefixing a 9 instead of  1, just to be on the safe side.

JavaScript ES6, 236 234 233 210 195 188 bytes
Saved a whole bunch 'a bytes thanks to usandfriends!
Uses the function* for generators. Probably a shorter way to do this, but it was fun. Way fun. I'll bet some golfing can be done. Those weird whitespace things are tabs.
z=prompt(i=x=0,l=[]);y=(function*(){while(i<z-x)yield(i?(/4/.test(i)||i==13?--x&&".":i):-1)+(0*++i)})();while(a=y.next().value)+a&&l.push(a);l.join`    `.match(/-?\d+  \d+/g).reverse().join`
`

z=+prompt(i=x=0,l=[]); ==> z=prompt(i=x=0,l=[]); (-1 byte)

@usandfriends Thank you! I forgot about automatic type conversion.

.join with tab and replace space in /-?\d+ \d+/g with tab, remove .map(x=>x.replace(/ /,"\t")) (should save 23 bytes)

@usandfriends And thanks again!

For some reason, I seem to be getting a byte count of 210.

@usandfriends That's weird, The length is 207 on my console...

Shows 210 when I use this, this, and wc -c. Just curious, what command do you use to check file size?

.filter(x=>x!=".0") ==> .filter(x=>+x), (-5 bytes)

^ Scratch that, just remove the whole .filter(..) part! Try l.push(a); ==> +a&&l.push(a); (-15 bytes)

@usandfriends Thank you so much for you golfs! :D

C, 282 Bytes
int main(int r,char*v[]){int c=atoi(v[1]),a[c],b,E=1E9,g,i,t,o=t=g=(E)-2;while(i++<c){while(t>0){r=t%10;t=t/10;if(r==4||g==(E)+13||g<=o||g==E)t=++g;}a[i-1]=o=t=g;}for(c-=3;c>=0;c-=2){printf("%d\t",a[c+1]-E);printf("%d\n",a[c+2]-E);}printf("%d\t",a[0]-E);if(i%2)printf("%d",a[1]-E);}

Formatted :
int main ( int r , char * v[] ) {
    int c = atoi ( v[ 1 ] ) , a[c] , b , E = 1E9 , g , i , t , o = t = g = ( E ) - 2;
    while ( i ++ < c ) {
        while ( t > 0 ) {
            r = t % 10;
            t = t / 10;
            if ( r == 4 || g == ( E ) + 13 || g <= o || g == E )t = ++ g;
        }
        a[ i - 1 ] = o = t = g;
    }
    for ( c -= 3 ; c >= 0 ; c -= 2 ) {
        printf ( "%d\t" , a[ c + 1 ] - E );
        printf ( "%d\n" , a[ c + 2 ] - E );
    }
    printf ( "%d\t" , a[ 0 ] - E );
    if ( i % 2 )printf ( "%d" , a[ 1 ] - E );
}

Features :
It can compute up to 2095984 floors, if each floor is 19.5m high (incl. ceiling) then this building is long enough to be wrapped around the equator! 2095984*19.5=40871688m=~40000km=one 'lap' around the planet.

Nice answer, but your geography's a bit off. The distance from the equator to the north pole is 10000km by definition https://en.wikipedia.org/wiki/Metre which means the circumference of the equator is a little over 40000km.

Nice comment, but your definition of the metre is a bit outdated. ;-)

@steveverrill i just used the first number i got off google, i'll update the calculation.

You can save a few bytes by dropping "int" from main. Are braces around E really necessary? First while can be converted to for and this allows you to drop some curly braces. t/=10 is a byte shorter than t=t/10. Add 1 to c in you for loop to save a couple bytes -> a[c+1] becomes a[c], while all other numbers have the same length. I'd also combine two printfs in the loop together, and dropped curly braces again.

I think your definition of "floor height" might be a bit off - a typical floor is about 3m tall, not 19.5m tall.

@aragaer yes, you're right about the int, t/=10 and everything.
Thank you.

@nneonneo if each floor is 19.5m, i didn´t say this was typical.
I'll suggest you look at my edits.

Julia, 134 132 bytes
x=[-1;filter(i->i!=13&&'4'∉"$i",1:2(n=parse(readline())))][1:n]
for i=2:2:endof(x) println(join((r=reverse)(r(x)[i-1:i]),"  "))end

That funny whitespace in there is a literal tab. As Conor O'Brien noted, this is a byte shorter than doing \t.
Ungolfed:
# Read an integer from STDIN
n = parse(readline())

# Generate all numbers from 1 to 2n, exclude 0, 13, and all numbers containing 4,
# prepend -1, then take the first n
x = [-1; filter(i -> i != 13 && '4' ∉ "$i", 1:2n)][1:n]

# Loop over pairs, print tab-separated
for i = 2:2:endof(x)
    println(join(reverse(reverse(x)[i-1:i]), "  "))
end

JavaScript, 116 122
Edit Saved 6 bytes thx @Neil
Simple array solution - not even using ES6
Try with any browser

/* test */ console.log=function(x){ O.innerHTML+=x+'\n'; }

n=prompt();for(r=[-1],v=1;n;v++)v!=13&!/4/.test(v)&&--n&&r.push(v);for(;r[0];)console.log(a=r.pop(b=r.pop())+'\t'+b)

You can save 6 bytes by using !/4/.test(v).

You could save a single byte with ' ' instead of '\t' (literal tab)

Python 2, 120 110 bytes
N=input()
n=['-1']+[`i`for i in range(N*2)if i!=13and'4'not in`i`][1:N]
while n:x=n.pop();print n.pop()+'\t'+x

I think you can use i-13 instead of i!=13

Python 2, 94 bytes
n=input();c=-1;s=''
while n:
 if('4'in`c`)==0!=c!=13:n-=1;s=(n%2*'%d	%%d\n'+s)%c
 c+=1
print s

Try it online!
There's a tab character in the string that SE doesn't render (thanks to Sp3000 for suggested to use it, saving a byte).
Tests floors c starting from floor -1 until the quota n of floors is reached. For each floor, tests that it doesn't contain a 4 nor equals 0 or 13. If so, prepends it to the elevator string s and decrements the quota n.
A trick with string formatting is used to get the two floors per column to appear in the proper order when prepended. Each new line is prepared as '%d\t%%d\n', so that when two floors are substituted in order, the first is on the left and the second is on the right. For example,
('%d\t%%d\n'%2)%3 == ('2\t%d\n')%3 == '2\t3\n'

Pretty cool, but it's actually 96 bytes. Probably remove the trailing comma?

@movatica Good catch on the trailing comma, since the challenge specifies trailing newline is OK. The 1 byte difference was because the SE code block can't display tabs, so I put in a \t. Ah, the days before TIO existed.

Ruby 2.3, 84 83 characters
(82 characters code + 1 characters command line option)
puts (["-1",*?1..?1+$_].grep_v(/^13$|4/)[0..$_.to_i]*?\t).scan(/\S+\t\d+/).reverse

Sample run:
bash-4.3$ ruby -ne 'puts (["-1",*?1..?1+$_].grep_v(/^13$|4/)[0..$_.to_i]*?\t).scan(/\S+\t\d+/).reverse' <<< '14'
15      16
11      12
9       10
7       8
5       6
2       3
-1      1

Ruby, 93 92 characters
(91 characters code + 1 character command line option)
puts ([-1,*1..2*n=$_.to_i].reject{|i|i==13||i.to_s[?4]}[0..n]*?\t).scan(/\S+\t\d+/).reverse

Sample run:
bash-4.3$ ruby -ne 'puts ([-1,*1..2*n=$_.to_i].reject{|i|i==13||i.to_s[?4]}[0..n]*?\t).scan(/\S+\t\d+/).reverse' <<< '14'
15      16
11      12
9       10
7       8
5       6
2       3
-1      1

C#, 296 bytes
namespace System.Collections.Generic{using Linq;class X{static void Main(){var a=new List<int>();var b=new List<int>();for(int i=int.Parse(Console.ReadLine()),j=-2;i>0;)if(++j!=13&&j!=0&&!(j+"").Contains("4"))(i--%2<1?a:b).Insert(0,j);Console.Write(string.Join("\n",a.Zip(b,(x,y)=>x+"\t"+y)));}}}

Ungolfed:
namespace System.Collections.Generic
{
    using Linq;
    class X
    {
        static void Main()
        {
            var a = new List<int>();
            var b = new List<int>();
            for (int i = int.Parse(Console.ReadLine()), j = -2; i > 0;)
                if (++j != 13 && j != 0 && !(j + "").Contains("4"))
                    (i-- % 2 < 1 ? a : b).Insert(0, j);
            Console.Write(string.Join("\n", a.Zip(b, (x, y) => x + "\t" + y)));
        }
    }
}

Golfing tricks used:

i (the running counter) and j (the current number under consideration) are decremented/incremented, respectively, inside the expression in the loop body instead of the for statement as is normal
j+"" instead of j.ToString()
Place everything inside namespace System.Collections.Generic not only so that we can access List<T>, but also implicitly use the namespace System without further qualification
Place the using inside the namespace so that we can write using Linq; instead of using System.Linq;
.Insert(0,j) is shorter than using .Add(j) and later applying .Reverse()

It is unfortunate that the using Linq; is necessary, since it is needed only for .Zip, but writing it as Linq.Enumerable.Zip() is longer.

Lua, 169 Bytes
t={-1}i=1 repeat if(i..""):find("4")or i==13 then else table.insert(t,i)end i=i+1 until #t==arg[1] for i=#t%2==0 and#t-1 or#t,1,-2 do print(t[i],t[i+1]and t[i+1]or"")end

Fairly straight forward, we first assemble a table filled with all the button values. Then we iterate through it backwards, printing two values at a time, or nothing if the second value does not exist.

Mathematica, 105 bytes
StringRiffle[Reverse[Select[Range[2#]-2,#!=13&&#!=0&&DigitCount[#,10,4]<1&][[;;#]]~Partition~2],"
","\t"]&

Replace the \t with an actual tab character.

Brachylog, 105 bytes
,Ll?,Lbb:1{h_.|[L:I]hhH,I+1=J((13;J:Zm4),L:J:1&.;Lb:J:1&:[J]c.)}:[1:-1]c{_|hJ,?bhw,[9:J]:"~c~w
"w,?bb:2&}

Would have been a lot shorter with CLPFD support, here I have to iteratively try integers in the first sub-predicate.
The new line before "w,?bb:2&} is mandatory, this is the new line that is printed between every row.

Nice! One question: Why not make all integer arithmetic in Brachylog use CLP(FD) constraints automatically? This would be a natural logical extension.

@mat because I'm lazy and I didn't. But I should!

That would be awesome! Built-in implicit CLP(FD) constraints for all integer arithmetic! Pave the future of declarative programming! "And it must seem blessedness to you to impress your hand on millennia as on wax. Blessedness to write on the will of millennia as on bronze--harder than bronze, nobler than bronze. Only the noblest is altogether hard."

@mat Could you join me in this chat room to discuss this? I need advice from someone obviously more experienced with Prolog than me.

Python 3, 155 bytes
I think listifying, reversing, and self-zipping the floor-number generator s() may have been too clever for its own good, but others have already done the alternative (popping two items at a time), not to mention using Python 2 which saves bytes on some key points.
def s(m,n=-1):
 while m:
  if not(n in(0,13)or'4'in str(n)):yield n;m-=1
  n+=1
*f,=s(int(input()))
g=iter(f[::-1])
h=zip(g,g)
for a,b in h:print(b,'\t',a)

The shorter, but already-done-better alternative takes 140 bytes.
def s(m,n=-1):
 while m:
  if not(n in(0,13)or'4'in str(n)):yield n;m-=1
  n+=1
*f,=s(int(input()))
while f:a=f.pop();print(f.pop(),'\t',a)

For the second alternative, (0!=n!=13)!=('4'in str(n)) is 5 bytes shorter than not(n in(0,13)or'4'in str(n)).

Japt, 42 bytes
JoU*2 k0 kD f@!Xs f4} ¯U ã f@Yv} w ®q'    } ·

The four spaces should be an actual tab char. Try it online!
How it works
          // Implicit: U = input integer, D = 13
JoU*2     // Create the range of integers [-1,U*2).
k0 kD     // Remove 0 and 13.
f@!Xs f4} // Filter out the items X where X.toString().match(/4/g) is not null, i.e. the numbers that contain a 4.
¯U ã      // Slice to the first U items, and generate all adjacent pairs of items.
f@Yv}     // Filter out the items where the index Y is odd. This discards every other pair.
w         // Reverse.
®q'\t}    // Join each item with tabs.
·         // Join the whole list with newlines.
          // Implicit: output last expression

C#, 277 343
using System;using System.Collections.Generic;static void f(int v){List<int>a=new List<int>();List<int>b=new List<int>();int s=1;for(int i=-1;i<v-1;i++){if(i==13||i.ToString().Contains("4")||i==0){ v++;continue;}if(s==1){s=2;a.Add(i);}else{s=1;b.Add(i);}}a.Reverse();b.Reverse();int l=0;foreach(int y in a){Console.WriteLine(y+" "+b[l]);l++;}}

This is as a function only. I'm new to C#. Increase was to make valid for 40-49, and for including usings
Ungolfed, as a complete running program:
using System;
using System.Collections.Generic;

class P {
    static void Main()
    {
        List<int> a = new List<int>();
        List<int> b = new List<int>();
        int v = Int32.Parse(Console.ReadLine());
        int s = 1;
        for (int i = -1; i < v - 1; i++)
        {
            if (i == 13 || i.ToString().Contains("4") || i == 0)
            {
                v++;
                continue;
            }
            if (s == 1)
            {
                s = 2;
                a.Add(i);
            }
            else {
                s = 1;
                b.Add(i);
            }
        }
        a.Reverse();
        b.Reverse();
        int l = 0;
        foreach (int y in a)
        {
            Console.WriteLine(y + " " + b[l]);
            l++;
        }
        Console.ReadLine();
    }
}

Explained
I create two lists, and alternate between pushing to them, reverse them, loop through one, and grab the other by index.

I don't know much about C# but can't you replace if(s==1) by if(s) (automatic cast from int to boolean?)

Nah, because the else is for s == 2, although I could make the flag 0 and 1 instead of 1 and 2. I'll try that.

C++11, 259 258 203 202 195 194 bytes
Slashed off 1 byte, thanks to Conor O'Brien's idea to use literal tab instead of \t.
UPD 2: slashed off 55 bytes with improved logic and comma abuse.
UPD 3: another byte off thanks to ceilingcat.
UPD 4: 7 bytes off courtesy of ceilingcat.
UPD 5: and another byte off by ceilingcat.
Happy to have all includes in place AND still beat the C and C# solutions.
#include<iostream>
#include<string>
int main(){std::string o="-1    1",c,b;int n,i=2,s=2;for(std::cin>>n;s<n;o=i==14|~c.find(52)?o:(++s&1?b=c,"":b+'    '+c+'\n')+o)c=std::to_string(i++);std::cout<<o;}

Ungolfed:
#include <iostream>
#include <string>

int main()
{
    std::string o = "-1 1", c, b;
    int n, i = 2, s = 2;
    for (std::cin >> n;
         s < n;
         o = i == 14 | ~c.find(52) ? o : (++s & 1 ? b = c, "" : b + '   ' + c + '\n') + o
    )
        c = std::to_string(i++);
    std::cout << o;
}

iostream includes string, so you can skip the second include for a big decrease in bytecount :)

@movatica Not according to cppreference.com, and compilation in VS2019 fails without it. So if it compiles somewhere else it's specific to that certain standard library implementation.

ok, seems to be a gcc thing.

191 bytes

Lua, 141 bytes
n,s=1,'-1 1'function g()repeat n=n+1 until s.find(n,4)==z and n~=13 return n end for i=4,io.read(),2 do s=g()..' '..g().."\n"..s end print(s)

Ungolfed
n,s = 1,'-1'1' --n is the current floor number, S is the string to be printed
function g() --This function raises n to the next valid floor
    repeat --Same as while loop except it runs the following block before checking the expression
        n = n + 1 --Self-explanatory, increases n by one
    until --Checks the expression, if it is true, it breaks out of the loop
        s.find(n,4) == z --[[Strings have a member :find(X) where it finds the position of
                             X in the string (X can also be a pattern). However, calling it
                             by .find(S,X) executes find on S with argument X. I can't
                             directly do n:find(4) because n is a number. This is a "hack"
                             (sort of) to cut down some bytes. Also, if X is not a string,
                             lua tries to (in this case, succeeds) cast X to a
                             string and then look for it. I check if this is equal to z
                             because z is nil (because it is undefined), and find returns
                             nil if X is not found in S.
                             TL;DR: Checks if 4 is not the last digit.]]
        and n ~= 13 --Self-explanatory, checks if n is not 13
        return n --Self-explanatory, returns n
end
for i = 4, io.read(), 2 do --[[Start at floor 3 (shows 4 because we're going by target
                               floor, not by starting floor), continue until we reach
                               floor io.read() (io.read returns user input), increment by
                               2 floors per iteration)]]
    s = g() .. ' ' .. g() .. "\n" .. s --[[Prepend the next floor, a space, the next floor,
                               and a newline to s]]
end
print(s) --Self-explanatory, output the string

Try it online (you need to click 'execute' on the top and then click the terminal on the bottom before typing input; I'm looking for a better way to test lua online with stdin and stdout)

05AB1E, 25 23 22 bytes
-1 byte thanks to @ASCII-only
·Ý<0K13Kʒ4å_}s£2ôR9çý»

Try it online!
Explanation
                           # Implicit input: integer n
·Ý<                        # Push list [-1,0,1,...,2n-1]
   0K                      # Remove 0 from [-1,0,1,...,2n-1]
     13K                   # Remove 13 from [-1,1,...,2n-1]
        ʒ4å_}              # Filter out every number containing a 4 from the list
             s£            # Pick out the n first element in the list
               2ôR         # Splice list into parts of length 2
                  9çý      # Join with tab character (ascii value 9)
                     »     # Join with newlines

22?

Ah. I knew there was a way to make that ugly 0 13ª part a bit better. Thanks!

wait. there's no logical and in 05AB1E? O_o

If 1 is true and 0 is false then multiplication works as logical and

-1 byte by changing ʒ4å_} to 4мïê. PS: based on your earlier comment: 0 13ª could have been ¾13ª as well.

Java, 333 Bytes
import java.util.*;interface E{static void main(String[]a){byte i=-1;Stack<Byte>s=new Stack<>();while(s.size()<Byte.valueOf(a[0])){if(i==13|i==0|String.valueOf(i).contains("4")){i++;continue;}s.add(i);i++;}if(s.size()%2!=0){System.out.println(s.pop());}while(!s.isEmpty()){int r=s.pop();int l=s.pop();System.out.println(l+"\t"+r);}}}

Adds allowed floor numbers to a stack then pops them back off to print them.
I played around using an IntStream, but with all the imports this one ended up being smaller.

Scala 147
val n=io.StdIn.readInt;(-1 to 4*n).filter(i=>i!=0&&i!=13&&(!(i+"").contains(52))).take(n).reverse.grouped(2).toList.map{i=>println(i(1)+"\t"+i(0))}

This is obviously the Scala'd down version.

PowerShell, 106 107 bytes
$c=,-1+$(while($i+1-lt"$args"){if(++$c-notmatch'^13$|4'){$c;++$i}})
while($c){$a,$b,$c=$c;$s="$a    $b
$s"}$s

Ungolfed
# Calculate floors:
$c=,-1 # Array with one element
  +
  $( # Result of subexpression
    while($i+1-lt"$args"){ # Uninitialized $i is 0, +1 ensures loop start from 1
      if(
        ++$c-match'^13$|4' # Expression increments uninitialized $c (i.e. start from 1)
                           # and matches resulting number to regex.
      ){
        $c;++$i # Return $c and increment $i counter
      }
    }
  )

# Print floors:
while($c){ # Loop until no more elements in $c
  $a,$b,$c=$c # Use PS's multiple assignment feature
              # $a - first element of $c array
              # $b - second element of $c array
              # $c - the rest of elements of $c array
  $s="$a    $b
$s" # Create string with tabs and newlines,
    # literal characters are used
}
$s # Output resulting string

Example
PS > .\Elevator.ps1 14
15  16
11  12
9   10
7   8
5   6
2   3
-1  1

Python 3, 117 Bytes
n=int(input())
l=[-1]+[i for i in range(n*2)if(i!=13)*(not'4'in str(i))][1:n]
while l:x=l.pop();print(l.pop(),'\t',x)

Modified version of the python 2 post to fit the python 3 specification.

Haskell 202 bytes
t=(-1):[x|x<-[1..],x/=13,all (/='4')(show x)]
by2 []=[[]]
by2 [a]=[[a]]
by2 [a,b]=[[a,b]]
by2 (a:b:xs)=[a,b]:(by2 xs)
main=do
 n<-getLine
 putStr$unlines$map unwords$by2$map show$reverse$take(read n) t

I’am haskell beginner…

first create the infinite list of values. (t list)
function by2 group a list into sublists of 2 elements.
main take the value.

take value elements of t list
reverse the list to have greaters elements first
map show function to convert int list to string list
group element 2 by 2 with by2 function
We have a list like [ ["4", "5"], ["6", "7"] ] transformed like [ "4 5", "6 7"] with unwords function mapped on list
unlines the list (each element of the list separate by '\n')
finish with putStrLn to write string on terminal.

You can save several bytes in defining by2 by using a 1 character name and re-ordering: use your last line as is, then b x = [x] after.

Javascript ES6 114 bytes
n=>[...Array(n)].map(_=>{while(/^13$|4|^0/.test(++i));return i;},i=-2).join`    `.match(/-?\d+  \d+/g).reverse().join`\n`

Usage
f=n=>[...Array(n)].map(_=>{while(/^13$|4|^0/.test(++i));return i;},i=-2).join`  `.match(/-?\d+  \d+/g).reverse().join`\n`

f(100);

Perl 6, 73 bytes
{.join("    ").say for (-1,|grep {$_-13&!/4/},1..Inf)[^$_].rotor(2).reverse}

Assumes an even number of floors, since the problem statement seems to assume it as well and at least one other provided solution breaks for odd numbers of floors.  Just add ,:partial as a second argument to rotor, for nine more bytes, to support odd numbers of floors.

55 bytes

Jelly, 20 bytes
ḟ13D_4Ȧµ#o-s2Ṛj€9Ọ¤Y

Try it online!
How?
ḟ13D_4Ȧµ#o-s2Ṛj€9Ọ¤Y - Main Link: no arguments
        #            - start at n=0 and collect the first INPUT values which are truthy under:
       µ             -   the monad (i.e. f(n)):        e.g.:    0      3      4      13     42        813
ḟ13                  -     filter out thirteens                 [0]    [3]    [4]    []     [42]      [813]
   D                 -     convert to decimal lists             [[0]]  [[3]]  [[4]]  []     [[4,2]]   [[8,1,3]]
    _4               -     subtract four (vectorises)           [[-4]] [[-1]] [[0]]  []     [[0,-2]]  [[4,-3,-1]
      Ȧ              -     any & all?                           1      1      0      0      0         1
         o-          - logical OR with -1 (replace floor 0 with floor -1)
           s2        - split into twos
             Ṛ       - reverse
                  ¤  - nilad followed by link(s) as a nilad:
                9    -   literal nine
                 Ọ   -   to character (a tab)
              j€     - join €ach
                   Y - join with newlines
                     - implicit print

JavaScript (ES6), 151 146
alert([for(a of Array((n=+prompt(i=0))*2).keys())if((i+=t=/4/.test(a)||a==13,!t&&a<n+i))a].reduce((a,b,j,r)=>j%2-1?(b||-1)+`  ${r[j+1]}
`+a:a,''))

Did this before I realized edc65 had already made a shorter one. Oh well!

R, 106 bytes
n=scan();x=-1:n^2;x=x[-grep(4,x)][-14][-2][n:1];cat(paste0(matrix(x,2,n/2)[2:1,],c("	","\n"),collapse=""))

Try it online!
Explanation: it starts with the vector of floors from \$-1\$ to \$n^2\$, which is more than enough in all my tests. Should that ever be insufficient, we could switch to \$n^3\$ or \$n^9\$. It then removes the unlucky floor numbers (as well as floor 0), converts to a 2-row matrix form and inverts the rows to get the numbers in correct order, then outputs in the desired format, recycling the vector c("\t","\n"). As suggested by Conor O'Brien, use a literal tab instead of \t for -1 byte.
n=scan();                                        # read number of floors n
x=-1:n^2;                                        # initial vector of numbers
x=x[-grep(4,x)]                                  # remove floors with a 4
               [-14]                             # remove floor 13
                    [-2]                         # remove floor 0
                        [n:1];                   # keep lowest n remaining floors, highest to lowest
cat(paste0(
  matrix(x,2,n/2)                                # split vector of floors into 2 rows
                 [2:1,],                         # take row 2 then row 1
                        c("   ","\n"),           # separate integers with alternating tabs and newlines (uses recycling)
                                    collapse=""))

APL (Dyalog), 34 bytes
{⊖(⍵÷2)2⍴o/⍨~'4'∊¨⍕¨o←13~⍨¯1,⍳⍵×⍵}

Try it online!

Perl 5 -MList::Util=pairmap -n, 62 bytes
pairmap{say"$b	$a"}reverse((-1,grep!/^13$|4/,1..121)[0..$_-1])

Try it online!

Japt -R, 23 22 21 bytes
È©DÀX«ìø4}jUJ ò Ômq9d

Try it
È©DÀX«ìø4}jUJ ò Ômq9d     :Implicit input of integer U
È                         :Function taking an integer X as argument
 ©                        :  Logical AND with
  D                       :    13
   ÀX                     :    Is not equal to X
     «                    :  Logical AND with logical NOT of
      ì                   :    Convert X to digit array
       ø4                 :    Contains 4?
         }                :End function
          jU              :Get the first U integers that return truthy
            J             :Starting with -1
              ò           :Partitions of length 2
                Ô         :Reverse
                 m        :Map
                  q       :  Join with
                   9d     :  Character at codepoint 9 (TAB)
                          :Implicit output joined with newlines

Husk, 25 bytes
↔mJc9†sC2↑¹fȯ¬€4d-0-13…_1

Try it online!

Thunno N, \$36\log_{256}(96)\approx\$ 29.63 bytes
1ns2*:gzt13Q&s4Aq!&kDLz0-Zy2Apre9Csj

Attempt This Online!
Port of Wisław's 05AB1E answer.
Explanation
1n        # Push -1
  s2*     # Swap and double the input
     :    # Push the range between -1 and 2*n
      g   # Filter this list by:
       zt #  Triplicate the integer       STACK:  i, i, i
13Q       #  Is it not equal to 13?       STACK:  i, i, i != 13
   &      #  Logical AND                  STACK:  i, (i and i != 13)
    s4Aq  #  Swap and check if it         STACK:  (i and i != 13), (4 in i)
          #  contains the digit 4
        ! #  Logical NOT                  STACK:  (i and i != 13), (4 not in i)
&         #  Logical AND                  STACK:  i and (i != 13) and (4 not in i)
 k        # End filter
  DL      # Duplicate and push the length
    z0-   # Subtract the input
       Zy # Remove this many elements from the back
2Ap       # Split into chunks of length 2
   r      # Reverse
    e     # Map over this list:
     9C   #  Push chr(9), a tab
       sj #  Join the list by a tab
          # N flag joins by newlines
          # Implicit output

Thunno 2 N, 21 bytes
ḌĖ⁻0o13oæṘ4Ƈ}ɱ2ẇr9Cȷj

Try it online!
Explanation
ḌĖ⁻0o13oæṘ4Ƈ}ɱ2ẇr9Cȷj  # Implicit input
ḌĖ⁻                    # Push the range [-1 .. 2*input)
   0o13o               # Remove the 0 and the 13
        æṘ4Ƈ}          # Remove anything containing 4
             ɱ         # Take the first (input) items
              2ẇ       # Split into pairs
                9Cȷj   # Join each by ASCII 9 (tab)
                       # Join on newlines
                       # Implicit output

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

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


text:
Euclidean Vectors
Given the ASCII art of two vectors, find the resultant vector's magnitude and degree.

Input
This can be received via STDIN, read from a local file, or provided through a function call. Here is an example of a two vector input:
^------>
|
|
|
x

This represents a change of 4 units north and 7 units east. Every input's starting point will be represented by an x (decimal 120).

All vectors are horizontal or vertical lines.
Each vector has one of these four endpoints: ^v<>, and is made up of either a dash (-, decimal 45) or a vertical bar (|, decimal 124).
Empty points on the plane are filled with spaces (, decimal 32).
The input may be a single x.
Adjacent vectors are always perpendicular to each other.
All vectors are tip-to-tail.

Output
This will be the displacement of the resulting point (distance from the starting point) and the degree to which it has moved, relative to the starting point.
For the above input, the output should be 8.06 units and 60.3 degrees. Each should have exactly 3 significant figures. Here are a few examples of numbers with 3 significant digits:

1.00
60.1
453
7.08
4.50
349

All unit measurements will be <= 999.

These numbers should be output in the below format. This is using the numbers from above.
8.06 units @ 60.3 degrees

This may be followed by a single trailing space or newline.

If the input is a single x, with no displacement and hence no angle of displacement, the output should be either an empty line (a single newline character) or in the following format:
0 units @ - degrees

If you're trying to qualify for the bonus, the direction should be - as well.

In the case that bonuses 2, 3, or both are completed, the output should follow the below model and abide by the same restrictions as the above.
8.06 units @ 60.3 degrees NE

Degrees should be measured according to the standard plane.
       90
  135  |  45
      \|/
180 ---x---- 0
      /|\
  225  |  315
      270

0 degrees is east, 1 - 89 degrees is northeast, 90 is north, etc.

Bonuses
The following are worth a total of -50%.

Take a -10% bonus for each additional vector that can be handled. This bonus can be applied to up to 3 times. Vectors will never overlap or cross.
Take a -10% bonus if your output includes the cardinal direction of the angle (north, south, east, west).
Take a -10% bonus if your output includes the intermediate directions of the angle (northeast, northwest, southeast, southwest).

Examples
In:
x---->
     |
     v

Out:
5.39 units @ 338 degrees

Optionally SE

In:
<--------------^
               |
               |
               x

Out:
15.3 units @ 169 degrees

Optionally NW

In:
x
|
|<-----^
|      |
v------>

Out:
2.24 units @ 297 degrees

Optionally SE

Examples (multiple vectors)
In:
x--->
    |
    |
    v----------->

Out:
16.3 units @ 349 degrees

Optionally SE

In:
<-------^
|       |
|       |
v       |
        |
        |
        x

Out:
8.54 units @ 159 degrees

Optionally NW

In:
^-->
|  |
|  v
|
<--------x

Out:
6.32 units @ 162 degrees

Optionally NW

Will vectors ever have a zero component in one direction? If so, what should output be for x? What's the boundary between North and Northwest?

I've added that information. Thanks for pointing it out! @ThomasKwa

You should add a test case where there's only one vector, e.g. x-->. Can vectors cross?

The regular input will be two vectors. The single exception is the empty x. There may be more than two (if attempting to complete the bonus), but not less. I'm working on examples for multiple vector inputs. In no inputs will vectors cross. @ThomasKwa

I've added them. @ThomasKwa

Yes, that's possible, but the example you gave would look like this: ->|. @user81655

I've added that test case @user81655

Is there a maximum number of units? (eg. <=999). Since we only have 3 significant digits.

Can two vectors go the same direction? (eg. x-->-->)

Ah, good point on the upper bound; I'll add that to the questions. And to your other question: adjacent vectors will always be perpendicular to each other @TFeld

You're correct. I've fixed that; thanks! @TFeld

@ZachGates will vectors always be tip-to-tail, or can several vectors originate at "x"?

They will always be tip-to-tail @GamrCorps

JavaScript (ES6), 305 bytes - 50% bonus = 152.5 score
v=>(l=v.search`
`+1,s=v.search`x`,u=0,d="-",v.replace(/[<>v^]/g,(p,i)=>{c=o=>v[i+o]!=q;with(Math)if(p<"?"?c(l,q="|")&c(-l):c(1,q="-")&c(-1))d=(atan2(x=i%l-s%l,y=(i/l|0)-(s/l|0))*180/PI+270)%360,u=sqrt(x*x+y*y)}),u[p="toPrecision"](3)+` units @ ${d[p](3)} degrees`)

Explanation
Input must be padded with spaces. Uses all bonuses.
v=>(
  l=v.search`
`+1,                                                     // l = line length
  s=v.search`x`,                                         // s = index of start point
  u=0,                                                   // u = units
  d=                                                     // d = degrees
  w="-",                                                 // w = cardinal direction
  v.replace(/[<>v^]/g,(p,i)=>{                           // for each endpoint
    c=o=>v[i+o]!=q;                                      // compares cell at offset to char
    with(Math)                                           // save having to write "Math."
      if(p<"?"?c(l,q="|")&c(-l):c(1,q="-")&c(-1))        // check for line branching off
        d=(atan2(
          x=i%l-s%l,                                     // x = relative x
          y=(i/l|0)-(s/l|0)                              // y = relative y
        )*180/PI+270)%360,                               // convert to degrees
        u=sqrt(x*x+y*y),
        w="N S"[sign(y)+1]+"W E"[sign(x)+1]              // get cardinal direction
  }),
  u[p="toPrecision"](3)+` units @ ${d[p](3)} degrees `+w // format output
)

Test

var solution = v=>(l=v.search`
`+1,s=v.search`x`,u=0,d=w="-",v.replace(/[<>v^]/g,(p,i)=>{c=o=>v[i+o]!=q;with(Math)if(p<"?"?c(l,q="|")&c(-l):c(1,q="-")&c(-1))d=(atan2(x=i%l-s%l,y=(i/l|0)-(s/l|0))*180/PI+270)%360,u=sqrt(x*x+y*y),w="N S"[sign(y)+1]+"W E"[sign(x)+1]}),u[p="toPrecision"](3)+` units @ ${d[p](3)} degrees `+w)
<textarea id="input" rows="6" cols="60">x
|
|<-----^
|      |
v------></textarea>

<button onclick="result.textContent=solution(input.value)">Go</button>

Python 2, 238.5 (594 562 482 477-50%) bytes
from math import*
def F(x):s='%.3g'%x;return[[s+'.',s]['.'in s].ljust(4,'0'),s][x>99]
I=input()
V=I.split('\n');N=len(V)
l=max(len(x)for x in V)
q=[' '*(l+2)];V=q+[' '+x.ljust(l+1)for x in V]+q
for k in range(N*l):
 i,j=k/l,k%l;c=V[i+1][j+1]
 if c in'<>^v'and['|'not in zip(*V)[j+1][i:i+3],'-'not in V[i+1][j:j+3]][c>'?']:a,b=i,j
 if c=='x':A,B=i,j
Y=A-a;X=b-B;a=atan2(Y,X)/pi*180%360
print[F(hypot(X,Y))+' units @ '+F(a)+' degrees '+' NS'[cmp(Y,0)]+' EW'[cmp(X,0)],''][I=='x']

Explanation
Finds the start and end positions by looking at each character in the input.
Start is x
End is found by looking at each arrow (<>^v), and their neighbors.
If neighbors are continuing vectors, ignore. Else, this is the end.
Look at the neighbors perpendicular to the arrow direction.
If they contain a perpendicular line, then it is a continuing vector.
Examples (_ indicates space):
_#_
->_   Neighbors marked by #
_#_

___
->_   (end)
___

_|_
->_   (not end)
___

___
->|   (end)
___

---
->_   (end)
___

Because the end point is found, there can be any number of vectors (30% bonus).

Are you sure this works in python 2? Plus, you can change "from math import " to "from math import" (remove the space).

@RikerW It works for me. Ideone: http://ideone.com/9j86yj uses \n as linebreaks...

Well done, with a nice explanation of the "neighbours". I was a little concerned by your use of input() and the corresponding wrapping of the input with "", but there doesn't seem to be a rule against it!


text:
Digital Clock Matches Puzzle
There are many puzzles with matches that involve adding, removing, or moving a certain number of matches to create new numbers or shapes. This is like that with a digital clock.
Given a valid time on a 12-hour digital clock, output the digit that requires moving the fewest lines to make it so every visible digit on the clock becomes that digit. If more than one digit is the minimum, output them all. If it is impossible to make every digit the same, output -1 or a falsy value other than 0 (you'll get a lot of these).
The clock digits look like this:
  |
  |
 _
 _|
|_
 _
 _|
 _|

|_|
  |
 _
|_
 _|
 _
|_
|_|
 _
  |
  |
 _
|_|
|_|
 _
|_|
 _|
 _
| |
|_|

Test Cases:
Input: 123
Clock Display:
       _   _
  | :  _|  _|
  | : |_   _|

Output: 4
Explanation: The display for 1:23 requires a total of 12 lines to be drawn. Therefore, for every digit to be the same, each digit would have to have 4 lines. The only digit that has 4 lines is 4. Therefore, the answer has to be 4.
Input: 1212
Clock Display:
     _        _
  |  _| :  |  _|
  | |_  :  | |_

Output: -1
Explanation: The display for 12:12 requires 14 lines. 14 divided by 4 is not an integer, therefore it is impossible for every digit to be the same.
Input: 654
Clock Display:
 _     _
|_  : |_  |_|
|_| :  _|   |

Output: 5
Explanation: The total number of lines is 15. 15 divided by 3 is 5, so each digit must have 5 lines. The only digits that have 5 lines are 2,3, and 5. The answer is 5 because it only requires 2 moves to make every digit 5. Simply move the line at the bottom left of the 6 to the bottom of the 4, then you have:
 _     _
|_  : |_  |_|
 _| :  _|  _|

Then, as you can see, all you need to do is move the line at the top right of the digit that was originally 4 to the top, and you get 5:55. To make every digit a 2 or 3 would require more than 2 moves.
Input: 609
Clock Display:
 _     _   _
|_  : | | |_|
|_| : |_|  _|

Output: 609 (6,0,9 or [6,0,9] also ok).
Explanation: 6, 0, and 9 are the only digits that have 6 lines. As such, they are also the only possible solutions. It's not hard to see that it would take two moves to make any of these the only digit. Therefore, you output all three digits.
Notes:

Although the input time must be valid, the output time does not (e.g. 999 as an output is OK.)
I am very flexible with input. You can require a leading 0. You can use a number with a decimal point. You can use a string. You can use an array. You can have a parameter for every digit.

Related: http://codegolf.stackexchange.com/q/54008/42545

Julia, 160 157 154
x->(c=count_ones;l=[119;36;93;109;46;107;123;37;127;111];m=l[x+1];n=map(a->c(a)==mean(map(c,m))?sum(map(b->c(a$b),m)):1/0,l);find(n.==minimum(n).!=1/0)-1)

This is a lambda function. Assign it to a variable to call it. Accepts a vector of integers in range 0-9 of any length and returns a (possibly empty) vector of results.
Test cases
julia> clock = x->(c=co...        # assign function to variable
(anonymous function)

julia> clock([1 2 3])
1-element Array{Int64,1}:
 4

julia> clock([1 2 1 2])
0-element Array{Int64,1}

julia> clock([6 5 4])
1-element Array{Int64,1}:
 5

clock([6 0 9])
3-element Array{Int64,1}:
 0
 6
 9

Explanation
Enumerate the seven segments and represent them as a bit vector.
+---+                     +-0-+
|   |      Enumerate      1   2
+---+   >  the seven  >   +-3-+
|   |      segments       4   5
+---+                     +-6-+

Example: 1 (segments 2 + 5 enabled) becomes 36 (bits 2 + 5 set).
Here are the representations for digits 0-9.
l=[119;36;93;109;46;107;123;37;127;111];
m=l[x+1];

We can use the digit as index to get it's bit vector representation. +1 because of 1-based indexing in julia.
The function c=count_ones; counts the number of 1-bits in an integer. We assign an alias because we need it more often.
The full program, somewhat ungolfed:
x->(
  c=count_ones;
  l=[119;36;93;109;46;107;123;37;127;111];
  m=l[x+1];
  n=map(a->c(a)==mean(map(c,m))?sum(map(b->c(a$b),m)):1/0,l);
  find(n.==minimum(n).!=1/0)-1
)

Now, the last two lines in detail:
mean(map(c,m)) calculates the average number of lines per input digit.
n=map(a->...,l) loops over the vector representation of all digits.
If the number of lines of our current digit a is unequal to the average linecount of the input, return inf.
c(a)==mean(map(c,m))?...:1/0

If not, return the sum of the Hamming Distances between our current and all input digits.
sum(map(b->c(a$b),m))

We now have a vector n of length 10 representing the numbers 0-9 that gives us the total number of additions/deletions we have to perform to tranform all input digits to that number, or inf, if such a transformation is impossible without changing the number of lines.
find(n.==minimum(n).!=1/0)-1

Finally, output the locations (0-based) of all minima that are not inf.


text:
Reverse Engineer Bracket Rectangles
Every programmer knows that rectangles □ are really fun. To exacerbate this fun, these cute and fuzzy diagrams can be transformed into groups of interwoven brackets.
This challenge is the inverse of my previous.
Let's say you have a group of interlocking rectangles like so:
   +------------+
   |            |
+--+-+     +----+-+
|  | |     |    | |
|  | | +---+--+ | |
|  | | |   |  | | |
+--+-+ | +-+--+-+-+-+
   |   | | |  | | | |
   |   | | |  | | | |
   |   | | |  | | | |    +-+
   |   +-+-+--+ | | |    | |
   |     | |    | | |  +-+-+-+
   +-----+-+----+ | |  | | | |
         | |      | |  | +-+ |
         | +------+ |  |     |
         |          |  |     |
         +----------+  +-----+

Additional Notes:

No two +s will ever be adjacent
No two rectangles will ever share an edge or corner
There will only ever be at most one vertical edge in each column

The first step is to look at the left-most edge of any rectangle.  Assign it one of four bracket types ({[<.  I choose [.
   +------------+
   |            |
[--+-]     +----+-+
[  | ]     |    | |
[  | ] +---+--+ | |
[  | ] |   |  | | |
[--+-] | +-+--+-+-+-+
   |   | | |  | | | |
   |   | | |  | | | |
   |   | | |  | | | |    +-+
   |   +-+-+--+ | | |    | |
   |     | |    | | |  +-+-+-+
   +-----+-+----+ | |  | | | |
         | |      | |  | +-+ |
         | +------+ |  |     |
         |          |  |     |
         +----------+  +-----+

Now look at the second left-most rectangle.  Since it overlaps a [ rectangle, it must be of a different type.  I choose (.
   (------------)
   (            )
[--(-]     +----)-+
[  ( ]     |    ) |
[  ( ] +---+--+ ) |
[  ( ] |   |  | ) |
[--(-] | +-+--+-)-+-+
   (   | | |  | ) | |
   (   | | |  | ) | |
   (   | | |  | ) | |    +-+
   (   +-+-+--+ ) | |    | |
   (     | |    ) | |  +-+-+-+
   (-----+-+----) | |  | | | |
         | |      | |  | +-+ |
         | +------+ |  |     |
         |          |  |     |
         +----------+  +-----+

The next left-most rectangle does not intersect with any previous rectangle, but does nest within the previous.  I choose to assign it ( again.  It is normally a good guess to assign a rectangle the same type as what it is nesting inside if possible, but sometimes backtracking is needed.
   (------------)
   (            )
[--(-]     +----)-+
[  ( ]     |    ) |
[  ( ] (---+--) ) |
[  ( ] (   |  ) ) |
[--(-] ( +-+--)-)-+-+
   (   ( | |  ) ) | |
   (   ( | |  ) ) | |
   (   ( | |  ) ) | |    +-+
   (   (-+-+--) ) | |    | |
   (     | |    ) | |  +-+-+-+
   (-----+-+----) | |  | | | |
         | |      | |  | +-+ |
         | +------+ |  |     |
         |          |  |     |
         +----------+  +-----+

This next rectangle can be assigned [ again.
   (------------)
   (            )
[--(-]     +----)-+
[  ( ]     |    ) |
[  ( ] (---+--) ) |
[  ( ] (   |  ) ) |
[--(-] ( [-+--)-)-+-]
   (   ( [ |  ) ) | ]
   (   ( [ |  ) ) | ]
   (   ( [ |  ) ) | ]    +-+
   (   (-[-+--) ) | ]    | |
   (     [ |    ) | ]  +-+-+-+
   (-----[-+----) | ]  | | | |
         [ |      | ]  | +-+ |
         [ +------+ ]  |     |
         [          ]  |     |
         [----------]  +-----+

This next rectangle is kinda fun.  It intersects both a ( and a [ rectangle, so I could call it a { rectangle (or < but nobody likes those).
   (------------)
   (            )
[--(-]     {----)-}
[  ( ]     {    ) }
[  ( ] (---{--) ) }
[  ( ] (   {  ) ) }
[--(-] ( [-{--)-)-}-]
   (   ( [ {  ) ) } ]
   (   ( [ {  ) ) } ]
   (   ( [ {  ) ) } ]    +-+
   (   (-[-{--) ) } ]    | |
   (     [ {    ) } ]  +-+-+-+
   (-----[-{----) } ]  | | | |
         [ {      } ]  | +-+ |
         [ {------} ]  |     |
         [          ]  |     |
         [----------]  +-----+

The last two rectangles aren't that bad.  They can be of any two different types.
   (------------)
   (            )
[--(-]     {----)-}
[  ( ]     {    ) }
[  ( ] (---{--) ) }
[  ( ] (   {  ) ) }
[--(-] ( [-{--)-)-}-]
   (   ( [ {  ) ) } ]
   (   ( [ {  ) ) } ]
   (   ( [ {  ) ) } ]    {-}
   (   (-[-{--) ) } ]    { }
   (     [ {    ) } ]  <-{-}->
   (-----[-{----) } ]  < { } >
         [ {      } ]  < {-} >
         [ {------} ]  <     >
         [          ]  <     >
         [----------]  <----->

Reading off the rectangles, I get [(]([{))}]<{}>.  This would be one possible output for the above input.  Here's a list of many possible options, not exhaustive:
[(]([{))}]<{}>
<(>(<{))}>{()}
{<}[{(]>)}[<>]
any of the 4! permutations of ([{<, you get the idea...

Input
ASCII-art rectangles, on the assumptions that they are unambiguous (see notes above) and can be properly converted into a string of brackets. You may assume either no trailing spaces or padded to a rectangle, with optional trailing newline.  There will be no leading whitespace.
Output
Any one of the valid bracket strings that obeys the intersection restrictions of the rectangles.  Other than an optional trailing newline, there should be no other characters than brackets.  The main rule is, if two squares intersect, then they should be assigned different bracket types.
Goal
This is code-golf, (lack of) quantity over quality.

FYI "exacerbate" means "make a bad thing worse".

@PaulR I believe that was the point

Oh, OK, evidently whatever the point was it went straight over my head!

Can we assume that each rectangle has some height?  i.e. it cannot have a + for it's top-left corner, and then (immediately below) the + for it's bottom-left corner?

Python 3, 519 bytes
def c(i):
 a,b,c,d={},0,[],{}
 for e in map("".join,zip(*i.split("\n"))):
  if"+"in e:
   f=e.index("+"),e.rindex("+")
   if f in a:j=a.pop(f);d[j]=f+(d[j],len(c));c.append(j)
   else:a[f]=b;d[b]=len(c);c.append(b);b+=1
 g,h={},0
 while d:
  i={list(d)[0]};
  for j,(k,l,m,n)in d.items():
   for(o,p,q,r)in(d[v]for v in i):
    if not(m>r or n<q or k>p or l<o or(q<m<n<r and o<k>l<p)):break
   else:i.add(j)
  for j in i:del d[j];g[j]=h
  h+=1
 s,u=set(),""
 for t in c:u+="[{(<]})>"[g[t]+4*(t in s)];s.add(t)
 return u

Here's a first attempt at a solution. The algorithm used purely looks at the corners in the diagram, abusing the fact only one vertical line can occur in a column, and therefore the first and last + in a column must be the corners of a rectangle. It then collects all rectangles and performs a naive (and somewhat nondeterministic) search for collisionless groups. I am not sure if this will always find the most optimal solution, but it worked for all examples I tried so far. Alternatively it could be replaced by a brute-force search for the least amount of groups.
Input: a string containing the ascii art. No trailing newline, and all lines must be padded to the same length using spaces. It is also completely fine with you not putting any of the |'s or -'s in there as it just looks at the corners.
As the golfing is quite simple (just whitespace minimalization and variable renaming mostly) it could probably be shorter, but as there are no other answers on this yet I'll leave it like this for now.

You get the bounty, because I don't forsee any other answers in <1 day. Thanks for answering, keep golfing!


text:
Format the reputation
You probably do know that the different reputation levels on Stack Exchange are formatted differently when seen from the questions page / a post. There're all the rep-formatting rules:

if a user has 1 to 999 (one to three digits) rep, it's left as-is.
if a user has 1000 to 9999 rep (four digits), it receives the comma as a separator: 9,999
if a user has 10000 to 99999 rep (five digits), it's shortened and rounded. I.e., 16741 rep is formatted as 16.7k, notice the dot separator unlike the comma for the lower rep (previous point).

16750 will already result 16.8k (since this seems to be fixed)
16941 results in 16.9k, 16950 rounds up to 17k, as well as does 17014, for example.
99941 rounds to 99.9k, 99950 rounds to 100k (this is something I actually hate with the rep-rounding on SE, because 100,000 is such a milestone, and 99950 is nowhere near).

If a user has 100000 to 999999 rep, it's rounded this way:

100100 rounds down to 100k, 100500 rounds up to 101k. The thing is, the rounding is done, but the decimal part is stripped (unlike the four-digits rep).
100450 rounds down to 100k, no step to round 450 to 500. Nor does 100499 - it's still 100k.
279843 rounds up to 280k, and 399999 rounds to 400k.

As input, you're given the raw reputation, and output it as formatted.
You can consider that input won't receive any invalid numbers / non-numbers, or numbers with leading zeros, i.e. 0001234.
Because Jon Skeet doesn't seem to be reaching 1,000,000 soon, your code must be as short as possible you don't need to handle the rep greater than one million (i.e. no special cases for 999500 and above).

"Because Jon Skeet doesn't seem to be reaching 1,000,000 soon" [citation needed]

@Milo Easy - he earned 93k for 2015. He has 163,685 left until 1,000,000, so this way it will take him more than 1,5 years (almost 2, I'd say). With this, you should also take into account that his yearly rep is decreasing with each year, since 2011. 2011: 134.7k, 2012: 131.8k, 2013: 116.8k, 2014: 104.3k, 2015: 94.3k.

A long explanation, but all in all, it's just the way rounding is usally done

@Edc See this answer by Peter Taylor.

Yes, there are many ways, but this is the usual way. For instance in javascript I just had to use the standard method .toFixed() to obtain the correct rounding

@edc Ok, but how I can know it's the default behavior in any language? I've just listed the rules so as not to make the question ambiguous. Otherwise there would certainly be the comments asking to clarify.

I think the explanation could be shortened by saying "If the rep is in the range 10000 to 994999 (both inclusive), it is rounded to 3 significant figures using the half-up rule, divided by 1000, and displayed with . for a decimal point and with a suffixed k; subject to the caveat that if the third significant figure is 0 and is to the right of the decimal point then the value is displayed only to 2 significant figures." The specific cutoffs could then be moved to a single list of test cases at the end of the post, which is more convenient for copy-pasting into a test framework.

(I'm assuming that by "you don't need to handle the rep greater than one million" you also don't require handling rep which would round to one million to 3s.f.)

@Peter Thanks,  made a correction. As for the golfed (:D) explanation, thanks again, but I'd like to keep it expanded for better illustration.

Japt, 50 48 bytes
First attempt; there may be a better method.
U<A³?U:U<L²?Us i1', :(U<1e5?Ue2n)r /A:Ue3n)r)+'k

Try it online!
How it works
          // Implicit: U = input integer, A = 10, L = 100
U<A³?U    // If U is less than A³ (10³ = 1000), return U.
:U<L²?    // Else, if U is less than L² (100² = 10000), return:
Us i1',   //  U.toString, with a comma inserted at position 1.
:(        // Else, return:
U<1e5?    //  If U is less than 1e5:
Ue2n)     //   U * (10 to the power of -2),
r /A      //   rounded and divided by 10.
:Ue3n)r)  //  Else: U * (10 to the power of -3), rounded.
+'k       //  Either way, add a "k" to the end.
          // Implicit: output last expression

JavaScript (ES6), 76 68 bytes
x=>x<1e4?x.toLocaleString():(x<1e5?(x/1e2+.5|0)/10:(x/1e3+.5|0))+"k"

Another first attempt. Thank goodness for that handy .toLocaleString(), the shortest alternative I could find is 21 bytes longer...
This separates thousands by either , or ., depending on what country you live in. For five two bytes more, you can make it always use a comma:
x=>x<1e4?x.toLocaleString`en`:(x<1e5?(x/1e2+.5|0)/10:(x/1e3+.5|0))+"k"

Your locale works fine for you, but here in Italy I get 1.234 (dot instead of comma)

@edc65 Now that's a problem I never thought I would run into with a code golf. Does it work now?

Perfect. Really I didn't think that was doable. And I tried just 'en' and it seems to work too

I don't think you need to adjust for locale, because it doesn't need to be portable.

@geokavel Wait, so I don't need to specify the locale, or I do need to so it's a comma instead of a period?

Basically, if it works on your computer, I think it's good enough.

@geokavel I agree, I was just bullying

JavaScript (ES6), 71
Beating @ETHProductions while he does not see my hint. He saw it.

x=>x<1e3?x:x<1e4?(x+='')[0]+','+x.slice(1):(x/1e3).toFixed(x<99950)+'k'

Test

f=x=>x<1e3?x:x<1e4?(x+='')[0]+','+x.slice(1):(x/1e3).toFixed(x<99950)+'k'

function test() { n=+I.value, O.textContent = n + ' -> ' + f(n) }

test()
<input id=I type=number value=19557 oninput=test()>

Test

Perhaps you should update your "beating ETHproductions" line...?

@CᴏɴᴏʀO'Bʀɪᴇɴ done.

ES6, 68 62 bytes
x=>x<1e4?`${x}`.split(/(?=...)/)+"":x.toPrecision(3)/1e3+"k"

Edit: Saved 6 bytes when I realised that ["1", "001"] stringifies to "1,001".
Edit: Saved 2 bytes to fix @Mwr247's comment!

16950 gives 16.9k instead of 17k

@Mwr247 Thanks, the fix saves me two more bytes!

Python 2.7, 58 bytes
lambda x:['%.3g'%((x+.5)/1e3)+'k','{:,}'.format(x)][x<1e4]

I had to use (x+.5) to deal with the 16950->17k case..


text:
Fractal Smoke Sequence
Introduction
A229037 has a quite intriguing plot (at least for the first few terms):

There is the conjecture, that it might indeed have some kind of fractal property.
How is this sequence constructed?
Define a(1) = 1, a(2) = 1 then for each n>2 find a minimal positive integer a(n) such that for every arithmetic 3 term sequence n,n+k,n+2k of indices, the corresponding values of the sequence a(n),a(n+k),a(n+2k) is not an arithmetic sequence.
Challenge
Given a positive integer n as an input, output the first n terms a(1), ... , a(n) of this sequence. (With any reasonable formatting. Possible leading/trainling characters/strings are irrelevant.)
There are snippets for generating this sequence available, but I think other approaches might be more golfable/more suitable for certain languages.
Please let us know how your progrm works. If you come a cross a particularly efficient algorithm you might want to mention that too, as it would allow to plot more terms of the sequence in shorter time.
First few test cases:
1, 1, 2, 1, 1, 2, 2, 4, 4, 1, 1, 2, 1, 1, 2, 2, 4, 4, 2, 4, 4, 5, 5, 8, 5, 5, 9, 1, 1, 2, 1, 1, 2, 2, 4, 4, 1, 1, 2, 1, 1, 2, 2, 4, 4, 2, 4, 4, 5, 5, 8, 5, 5, 9, 9, 4, 4, 5, 5, 10, 5, 5, 10, 2, 10, 13, 11, 10, 8, 11, 13, 10, 12, 10, 10, 12, 10, 11, 14, 20, 13

More testcases:
  a(100)  =   4
  a(500)  =   5
 a(1000)  =  55
 a(5000)  =  15
a(10000)  = 585

All terms up to n=100000 are available here: https://oeis.org/A229037/b229037.txt
Thanks @MartinBüttner for the help and encouragement.

Hey, where have I seen this graph before? :-D

Shift your head somewhat to the left, zoom in a bit, there you go! (:

A numberphile video just popped up: https://www.youtube.com/watch?v=o8c4uYnnNnc

I bet his code is not nearly as golfy!

Python 2, 95 bytes
l=[];n=input()
exec"a=min(set(range(n))-{2*b-c for b,c in zip(l,l[1::2])});print-~a;l=[a]+l;"*n

The main trick is in generating the numbers the new value must avoid. Keeping the reversed sequence so far in l, let's look at what elements might form a three-term arithmetic progression with the value we're about to add.
? 4 2 2 1 1 2 1 1   a b c
^ ^ ^               ? 4 2
^   ^   ^           ? 2 1
^     ^     ^       ? 2 2
^       ^       ^   ? 1 1

The other numbers are the paired members of l and every second element of l, so zip(l,l[1::2]). If this pair is (b,c) then the arithmetic progression (a,b,c) happens for a=2*b-c. After generating the set of a's to avoid, the code takes the minimum of the complement, prints it, and prepends it to the list. (Actually, the computation is done with numbers decreased by 1, and printed 1 higher, to let range(n) serve as a universe of candidates.)

Mathematica, 95 bytes
For[n_~s~k_=0;n=0,n<#,For[i=n,--i>0,s[2n-i,2f@n-f@i]=1];For[++n;i=1,n~s~i>0,++i];Print[f@n=i]]&

Certainly not the golfiest approach, but this is actually fairly efficient, compared to the algorithms I tried from the OEIS page.
As opposed to checking all the forbidden values for each s(n) when we get there I'm using a sieve-based approach. When we find a new value s(n) we check immediately which values this forbids for m > n. Then we just solve the s(n+1) by looking for the first value that wasn't forbidden.
This can be made even more efficient by changing the conditional --i>0 to 2n-#<=--i>0. In that case, we avoid checking forbidden values for n greater than the input.
For a somewhat more readable version, I started with this code, which stores the results up to max in a function f, and then golfed it to the above one-line pure function:
 max = 1000;
 ClearAll[sieve, f];
 sieve[n_, k_] = False;
 For[n = 0, n < max,
  temp = f[n];
  For[i = n - 1, i > 0 && 2 n - i <= max, --i,
   sieve[2 n - i, 2 temp - f[i]] = True;
   ];
  ++n;
  i = 1;
  While[sieve[n, i], ++i];
  f@n = i;
  ]

Haskell, 90, 89, 84, 83 bytes
Can probably be golfed more, but this is still a decent first attempt:
a n|n<1=0|n<3=1|1<2=[x|x<-[1..],and[x/=2*a(n-k)-a(n-k-k)||a(n-k-k)<1|k<-[1..n]]]!!0

Ungolfed:
a n | n<1        = 0
    | n<3        = 1
    | otherwise  = head (goods n)

goods n = [x | x <- [1..], isGood x n]

isGood x n = and [ x - a(n-k) /= a(n-k) - a(n-k-k) || a(n-k-k) == 0 | k <- [1..n] ]

This is a simple implementation which returns '0' for out of bounds. Then, for each possible value, it checks that for all k <= n and in bounds, [x, a(x-k), a(x-2k)] is not an arithmetic sequence.
Upper bound on time complexity (using the fact from the OEIS page that a(n) <= (n+1)/2:
t n <= sum[ sum[2*t(n-k) + 2*t(n-k-k) | k <- [1..n]] | x <- [1..(n+1)/2]]
    <= sum[ sum[4*t(n-1)              | k <- [1..n]] | x <- [1..(n+1)/2]]
    <= sum[     4*t(n-1)*n                         ] | x <- [1..(n+1)/2]]
    <=          4*t(n-1)*n*(n+1)/2
    ->
O(t(n)) == O(2^(n-2) * n! * (n+1)!)

I'm not sure how good this bound is because calculating the first 1k values of 't' and using a linear model on the logs of the values gave appx. O(22^n), with p-value < 10^(-1291), in case it matters.
On an implementation level, compiling with '-O2', it took ~35 min to calculate the first 20 values.

What is the time complexity for your program?

@flawr Added some time complexity analysis to the post

Brachylog, 33 31 bytes
;Ė{~b.hℕ₁≜∧.¬{ġh₃hᵐs₂ᶠ-ᵐ=}∧}ⁱ⁽↔

Try it online!
In case it matters: The 2-byte golf was possible thanks to a feature I requested after working on this challenge.
Explanation
We iteratively generate the sequence as a list in reverse order, e.g. [2,2,1,1,2,1,1], and reverse it at the end.
There are a couple of nested predicates here. Let's look at them from the inside out. The first one, ġh₃hᵐs₂ᶠ-ᵐ=, takes a candidate subsequence a(n),a(n-1),...,a(0) and determines whether a(n),a(n-k),a(n-2k) is an arithmetic sequence for some k.
ġ            Group the list into equal-length sublists (with the possible exception of
             the last sublist, which might be shorter)
 h₃          Get the first 3 sublists from that list
   hᵐ        and get the head of each of those 3 sublists
             We now have a list containing a(n),a(n-k),a(n-2k) for some k
     s₂ᶠ     Find all 2-element sublists of that list: [a(n),a(n-k)] and [a(n-k),a(n-2k)]
        -ᵐ   Find the difference of each pair
          =  Assert that the two pairwise differences are equal

For example, with input of [1,2,1,1,2,1,1]:
ġ has possible outputs of
    [[1],[2],[1],[1],[2],[1],[1]]
    [[1,2],[1,1],[2,1],[1]]
    [[1,2,1],[1,2,1],[1]]
    [[1,2,1,1],[2,1,1]]
    [[1,2,1,1,2],[1,1]]
    [[1,2,1,1,2,1],[1]]
    [[1,2,1,1,2,1,1]]
h₃ has possible outputs of
    [[1],[2],[1]]
    [[1,2],[1,1],[2,1]]
    [[1,2,1],[1,2,1],[1]]
hᵐ has possible outputs of
    [1,2,1]
    [1,1,2]
    [1,1,1]
s₂ᶠ has possible outputs of
    [[1,2],[2,1]]
    [[1,1],[1,2]]
    [[1,1],[1,1]]
-ᵐ has possible outputs of
    [-1,1]
    [0,-1]
    [0,0]
= is satisfied by the last of these, so the predicate succeeds.

The next predicate outwards, ~b.hℕ₁≜∧.¬{...}∧, inputs a subsequence a(n-1),a(n-2),...,a(0) and outputs the next bigger subsequence a(n),a(n-1),a(n-2),...,a(0).
~b.hℕ₁≜∧.¬{...}∧
~b.                 The input is the result of beheading the output; i.e., the output is
                    the input with some value prepended
  .h                The head of the output
    ℕ₁              is a natural number >= 1
      ≜             Force a choice as to which number (I'm not sure why this is necessary,
                    but the code doesn't work without it)
        ∧           Also,
         .          the output
          ¬{...}    does not satisfy the nested predicate (see above)
                    I.e. there is no k such that a(n),a(n-k),a(n-2k) is an arithmetic sequence
                ∧   Break unification with the output

Finally, the main predicate ;Ė{...}ⁱ⁽↔ takes an input number and outputs that many terms of the sequence.
;Ė{...}ⁱ⁽↔
;           Pair the input number with
 Ė          the empty list
  {...}ⁱ⁽   Using the first element of the pair as the iteration count and the second
            element as the initial value, iterate the nested predicate (see above)
         ↔  Reverse, putting the sequence in the proper order

Jelly, 24 19 bytes
This is my first Jelly answer in quite a while. Glad to be back.
This is a port of my APL answer which itself is an adaptation of many of the algorithms used here. The main difference is that this is 0-indexed.
Edit: -5 bytes thanks to Jonathan Allan.
Try it online!
Ḋm2ɓṁḤ_
ŻJḟÇṂ;
1Ç¡U

Explanation
Ḋm2ɓṁḤ_  First link. Takes our current sequence S as our left argument.

         We are trying to calculate, of an arithmetic progression A B C,
           the C using the formula, C = 2*B - A
Ḋ        Remove the first element of S.
 m2      Get every element at indices 0, 2, 4, ...
           This is equivalent to getting every second element of S, a list of As.
   ɓ     Starts a dyad with reversed arguments.
           The arguments here are S and As.
    ṁ    This molds S in the shape of As, giving us a list of Bs.
     Ḥ   We double the Bs.
      _  And subtract As from 2 * Bs.

ŻJḟÇṂ;  Second link. Takes S as our left argument.

Ż       Append a 0 to S.
 J      Range [1, len(z)]. This gets range [1, len(S) + 1].
  ḟÇ    Filter out the results of the previous link, our Cs.
    Ṃ   Take the minimum of Cs.
     ;  And concatenate it with the rest of the sequence so far.

1Ç¡U  Third link. Where we feed our input, n.

1     A list with the element 1.
 Ç¡   Run the previous link n times.
   U  Reverse everything at the end.

ḟ will do just as well as œ- saving a byte

Pretty sure you can zero index (as per sequence) and so replace “” with 1 outputting a Jelly representation of a list from a full-program, saving one more.

Œœị@2 may be golfed to Ḋm2 saving two.

L‘R may be golfed to ŻJ saving one.

@JonathanAllan Five whole bytes! Thanks!

APL (Dyalog Extended), 37 bytesSBCS
Many thanks to Adám for his help in writing and golfing this answer in The APL Orchard, a great place to learn the APL language. Try it online!
Edit: -6 bytes thanks to Adám
⌽{⍵,⍨⊃(⍳1+≢⍵)~-¯2⊥⍵[2×⍀⍥⍳⌊2÷⍨≢⍵]}⍣⎕,⍬

Explanation
{⍵,⍨⊃(⍳1+≢⍵)~-¯2⊥⍵[2×⍀⍥⍳⌊2÷⍨≢⍵]}  ⍵ is our right argument, the sequence S

                        ⌊2÷⍨≢⍵    We start by calculating X = ⌊len(S)÷2⌋
                       ⍳          Get a range [1, X]
                   2×⍀⍥           With that we can get S[:X] and S[:X×2:2]
                                  or S up to halfway and every 2nd element of S
             -¯2⊥⍵[           ]   And with that we can get 2*S[:X] - S[:X×2:2]
                                  Which is C=2*B-A of a progression A B C
     (⍳1+≢⍵)~                     We remove these Cs from our possible a(n)s
                                  I use range [1, len(S)+1]
    ⊃                             Get the first result, which is the minimum
 ⍵,⍨                              And then prepend that to S

⌽{...}⍣⎕,⍬

 {...}⍣⎕    We iterate an "input" ⎕ times
        ,⍬  with an empty list ⍬ as the initial S
⌽           and reversing S at the end as we have built it backwards

APL (Dyalog Unicode), 43 39 38 bytesSBCS
Here is a faster but less golfy solution that can calculate ⍺(10000) in a few seconds.
⌽{⍵,⍨⊃(⍳1+≢⍵)~-⌿⍵[1 2 1∘.×⍳⌊2÷⍨≢⍵]}⍣⎕,⍬

Try it online!

Ruby, 71 bytes
->n,*a{a.fill(0,n){|s|([*1..n]-(1..s/2).map{|o|2*a[s-o]-a[s-2*o]})[0]}}

Try it online!
Generates all forbidden values, then takes the complement of that array in (1..n) and takes the first value of the result. That means I am assuming that a[n] <= n for all n, which is easily proven using induction (if the first n/2 terms are all less than n/2, then there can't be an arithmetic progression leading to n).
The syntactic trick here is also mildly interesting: *a is used to initialize an array of additional arguments (which would be ignored if we passed any), and then a.fill mutates the argument array and implicitly returns it.

-1 byte: instead of a[s-o] and a[s-2*o], you can use a[s-=1] and a[s-o]

MATLAB, 156 147 bytes
I've finally gotten to golf this down a bit:
N=input('');s=[0;0];for n=1:N,x=s(n,~~s(n,:));try,a(n)=find(~ismember(1:max(x)+1,x),1);catch,a(n)=1;end,s(n+1:2*n-1,end+1)=2*a(n)-a(n-1:-1:1);end,a

Ungolfed:
N=input('');                                   % read N from stdin

s=[0;0];
for n=1:N,
    x=s(n,~~s(n,:));                           % x=nonzeros(s(n,:));
    try,
        a(n)=find(~ismember(1:max(x)+1,x),1);  % smallest OK number
    catch,
        a(n)=1;                                % case of blank page for n
    end,

    s(n+1:2*n-1,end+1)=2*a(n)-a(n-1:-1:1);     % determined new forbidden values
end,
a                                              % print ans=...

Input is read from STDIN, and printing is done automatically with ans= and stuff appended. I hope this qualifies as "reasonable" output.
This is also a sieve-based solution: the variable s(i,:) keeps track of those sequence values which are forbidden for a(i). The try-catch block is needed to treat the case of an empty (meaning full zero) s matrix: in this case the lowest value of 1 is already allowed.
However, the memory need (or runtime?) gets pretty messy above N=2000. So here's a non-competing, more efficient solution:
%pre-alloc
s = zeros([N,fix(N*0.07+20)]); %strict upper bound, needs adjusting later
i = zeros(1,N);

a = 1;
for n = 2:N,
    x = s(n,1:i(n));
    if isempty(x),
        a(n) = 1;
    else
        a(n) = find(~ismember(1:max(x)+1,x),1);
    end,

    j = n+1:min(2*n-1,N);
    i(j) = i(j)+1;
    s(N,max(i(j))) = 0;   %adjust matrix size if necessary
    b = a(n-1:-1:1);
    s(sub2ind([N,size(s,2)+1],j,i(j))) = 2*a(n)-b(1:length(j));
end

In this implementation the s matrix again contains forbidden values, but in a well-ordered way, without any zero blocks (which are present in the competing version).  The index vector i keeps track of the number of forbidden vectors in s. At first sight cells would be great to keep track of the information stored in s, but those would be slow, and we couldn't index a bunch of them at the same time.
One nasty feature of MATLAB is that while you can say M(1,end+1)=3; and automatically expand a matrix, you can't do the same with linear indexing. It sort of makes sense (how should MATLAB know the resulting array size, in the framework of which it should interpret the linear indices?), but it still surprised me. This is the reason for the superfluous line s(N,max(i(j))) = 0;: this will expand the s matrix for us whenever necessary. The starting size guess N*0.07+20 comes from a linear fit to the first few elements, by the way.
In order to test runtime, I also checked a slightly modified version of the code, where I initialized the s matrix to have size N/2. For the first 1e5 elements this seems to be a very generous guess, so I removed the expansion step of s mentioned in the previous paragraph. These together imply that the code will be faster, but also less robust at very high N (since I don't know how the series looks like there).
So here are a few runtimes, comparing

v1: the competing golfed version,
v2: the low-starting-size, fool-proof version and
v3: the generous-starting-size, might-fail-for-large-N version.

I measured these on R2012b, taking the best of 5 runs inside a named function definition with tic/toc.

N=100:

v1: 0.011342 s
v2: 0.015218 s
v3: 0.015076 s

N=500:

v1: 0.101647 s
v2: 0.085277 s
v3: 0.081606 s

N=1000:

v1: 0.641910 s
v2: 0.187911 s
v3: 0.183565 s

N=2000:

v1: 5.010327 s
v2: 0.452892 s
v3: 0.430547 s

N=5000:

v1: N/A (didn't wait)
v2: 2.021213 s
v3: 1.572958 s

N=10000:

v1: N/A
v2: 6.248483 s
v3: 5.812838 s

It would seem that the v3 version is significantly, but not overwhelmingly faster. I don't know whether an element of uncertainty (for very large N) is worth the minor increase in runtime.

M=1;M(end+1)=2; works perfectly fine for me?

@flawr that will work for scalars and vectors. Try M=rand(2); M(end+1)=2 instead:)

Ah now I see =)

Uiua, 28 bytes
⇌⍥(⊂⊗0⍘⊚∸↥0-⬚∞-,▽◿2⇡⧻...)∶[]

Try it online!
I don't think I like the "quadruplicate" up front...
Takes n and outputs the first n values of the sequence.
⇌⍥(⊂⊗0⍘⊚∸↥0-⬚∞-,▽◿2⇡⧻...)∶[]    input: n
⇌⍥(...):[]    repeat n times to the empty list and reverse the result...
⊂⊗0⍘⊚∸↥0-⬚∞-,▽◿2⇡⧻...    input: current list L reversed, output: next item prepended
                 ▽◿2⇡⧻.      extract every 2nd element using mask 0 1 0 1...
           -⬚∞-,        .     2L minus the above, where the above is padded with ∞
         ↥0                    convert negatives to 0 to appease ⍘⊚
        ∸                     prepend 0 to get 1 at the first iteration
     ⍘⊚                      inverse where; counts of 0, 1, ...
  ⊗0                         index of 0 (the smallest nonnegative integer
                              not in the list before ⍘⊚)
⊂                        .   prepend it to L

Save a byte by starting with 1 instead of the empty list []...

Bubbler what are your thoughts on Uiua vs the other array langs?

ES6, 114 bytes
n=>[...r=Array(n)].map((x,i,s)=>{for(y=1;x&&x[y];y++);r[i]=y;for(j=i;++j<n;s[j][y+y-r[i+i-j]]=1)s[j]=s[j]||[]}&&r

Returns an array of the first n elements of the sequence, so the indices are 1 off the ungolfed version below. I used the sieve approach. This version slows down after about n=2000; a previous version avoided reading off the beginning of the array which meant it didn't slow down until about n=2500. An older version used the sieve array as a list of forbidden values rather than a boolean array of which values were forbidden; this could get to about n=5000 without breaking sweat. My original version tried to use bitmasks but that turned out to be unhelpful (and was also far too long at 198 bytes).
The not quite so slow version ungolfed:
function smoke(n) {
    result = [];
    sieve = [];
    for (i = 1; i <= n; i++) {
        value = 1;
        if (sieve[i]) {
            while (sieve[i][value]) {
                value++;
            }
        }
        result[i] = value;
        for (j = 1; j < i && i + j <= n; j++) {
            if (!sieve[i + j]) sieve[i + j] = [];
            sieve[i + j][value + value - result[i - j]] = true;
        }
    }
    return result;
}

Nibbles, 12.5 10.5 bytes (21 nibbles)
.~~1/-,~!*2$`%~>>@-

Attempt This Online!
Outputs the infinite sequence.
'Nnumbers-the-new-value-must-avoid' approach taken from xnor's Python answer.
.~~1/-,~!*2$`%~>>@-     # full program
.~~1/-,~!*2$`%~>>@-$    # with implicit variable shown:
.~~                     #  append until null,
   1                    #  starting with the 1-element list [1]:
                        #   get the numbers the new value must avoid:
        !               #    zip together:
         *2$            #     twice the current list
            `%~>>@      #     and its even-indexed elements
                  -     #     by subtraction,
     -                  #   now remove the numbers to avoid from
      ,~                #    the infinite list of natural numbers
    /              $    #   and get the first element.

05AB1E, 13 bytes
ƒ¯Âxsιθ-∞sKнˆ

Inspired by the Python, Nibbles, and Jelly answers, so make sure to upvote those as well!
Try it online.
Explanation:
ƒ             # Loop the (implicit) input+1 amount of times:
 ¯            #  Push the global array (empty by default)
  Â           #  Bifurcate it; short for Duplicate & Reverse copy
   x          #  Double each value in the reversed list (without popping)
    s         #  Swap so the non-doubled reversed list is at the top again
     ι        #  Uninterleave it into two parts
      θ       #  Pop and leave the last part, for all (0-based) odd-indiced values
       -      #  Remove the values in the lists from one another at the same positions,
              #  removing any trailing items, since the lists are of unequal lengths
        ∞     #  Push an infinite positive list: [1,2,3,...]
         s    #  Swap so the generated list is at the top again
          K   #  Remove all those values from the infinite list
           н  #  Pop and keep the first/smallest value remaining
            ˆ #  Pop and add it to the global array for the next iteration
              # (after the loop, the global array that's still on the stack after the
              # bifurcation is output implicitly as result, hence why we loop +1 amount
              # of times)

JavaScript (Node.js), 65 bytes
f=(n,x=1,g=d=>--d?2*f(d)-x!=f(2*d-n)?g(d):g(n,++x):x)=>n>0?g(n):f

Try it online!
Slow