text:
Sum the First n Even Fibonacci Numbers
There seems not to be a contest for this one yet.
The task is simple. Add the first n numbers of the Fibonacci sequence that are even and output the result.
This is given by OEIS A099919, except that sequence is shifted by one, starting with fib(1) = 0 instead of fib(1) = 1.
This is code golf. Lowest byte count wins.
Examples
n sum
1 0
2 2
3 10
4 44
5 188
6 798
7 3382
8 14328
9 60696

Related

https://oeis.org/A099919

@EasterlyIrk The test cases imply the latter, but it should be explicitly stated.

@Mego yeah, I figured as much.

@EasterlyIrk, Mego is right. It is the latter.

Please don't accept answers so fast. It's only been an hour, golfier answer could come in. EDIT: I see now there's already a shorter answer that's not accepted yet.

It's customary to wait at least a week before accepting an answer, because many people interpret it as a sign that the challenge is no longer active.

Shouldn't it be n(1) = 0? Your statement n = 0 makes no sense.

@devRicher I have corrected that. Someone else added that statement to my original post and I did not spot the mistake.

Oasis, 8 7 5 bytes
1 byte saved thanks to @ETHProductions and 2 more saved thanks to @Adnan!
zc»+U

Try it online!
Explanation:
This uses the same recurrence formula as my MATL answer.

Oasis's info.txt says U is replaced in the code with 00, might that save you a byte?

@ETHproductions Thanks! I forgot that

Nice! You can replace 4* with z and 2+ with » :)

@Adnan Thank you! I really should read the doc :-)

Python, 33 bytes
c=2+5**.5
lambda n:(7-c)*c**n//20

Try it online
Magic formula!

Oh god. It took me much longer than it should have to realize why you were "commenting out" that 20 on the second line :P

@xnor, Any reference to this magic formula?

@TheChetan: possibly a(n) = (-10 + (5-3*sqrt(5))*(2-sqrt(5))^n + (2+sqrt(5))^n*(5+3*sqrt(5)))/20 (Colin Barker, Nov 26 2016) from the OEIS page

@TheChetan bit late, but it's Binet's formula

JavaScript (ES6), 27 bytes
f=x=>x>1&&4*f(x-1)+f(x-2)+2

Recursion to the rescue! This uses one of the formulas on the OEIS page:

f(n < 1) = 0, f(n) = 4*a(n+1)+a(n)+2

(but shifted by one because the challenge shifts it by one)

Python 2, 35 bytes
f=lambda n:n/2and 4*f(n-1)+f(n-2)+2

Try it online!

Actually, 6 bytes
r3*♂FΣ

Try it online!
Explanation:
Every third Fibonacci number (starting from F_0 = 0) is even. Thus, the first n even Fibonacci numbers are F_{i*3} for i in [0, n).
r3*♂FΣ
r       [0, n)
 3*     multiply each element by 3
   ♂F   retrieve the corresponding element in the Fibonacci sequence
     Σ  sum

Pyke, 6 bytes
3m*.bs

Try it here!
3m*    -   map(i*3, range(input))
   .b  -  map(nth_fib, ^)
     s - sum(^)

Perl 6,  38 35  32 bytes
{[+] grep(*%%2,(1,&[+]...*))[^($_-1)]}

Try it
{[+] grep(*%%2,(0,1,*+*...*))[^$_]}

Try it
{[+] (0,1,*+*...*)[3,6...^$_*3]}

Try it
Expanded:
{  # bare block lambda with implicit parameter ｢$_｣

  [+]                       # reduce with ｢&infix:<+>｣

    ( 0, 1, * + * ... * )\  # fibonacci sequence with leading 0

    [ 3, 6 ...^ $_ * 3 ]    # every 3rd value up to
                            # and excluding the value indexed by
                            # the input times 3

}

Mathematica,  27 21 bytes
Thanks to xnor for pointing out an alternate formula, alephalpha for correcting for starting index
Fibonacci[3#-1]/2-.5&

Might the (Fibonacci(3*n+2)-1)/2 formula be shorter?

Octave, 36 35 33 bytes
@(n)filter(2,'FAD'-69,(1:n)>1)(n)

Try it online!
Explanation
This anonymous function implements the difference equation a(n) = 4*a(n-1)+a(n-2)+2 as a recursive filter:

Y = filter(B,A,X) filters the data in vector X with the
      filter described by vectors A and B to create the filtered
      data Y.  The filter is a "Direct Form II Transposed"
      implementation of the standard difference equation:
a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb) - a(2)*y(n-1) - ... - a(na+1)*y(n-na)

In our case A = [1 -4 -1], B = 2, and the input x should be a vector of ones, with the result appearing as the last entry of the output y. However, we set to 0 the first value of the input so that an initial 0 appears in the output, as required.
'FAD'-69 is just a shorter way to produce the coefficient vector A = [1 -4 -1]; and (1:n)>1 produces the input vector x = [0 1 1 ... 1].

dc, 25 22 bytes
9k5v1+2/3?*1-^5v/0k2/p

Try it online!
Or save the program in a file and run it by typing
dc -f *filename*

The program accepts a non-negative integer n on stdin, and it outputs the sum of the first n even Fibonacci numbers on stdout.  (The Fibonacci sequence is taken to start with 0, as per the OP's examples.)

This program uses the formula (F(3n-1)-1)/2 for the sum of the first n even Fibonacci numbers, where F is the usual Fibonacci function, given by F(0) = 0, F(1) = 1, F(n) = F(n-2) + F(n-1) for n >= 2.

dc is a stack-based calculator.  Here's a detailed explanation:
9k  # Sets the precision to 9 decimal places (which is more than sufficient).

5v  # Push the square root of 5

1+  # Add 1 to the number at the top of the stack.

2/  # Divide the number at the top of the stack by 2.

At this point, the number (1+sqrt(5))/2 is at the top of the stack.
3   # Push 3 on top of the stack.

?   # Read a number from stdin, and push it.

\*  # Pop two numbers from the stack, multiply them, and push the product

1-  # Subtract 1 from the number at the top of the stack.

At this point, 3n-1 is at the top of the stack (where n is the input), and (1+sqrt(5))/2 is second from the top.
^   # Pop two numbers from the stack (x, then y), compute the power y^x, and push that back on the stack.

5v/ # Divide the top of the stack by sqrt(5).

At this point, the number at the top of the stack is (((1+sqrt(5))/2)^(3n-1))/sqrt(5).  The closest integer to this number is F(3n-1).  Note that F(3n-1) is always an odd number.
0k # Change precision to 0 decimal places.

2/ # Divide the top of the stack by 2, truncating to an integer.

p # Print the top of the stack on stdout.

Forth (gforth), 38 bytes
: f 1 1 rot 1 ?do tuck 4 * + loop 2/ ;

Try it online!
Wins over existing Forth answer by porting this formula:
$$
G(0)=G(1)=1, G(n+2)=4G(n+1)+G(n) \\
a(n) = \left\lfloor \frac{G(n)}2 \right\rfloor
$$
: f ( n -- a_n )  \ Take single number n and return a_n
  1 1 rot 1       \ g0 g1 n 1
  ?do             \ loop n-1 times
    tuck 4 * +    \ gn-1 gn -> gn gn+1=4gn+gn-1
  loop            \ end loop; top is gn
  2/              \ an = gn/2 (floor division)
;

C, 82 38 36 bytes
2 bytes saved thanks to @BrainSteel
The formulas at the OEIS page made it much shorter:
a(n){return--n<1?0:4*a(n)+a(n-1)+2;}

Try it online!
82 bytes:
x,s,p,n,c;f(N){s=0;p=n=1;c=2;while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;}

The first version is 75 bytes but the function is not reusable, unless you always call f with greater N than the previous call :-)
x,s,p=1,n=1,c=2;f(N){while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;}

My first answer here. Didn't check any other answers nor the OEIS. I guess there are a few tricks that I can apply to make it shorter :-)

You can make this a tad shorter by shuffling things around a bit: a(n){return--n<1?0:4*a(n)+a(n-1)+2;} (36 bytes)

MATL, 15 14 bytes
OOi:"t4*b+2+]x

Try it online!
Explanation
This uses one of the recurrence formulas from OEIS:

a(n) = 4*a(n-1)+a(n-2)+2

For input N the code iterates N times, which is 2 more times than necessary. This is compensated for by setting 0, 0 (instead of 0, 2) as initial values, and by deleting the last obtained value and displaying the previous one.
OO      % Push two zeros as initial values of a(n-2), a(n-1)
i       % Input N
:"      % Do this N times
  t     %   Duplicate a(n-1)
  4*    %   Multiply by 4
  b+    %   Bubble up a(n-2) and add to 4*a(n-1)
  2+    %   Add 2. Now we have 4*a(n-1)+a(n-2)+2 as a(n), on top of a(n-1)
]       % End
x       % Delete last value, a(n). Implicitly display the remaining value, a(n-1)

Batch, 80 bytes
@set/at=x=0,y=1
@for /l %%i in (2,1,%1)do @set/az=x+y,y=z+x,t+=x=y+z
@echo %t%

Uses the fact that every third Fibonacci number is even, and just calculates them three at a time (calculating more than one at a time is actually easier as you don't have to swap values around). I tried the (Fibonacci(3*n+2)-1)/2 formulation but it's actually a few bytes longer (t+= turns out to be quite efficient in terms of code size).

APL (Dyalog Unicode), 22 21 bytes
-1 byte thanks to Adám
(2+5*.5)∘(⌊20÷⍨*×7-⊣)

Try it online!
Uses xnor's magic formula
(2+5*.5)∘(⌊20÷⍨*×7-⊣)

(2+5*.5)               ⍝ constant c
        ∘(           ) ⍝ joined to
                 7-⊣  ⍝ 7-c
                ×      ⍝ multiplied by
               *       ⍝ input^c
           20÷⍨        ⍝ all over 20
          ⌊            ⍝ floor

Or with APL (Dyalog Extended), 19 bytes
(Thanks to Adám)
(2+√5)∘(⌊20÷⍨*×7-⊣)

Try it online!

Save a byte by answering with the tacit function (2+5*.5)∘(⌊20÷⍨*×7-⊣) Try it online! and optionally another two from Dyalog Extended's √ Try it online!

Why is your bounty request for 50 instead of 100 (doubled by being well-explained)?

I didn't know what would count for well explained and is it is just a re-implementation of someone else's formula, I didn't think think it would count. @Adám

APL (Dyalog Unicode), 16 bytesSBCS
⌊⊃⌽(4∘⊥,⊃)⍣⎕÷2 2

Try it online!
A full program.
How it works: the math
Uses a(n) = (Fibonacci(3*n + 2) - 1)/2 from the OEIS page, but we have offset 1 in a(n), so the actual formula is:
$$
a(n) = \frac{F(3 n - 1) - 1}{2}
= \Bigl\lfloor \frac{F(3 n - 1)}{2} \Bigr\rfloor
$$
And using \$ F(2) = F(-1) = 1 \$ and \$ F(n+3) = 4F(n) + F(n-3) \$, we define a derived sequence \$ G(n) \$ such that
$$
G(0)=G(1)=\frac12, G(n+2)=4G(n+1)+G(n)
$$
Then the desired value is \$ a(n) = \lfloor G(n) \rfloor \$.
How it works: the code
⌊⊃⌽(4∘⊥,⊃)⍣⎕÷2 2  ⍝ Input: n
            ÷2 2  ⍝ 2-element vector [.5 .5] i.e. [G(1) G(0)]
   (4∘⊥,⊃)⍣⎕      ⍝ Derive [G(x+2) G(x+1)] from [G(x+1) G(x)] n times:
    4∘⊥           ⍝   G(x+2) = 4×G(x+1) + G(x)
        ⊃         ⍝   G(x+1) as first element of the vector
       ,          ⍝   Concatenate
 ⊃⌽               ⍝ Get the last element of the result vector, i.e. G(n)
⌊                 ⍝ Floor

Japt, 10 bytes
Uo@MgX*3Ãx

Try it online!
Thanks ETHproductions :)

R, 42 41 bytes
sum(DescTools::Fibonacci(3*(scan():2-1)))

scan() : take n from stdin.
scan():2-1 : generate integers from n to 2, decrement by 1, yielding n-1 through 1.
3*(scan():2-1) : multiply by 3, as every third fibonacci number is even.
DescTools::Fibonacci(3*(scan():2-1)) : Return these fibonacci numbers (i.e. 3 through (n-1)*3).
sum(DescTools::Fibonacci(3*(scan():2-1))) : Sum the result.

Previously, I had this uninteresting solution using one of the formulae from OEIS:
a=function(n)`if`(n<2,0,4*a(n-1)+a(n-2)+2)

I managed to match your bytecount without recursion :)

@JarkoDubbeldam Nice! I've ditched the recursion also and made a one-byte improvement :)

Nice, what exactly does desctools::fibonacci do that numbers::fibonacci cant? Because that mist be a bit shorter.

Oh nevermind, found it. Sweet, the other implementations I found don't support asking for multiple numbers at once.

And for some reason sapply(1:10,gmp::fibnum) does really weird stuff.

numbers::fibonacci has a second argument that allows display of numbers 1 to n, which is a nice feature, but then you still need to do careful indexing to extract every third element. So you end up with something like this: sum(numbers::fibonacci((n=scan())*3-3,T)[1:(n-1)*3]), 52 bytes.

@JarkoDubbeldam Yeah, ``gmp::fibnum'' returns objects of type bigz, which the *apply class of functions converts to type raw because reasons...

PHP, 73 70 bytes
for(${0}=1;$i++<$argv[1];$$x=${0}+${1})${$x^=1}&1?$i--:$s+=$$x;echo$s;

showcasing variable variables. O(n).
Run with -nr.
breakdown
for(${0}=1;         # init first two fibonaccis (${1}=NULL evaluates to 0 in addition)
                    # the loop will switch between $0 and $1 as target.
    $i++<$argv[1];  # loop until $i reaches input
    $$x=${0}+${1}       # 3. generate next Fibonacci
)
    ${$x^=1}            # 1. toggle index (NULL => 1 => 0 => 1 ...)
    &1?$i--             # 2. if current Fibonacci is odd, undo increment
    :$s+=$$x;           #    else add Fibonacci to sum
echo$s;             # print result

Numbers are perfectly valid variable names in PHP.
But, for the literals, they require braces; i.e. ${0}, not $0.
36 bytes, O(1)
<?=(7-$c=2+5**.5)*$c**$argv[1]/20|0;

port of xnor´s answer

R, 42 bytes
Non-recursive solution, as contrast to the earlier solution by @rtrunbull here.
for(i in 1:scan())F=F+gmp::fibnum(3*i-3);F

Uses the property that each third value of the Fibonacci sequence is even. Also abuses the fact that F is by default defined as FALSE=0, allowing it as a basis to add the values to.

Mathematica, 32 27 bytes
Fibonacci[3Input[]-1]/2-1/2

Credit to xnor. Saved 5 bytes thanks to JungHwan Min.

Surely Mathematica has Fibonacci and it's shorter to do either (Fibonacci(3*n+2) - 1)/2 or write the sumi?

@JungHwanMin This isn't plagiarism; it mentions the OEIS page. Also, this isn't a candidate for community wiki. See How should Community Wikis be used?.

@devRichter Sorry for undeleting your post, but it was necessary to have a conversation. If you want to keep it deleted, let me know and I'll move this conversation to a chat room.

@Dennis still, I believe credit should be given to Vincenzo Librandi explicitly -- (accidentally deleted my last comment... could that be undeleted?) For the community post suggestion, I stand corrected.

What I meant was to mention his name in the post... (or perhaps include the Mathematica comment (* Vincenzo Librandi, Mar 15 2014 *) in the post, as it is on OEIS.)

@JungHwanMin Why are you singling out this answer? Most answers to this question use one formula or another from the OEIS page, and I don't see anyone mentioning Gary Detlefs by name...

@devRichter I don't know or have Mathematica. How does this accept user input?

@Dennis I found a shorter one. This is how the input screen looks like.

@Dennis While other answers are implementations of a formula, this is a copy/pasted answer, with spaces removed...

@devRicher Welp, it was. Now, my point does not matter. +1

-6 bytes: Fibonacci[3Input[]-1]/2-.5

Seems to output a(n). instead of a(n). @JungHwanMin

@devRicher If you want an exact integer... -5 bytes: Fibonacci[3Input[]-1]/2-1/2

Haskell (32 31 bytes)
Saved one byte thanks to @ChristianSievers.
Using the formula given in OEIS: a(n) = 4*a(n-1)+a(n-2)+2, n>1 by Gary Detlefs
a n|n>1=4*a(n-1)+a(n-2)+2|n<2=0

A golfier way to say n<=1 for integers is n<2. Also, the second condition doesn't need to be the negation of the first (the idiomatic otherwise is simply True), so usally in golfing something like 1<2 is used.

@ChristianSievers indeed the n<2 is an obvious improvement, thank you. The second one works as well, though it does not save me anything in this case. I'm still learning Haskell and did not realise I could have a guard like that. Thank you!

Forth (gforth), 47 bytes
: f 3 * 1- 0 1 rot 0 do tuck + loop d>s 1- 2/ ;

Try it online!
Uses the first formula for OEIS a(n) = (Fibonacci(3*n + 2) - 1)/2, since the code for Fibonacci is relatively small in forth.
: f              \ start a new word definition
  3 * 1-         \ multiply by 3 and subtract 1 (simplified form of 3*(n-1) + 2 )
  0 1 rot 0      \ create starting Fibonacci values and set up loop parameters
  do tuck + loop \ Fibonacci code - iteratively copy top value add top 2 stack values
  d>s            \ drop the top stack value
  1- 2/          \ subtract 1 and divide result by 2
;                \ end word definition

Husk, 8 bytes
Σ↑Θnİ0İf

Try it online!
painfully slow due to intersecting two infinite lists.

Nice.  This is another, rather faster, 8-byter, but obviously golf doesn't care about speed!

PARI/GP, 21 bytes
n->fibonacci(3*n-1)\2

\ is the integer quotient.

Excel (Version 1911), 119 Bytes
Using iterative calculations (Maximum iteration 1024)
A1 'Input
B1 =IF(B1=4^5,1,B1+1)
C1 =SEQUENCE(A1*3-1)-1
D1 =IF(B1=1,N(C1#>0),IF(C1#=B1,SUM(INDEX(D1#,B1-{0,1})),D1#))
E1 =SUM(D1#*(MOD(D1#,2)=0)) 'Output

Tests

GolfScript, 46 bytes
(:m;5 2 -1??:i 3*5\- 2i-m?*3i*5+2i+m?*+-10+20/

Ignore the floating point, TIO isn't perfect.
Yeah, yeah. I cheated. This is just a fancy arithmetic equation to calculate the result. Works in O(1) time, though, assuming a^n can be calculated in O(1) time, which might not be true.
(:m;5 2 -1??:i 3*5\- 2i-m?*3i*5+2i+m?*+-10+20/ #Sum the first n even F
(:m;                                           #Set m to our input minus one, pop the value from the list.
    5 2 -1??:i                                 #Set i to sqrt(5), but don't pop it since we're gonna use it (saves 1 byte)
               3*5\-                           #5-3sqrt(5)
                     2i-m?                     #[2-sqrt(5)]^m
                          *                    #Multiply those two together
                           3i*5+2i+m?*         #Same as the above lines, but + instead of -.
                                      +        #Add the left part with the right part
                                       -10+    #Add -10 (-10+20/ and 10- 20/ are the same size)
                                           20/ #Divide by twenty.

Try it online!

GolfScript, 15 bytes
0.@{.4*@2++}\*;

This one actually does the "operation" using a neat little trick I found. The sum is actually just a 0, 0 leading sequence, with a(n) = 4a(n-1) + a(n-2) + 2. So I do that.
0.@{.4*@2++}\*; #Print the sum of the first n even F
0.              #Add two 0s to the stack. [n 0 0]
  @             #Bring the n up front. [0 0 n]
   {       }    #A block of "do something" [0 0 n {}]
   {       }\   #Bring n to the front again [0 0 {} n]
   {       } *  #Perform the block n times on the stack below it [0 0]
   {.      }    #Duplicate our top element (a[n-1] a[n-1])
   { 4*    }    #Multiply the dupe by 4 (a[n-1] 4a[n-1])
   {   @   }    #Bring up our bottom element (a[n-1] 4a[n-1] a[n-2])
   {    2++}    #4a[n-1]+a[n-2]+2 = a[n]
   {       }    #Stack is now a[n-1] a[n], so we dop the loop until our n is right!
              ; #The stack has a[n-1] a[n], but our "n" in question is 1 too high
                #So we pop the top element, leaving a[n-1], W5.

Try it online!

05AB1E, 7 bytes
L<3*ÅfO

Try it online!

Jelly, 6 bytes
Ḷ×3ÆḞS

Try it online!
Uses the formula
$$a(n) = \sum_{i=0}^{n-1}f(3i)$$
where \$f(n)\$ is the \$n\$-th Fibonacci number
How it works
Ḷ×3ÆḞS - Main link. Take n on the left
Ḷ      - [0, 1, 2, ..., n-1]
 ×3    - [0, 3, 6, ..., 3n-3]
   ÆḞ  - n'th Fibonacci number for each
     S - Sum

CJam, 15 bytes
1_{_4*@+}qi*;2/

Try it online!
Uses Bubbler's wonderful formula.


text:
Converting "0xUsernames"
0xUsernames
There's so many people using a messaging service that they're running out of space to store all the usernames! To fix this, they are going to start storing usernames as hexadecimal, where possible.
If a username consists of only the characters 0123456789ABCDEF (case  insensitive), it can be converted to a hexadecimal and stored as an integer. For example, the username ba5eba11 can be interpreted as 0xBA5EBA11, a hexadecimal integer.
But what about 05AB1E? That's got a leading zero, which would be lost. So, whenever we convert a username, we make sure to prepend a 1 before reading it as an integer.

The Challenge
Your task is to write a program or function which, given a non-empty username as a string, 'hexa-compresses' the username:

If it can be interpreted as a hexadecimal integer, prepend a 1, interpret as hexadecimal, and then print the result as base 10.
Otherwise, just return the string unmodified.

This is code-golf, so the shortest solution (in bytes) wins! Built-in base conversion functions are permitted.

Test Cases
You can assume that any resulting integers with be within your language's standard integer range.
As with usernames on most messaging systems, the input strings will only contain alphanumerics and underscores.
Remember, you always need to add a leading 1 before conversion!
"ba5eba11" -> 7421737489
"05AB1E"   -> 17148702
"dec0de"   -> 31375582
"Beef"     -> 114415
"da7aba5e" -> 7960443486
"500"      -> 5376

"DENNIS" -> "DENNIS"
"Garth"  -> "Garth"
"A_B_C"  -> "A_B_C"
"0x000"  -> "0x000"

For reference, here is a Python 3 implementation I used for the test cases (ungolfed):
import re

def convert_name(name):
    if re.fullmatch('^[0-9A-Fa-f]+$', name):
        return int('1' + name.upper(), base = 16)
    else:
        return name

Ah, didn't see that. Also, what if some of the larger test cases result in numbers outside the bounds of our language's largest integer type?

@Doorknob good catch. I'll say that a resulting integer will never be more than your language's standard integer type. (please don't abuse this and use a language with 1-bit integers)

Is it ok to assume the input is uppercase only?

@Adám sorry, but your program should be case insensitive (see test cases)

Like Unary except it's encoding usernames instead of BF

05AB1E, 4 bytes
D1ìH

Explanation
D    Duplicate input
 1ì  Prepend 1
   H Interpret as hexadecimal and implicitly display the value in base 10

If the input has invalid hex characters, H won't push anything so the last value on the stack will be the duplicated input, that's why the program prints its input in case of invalid input.
Try it online!

The irony is pretty strong here. 05AB1E is a valid username.

That's right, however the name was chosen as a hexadecimal number. Hence it's valid :)

Wondered why you were duping. Trying to think of a way to use $ instead though....

This is invalid: DENNIS outputs 1DENNIS, not DENNIS.

This answer is five years old. TIO's 05AB1E legacy is based on a commit from July 2018. Well, It appears that this answer is even more legacy ;) .

JavaScript (ES6), 15 bytes
s=>'0x1'+s-0||s

How it works
'0x1'+s converts the input into a literal hexadecimal string with a prepended 1, e.g. 0x105ab1e. Then -0 casts the result to a number. JavaScript sees the 0x at the beginning and implicitly tries to convert from hexadecimal; if s contains any non-hexadecimal chars, this returns NaN. Since this is falsy (and output 0 can never be given because of the prepended 1), we can use ||s to return s if the hex conversion failed.
Test snippet

f = s=>'0x1'+s-0||s

for(i of [
  "ba5eba11", "05AB1E", "dec0de", "Beef", "da7aba5e", "500",
  "DENNIS", "Garth", "A_B_C", "0x000"
]) console.log(i + ":", f(i));

Very nice solution!

Implicit casting is truly beautiful... :')

Python 2, 44 bytes
Takes input as a quoted string. -2 bytes thanks to Rod!
a=input()
try:exec'a=0x1'+a
except:1
print a

As we're guaranteed that the input will only contain alphanumerics and underscores, there's no way to create valid Python after 0x1 other than having a hex string. If the input is anything else, the error is ignored, and printing as it originally was.
I couldn't seem to make a regex match any shorter than try/except. In fact, regex turned out to be terribly verbose:
import re
lambda n:re.match('^[0-9A-F]+$',n,2)and int('1'+n,16)or n

you can also replace a=int('1'+a,16) with exec'a=0x1'+a (probably, need to test)

You know, we are going to have to same exact answer if I continue golfing right?

Doesn't work for usernames that would be valid Python in that context, e.g. "+input()".

fails for "abc " (notice the whitespace at the end)(int allows whitespace at beginning and end)

I don't know exactly how it is for Python 2, but I think you can remove the brackets () at input()

@RudolfLJelinek no, that would assign a to the input function. The function has to be called to take input from the user.

Perl 6, 19 bytes
{:16(1~S/_/Z/)//$_}

Test it
Expanded:
{   # bare block lambda with implicit parameter ｢$_｣

    :16(     # convert from base 16
      1
      ~      # Str concatenated
      S/_/Z/ # replace an underscore with an invalid base 16 character
    )

  //         # defined or

    $_       # the input unchanged

}

Perl, 27 bytes
-1 byte thanks to @ardnew.
26 bytes of code + -p flag.
$_=hex"1$_"if!/[^0-9a-f]/i

Supply the input without final newline. With echo -n for instance:
echo -n 05AB1E | perl -pe '$_=hex"1$_"if!/[^0-9a-f]/i'

Explanation
This is pretty straight forward: /[^0-9a-f]/i is true if the input contains a character other than those allowed inside hexadecimal numbers. If it's false, $_ (which contains the input) it is set to the converted value (the conversion is done by the builtin hex).
And $_ is implicitly printed thanks to -p flag.

you can shave a byte by avoiding the ternary operation $_=hex"1$_"if!/[^0-9a-f]/i

@ardnew Hum, now that you say it, that ternary was pretty awful... Anyway, thanks!

Pyth - 9 bytes
.xi+1z16z

Same idea as fliptack's answer. Try hexadecimal-decimal conversion else output the input.
Try it here!

Common Lisp, 71
(lambda(n)(or(ignore-errors(parse-integer(format()"1~A"n):radix 16))n))

Tests
Define function
CL-USER> (lambda(n)(or(ignore-errors(parse-integer(format()"1~A"n):radix 16))n))
#<FUNCTION (LAMBDA (N)) {10041D213B}>

Quote a list of expected inputs, as given by the question:
CL-USER> '("ba5eba11" -> 7421737489
"05AB1E"   -> 17148702
"dec0de"   -> 31375582
"Beef"     -> 114415
"da7aba5e" -> 7960443486
"500"      -> 5376

"DENNIS" -> "DENNIS"
"Garth"  -> "Garth"
"A_B_C"  -> "A_B_C"
"0x000"  -> "0x000")
("ba5eba11" -> 7421737489 "05AB1E" -> 17148702 "dec0de" -> 31375582 "Beef" ->
 114415 "da7aba5e" -> 7960443486 "500" -> 5376 "DENNIS" -> "DENNIS" "Garth" ->
 "Garth" "A_B_C" -> "A_B_C" "0x000" -> "0x000")

Parse it and collect results
CL-USER> (loop for (in _ out) on * by #'cdddr
               collect (list in out (funcall ** in)))
(("ba5eba11" 7421737489 7421737489) ("05AB1E" 17148702 17148702)
 ("dec0de" 31375582 31375582) ("Beef" 114415 114415)
 ("da7aba5e" 7960443486 7960443486) ("500" 5376 5376)
 ("DENNIS" "DENNIS" "DENNIS") ("Garth" "Garth" "Garth")
 ("A_B_C" "A_B_C" "A_B_C") ("0x000" "0x000" "0x000"))

Check that the expected outputs match the actual ones:
CL-USER> (every (lambda (x) (equalp (second x) (third x))) *)
T

Batch, 33 bytes
@(cmd/cset/a0x1%1 2>nul)||echo %1

How it works
A string is passed in as an argument, 1 is prepended to it, and the string is implicitly converted to decimal and printed. If the string is not valid hexadecimal, it is simply displayed.
It should be noted that since batch math uses signed 32-bit integers, the biggest allowed username is FFFFFFF.
cmd /c takes the next command, runs it in a new terminal, and exits.
set /a performs math and implicitly displays the result in decimal when not stored to a variable.
0x1%1 tells set to prepend a 1 to the first argument (this is easy since all batch variables are strings) and indicates that the string should be treated as hexadecimal.
2>nul silences any errors resulting from an invalid hexadecimal number
|| is a logical OR and performs the command on the right if the command on the left is not successful. The parentheses make everything up to this point one command.
echo %1 simply displays the first argument.

Python 2 - 63, 52, 50, 46 Bytes
n=input()
try:n=int("1"+n,16)
except:1
print n

This uses Python's int() which converts any string with its appropriate base into base 10. In this case, the string is the number 1 attached to the input. If the input is invalid (has characters other than 0123456789ABCDEF (case-insensitive), it returns ValueError:
n = input()                   # Get input (with quotes)
try:                          # Trying conversion to base 10
    n = int("1"+n,16)
except:                       # If invalid string for base 36,
    1                         # do nothing to n
print n                       # Print result

Try it here!
Thanks to @FlipTack for saving 15 bytes!

What if the string doesn't start with a zero? You should only be adding a one to the left of the string if it starts with a zero.

@FlipTack Whoops, silly me.

C, 108 bytes
i;f(char*s){char*S=malloc(strlen(s)+2);*S=49;strcpy(S+1,s);sscanf(S,"%x%c",&i,&i)<2?printf("%d",i):puts(s);}

This is a function that takes the string as an argument and prints the result to STDOUT.
i;                           // declare i as an int
f(char*s){
char*S=malloc(strlen(s)+2);  // allocate space for a new string with 1 more char
*S=49;                       // set the first char to '1' (ASCII 49)
strcpy(S+1,s);               // copy the original string to the remainder
sscanf(S,"%x%c",&i,&i)       // scan a hex integer followed by any char
<2?                          // if less than 2 items were scanned (i.e. the hex
                             // integer made up the entire string),
printf("%d",i)               // output the hex integer
:puts(s);}                   // otherwise, output the original string

Nice use of implicit int :)

100 bytes

JavaScript: 46 41 bytes
s=>/[^\dA-F]/i.test(s)?s:parseInt(1+s,16)

The regex can be 2 bytes shorter:
/[^0-9a-f]/i

I saved 1 byte by replacing 0-9 by \d, 3 bytes by adding the case-insensitive flag (thanks @GilZ) and 2 more bytes by removing F=, which isn't needed. Thanks for the suggestion.

PHP, 42 bytes
hex2bin() returns false if the input is not a valid hex string. This is shorter than using regex to look for non hex digits, but we need the @ operator because it's not silent when it fails.
<?=@hex2bin($s=$argv[1])?hexdec("1$s"):$s;

hex2bin fails for strings with uneven lengths. Still two bytes shorter than with preg_match though: <?=@hex2bin($s=$argv[1])|@hex2bin($s.a)?hexdec("1$s"):$s; for 57 bytes.

bash, 46 35 31 bytes
(echo $[0x1$1])2> >(:)||echo $1

Save as a script, and pass the username as an argument.

Dyalog APL, 37 bytes
Uses no built-in validation or hex-dec conversion. Requires ⎕IO←0 which is default on many systems.
{∧/(u←1(819⌶)⍵)∊d←⎕D,6↑⎕A:16⊥1,d⍳u⋄⍵}

Ungolfed:
{
    d ← ⎕D , 6 ↑ ⎕A
    u←1 (819⌶) ⍵
    ∧/ u ∊ d: 16 ⊥ 1 , d ⍳ u
    ⍵
}

d ← ⎕D , 6 ↑ ⎕A d gets Digits followed by the first 6 elements of the Alphabet
u ← 1 (819⌶) ⍵ u gets uppercased (819 ≈ "Big") argument
∧/ u ∊ d: if all elements of u are members of d, then:
 16 ⊥ 1 , d ⍳ u find the indices of u in d, prepend a 1, and evaluate as base 16
⍵ else: return the (unmodified) argument
TryAPL online:

Set ⎕IO to zero, define a replacement for ⌶ (forbidden on TryAPL for security reasons), and set ⎕PP (Print Precision) to 10 for the large results

Try all the test cases

Ruby, 47 44 bytes
p gets=~/^[a-f\d]+\s$/i?('1'+$&).to_i(16):$_

I could remove 3 bytes by changing puts for p, but I feel like the output would be considered wrong since it has a newline at the end.
Edit: Changed puts for p as trailing newlines are typically accepted, thanks @Mego.

Trailing newlines on STDOUT are typically considered acceptable.

REXX, 49 48 bytes
signal on syntax
pull a
a=x2d(1||a)
syntax:
say a

The signal on syntax tells the interpreter to jump to the label syntax whenever a syntax error occurs. The program tries to reassign a with a hex-to-decimal converted version with a leading 1, but jumps to the syntax label if that fails. If the conversion does pass, it simply ignores the label and outputs the reassigned variable.

Could you explain your code please

Japt, 11 bytes
+`0x1{U}`ªU

Try it Online!
Big thanks to ETHproductions!

This is one of the rare cases where you can get rid of the space :-) (Also, the TIO link is to the "Hello, World!" program)

Vyxal, 8 bytes
k6↔=[1pH

Try it Online!
k6↔      # Remove non-hex chars from input
   =[    # If it equals the original
     1p  # Prepend a 1
       H # Convert from hexadecimal

Whython, 34 bytes
lambda n:eval("_"in n or"0x1"+n)?n
Attempt This Online!
Explanation
The ? operator in Whython returns the value of its left operand, unless the left operand raised an error during execution, in which case it returns the value of its right operand. So in theory, all we have to put on the left is eval("0x1" + n): prepend a 1 and evaluate as a hexadecimal literal.
In practice, since Whython is based on Python 3, we run afoul of the Python 3 feature that underscores can be used as separators in numeric literals. Thus, an input like A_B_C does not error, but is treated as if it were ABC. That's not what we want. We need to make inputs with underscores cause errors too. Thus, we pass the following to eval:
"_" in n or "0x1" + n

If n contains any underscores, "_" in n is True, the or short-circuits, and we're left with eval(True), which errors because eval expects a string. If there are no underscores, "_" in n is False, and we go on to eval the hex-literal string as usual.

PowerShell, 35 bytes
param($v)(($h="0x1$v"|iex),$v)[!$h]

Try it online! or Run all test cases!
Explanation

Take parameter ($v)
Create a two-element array where the first element (0) is the result of a string containing 0x1$v piped into Invoke-Expression (iex), while simultaneously assigning this value to $h. If the conversion fails, $h will remain $null.
The second element of the array is the original parameter.
Index into the array with the boolean -not value of $h. Whatever $h is will be implicitly converted to [bool] ($null in the case of an invalid conversion will become $false, a positive integer in the case of successful conversion will become $true) before being negated, which is then implicitly converted to [int] by the array indexer [] ($true will be 1, $false will be 0), thus resulting in the first element of the array (the conversion result) chosen if the conversion was successful, and the second element chosen if the conversion was unsuccessful.

Scala, 40 bytes
s=>try{BigInt("1"+s,16)}catch{case e=>s}

Usage:
val f:(String=>Any)=s=>try{BigInt("1"+s,16)}catch{case e=>s}
f("ba5eba11") //returns 7421737489

Explanation:
s=>                //define a anonymous function with a parameter called s
  try {              //try...
    BigInt("1"+s,16)   //to contruct a BigInt from "1" prepended to the number, parsing it as base 16
  } catch {          //if the constructor throws an exception
    case e =>          //in case of an execption which we'll call e
      s                  //return s
  }

C#, 58 bytes
u=>{try{u=Convert.ToInt64("1"+u,16)+"";}catch{}return u;};

Ungolfed with test cases:
using System;
class Class
{
    public static void Main()
    {
        Func<string, string> convert =
            u=>
            {
                try
                {
                    u = Convert.ToInt64("1" + u, 16) //Prepends "1" and tries to convert the string to and integer using base 16.
                        + ""; //Appending an empty string converts the integer to a string. Shorter than calling .ToString()
                }
                catch { } //If the conversion fails catch the exception and discard it.
                return u; //Return the result, or the unmodified input if the conversion failed.
            };

        Console.WriteLine(convert("ba5eba11"));
        Console.WriteLine(convert("05AB1E"));
        Console.WriteLine(convert("dec0de"));
        Console.WriteLine(convert("Beef"));
        Console.WriteLine(convert("da7aba5e"));
        Console.WriteLine(convert("500"));
        Console.WriteLine(convert("DENNIS"));
        Console.WriteLine(convert("Garth"));
        Console.WriteLine(convert("A_B_C"));
        Console.WriteLine(convert("0x000"));
        Console.Read();
    }
}

Try online

Dart, 51 bytes
(s)=>int.parse('1$s',radix:16,onError:(_)=>null)??s

Try it here
Most of the overhead comes from named parameters... Oh well!
At least Dart lets you be dynamically typed, if you want to :D

05AB1E, 19 bytes
"0x1ÿ".EDн>ΘI'_å~_×

Try it online!

source: Stack Exchange

license: 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/

sort: votes


text:
Arnold's Cat Map
Challenge
Given a colour raster image* with the same width and height, output the image transformed under Arnold's cat map. (*details see below)
Definition
Given the size of the image N we assume that the coordinates of a pixel are given as numbers between 0 and N-1.
Arnold's cat map is then defined as follows:
A pixel at coordinates [x,y] is moved to [(2*x + y) mod N, (x + y) mod N].
This is nothing but a linear transform on torus: The yellow, violet and green part get mapped back onto the initial square due to the mod N.

This map (let's call it f) has following properties:

It is bijective, that means reversible: It is a linear transformation with the matrix [[2,1],[1,1]]. Since it has determinant 1 and and it has only integer entries, the inverse also has only integer entries and is given by [[1,-1],[-1,2]], this means it is also bijective on integer coordinates.
It is a torsion element of the group of bijective maps of N x N images, that means if you apply it sufficiently many times, you will get the original image back: f(f(...f(x)...)) = x The amount of times the map applied to itself results in the identity is guaranteed to be less or equal to 3*N. In the following you can see the image of a cat after a given number of iterated applications of Arnold's cat map, and an animation of what a repeated application looks like:

Details

Your program does not necessarily have to deal with images, but 2D-arrays/matrices, strings or similar 2D-structures are acceptable too.
It does not matter whether your (0,0) point is on the bottom left or on the top left. (Or in any other corner, if this is more convenient in your language.) Please specify what convention you use in your submission.

Testcases
In matrix form ([1,2,3,4] is the top row, 1 has index (0,0), 2 has index (1,0), 5 has index (0,1))
 1     2     3     4
 5     6     7     8
 9    10    11    12
13    14    15    16

maps to:

 1    14    11     8
12     5     2    15
 3    16     9     6
10     7     4    13

 --------------------

 1     2     3
 4     5     6
 7     8     9

 map to:

 1     8     6
 9     4     2
 5     3     7

As image (bottom left is (0,0)):

Poor Lena. I hope you kept iterating long enough

Can we take the image size as input?  Is it always square?

Yes the image is always square, and I'm not sure about the size, is there anything against allowing that?

Jelly, 9 bytes
Zṙ"JC$µ2¡

Try it online! The coordinates are as in the answer.
Explanation
      µ2¡   Twice:
Z             Transpose, then
 ṙ"           Rotate rows left by
   JC$          0, -1, -2, -3, …, 1-n units.

This wrap-shears the matrix in one direction, then the other.

Fantastic algorithm!

MATL, 23 bytes
tt&n:qt&+&y\tb+&y\b*+Q(

The (0,0) point is upper left, as in the examples in the challenge text.
Try it online!
Explanation
A matrix in MATL can be indexed with a single index instead of two. This is called linear indexing, and uses column-major order. This is illustrated by the following 4×4 matrix, in which the value at each entry coincides with its linear index:
1   5   9  13
2   6  10  14
3   7  11  15
4   8  12  16

There are two similar approaches to implement the mapping in the challenge:

Build an indexing matrix that represents Arnold's inverse mapping on linear indices, and use it to select the values from the original matrix. For the 4×4 case, the indexing matrix would be
 1  8 11 14
15  2  5 12
 9 16  3  6
 7 10 13  4

telling that for example the original 5 at x=2, y=1 goes to x=3, y=2. This operation is called reference indexing: use the indexing matrix to tell which element to pick from the original matrix. This is functon ), which takes two inputs (in its default configuration).
Build an indexing matrix that represents Arnold's direct mapping on linear indices, and use it to write the values into the original matrix. For the 4×4 case, the indexing matrix would be
 1 10  3 12
 6 15  8 13
11  4  9  2
16  5 14  7

telling that the entry x=2, y=1 of the new matrix will be overwritten onto the entry with linear index 10, that is, x=3, y=2. This is called assignment indexing: use the indexing matrix, a data matrix and the original matrix, and write the data onto the original matrix at the specified indices. This is function (, which takes three inputs (in its default configuration).

Method 1 is more straightforward, but method 2 turned out to be shorter.
tt     % Take the input implicitly and push two more copies
&n     % Get its size as two (equal) numbers: N, N
:qt    % Push range [0  1 ... N-1] twice. This represents the original x values
&+     % Matrix of all pairwise additions. This represents x+y
&y     % Push a copy of N onto the top of the stack
\      % Modulo. This is the new y coordinate: y_new
t      % Push another copy
b+     % Bubble up the remaining copy of [0 1 ... N-1] and add. This is 2*x+y
&y     % Push a copy of N onto the top of the stack
\      % Modulo. This is the new x coordinate: x_new
b*+    % Bubble up the remaining copy of N, multiply, add. This computes
       % x_new*N+y_new, which is the linear index for those x_new, y_new
Q      % Add 1, because MATL uses 1-based indexing
(      % Assigmnent indexing: write the values of the original matrix into
       % (another copy of) the original matrix at the entries given by the
       % indexing matrix. Implicitly display the result

Mathematica, 44 bytes
(n=MapIndexed[RotateLeft[#,1-#2]&,#]&)@*n

A port of Lynn's fantastic algorithm. There's an invisible 3-byte character, U+F3C7 in the UTF-8 encoding, before the last ]; Mathematica renders it as a superscript T, and it takes the transpose of a matrix.
Mathematica, 54 bytes
Table[#2[[Mod[2x-y-1,#]+1,Mod[y-x,#]+1]],{x,#},{y,#}]&

Unnamed function taking two arguments, a positive integer # and a 2D array #2 of dimensions #x#, and returning a 2D array of similar shape. As in the given test case, the point with coordinates {0,0} is in the upper left and the x-axis is horizontal. Straightforward implementation using the inverse [[1,-1],[-1,2]] mentioned in the question, with a -1 in the first coordinate to account for the fact that arrays are inherently 1-indexed in Mathematica. If we're not allowed to take the dimension of the matrix as an additional argument, then this solution becomes nine bytes longer (replace the first #—not the #2—with a=Length@# and all the subsequent #s with as).

Dang, beat me to it

Python 2, 89 82 77 73 bytes
def f(a):exec'a=[l[-i:]+l[:-i]for i,l in enumerate(zip(*a))];'*2;return a

Input is a list of lists
The string inside the exec transpose the list of lists and cyclically rotate each list by the line index (0 based - 3rd line is rotated 2 times to the right).
This process is done 2 times to the input.
+4 bytes that will do the transformation N times
def f(a,n):exec'a=[l[-i:]+l[:-i]for i,l in enumerate(zip(*a))];'*2*n;return a

Haskell, 55 bytes
m#n|r<-[0..n-1]=[[m!!mod(2*y-x)n!!mod(x-y)n|x<-r]|y<-r]

Usage example: [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]] # 4 -> [[1,14,11,8],[12,5,2,15],[3,16,9,6],[10,7,4,13]].
0,0 is the upper left corner. This uses the inverse transformation.

ImageJ macro, 29 bytes
v=getPixel((x+y)%w,(2*y+x)%h)

Open image of Lena
From Process menu select Math / Macro...

Doesn't this perform f^(-1)? It gets the pixel value at the coordinates it is suppossed to move it to. You probably mean v=getPixel((2*y-x)%w,(x-y)%h).

@RobinKoch Thanks, 2*x+y changed to 2*y+x

That's neither what I wrote nor what I meant. You need the inverse transformation for your approach. For f(x,y) = (2x+y, x+y) this inverse transformation is described by f^(-1) = (x-y, 2y-x). (My other comment was wrong.) So your code shold be v=getPixel((x-y)%w,(2*y-x)%h).

I tested my formula and the result is the same as Lena image in the question

@RobinKoch You can download ImageJ and test both formula

I see. I assumed you use the top left corner as origin as ImageJ does. But apparently you use the bottom left corner as the example does.

Python, 69 bytes
lambda M:eval("[r[-i:]+r[:-i]for i,r in enumerate(zip(*"*2+"M))]))]")

An improvement on Rod's transpose-and-shift-twice method. Applies the operation M -> [r[-i:]+r[:-i]for i,r in enumerate(zip(*M))] twice by creating and evaluating the string
[r[-i:]+r[:-i]for i,r in enumerate(zip(*[r[-i:]+r[:-i]for i,r in enumerate(zip(*M))]))]

This narrowly beats out a direct transformation (70 bytes), assuming the image is square and its length can be taken as input:
lambda M,n:[[M[(2*j-i)%n][(i-j)%n]for i in range(n)]for j in range(n)]

Java, 160
Golfed:
int[][]f(int[][]m){int x=0,y,l=m.length,r[][]=new int[l][];for(;x<l;++x)r[x]=new int[l];for(x=0;x<l;++x)for(y=0;y<l;++y)r[(x+y)%l][(2*x+y)%l]=m[y][x];return r;}

Ungolfed:
  int[][] f(int[][] m) {
    int x = 0, y, l = m.length, r[][] = new int[l][];
    for (; x < l; ++x) {
      r[x] = new int[l];
    }
    for (x = 0; x < l; ++x) {
      for (y = 0; y < l; ++y) {
        r[(x + y) % l][(2 * x + y) % l] = m[y][x];
      }
    }
    return r;
  }

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


text:
Compute the Wilson score interval
The Wilson score interval is a confidence interval of the probability of success, based on the proportion of successes in a set of Bernoulli trials (a Bernoulli trial is a trial in which exactly two outcomes are possible: success or failure). The interval is given by the following formula:

The two values given by the formula are the upper and lower bounds of the interval. nS and nF are the number of successes and failures, respectively, and n is the total number of trials (equivalent to nS + nF). z is a parameter dependent on the level of confidence desired. For the purposes of this challenge, z = 1.96 will be used (corresponding to a 95% confidence interval)1.
Given non-negative integers nS and nF, output the bounds of the Wilson score interval.
Rules

The outputs must be as accurate as possible to the true values, within the limits of your language's floating-point implementation, ignoring any potential issues due to floating-point arithmetic inaccuracies. If your language is capable of arbitrary-precision arithmetic, it must be at least as precise as IEEE 754 double-precision arithmetic.
The inputs will be within the representable range for your language's native integer type, and the outputs will be within the representable range for your language's native floating-point type.
n will always be positive.
The order of the outputs does not matter.

Test Cases
Format: n_s, n_f => lower, upper
0, 1 => 0.0, 0.7934567085261071
1, 0 => 0.20654329147389294, 1.0
1, 1 => 0.09452865480086611, 0.905471345199134
1, 10 => 0.016231752262825982, 0.3773646254862038
10, 1 => 0.6226353745137962, 0.9837682477371741
10, 90 => 0.05522854161313612, 0.1743673043676654
90, 10 => 0.8256326956323345, 0.9447714583868639
25, 75 => 0.17545094003724265, 0.3430464637007583
75, 25 => 0.6569535362992417, 0.8245490599627573
50, 50 => 0.40382982859014716, 0.5961701714098528
0, 100 => 0.0, 0.03699480747600191
100, 0 => 0.9630051925239981, 1.0

The z value is the 1-α/2th quantile of the standard normal distribution, where α is the significance level. If you want a 95% confidence interval, your significance level is α=0.05, and the z value is 1.96.

Related: Fastest Gun in the West Problem. I was going to make it a challenge, but I guess you beat me to it. :/

Mathematica, 48 bytes (UTF-8 encoding)
({-1,1}√((s=1.4^4)##/+##+s^2/4)+#+s/2)/(s+##)&

Unnamed function taking two arguments in the order n_s, n_f and returning an ordered pair of real numbers. The three-byte symbol √, representing the square-root function, is U-221A.
Uses the fact that preceding ## by a number results in the product of the two arguments, while +## results in their sum. Also uses the fact that products and sums automatically thread over lists, so that {-1,1}√(...) implements the ± in the formula. Defining the constant s = z^2 instead of z itself also saved a couple of bytes. (Mostly I'm just proud of saving a byte by noticing that 1.4^4 is exactly 1.96^2!)

Can Mathematica use arbitrary encodings? The square root symbol is 1 byte in a lot of single-byte encodings.

It can indeed use many encodings—for example, Mac OS Roman, which has the property you mention. My understanding, though, is that I would need to include the bytes necessary to switch to a non-default encoding, which in this case is more than the 2 "wasted" bytes.

Oh, it requires a command line switch (or some function call)? Gross.

Mathematica is a wonderful juxtaposition of awesome and gross :D

Perl 6, 66 bytes
->\s,\f,\z=1.96 {(s+(-z|z)*sqrt(s*f/(s+f)+z*z/4)+z*z/2)/(s+f+z*z)}

This function actually returns an or-junction of the lower and upper bounds; for example, if called with the arguments 100 and 0, it returns:
any(0.963005192523998, 1)

It's a non-traditional output format to say the least, but no particular format was specified, and both of the required values are present.

This seems fine to me. The lack of a specific output format was intentional - requiring a specific format for output gives advantages to some languages, and unnecessarily complicates the challenge. As long as both output values are present in some usable form, it's acceptable.

05AB1E, 34 bytes
"1.96"Dn©4/¹P¹O/+t*D()®;+¹0è+®¹O+/

Input is of the form [n_s, n_f]

Output is of the form [upper, lower]
Try it online!
Explanation
"1.96"                             # push 1.96
      Dn©                          # duplicate, square, store a copy in register
         4/                        # divide by 4
           ¹P¹O/                   # product of input divided by sum of input
                +                  # add this to (z^2)/4
                 t*                # sqrt and multiply with z
                   D()             # wrap in list together with a negated copy
                      ®;+          # add (z^2)/2
                         ¹0è+      # add n_s
                             ®¹O+/ # divide by z^2+n

R, 58 53 51 49 41 bytes
-15 bytes thanks to J.Doe. -2 bytes thanks to Giuseppe.
function(x,y)prop.test(t(c(x,y)),cor=F)$c

I like it when R is competitive with golfing languages...

Runic Enchantments, 105 bytes
#StillBetterThanJava
/:2,:2,i:3s:3s:i:3s*3s+::6s4s,+'qA{*:Z4s3TRr4s{++}\
\p2:,C1Ä'<> yyyyyyyyyyyyyyyyyyy'Ä1C,2p:2,//@S ',+ /

Try it online!
Input is of the form n_s n_f
Output is of the form lower upper and has a trailing space
AH GOD this one's a mess. Here's the unwrapped version:
>'Ä1C,:2p:2,:2,i:3s:3s:i:3s*3s+::6s4s,+'qA{*:Z4s3TRr4s{++}+,' S@
                  > yyyyyyyyyyyyyyyyyyy'Ä1C,2p:2,//

All those ys are to slow down the second IP so that it arrives at the Transfer point at the right time (i.e. second). This shoves the top 3 items of the one pointer over to the other (the setup to this action is depicted below). 'Ä1C, generates z by dividing character 196 by 100 (dup, square, dup, div 2, dup, div 2...). The everything-else is just a bunch of math and stack manipulation to shove future values down the stack until they're needed. For the most part, they end up in the right order and its only until r4s{++} that we have to reverse the stack and rotate the whole thing to get the values we want next to each other next to each other.
There's probably room for improvement, but its complex enough that I can't see it. Heck, had inadvertently read "z" instead of "n" in the original formula at one point and fixing that was rough.
I had to pull out notecards and simulate the stacks in order to make sure it was correct:

Every single one has a value on both ends due to how many variables there were (eg. I'd have one with S and one with F, I'd pop them both, flip one around and add the S+F that was on the other end to the top of the stack). You can see one of the sqrt(...) cards has an S on the lower edge.

MATL, 38 37 bytes
pGs/1.96XJU4/XI+X^J*t_hIE+G1)+GsJU+/S

Input is an array of two numbers, in any of these formats: [25 75], [25, 75], [25; 75].
Try it online! or verify all test cases.

Haskell, 70 69 68 67 bytes
s#f|y<-1.96^2=[(s+y/2+k*sqrt(s*f*y/(s+f)+y^2/4))/(s+f+y)|k<-[-1,1]]

Try it online!

APL (Dyalog Unicode), 50 bytes
{(+/⍺⍵z)÷⍨(⍺+z÷2)(-,+).5*⍨z×(⍺×⍵÷⍺+⍵)+4÷⍨z←3.8416}

Try it online!
Infix Dfn, taking \$⍺←n_s\$ and \$⍵←n_f\$.
Thanks to H.PWiz and dzaima for helping out.
How:
                                        z←3.8416  ⍝ Set z=1.96²
                                     4÷⍨          ⍝ Divide it by 4
                                    +             ⍝ plus
                           (⍺×⍵÷⍺+⍵)             ⍝ (nf×ns)÷n
                         z×                       ⍝ ×z²
                     .5*⍨                         ⍝ to the power .5 (square root)
                (-,+)                             ⍝ ±
         (⍺+z÷2)                                  ⍝ ns+(z²/2)
(+/⍺⍵z)÷⍨                                        ⍝ all divided by nf+ns+z²

40: z←1.9208⋄(z+⊣(-,+).5*⍨z×z+2×⊣×⊢÷+)÷z+z++

@Adám That's neither an expression, nor a complete program, but you could make it an expression by initialising z at its rightmost usage: ...÷z+(z←1.908)++ for the same byte count. Also: ⊣×⊢÷+ -> ×÷+

@ngn Right, but actually, this is allowed by double meta consensus: (1) and (2).

dc, 71 bytes
16k?dsa2*?sb1.96 2^dso+dlalb4**lalb+/lo+vlov*dsd+lalblo++2*dsx/rld-lx/f

Takes both inputs on two separate lines upon invocation, and outputs on two separate lines with the upper bound on the bottom and the lower bound on top.
For example:
bash-4.4$ dc -e '16k?dsa2*?sb1.96 2^dso+dlalb4**lalb+/lo+vlov*dsd+lalblo++2*dsx/rld-lx/f'
10                # Input n_s
90                # Input n_f
.0552285416131361 # Output lower bound
.1743673043676654 # Output upper bound

Python, 79 67 bytes
lambda s,f,z=3.8416:2j**.5*(s-(-z*(f*s/(f+s)+z/4))**.5+z/2)/(f+s+z)

Output is a complex integer with the interval stored as the real/imaginary part.

Racket 134 bytes
(let*((n(+ s f))(z 1.96)(h(* z z))(p(/ 1(+ n h)))(q(+ s(/ h 2)))(r(* z(sqrt(+(/(* s f) n)(/ h 4))))))(values(* p(- q r))(* p(+ q r))))

Ungolfed:
(define (g s f)
  (let* ((n (+ s f))
         (z 1.96)
         (zq (* z z))
         (p (/ 1 (+ n zq)))
         (q (+ s (/ zq 2)))
         (r (* z (sqrt (+ (/(* s f) n) (/ zq 4))))))
    (values (* p (- q r)) (* p (+ q r)))))

Testing:
(g 1 10)

Output:
0.016231752262825982
0.3773646254862038

Java 7, 130 bytes
Golfed:
double[]w(int s,int f){double n=s+f,z=1.96,x=z*z,p=s+x/2,d=z*Math.sqrt(s*f/n+x/4),m=1/(n+x);return new double[]{m*(p-d),m*(p+d)};}

Ungolfed:
double[] w(int s, int f)
{
    double n = s + f, z = 1.96, x = z * z, p = s + x / 2, d = z * Math.sqrt(s * f / n + x / 4), m = 1 / (n + x);
    return new double[]
    { m * (p - d), m * (p + d) };
}

Try it online
Returns an array of type double of length 2, can probably be golfed more.

><> with -v flag, 100 bytes
:{:@:}*@+:@,24a,a,-:@:*:&4,+:\$~*{&:&2,+}:{:@@-{&+:&,nao+&,n;
,}:{::*@@-:0$0(?$-1a,:*:*:*(?\}:{:@,+2

Expects the input to be present on the stack at execution start, in the order n_s, n_f. Try it online!
What a stupid language to attempt this in...
As ><> lacks an exponent or root operator, the square root is calculated in the second line of code using the Babylonian method, to an accuracy of 1e-8 - for every example I've tried, this is accurate to at least 10 decimal places. If this isn't precise enough, the bounds can be tightened by adding more :* in the second line, shuffling things around to keep the mirrors in line.
Output is in the following form:
<lower bound>
<upper bound>

Pyth, 38 bytes
J*K1.96Kmc++dhQcJ2+sQJ_B*K@+cJ4c*FQsQ2

Input is as a list of values, [n_s, n_f]. Output is [upper, lower] Try it online here, or verify all the test cases at once here.
J*K1.96Kmc++dhQcJ2+sQJ_B*K@+cJ4c*FQsQ2   Implicit: Q=eval(input())

  K1.96                                  Set variable K=1.96 (z)
J*K    K                                 Set variable J=K*K (z^2)
                                *FQ      Product of input pair
                               c   sQ    Divide the above by the sum of the input pair
                            cJ4          J / 4
                           +             Add the two previous results
                          @          2   Take the square root of the above
                        *K               Multiply by K
                      _B                 Pair the above with itself, negated
        m                                Map each in the above, as d, using:
             hQ                            First value of input (i.e. n_s)
               cJ2                         J / 2
          ++d                              Sum the above two with d
         c                                 Divided by...
                  +sQJ                     ... (J + sum of input)

Jelly, 30 bytes
×÷++1.96²©HH¤×®½×Ø-+®H¤+³÷++®ɗ

Try it online!
Explanation
                   Inputs: s and f
×÷+                (s×f)÷(s+f)
    1.96²©HH¤      (© ← 1.96²)÷4      (call this W)

   +                         (s×f)÷(s+f)+W
             ×®             ((s×f)÷(s+f)+W)×©
               ½      sqrt[ ((s×f)÷(s+f)+W)×© ]   (call this R)

                ×Ø-            [   -R,      +R  ]
                   +®H¤        [©/2-R,   ©/2+R  ]
                       +³      [©/2-R+s, ©/2+R+s]

                         ÷           Divide both by:
                          ++®ɗ       (s+f)+©

Note
Some of these features are newer than the challenge. I believe around the time this challenge was posted, ++®¶×÷++1.96²©HH¤×®½×-,1+®H¤+³÷ç was valid Jelly (32 bytes), lacking ɗ and Ø-.

APL(NARS), 49 chars, 98 bytes
{k←1.9208⋄(2+n÷k)÷⍨(1+⍺÷k)+¯1 1×√1+2×⍺×⍵÷k×n←⍺+⍵}

test
  f←{k←1.9208⋄(2+n÷k)÷⍨(1+⍺÷k)+¯1 1×√1+2×⍺×⍵÷k×n←⍺+⍵}
  25 f 75
0.17545094 0.3430464637
  0 f 1
0 0.7934567085
  1 f 0
0.2065432915 1


text:
2016 Time Capsule String: How Versatile Is Your Language?
About a year ago on Dec 31, 2015, I had the idea that:

We should make a time capsule string. Everybody gets to add one character and next new years we'll see who can make the best program out of all the characters with the esolangs that exist then.

Doorknob graciously collected characters from the PPCG community and kept them safe for a year.
A whopping 74 people participated so we have a spiffing 74 printable-ASCII characters to play with!
Here are the 74 characters of the 2016 time capsule string in the order they were submitted:
H@~*^)$.`~+1A|Q)p~`\Z!IQ~e:O.~@``#|9@)Tf\eT`=(!``|`~!y!`) Q~$x.4|m4~~&!L{%

Here are the 74 characters of the 2016 time capsule string in ASCII order (note leading space):
 !!!!!#$$%&())))*+...1449:=@@@AHILOQQQTTZ\\^`````````eefmpxy{||||~~~~~~~~~

It's not a whole lot to work with, but round here we like a challenge.
The Challenge
To determine what language is "best" with the time capsule string we'll have 6 (for 2016) challenges that increase in difficulty where in each you must use a subset of the 74 time capsule characters.
Having 6 distinct challenges helps ensure more languages can compete, but only the best languages will be able to answer all of them and score high.
Scoring:

Each challenge will be scored from 0 to 74 depending on how many characters are used.
Higher scores are better.
If your language cannot complete a challenge, your score for that challenge is 0.
Any nonempty subset of the challenges may be completed.
Your final score is the sum of scores from all 6 challenges.
The best final score possible is 6×74 or 444.

The Challenges
1. Run
If a language's code can't run in the first place it won't be able to do anything at all.
Write the longest full program possible (using only the 74 time capsule characters, remember) that runs/executes without compile-time or runtime errors.
It doesn't matter what the program does, it doesn't matter if it has input/output or enters an infinite loop, it only matters that it runs without errors. (Warnings are ok, as are errors caused by bad user input.)
Comments are allowed, so this could be as simple as
#H@~*^)$.`~+1A|Q)p~`\Z!IQ~e:O.~@``|9@)Tf\eT`=(!``|`~!y!`) Q~$x.4|m4~~&!L{%

in Python for a score of 74.
(Don't be afraid to answer if this is the only challenge your language can complete, but don't expect lots of votes either.)
Score = program length (longer program is better)
2. I/O
A language that has no form of input or output is almost as useless as one that can't run.
Given a printable ASCII character from ! (0x33) to } (0x7D) inclusive, output the printable ASCII character before and after it.
The output can be a length two string or list, or the characters separated by a space or newline.
For example if the input is } the output might be |~ or ["|", "~"] or | ~ or |\n~.
Likewise,  " is the output for ! and AC is the output for B.
Score = 74 - program length (shorter program is better)
3. Branchability
Conditionals are often a requirement for Turing completeness, which is often a requirement for a language being useful.
Given a positive integer, if it ends in the decimal digits 16 then change the 6 to a 7 and output the result; otherwise, output the input unchanged. You may use strings for input/output if preferred.
Examples:
2016 -> 2017
16 -> 17
116 -> 117
1616 -> 1617
6 -> 6
15 -> 15
17 -> 17
106 -> 106
2106 -> 2106

Score = 74 - program length (shorter program is better)
4. Loopability
A language that can't do loops will spawn repetitive code so tedious you'll need to take a programming break for a while.
Given a positive integer, output an ASCII-art square of that side length filled with a pattern of concentric smaller squares that alternates between any two distinct printable ASCII characters. They don't have to be the same two characters for different inputs.
For example:
1    <- input
X    <- output

2
XX
XX

3
XXX
X-X
XXX

4
XXXX
X--X
X--X
XXXX

5
YYYYY
Y...Y
Y.Y.Y
Y...Y
YYYYY

6
XXXXXX
X----X
X-XX-X
X-XX-X
X----X
XXXXXX

7
ZZZZZZZ
Z-----Z
Z-ZZZ-Z
Z-Z-Z-Z
Z-ZZZ-Z
Z-----Z
ZZZZZZZ

Score = 74 - program length (shorter program is better)
5. Math
A language that's not good with numbers and math may as well be for humanities majors.
Take no input but output the 72 integer divisors of 2016, positive and negative, in any order. The output can be formatted as a string or list in a reasonable way.
Example:
-1, -2, -3, -4, -6, -7, -8, -9, -12, -14, -16, -18, -21, -24, -28, -32, -36, -42, -48, -56, -63, -72, -84, -96, -112, -126, -144, -168, -224, -252, -288, -336, -504, -672, -1008, -2016, 1, 2, 3, 4, 6, 7, 8, 9, 12, 14, 16, 18, 21, 24, 28, 32, 36, 42, 48, 56, 63, 72, 84, 96, 112, 126, 144, 168, 224, 252, 288, 336, 504, 672, 1008, 2016

Score = 74 - program length (shorter program is better)
6. Esotericism
(No, not that.) We at PPCG like our esoteric stuff, and quines are a good example of that.
Write the longest quine you can, according to usual quine rules. A quine is a program that takes no input and outputs itself.
Score = program length (longer program is better)
Specific Rules

In each of the 6 challenges your program must be a subset of the 74 time capsule characters rearranged any way you like. It may be an empty subset or an improper subset, so each of your programs could have as few as 0 and as many as 74 characters.
A single trailing newline at the end of input/output/code is alright anywhere since some languages require this or it cannot be easily avoided.
Unless otherwise specified, each challenge may be completed as a function or full program according to our defaults.
All challenges must be completed in the same language.
You must use a language (or version of a language) made before it was 2017 anywhere on Earth.
Anyone is welcome to answer, whether you added a character to the time capsule or not.

Feel free to use the 2016 time capsule characters in your own challenges.

Yay :D a challenge where JavaScript can potentially excel!

Discussion chat room for collaborating on some solutions.

fairly sure that 6×74 or 444 is not possible, as that would mean empty programs, which somehow behave differently. hence, 442 is the actual minimum, as that means that two of the 3 input taking programs have a char in them

Is it OK if the characters for question 2 are output as their character codes? (I discovered an interpreter bug in the 7 interpreter that's causing character output to not work, but I can output integers just fine.)

For the second challenge, do they have to be in order?

@ais523 No, output the chars themselves.

@FlipTack Yes. The lower one should come first.

@HelkaHomba: OK, then, seems that PPCG's policy on interpreter bugs means it's not worth me trying to compete on this.

My language is Java. I lose by default :P

Suppose the task is to raise a number to the 4th power. Can I do the following? Write a script Q^4 in the file T. In the command window you write Q=3;T. This will write 81 to STDOUT. The input is to STDIN (allowed by default), but it's given before calling the script.

Is using Minecraft command blocks allowed? 'cause Minecraft gets to score 74 :)

@RudolfL.Jelínek I guess but you may have to stretch rules with byte counting. You can answer but since it might be kinda contrived I may not consider it when selecting a winner.

Let's do this again!

For challenge 1, is requiring user input allowed? As in a script that only works for certain types of user input.

@isaacg Yes that's OK.

@HelkaHomba Minecaft, as I said, could get to score 74 by me H@~*^)$.\~+1A|Q)p~`\Z!IQ~:O.~@``#|9@)Tf\eT`=(!``|`~!y!`)Q~$x.4|4~~&!L{%(note the space afterme), when run either in chat, or in a command block. The problem is, in chat it uses an extra /` and with a command block it uses the block :) How would/could one count the score with this? Is it possible (allowed) to ignore the command block and just paste the code?

damn, i just need one more Q...
Next episode : count number of supplementary characters needed to implement a challenge (0 if no other characters than those in time capsule string). Lowest number of supplementary characters win.

@ev3commander: Are we collecting chars for next year?

@joshua: I don't know..

In other other code-golf challenges on this site, I've seen people submit Perl answers meant to be run like perl -pe "ANSWER HERE", where the p switch provides automatic input & output. They then count the p as +1 bytes, but consider the perl -e "" to be free. Is this allowed here, if the letter p is taken from the 74 characters? (I see no other way to get I/O, and thus attempt challenges 2-6, with Perl or Perl 6.)

Are we allowed to interpret the ASCII characters as bytes?
for example, =e would be 3D 65, which is SE vD,65 in Chip-8.
If not, are there any other options? Using assembly wouldn't be fair since it's not standardized.

Glypho, 74 + (74 - 36) = 112
1. Run (74 bytes)
!!#%QTQT@=A@$!!$)()*!&))+...1449:@HILOQZ\\^`````````eefmpx|||{~~~~~~y~|~ ~

2. IO (36 bytes)
!!!#!$!$4419TAHT\ee\OQQQ))*+)..)|~~~

Explanation
Glypho seemed like a fairly good choice for this challenge, because it doesn't care about the actual characters being used. Instead, it looks at groups of four characters and chooses the command based on the pattern of repetition in those four characters. Since there are a lot of duplicates among the time capsule string, we're fairly flexible in the programs we can write, except that we're limited to programs of 18 commands (which isn't a whole lot in Glypho). While this allowed me to solve the first two problems quite easily, I doubt that Glypho can run the others with so few characters.
I've tested these using the Java interpreter retrieved from 2006-06-23 on the wayback machine, which uses a slightly different mapping of the commands:
0000 n
0001 i
0010 >
0011 \
0012 1
0100 <
0101 d
0102 [
0110 +
0111 o
0112 *
0120 -
0121 ]
0122 !
0123 e

The Run program translates to:
1d-+[...]

Where ... is some junk that I didn't bother translating.
1      Push 1.
d      Duplicate.
-      Turn into -1.
+      Add. Gives 0.
[...]  Skip the rest because the top of the stack is zero.

The IO program translates to:
id1-+o1+o

Here is what this does:
i   Read a character.
d   Duplicate.
1   Push 1.
-   Turn into -1.
+   Add to character, i.e. decrement it.
o   Output it.
1   Push another 1.
+   Add to character, i.e. increment it.
o   Output it.

CJam, 74 + (74 − 14) + (74 − 26) = 182 score
1. Run (74 bytes)
e# !!!!!$$%&())))*+...1449:=@@@AHILOQQQTTZ\\^`````````efmpxy{||||~~~~~~~~~

Moving e# to the front comments out the entire line.
2. I/O (14 bytes)
9`)ZH*+~):Q(Q)

Dennis saved 8 bytes.
Explanation:
9`                   Push "9".
  )                  Extract character '9'.
   ZH*               Push 3 * 17 = 51.
      +              Add to get character 'l'.
       ~             Eval as CJam code. Command l reads a line.
        )            Extract the only character from the input line
         :Q(         Assign to Q and decrement
            Q)       Push Q and increment

3. Branchability (26 bytes)
4`)4Z|`I!`|~^~~T$AT$*%H(=+

Explanation:
4`)                            Push character '4'
   4Z|`                        Push 4 | 3 = 7, stringify
       I!`                     Push !18 = 0, stringify
          |~                   Setwise or and eval to get 70
            ^                  XOR to get 'r'
             ~                 Eval to read input
              ~                Eval the input as CJam code to turn
                               it into an integer
               T$              Duplicate it
                 A             Push 10
                  T$*          Duplicate that and multiply → 100
                     %         Mod the copy by 100
                      H(=      Compare to 17 - 1 = 16
                         +     Add the result (1 or 0) to the original

I’ll look at the others later. (EDIT: I doubt they’re possible, without block or string literals… maybe the math one?)

For #2, you can use 9`)ZH*+~):Q(Q).

J, score 71 + (74 - 19) = 126
Task 1, length 71
AHILO=:( |T`T`Z`e`e`f`m`p`x`y|.~~%~@{|~^|Q@Q@Q+.*.449!~!~!~!!#$$&1\\~~)

This defines a verb AHILO to be the inside. Unused:
)))

I don't think there's any way to get longer than this.
Task 3, length 19
+($#~$~4)=1e4|&%:*~

The way to do this task with no restrictions is +16=100|], which reads as follows:
        ]  Input
    100|   mod 100
 16=       equals 16? (Evaluates to 1 or 0)
+          Add to input.

We have +, = and several copies or | in our disposal, and it's easy to get around ], but the numbers are more problematic.
Here's the first part that computes input modulo 100:
1e4|&%:*~
       *~  Input squared (multiplied with itself).
1e4        The number 10000.
   |       Perform modulo
    &      on
     %:    their square roots.

After we're done with that, let's produce the number 16.
The easy way is with *~4 (4 multiplied with itself), but we already used * so that's forbidden.
Instead, we'll do some array manipulation.
($#~$~4)
    $~4   Reshape 4 to shape 4, resulting in the array 4 4 4 4.
  #~      Replicate wrt itself: replace each 4 by four 4s.
 $        Take length.

Work
2
This is most definitely impossible. The only ways to manipulate character values are a. and u:, and we have access to neither.
Now, if we could use a instead of, say, A, then this would be a solution:
Q{~(*^.4%9 1)+I.~&Q=:a.

The hardest part to getting this to work was producing the number -1.
Q{~(*^.4%9 1)+I.~&Q=:a.
                     a.  The array of all bytes.
                  Q=:    Bind it to Q
              I.~&       and find the input's index in it.
   (        )+           Add the following array:
    *                    Signum of
     ^.                  logarithm of
       4%                4 divided by
         9 1             the array 9 1.
                         This evaluates to -1 1.
Q{~                      Index back into Q.

4
(*.1:"|~@+.)

This generates the shape of the husk, but I can't seem to find a way to generate characters. Alas.
5
Admittedly, this seems like the easiest of the tasks to do in J. However, without i., this will be quite hard.
6
This is likely impossible without a fake-out quine like 449 or something like that, because the capsule string doesn't contain quotes or any other way of producing J strings.

For task 2, Q{~1+I.~&Q=:a. gives the next character: bind the alphabet a. to Q, find the input's index in it with I., add one, and index into Q. Try it. The only remaining problem is to produce -1...

Also, task 3 can be done without string functions: +16=100&|. You just need to produce 16 and 100 somehow.

@Zgarb (1) Yeah... (2) Oh! That's cool! Hmmm shouldn't be too hard

Ha, I think I got 3: +($@#~@$~4)=1e4|&%:*~ It was extremely annoying because we only have one each of (&=:+* and two 4s.

Aaand here's 2: Q{~(*^.4%9 1)+I.~&Q=:a. I realized that the logarithm ^. gives negative numbers for inputs strictly between 0 and 1, and we have % for producing fractions and * for taking the results to -1 and 1.

Oh dang, 2 doesn't work because we have A and not a. I suppose it might be impossible then.

@Zgarb Darn. I thought it was lowercase, too. And nice on 3! I totally forgot about exponential notation. Also, couldn't +(*:4)=1e4&| work? I can't test it right now, as I don't have access to an interpreter.

It doesn't work, because 1e4 is 10000, not 100.

@Zgarb Oops, haha. Fixing.

PowerShell - Total Score: 74
1. Run - Score: 74
#~= `TeQ.)`~H|$QL4yA)\*`!^O$1)!Z`!`~|\`&T@!x+e(f|Q`.|!4%.{~`:~~)m@~`@p~I9~

Since this is extremely difficult in PowerShell (every possible method of obtaining input is impossible with the characters given, as far as I can tell), I've at least decided to randomize the first challenge so we're not all copying the example directly from the post.
So here's a random challenge 1 answer generator (for languages where # is a comment):
'#'+$(-join([char[]]' !!!!!$$%&())))*+...1449:=@@@AHILOQQQTTZ\\^`````````eefmpxy{||||~~~~~~~~~'|Get-Random -Count 73))

Try it online!

I think you're correct. The closest we could get would be $^ which is "the first token of the previous line in the session," which would be extremely limited and very likely a severe bending of standard I/O rules.

@TimmyD yeah, $^ is blank in a new session anyway.

Brainfuck, 74 bytes
H@~*^)$.`~+1A|Q)p~`\Z!IQ~e:O.~@``#|9@)Tf\eT`=(!``|`~!y!`) Q~$x.4|m4~~&!L{%

I just had to.
Explanation:
Any character that is not a valid Brainfuck character is treated as a comment. The only code that actually gets run is this:
.+..

This produces no printable output, since neither 0 nor 1 are printable characters in ASCII. However, it does not cause an error, so we successfully complete the first challenge.

It actually does produce output. It produces those characters. They may not be "printable" (read: visible), but they are still sent to stdout nonetheless.

memes, score of (62 65 + 70) 135
1: Run
I removed all backticks (`) and mathematical operators. They conflicted because there weren't enough numbers to satisfy every unary and binary operator. I left some in, resulting in +3 bytes. Resulting program:
 !!!!!#$$%&())))...+1^4*49:=@@@AHILOQQQTTZ\\eefmpxy{||||~~~~~~~~~

I have no idea why and how this worked. Atleast it doesn't throw any C# runtime exception, and doesn't therefore crash.
6: Quine

You know, if there would've been an - or lowercase q somewhere in those 74 characters, this would be way too easy. I'm glad for the I operator, atleast.
1/4I

This code isn't exactly obvious. Here's an explanation:
1    Set object to 1 (1)
/4   Divide by 4     (0.25)
I    Set object to a fraction string. (1/4)

Fraction strings (e.g. 1/4) are displayed with an I at the end, to indicate exactly that. The I operator is usually useless, I added it for other means, but hey, it works like this!
Above code is invalid. Stupid me didn't see that the 74 characters don't contain a single division operator, forwardslash (/). I came up with something else though:
True

Explanation:
T    Set object to "true" (bool value)
rue  None of these are valid tokens, so they don't get interpreted.

Outputs True (because of how the way C# handles Boolean.ToString() uppercase and not lowercase). Not sure if this is a proper quine, meanwhile I'm still cracking my head for a valid, really proper, and intuitive one.
Could maybe also solve I/O and Math challenge, but I'm missing specific tokens (characters) which aren't included in the 74 characters.

Mathematica, score of 62
I'd be surprised if anyone can make challenges 2-6 work in Mathematica. Here's the best I did with challenge 1:
A:=1.`!#&@(4`+4.`*9.`^$$H~I~L~O~Q~Q~Q~T~T||Z||e@@efmpxy%)!!!!

Defines a pretty stupid function A with a constant value. The 12 unused characters are:
)))\\`````{~

Octave, score 74
1. Run
x =@(AHILOQQQTTZeefmpy)+.1||!!!!!~~~~~~~~~4.^.4||9%#$$)))*@@\`````````{\&:

50 of these characters are part of the function, while the remaining 24 are not.
What it does:
x =@(AHILOQQQTTZeefmpy) creates a function x that can take a variable AHILOQQQTTZeefmpy as input.
To understand the rest:
a||b calls the function all() on both a and b. If one or both of those return true, the || operator will return true.
!a and ~a means the same thing here, they are both not(a).
a.^b is an element-wise power (a(1)^b(1), a(2)^b(2) ...)
Continued explanation
I'll shorten each of the steps as I go along:
4.^.4||9  % This is 4 raised to the power of .4||9
          % .4||9 is true, since both .4 and 9 are true
          % true is evaluated to 1 when used in an expression
...       % 4 raised to the power of 1 is simply 4.
4         % The above expression simplified

And:
!!!!!~~~~~~~~~4  % ! and ~ are the not() operator, so this is equivalent to:
not(not(not(not(not(not(not(not(not(not(not(not(not(not(4))))))))))))))

There is an even number of not, so this is equivalent to not(not(4)) which is true or 1.
+.1||1      % This is equivalent to all(+.1) | all(1), which returns true

The rest is commented out.

*><>, total score = 74
1. Run, score 74
f:4%*e+e14=p!Q H@~^)$.`~A|Q)~`\ZI~O.~@``#|9@)T\T`(!``|`~!y!`)Q~$x.|m~~&!L{

Try it here!
This was extremely hard to do without the ; character. I actually thought it was going to be impossible for a couple moments, until I saw the %, I had basically given up.
This is also a valid ><> program.
Explained (irrelevant parts omitted)
f:4%*e+e14=p!Q

f:               copy 15
  4%             pop 15, push 15%4 (3)
    *            pop 15 and 3, push 15*3 (45)
     e+          pop 45, push 45+14 (59, ascii ";")
       e         push 14
        14=      push 0
           p     replace coord (14, 0) with ";"
            !Q   skip Q (this is just filler)
              ;  end execution

Challenges faced
I might try the other challenges ... they'd be extremely hard and may involve bending the rules in weird ways but liberal use of the | mirrors and the ! trampolines should make at least one more challenge possible.
These challenges are particularly hard because we're not allowed any outputs with *><> (o and n), or even function calls (C), function returns (R), or program terminators (;). Even though we're also missing i for input, we can still have input placed on the stack which is a plus. Another plus is that we get a single p instruction, which allows us to replace an instruction in the codebox. This might be able to be used multiple times (haven't figured out a practical way yet), which would start to make the other programs seem more possible (as we'd be able to generate two or more instructions).

Haskell, score 63
1. Run:
(!!!!!#$$%&*+...:@@@\\^||||~~~~~~~~~)fmpxyAHILOQQQTTZ e=14`e`49

Not used are )))```````{. Comments in Haskell are -- or {- ... -}, so there is no easy all-comment version.
This code defines an infix operator !!!!!#$$%&*+...:@@@\^||||~~~~~~~~~ which takes two arguments:

fmpxyAHILOQQQTTZ which is ignored and can therefore be of an arbitrary type
e, which must be a function taking two numbers

In the function body e is then applied to 14 and 49, using the `-infix notation.
Usage example:
Prelude> () !!!!!#$$%&*+...:@@@\\^||||~~~~~~~~~ (*)
686

The operator is applied to (), the empty tuple, and (*), the multiplication operator, so 14*49 = 686 is computed.
Try it online!
Other challenges
I doubt that any of the other challenges are possible, most notably because of the lack of possible variable names that can appear twice, which is only e (or something like eQT), because variable names can't start with an uppercase letter. Of course, having only one = doesn't help either.

Pyth, 131 for now (2 challenges complete)
1. Run, 74
# `````````!!!)!)!)*$AOeIefLmpxQ|Q|y|Q|~~~~~~~~~()${+%&\=@@@^\:.1.4.49TTZH

This program takes no input and creates no output.
This program uses $$, which allows arbitrary code execution, and so is banned online, so this program online runs offline. Here's its compilation output, so you can see what actually gets run:
while True:
 try:
  (repr(repr(repr(repr(repr(repr(repr(repr(repr(Pnot(Pnot(Pnot()))))))))))))
  imp_print(Pnot())
  imp_print(Pnot())
  imp_print(times(AOeIefLmpxQ|Q|y|Q|~~~~~~~~~(),uniquify(plus(mod(("=" and lookup(lookup(lookup(Ppow(":",.1),.4),.49),T)),T),Z))))
  imp_print(H)
 except Exception:
  break

It's fairly tricky to write a program with arbitrary characters that doesn't error in Pyth. I set myself the additional challenge of requiring that the program run without requiring user input, as well.
The first step is to use # to eat all of the errors. Next, we need to avoid errors caused by ~, I and L, which each have their own details. This is achieved by putting them inside the $$, which embeds them inside the output compilation, and thus subjects them to Python's compilation rules, not Pyth's. Finally, to avoid taking user input, the various arity 0 tokens (Variables and similar) are placed at the end, and the Qs are moved inside the $$ block.
2. IO
This will be incredibly difficult, if it's even possible. None of the Pyth functions that create arbitrary strings or characters are present except .f, and that does a really poor job of creating arbitrary characters.
3. Branchability: 74 - 17 = 57
|&x%Q*TTye|LZ9Q+1

Try it online
An equivalent Pyth program  would be:
?n%Q100 16Q+1

This code takes the input mod 100, compares it to 16, and then uses a ternary to choose between the input and the input plus one. Due to character restrictions, I made some substitutions:

Instead of ?, the ternary, I used |&, or then and, which has the same functionality, except that it breaks if the input is zero, but since we're guaranteed positive integer input, it's fine. (This could have been fixed for no additional characters, but it's simpler this way.)
Instead of directly comparing the two numbers, I take their XOR with x, which is zero if and only if they're equal, as desired.
Instead of writing 100 directly, I generate it with *TT, since T is initialized to 10.
Instead of writing 16 directly, I generate it with ye|LZ9. |LZ essentially functions as the range function, so |LZ9 gives [0, 1, 2, 3, 4, 5, 6, 7, 8]. e takes the final element of a list, giving 8. y doubles it, giving 16 as desired. With an extra + or an extra * I could save a character, but they're both more useful elsewhere.

More to come!

Ruby - Score: 74
1. Run
#H@~*^)$.`~+1A|Q)p~`\Z!IQ~e:O.~@``|9@)Tf\eT`=(!``|`~!y!`) Q~$x.4|m4~~&!L{%

Grabbed from the challenge.

Same for Python

JavaScript (ES6), score = 74
1. Run, 74 bytes
Z=` !!!!!#$$%())))...1449:@@@\AHILOQQQTT^\`eefmpxy{||||~~~~~~~~~`*``+``&``

6. Esotericism (invalid)
For the record, my suggested quine was:
1.4e+49

which turned out to be invalid, as discussed in the comments below.

That quine is valid.

The quine is not valid. The relevant rules are linked in the challenge. In particular, any quine that is based on a single literal fails to encode part of source in a different part of the source. cc @wizzwizz4

@MartinEnder In my browser, that program outputs its source code literally. It's a statement that evaluates to itself. I'm not sure what you're saying; there is no different part of the source.

@wizzwizz4 this community has more requirements for quines than just "the program prints its own source", because that allows for various kinds of cheating solutions that are not in the spirit of quines. See the link.

@MartinEnder Thanks for the clarification.

@MartinEnder I read all three answers to that question, but there's nothing about statements. There is something about structure (as explained in the comment below), but there are many popular quines on Golf you a quine for great good, notably this one, that do not fit that structure and in fact use a similar technique to this one. (Although, the question does link to specific rules, and that overrules any general rules that there may be).

@wizzwizz4 from the top voted answer "It must be possible to identify a section of the program which encodes a different part of the program. ("Different" meaning that the two parts appear in different positions.)" As for Golf you a quine for great good, the challenge (and the linked answer) are several years older than the linked meta post.

Retina, score 74
1. Run, score 74
)))` !!!!!#$$%&()*.+..1449:=@@@AHILOQQQTTZ\\^````````eefmpxy{||||~~~~~~~~~

I moved the extra parens to the config in order for them to balance in the regex. I also moved the ` right after those, and changed +. to .+.
Try it online
The others are likely impossible, since there are no newlines. There's also no - for Transliteration or d for a digits character class.

Pip, score 74 + (74 - 19) = 129
So many backticks with nary a quote to be seen, single or double!
Task 1, score 74
`` `\``!!!!!`#$$%&())))*+...1449:=@@@ILOQQQTTZ\^efmpx{|||~~~~~~~~~`|`yeAH`

Basically just a series of pattern (regex) literals in backticks, the last of which is printed. Since there are an odd number of backticks, we have to backslash-escape one of them (`\``). Try it online, with the -w flag added to prove that no warnings are generated.
Task 3, score 55 (length 19)
e+!!e%(1.#x.!9)=4*4

Using a rather odd input method--the fifth command-line argument--this is possible. Try it online!
                     e is 5th cmdline arg; x is empty string
       1.#x.!9       Concatenate 1, 0 (length of x), and 0 (not 9)
    e%(       )      e mod 100...
               =4*4  ... equals 16?
  !!                 Logically negate twice
e+                   Add to e (+1 if number mod 100 is 16, +0 otherwise)
                     Expression is autoprinted

Other tasks
It's possible to get input for task 2, by the same method as task 3 above. The trouble is converting to ASCII code and back to a character. The former can be done with A, but the latter requires C, or possibly indexing into the PA variable. Constructing and evaluating code can't be done without V. I don't think the task is possible.
Task 4 is challenging even without a restricted character set. At a guess, it would require lists (without using the [] delimiters or RL (repeat list) and only having one chance to use AL (append list)--not likely) or possibly something with CG (coordinate grid) or MC (map coords), both disallowed.
Task 5 is on the edge of possibility. Loops would be difficult, since For and Map aren't possible, and ranges can't be constructed with ,. There might be something to be done with Till. Increment could be of the x:x+1 variety (obviously with a variable other than x, though). Divisibility checks can use %. Still, I don't think there are enough characters--especially repeated letters--to do everything that needs to happen.
Task 6 looks completely impossible. All known Pip quines have " in them. They also use R (replace), RP (repr), or V (eval), none of which are available.

Actually, score (74 + 0 + 0 + 0 + 0 + 0) = 74
Yes, the capsule string will work with Actually as it is for Run, as Actually dismisses any errors and every error becomes a NOP.
H@~*^)$.~+1A|Q)p~\Z!IQ~e:O.~@#|9@)Tf\eT`=(!|~!y!) Q~$x.4|m4~~&!L{% (Try it online!)
It will output a mess of things, though (but also its source once :3).
I'll be working on other challenges, however.

The quine program will (hopefully) be quite simple, if you can make some ops into noops.

The quine program is not simple. You cannot use Q at all (since it's the quining builtin), and there's no double quotes, so you can't do any string formatting. I worked for a while on this yesterday, and I'm fairly certain the other programs are not possible solely with the 74 characters.

And there doesn't seem to be the italic f... :(

05AB1E - Total score: 74
1. Run, 74 bytes
H@~*^)$.`~+1A|Q)p~`\Z!IQ~e:O.~@``#|9@)Tf\eT`=(!``|`~!y!`) Q~$x.4|m4~~&!L{%

Everything that causes an error is skipped by 05AB1E. This whole line of code is a NOP.
Try it online!

Mathematica, score 68
`A:= .1%*.44y#+.9^`H@`$I@`L@(`$O~`Q~`Q~`Q~`T~T~Z~e~e|f|m|p|x)!!!!!&\

Notice the trailing newline. I do not believe that any of the other challenges can be achieved with Mathematica.

(abused) PHP, 74 + 74 = 148
H@~*^)$.`~+1A|Q)p~`\Z!IQ~e:O.~@``#|9@)Tf\eT`=(!``|`~!y!`) Q~$x.4|m4~~&!L{%

The PHP interpreter simply dumps the source code until it finds a <? since we lack < every permutation of those chars is a running quine. I guess this is not that worse than using a builtin quine command :P

This doesn't meet our specifications for quines, see here. It doesn't encode itself (i.e. it doesn't actually print itself, it just happens to be outputted because of the compiler.

@Easterly the interpreter treats every char as output this char until it meets an <. I'm not saying it's payload-capable or sth I'm just saying that's no difference to a language having a char saying output the source. If this is not a valid answer for part 1 than any language that accepts any input without error is not valid answer, too. I don't think this is more abusive than most answers here.

@Christoph it's valid for part one, but it's not a valid quine by the rules linked in the challenge. This community considers a quine valid if you can identify a section of the source that encodes a different part of the code. In your program, every character only encodes itself.

@MartinEnder: #!/bin/cat was considered a quine earlier.

@Joshua indeed, but these days it's not and neither is cat considered a programming language.

Labyrinth, score 74
AH)
IL)
OQ:
`=!)~`{+4.@ !!!$$%&(*..149@@TTZ\\^```eefmpxy||||~~~~~~~~
`Q#
`Q)
``!

I'm pretty sure any assortment of these characters produces a valid Labyrinth program, but to make it at least slightly more interesting, this prints out 2016 digit by digit. (In summary: push 2 2's on the stack, pop/print one, move the other to the aux stack, print 0, push 2 1's on the stack, pop/print 1, increment, bitwise not, negate (that last 1 is a 3 at this point), sum with the 2 from the aux stack, 5*10+4 = 54, print as ascii value, terminate)
Most of the long line is simply ignored, as the @ terminates the program.
Challenges 2, 3, and 4 are impossible since neither of Labyrinth's input commands are available (, or ?), and I didn't come up with anything for 5 or 6.

SmileBASIC, 48 points
challenge 1:
@LOQQQTTZ A$=H$+@efmy+@9414*!exp(!!.||!!.#||I%):

explanation:
@LOQQTTZ 'label
A$= 'set value of A$ (string)
H$ 'string
+@efmy 'adds label, interpreted as string literal
+@9414 'adds label, interpreted as string literal
*!exp( 'multiplies by logical not e^x (= 0)
!!. 'not not 0.0 (= 0)
||!!.# 'or not not 0.0 converted to a float (= 0)
||I% 'or I% (integer variable)
: 'equivalent to a line break, does nothing here

others:
No input/output commands are avaliable, so the rest are not possible.
Still, not bad for a real language without using comments.

+1 truly beautiful. I was wondering how I would do any of these and could never get it. What does this even do?

bash, score 74
1: Run. We can run all 74
#H@~*^)$.`~+1A|Q)p~`\Z!IQ~e:O.~@``|9@)Tf\eT`=(!``|`~!y!`) Q~$x.4|m4~~&!L{%

6: Esotericism:
The empty program is a quine in bash.
Without any whitespace characters, nothing else on the list can be accomplished. Ergo, I have the winning bash entry.

Rule note: If somebody challenges that empty isn't a valid quine and wins, I still have the winning entry (w/o any quine). If on the other hand I don't place it and somebody else does and they win the challenge they beat me. So there it stays.

MATL, total score 74
1. Run, score 74
`4.e4 1.$!!!!!T+Zyf9.)AH^ILx@Q@Q@Qm||||~~~~~~~~~:=Tp*O%#$&()))\\````````e{

Everything up to % is actual code. % is a comment symbol, so the characters to its right are ignored.
The program outputs 1 without errors.
Try it online!

Perl 6, total score 74
1. Run, score 74
my @TOTAL=$!||(e*4...9^e)Z+1~4||!!Q`{fp)))\#\&`~Q!```HI````!~Q:x~~~$~@~@~%

No comments.
(Just putting the # at the front to make everything a comment also works, but this is more fun.)
Work
This is the subset of the Perl 6 language that only uses the allowed characters:

Constants:   e

Type names:  IO

Functions:   exp

Methods:
    on type IO:   .e  .f  .x
    (...probably more.)

Operators:     |  infix:               |  prefix:
    -----------+-----------------------+---------
    numeric:   |  +  *  +^  +|  +&  %  |  +  +^
    string:    |  ~  x  ~^  ~|  ~&     |  ~
    boolean:   |  ||  ~~               |  !
    junctions: |  |  &  ^              |
    misc:      |  =  :=  Z  ..  ...    |

syntax:
    number literals:  1  4  9
    string literals:  Q` `  Q! !   etc.
    shell commands:   Q:x` `  Q:x! !   etc.
    Whatever star:    *
    variables:        my  \  $  @  &
    grouping:         (  )
    comments:         #  #`( )
    unspace:          \

The immediate hurdle preventing the challenges 2-6, is that there doesn't seem to be a way to do I/O:

If we assume there's a file called f, we could use Q`f`.IO.e to check if it exists or Q`f`.IO.x to check if it is executable. But we can't read it or write from it.
We could use Q:x` ` to run a shell command (assuming we find the characters for one). But we can't interpolate anything into, so it would only be good for reading, not writing.
Since there is no closing brace, we can't make a block lambda (e.g. {1 + $_}) that automatically returns the value of its last statement.
We could use the asterisk to make an expression lambda (e.g. 1+*), but then we can only take one argument, refer to this argument only once, and are even more limited in the syntax/operators we can use.

Nicely done, really! :)

abcn, score 65
The Challenges :
RUN : (73 bytes)
H@~*^)$.`~+1A|Q)p~`\Z!IQ~e:O.~@``|9@)Tf\eT`=(!``|`~!y!`) Q~$x.4|m4~~&!L{%

How it works :
Every thing other than @ (which is for input) is not present in current version of abcn.
Note : abcn treats everything save its commands as simple comments so all of it is one big comment the three @ since we give no output are automatically set to 0.
I can obviously increase the length infinitely by doing nothing but bull but wont do it. (Alternate program down below)
(scrapped it since I was 130 bytes in and not even 1/4th of the way done)
I/O : (8 bytes)
@agxbbgx

How it works :
@                                 --> asks for input
a                                 --> adds one
g                                 --> converts to ASCII
x                                 --> prints
bb                                --> b takes back to input second takes back by 1 more so we at input - 1
gx                                --> converts to ASCII and prints

Don't think can do remaining now.
Total score : 73 - 8 => 65

a, g, b and x  aren't in the string.

Vyxal, score 74
Run, 74 bytes
#H@~*^)$.`~+1A|Q)p~`\Z!IQ~e:O.~@``|9@)Tf\eT`=(!``|`~!y!`) Q~$x.4|m4~~&!L{%

Try it Online!
The rest aren't easily possible.

Lua, score 31
1. Run (31 of 74 points)
AHILOQQQTTZeefmpxy=1.%4+(4.*9.)

You missed the space. variable =stuff is 1 byte longer.

Jelly, score 74
1. Run, 74
 ||||!!!!!$$~~~~~~~~^@=@~%449:`e@`e`QAHILOQQTTZ{\\f`m`p`x`y`&`*.#1+.()))).

Not sure how to do any of the others.

///, Score: 146
1. Run, Score: 74
 !!!!!#$$%&())))*+...1449:=@@@AHILOQQQTTZ\\^`````````eefmpxy{||||~~~~~~~~~
6. Quine, Score: 72
 !!!!!#$$%&())))*+...1449:=@@@AHILOQQQTTZ^`````````eefmpxy{||||~~~~~~~~~
Yay, when there aren't any forward or back slashes in the code, it just prints itself.