text:
Greatest Number in a Range When The Sum of Squares of its Prime Factors are Subtracted
The formula
Take for instance the number 300

The prime factors of 300 are [2, 3, 5] (unique numbers that are
factors of 300 and prime)
Squaring each of those numbers will give
you [4, 9, 25]
Summing that list will give you 4 + 9 + 25 = 38
Finally subtract that sum (38) from your original number 300-38 = 262 (this is the result)

Input
Your input will be a positive integer greater than 2. You must check all numbers from 2 to the input value (inclusive) and find the number that produces the greatest result with the formula above.

Output
Your output will be two numbers separated by a space, comma, newline or whatever you language allows (the separation is necessary to distinguish the two numbers). These can be output to a file, stdout, or whatever your language uses. Your goal is to find the number in the range that produces the maximum output when run through the formula above. The first number displayed should be the starting number (like 300) and the second number should be the output that the formula produced (like 262)

Test Cases
Input: 3       Output: 2, -2
Input: 10      Output: 8, 4
Input: 50      Output: 48, 35
Input: 1000    Output: 1000, 971
Input: 9999    Output: 9984, 9802

Worked Through Example
Consider the input of 10, we must run the formula for all numbers from 2-10 (inclusive)
Num PrimeFacs PrimeFacs^2 SumPrimeFacs^2 Result
2   [2]       [4]         4              -2
3   [3]       [9]         9              -6
4   [2]       [4]         4               0
5   [5]       [25]        25             -20
6   [2, 3]    [4, 9]      13             -7
7   [7]       [49]        49             -42
8   [2]       [4]         4               4
9   [3]       [9]         9               0
10  [2, 5]    [4, 25]     29             -19

As you can see the greatest result is 4, which was a result of inputting the value 8 into the formula. That means the output for an input of 10 should be 8, 4

Scoring & Rules
The default rules for inputs and outputs apply: Default for Code Golf: Input/Output methods

The standard loopholes are forbidden: Loopholes that are forbidden by default

Submissions can be functions or full programs
Shortest code in bytes wins

I've fixed a few spelling and grammar errors, and made the title more descriptive. I also changed the bit about disallowing whitespace separators, since that's clearly not what you meant (since newlines and spaces are whitespace characters). If this is not what you intended, feel free to revert the edit and make your intention clearer.

What should happen if several numbers are tied for the maximal result?

@Dennis is it acceptable for me to allow it to be any number that generates the maximum result? I don't want to impose a new rule that breaks all the existing solutions.

Yes, that's probably the best option. 950 could be an example, where both [900, 862] and [945, 862] would be valid answers.

Can I output the numbers in reverse order, e.g. for input 50:  35, 48?

@nimi No they can't be output reversed, sorry.

@Keatinge, can you output as an array?

@SolomonUcko Yes you can output an array

Pyth, 17 15 bytes
_eSttm,-ds^R2{P

Test suite.

Java 8 lambda, 247 239 233 225 224 219 198 161 characters
I thought that must be possible in under 300 chars because... you know... Java!
And it is indeed possible even in under 200 chars!
m->{int n=1,u,f,F[],g,G=g=1<<31;for(;++n<=m;){u=n;F=new int[m+1];for(f=1;++f<=u;)u/=u%f<1?(F[f]=f--):1;f=0;for(int p:F)f+=p*p;g=n-f>g?(G=n)-f:g;}return G+","+g;}

I don't know whether this use of imports is legit but I assume, that it should be okay. Here is the lambda ungolfed into a class:
public class Q80507 {
    static String greatestAfterReduction(int maxNumber) {
        int number = 1, upper, factor, primeFactors[], greatestResult, greatestNumber = greatestResult = 1 << 31; // <-- Integer.MIN_VALUE;
        for (;++number <= maxNumber;) {
            // get unique primefactors
            upper = number;
            primeFactors = new int[maxNumber + 1];
            for (factor = 1; ++factor <= upper;)
                upper /= upper % factor < 1 ? (primeFactors[factor] = factor--) : 1;

            factor = 0;
            for (int prime : primeFactors)
                factor += prime * prime;

            greatestResult = number - factor > greatestResult ? (greatestNumber = number) - factor : greatestResult;
        }
        return greatestNumber + "," + greatestResult;
    }
}

The primefactor-finding is based on this answer. The code uses the functionality of sets as they only save each value once, thus I don't have to care about added duplicates later on. The rest of the code is pretty straight forward, just following the question.
Updates
Removed the newline from the output.
Thanks to @ogregoire for golfing the Integer.MIN_VALUE to 1<<31!
After looking on the code again I found some more places where things could been golfed.
Thanks to @Blue for the ==0 to <1 trick!
Removed some leftover whitespace. Also for separation only one char is needed so no need to waste one char.
Thanks again to @ogregoire for pointing out that I can return the value instead of printing it and putting together the declarations! This saved a lot!
Found out I can use a ternary instead of the second if to save one more char.
Thanks to @AstronDan for the awesome usage of an array which saves the import. That also gave me the possibility to shorten the first if into a ternary.

Is it impossible for the value to get smaller than -3? What I just saw: I can just use the actual value of the literal, which is also some chars shorter. Thanks for the ln part!

Integer.MIN_VALUE can be shortened as 1<<31.

Save 1 bytes with if(u%f<1) instead

@Frozn, what's up with the weird class name (Q80507)?

@SolomonUcko 80507 is the question id you find in the link to the question. I name the classes in my IDE that way so I can lookup the question later on.

Declare all your ints at the same place to avoid repeating int several times, and assign them their value there if possible.

Also, get rid of that System.out.println(...) and return a value instead of printing it: as the OP mentions, standard I/O method is in use.

@ogregoire you won't believe it but I had the same idea like an hour ago after waking up. Regarding the I/O: that's interesting, will do all this when coming back home

You can also use the array trick that I used in C# to turn the hashset into an int array. This will likely let you drop the import saving many bytes.

Actually, 21 bytes
u2x;`;y;*@-`M;M;)@í@E

Try it online!
Explanation:
u2x;`;y;*@-`M;M;)@í@E
u2x;                   push two copies of range(2, n+1) ([2, n])
    `      `M          map:
     ;                   duplicate
      y;                 push two copies of prime divisors
        *                dot product of prime divisors lists (equivalent to sum of squares)
         @-              subtract from n
             ;M;)      duplicate, two copies of max, move one copy to bottom of stack
                 @í    get index of max element
                   @E  get corresponding element from range

Can you link to this language?

@NotthatCharles You can click the language's name in the online interpreter.

Ok  I googled Actually Programming Language and found nothing even after browsing the 5th page of google results. What is this language?

@Tejas You could click on the name of the language which would send you to its source: https://github.com/Mego/Seriously

MATL, 18 bytes
:"@tYfu2^s-]v2#X>w

Try it online!
The last case takes too long for the online compiler, but it produces the correct result (it takes about 11 seconds in my computer, running on Matlab):

Explanation
Straightforward application of the described procedure.
:         % Implicit input n. Range [1 2 ... n]
"         % For each
  @       %   Push that number
  tYfu    %   Duplicate. Prime factors. Unique values
  2^s-    %   Square. Sum of array values. Subtract
]         % End for each
v         % Concatenate stack contents into vertical vector
2#X>      % Max and arg max
w         % Swap. Implicit display

05AB1E, 19 17 16 bytes
Code:
L©f€n€O®-®)ø¦{¤R

Explanation:
L                    # make a list of 1..input [1,2,3,4,5,6]
 ©                   # save the list for reuse
  f                  # get primefactors of numbers in list [[],[2],[3],[2],[5],[2,3]]
   €n                # square each factor [[],[4],[9],[4],[25],[4,9]]
     €O              # sum the factors [0,4,9,4,25,13]
       ®-            # subtract from saved list [1,-2,-6,0,-20,-7]
         ®)ø         # zip with saved list [[1,1],[-2,2],[-6,3],[0,4],[-20,5],[-7,6]]
            ¦        # drop the first item (n=1) [[-2,2],[-6,3],[0,4],[-20,5],[-7,6]]
             {       # sort [[-20,5],[-7,6],[-6,3],[-2,2],[0,4]]
              ¤      # get last item [0,4]
               R     # reverse [4,0]

Try it online

This can be 12 bytes these days with some vectorization and using Ð+s instead of ©+2x®: LÐfnO-sø¦{θR - try it online.

Bash + GNU utilities, 74
seq 2 $1|factor|sed -r 's/:?( \w+)\1*/-\1*\1/g'|bc|nl -v2|sort -nrk2|sed q

seq generates all integers 2 to n
factor gives the number followed by a colon, then a space separated list of all prime factors, including duplicates.  e.g. the result for 12 is 12: 2 2 3
sed removes the colon and duplicate factors, then generates the required arithmetic expression.  e.g. for 12: 12- 2* 2- 3* 3
bc evaluates this
nl prefixes n back in (starting at 2)
sort by the second column, numerically, in descending order
seq prints the first line and quits.

Ideone.

C#, 194 bytes
My first Code Golf :). I used my favorite language despite its verbosity. I started this as a C# function port of @Frozn's Java but found several ways to shrink the code further with optimizations.
string R(int a){int u,f,g,N=g=1<<31;for(int n=1;++n<=a;){u=n;int[]P=new int[a+1];for(f=1;++f<=u;){if(u%f<1){u/=f;P[f]=f--;}}f=0;foreach(var p in P){f+=p*p;}if(n-f>g){g=(N=n)-f;}}return N+","+g;}

This uses an array to store the prime factors. Because it is indexed by the factor it will replace repeated factors with copies of the factor. This allows the function to have no imports. This does not even require System.

This is a REALLY nice trick! Will try use it in my version

Brachylog, 48 bytes
:2:{eI$pd:{:2^.}a+:I--:I.}fF$\hor:0m:Ir.r~m[F:J]

Explanation
Main predicate:

:2:{}fF                     Unify F with the list of all binding for which predicate 1 is
                            true, given [Input, 2] as input.
       $\hor:0m             Retrieve the max of F by diagonalizing it, taking the
                            first row, sorting that row and reversing the sorted row.
               :Ir.         Unify the Output with [I, Max],
                   r~m[F:J] [I, Max] is in F at index J (the index is unimportant)

Predicate 1:

eI                          I is an integer in the range given in Input
  $pd                       Get the list of prime factors of I, with no duplicates
     :{:2^.}a               Apply squaring to each element of that list
             +              Sum the list
              :I-           Subtract I from the sum
                 -          Multiply by -1 (let's call it Result)
                  :I.       Unify the Output with [Result, I]

Jelly, 13 bytes
ÆfQ²S_@,µ€ḊṀṚ

Try it online! or verify all test cases.
How it works
ÆfQ²S_@,µ€ḊṀṚ  Main link. Argument: n

        µ      Combine the chain to the left into a link.
         €     Apply it to each k in [1, ..., n].
Æf               Yield k's prime factors as a list.
  Q              Unique; deduplicate the prime factors.
   ²             Square each unique prime factor.
    S            Compute their sum.
     _@          Subtract the result from k.
       ,         Pair with k, yielding [result(k), k].
          Ḋ    Dequeue; discard the first pair which corresponds to k = 1.
           Ṁ   Get the maximum (lexicographical order).
            Ṛ  Reverse the pair.

Julia, 56 bytes
!n=maximum(k->(k-sumabs2(k|>factor|>keys),k),2:n)[[2,1]]

Try it online!
How it works
Given an input n, for each integer k such that 2 ≤ k ≤ n, we generate the tuple (f(k), k), where f(k) is the difference between k and the sum of the squares of its prime factors.
f(k) itself is calculated with k-sumabs2(k|>factor|>keys), which factors k into a Dict of prime keys and exponent values, extracts all the keys (prime factors), takes the sum of their squares and subtracts the resulting integer from k.
Finally, we take the lexicographical maximum of the generated tuples and reverse it by accesing it at indices 2 and 1.

05AB1E, 13 bytes
Ties Dennis's Jelly answer for #1.
L¦DfnO-Z©kÌ®)

Try it online!
L¦DfnO-Z©kÌ®)  # full program
         k     # push 0-based index of...
       Z       # maximum of...
               # (implicit) list of...
     O         # sums of...
               # (implicit) each element of list of...
   f           # unique prime factors of...
               # (implicit) each element of...
L D            # [1, 2, 3, ...,
               # ..., implicit input...
L D            # ]...
 ¦             # excluding the first element...
               # (implicit) with each element...
    n          # squared...
               # (implicit) with each element...
      -        # subtracted from...
               # (implicit) corresponding element in...
L              # [1, 2, 3, ...,
               # ..., implicit input...
L              # ]...
 ¦             # excluding the first element...
         k     # in...
               # (implicit) list of...
     O         # sums of...
               # (implicit) each element of list of...
   f           # unique prime factors of...
               # (implicit) each element of...
L D            # [1, 2, 3, ...,
               # ..., implicit input...
L D            # ]...
 ¦             # excluding the first element...
               # (implicit) with each element...
    n          # squared...
               # (implicit) with each element...
      -        # subtracted from...
               # (implicit) corresponding element in...
L              # [1, 2, 3, ...,
               # ..., implicit input...
L              # ]...
 ¦             # excluding the first element...
          Ì    # plus 2
       Z©  ®   # push maximum of...
               # (implicit) list of...
     O         # sums of...
               # (implicit) each element of list of...
   f           # unique prime factors of...
               # (implicit) each element of...
L D            # [1, 2, 3, ...,
               # ..., implicit input...
L D            # ]...
 ¦             # excluding the first element...
               # (implicit) with each element...
    n          # squared...
               # (implicit) with each element...
      -        # subtracted from...
               # (implicit) corresponding element in...
L              # [1, 2, 3, ...,
               # ..., implicit input...
L              # ]...
 ¦             # excluding the first element
            )  # push stack
               # implicit output

Note: If only the calculated number needed to be output, then 5 bytes could be saved by removing ©kÌ®).

Clojure, 215 bytes
(fn j[x](apply max-key second(map(fn[w][w(- w(let[y(reduce +(map #(* % %)(set(flatten((fn f[q](let[c(filter(fn[r](=(mod q r)0))(range 2 q))](if(empty? c)q(map f c))))w)))))](if(= y 0)(* w w)y)))])(range 2(inc x)))))

Just follows the rules. Calculates prime factors of each number, put them to square and sum them. After that generate a list of vectors of 2 elements: initial number and its result and find the element with maximum value of second element.
You can see it online here: https://ideone.com/1J9i0y

CJam, 32 bytes
ri({))_mf_|2f#:+-}/]_:e>_@#))\]p

Try it online!

R 109 bytes
y=sapply(x<-2:scan(),FUN=function(x)x-sum(unique(as.numeric(gmp::factorize(x))^2)));c(x[which.max(y)],max(y))

I cheated and used a package, gmp.

PowerShell v2+, 124 120 117 bytes
2..$args[0]|%{$y=$z=$_;2..$_|%{$y-=$_*$_*!($z%$_)*('1'*$_-match'^(?!(..+)\1+$)..')};if($y-gt$o){$o=$y;$p=$_}}
"$p $o"

The first line calculates the values, the second is just output.
We start with creating a range from 2 up to our command-line argument $args[0] and loop that |%{...}. Each loop we set helper variables equal to our current value with $y=$z=$_. We then loop through every number from 2 up to our current number. Each inner loop we check whether that number is a divisor !($z%$_) and whether it's prime ('1'*$_-match'^(?!(..+)\1+$)..'), and if it's both we subtract the square from $y (the checks are done using Boolean multiplication).
Once we've gone through all prime divisors and subtracted the squares, if the number remaining is the largest we've seen so far $y-gt$o, we set our output variables $o=$y;$p=$_. After we've looped through the whole range, we simply output with a space between.

Pyke, 17 bytes
FODP}mXs-)DSei@Oi

Try it here!

JavaScript (ES6), 111 105 bytes
f=n=>{r=n<2?[]:f(n-1);for(s=[],j=n,i=2;j>1;k%i?i++:j/s[i]=i);s.map(i=>j-=i*i,j=n);return j<r[1]?r:[n,j]}

No idea why I didn't think to do this recursively before.

Python 2, 108 105 100 bytes
f=lambda n,m=2,p=1:m>n or-~f(n,m+1,p*m*m)-(n%m<p%m)*m*m
r=max(range(2,input()+1),key=f)
print r,f(r)

Test it on Ideone.

Haskell, 91 bytes
f m=reverse$maximum[[n-sum[p^2|p<-[2..n],mod n p<1,mod(product[1..p-1]^2)p>0],n]|n<-[2..m]]

Usage example: f 50-> [48,35].
Prime factor functions are available only via import Data.Numbers.Primes which costs too many bytes, so I'm using @Lynn's prime checker. The rest is straight forward: for input m loop n through [2..m] and in an inner loop p through [2..n]. Keep all p that are prime and divide n, square and sum.

J, 44 bytes
[:((],.~2+I.@e.)>./)@:}.1(-[:+/*:@~.@q:)@+i.

Straight-forward approach. Also returns all values of n that result in a maximum value.
Usage
   f =: [:((],.~2+I.@e.)>./)@:}.1(-[:+/*:@~.@q:)@+i.
   f 3
2 _2
   f 10
8 4
   f 50
48 35
   f 1000
1000 971
   f 9999
9984 9802
   f 950
900 862
945 862

Vyxal, 10 bytes
ḢλǏ²∑-;Z↑Ṅ

Try it Online!
Maximum by tail is useless they said. No one ever uses it they said. Well look who's laughing now.
Explained
ḢλǏ²∑-;Z↑Ṅ
Ḣ      Z   # Create a list of [x, f(x)] from range(2, input + 1) where f(x) =
 λ    ;    # lambda x:
  Ǐ        #  prime factors
   ²       #  squared
    ∑      #  summed
     -     #  subtracted from x
        ↑  # maximum by tail
         Ṅ # joined on spaces

9 bytes by using the S flag instead of Ṅ?

Japt -h, 17 bytes
Tried a few different approaches but can't seem to do better than 17 :\
ô í ¤mÇ-k â x²ÃñÌ

Try it
õ@[XX-k â x²]ÃÅñÌ

Try it

Yeah my approach was pretty much the same and lead to the same old seventeen


text:
Find a function with cycles of every length
A function is said to have a cycle of length n if there exists an x in its domain such that fn(x) = x and fm(x) ≠ x for 0 < m < n, where the superscript n denotes n-fold application of f. Note that a cycle of length 1 is a fixed point f(x) = x.
Your task is to implement a bijective function from the integers to themselves, which has exactly one cycle of every positive length n. A bijective function is a one-to-one correspondence, i.e. every integer mapped to exactly once. Having exactly one cycle of length n means that there are exactly n distinct numbers x for which fn(x) = x and fm(x) ≠ x for 0 < m < n.
Here is an example of what such a function might look like around x = 0:
x     ... -7 -6 -5 -4 -3 -2 -1  0  1  2  3  4  5  6  7 ...
f(x)  ...  2  4  6 -3 -1  1 -4  0 -2  5  7 -7 -6  3 -5 ...

This excerpt contains cycles of length 1 to 5:
n   cycle
1    0
2   -2  1
3   -4 -3 -1
4   -5  6  3  7
5   -7  2  5 -6  4
...

Note that above I'm using "function" only in the mathematical sense. You may write either a function or a full program in your language of choice, as long as it takes a single (signed) integer as input and returns a single (signed) integer. As usual you may take input via STDIN, command-line argument, function argument etc. and output via STDOUT, function return value or function (out) argument etc.
Of course, many languages don't (easily) support arbitrary-precision integers. It's fine if your implementation only works on the range of your language's native integer type, as long as that covers at least the range [-127, 127] and that it would work for arbitrary integers if the language's integer type was replaced with arbitrary-precision integers.
Standard code-golf rules apply.

Closely related. While the differences seem minor, they imply that none of the old approaches work without significant modification, and in particular I don't think the winning approach from that challenge can be adapted at all.

"has exactly one cycle of every length", "has many cycles of evry length": is this the only difference which distingishes thid from other ?

@Agawa001 That's one difference, the other is that the other challenge is about functions on the positive integers, whereas this challenge asks for a function on all integers.

I think your definition of cycle needs to include that n is minimal. Otherwise, your cycle of length 2 also counts as your cycle of length 4 and 6 and so on.

@xnor Whoops, good point.

Pyth, 27 18 bytes
_h?gQ0^2Q*.5@,Q-xh

Explanation (Pyth initializes Q to the input integer):
_                       negative of (
                          (
  ?gQ0                      if Q >= 0:
      ^2Q                     2**Q
                            else:
         *.5                  half of
            @        Q          element Q (modulo list length) in
             ,                    the two element list [
              Q                     Q,
                 hQ                 ((Q plus 1)
                x  Q                 XOR Q)
               -    Q               minus Q
                                  ]
 h                        ) plus 1
                        )

This has cycles
(−1)
(0, −2)
(1, −3, −4)
(2, −5, −7, −6)
(3, −9, −13, −11, −8)
(4, −17, −25, −21, −15, −10)
(5, −33, −49, −41, −29, −19, −12)
(6, −65, −97, −81, −57, −37, −23, −14)
(7, −129, −193, −161, −113, −73, −45, −27, −16)
(8, −257, −385, −321, −225, −145, −89, −53, −31, −18)
(9, −513, −769, −641, −449, −289, −177, −105, −61, −35, −20)
⋮
The cycle of length n is given by
(n − 2,
−2^(n − 2)⋅1 − 1,
−2^(n − 3)⋅3 − 1,
−2^(n − 4)⋅5 − 1,
…,
−2^2⋅(2·n − 7) − 1,
−2^1⋅(2·n − 5) − 1,
−2^0⋅(2·n − 3) − 1).
Each integer k ≥ −1 appears as the first element of the (k + 2)-cycle.  For each integer k < −1, we can uniquely write 1 − k = 2^i ⋅ (2⋅j + 1) for some i, j ≥ 0; then k appears as the (j + 2)th element of the (i + j + 2)−cycle.

MATL, 47 bytes
E|G0<-QXJ:tQ*2/0hStJ<f0))Q2MQ)&:J6M-)2/ttk>Eq*k

Try it online!
General explanation
Function 2 below is the same as used in @Sp3000's answer to the related challenge. Thanks to @Agawa001 for noticing.
The function is the composition of three:

Bijection from Z (the integers) to N (the naturals).
Bijection from N to N with the desired characteristic (one cycle of each length).
Inverse of function 1.

Functions 1 and 3 are used because it's easier (I think) to achieve the desired behaviour in N than in Z.
Function 2 is as follows: upper line is domain, lower line is codomain. Commas are used for clarity:
1,  2  3,  4  5  6,  7  8  9  10  ...
1,  3  2,  6  4  5, 10  7  8   9  ...

The first block (from upper 1 to lower 1) is a cycle of length 1. The second (from 2 3 to 3 2) is a cycle of length 2, etc. In each block, the lower part (image of the function) is the upper part circularly shifted one step to the right.
Function 1 is as follows:
 -5  -4  -3  -2  -1   0  +1  +2  +3  +4  ...
+10  +8  +6  +4  +2  +1  +3  +5  +7  +9  ...

Function 3 is the same as 1 with the two lines swapped.
Examples
The image of 3 is -5. First 3 is mapped to 7 by function 1; then 7 is mapped to 10 by function 2; then 10 is mapped to -5` by function 3.
The length-1 cycle is 0. The length-2 cycle is -1 1. The length-3 cycle is -3 2 -2, etc.
Code explained
Functions 1 and 3 are straightforward.
Function 2 works by finding the lower endpoint of the corresponding input block. For example, if the input to this function is 9 it finds 7 (see blocks above). It then picks the upper endpoint, which is 10 in the example. The circular shift of the block is achieved thanks to MATL's 1-based, modular indexing.
         % FUNCTION 1
         % Implicit input
E|       % Multiply by two. Absolute value
G0<      % 1 if input is negative, 0 otherwise
-        % Subtract
Q        % Add 1
XJ       % Copy to clipboard J. Used as input to the next function

         % FUNCTION 2
:        % Range [1 2 ... J], where J denotes the input to this function
tQ*      % Duplicate, increment by 1, multiply
2/       % Divide by 2
0hS      % Prepend a 0. This is needed in case J is 0
tJ<f     % Duplicate. Find indices that are less than the input J
0)       % Pick the last index.
)        % Apply as index to obtain input value that ends previous block
Q        % Add 1: start of current block
2M       % Push the two arguments to second-to-last function call
Q)       % Add 1 and use as index: end of current block
&:       % Inclusive binary range: generate input block
J        % Push J (input to function 2)
6M-      % Subtract start of block
)        % Apply as index (1-based, modular). This realizes the shifting

         % FUNCTION 3
2/       % Divide by 2
ttk>     % Duplicate. 1 if decimal part is not 0; 0 otherwise
Eq       % Multiply by 2, add 1
*        % Multiply
k        % Round down
         % Implicit display

this is a twist of sp3000 s function right ?

@Agawa001 Oh is it? I didn't see the other challenge. I'll take a look

Oh. It definitely is. At least that clarifies that my reasoning, if not original, was correct :-)

it is surprising how more than one mind are closely framed to exude close ideas.

Python 2, 55 bytes
g=lambda n,k=1:n/k and~g(~n+k*(n>0),k+1)+k*(n>0)or-~n%k

59 bytes:
g=lambda n,k=1:n<0and~g(~n,2)or n/k and k+g(n-k,k+2)or-~n%k

Creates the cycles
[0]
[-1, -2]
[1, 2, 3]
[-3, -4, -5, -6]
[4, 5, 6, 7, 8]
...

Modified from my solution on the earlier challenge, which is modified from Sp3000's construction.
The function
g=lambda n,k=1:n/k and k+g(n-k,k+2)or-~n%k

makes odd-size cycles of non-negative numbers
[0]
[1, 2, 3]
[4, 5, 6, 7, 8]
...

To find the correct cycle size k, shift the input n down by k=1,3,5,7,... until the result is in the interval [0,k). Cycle this interval with the operation n->(n+1)%k, then undo all the subtractions done on the input. This is implemented recursively by k+g(n-k,k+2).
Now, we need the negative to make the even cycles. Note that if we modify g to start with k=2 in g, we'd get even-size cycles
[0, 1]
[2, 3, 4, 5]
[6, 7, 8, 9, 10, 11]
...

These biject to negatives via bit-complement ~. So, when n is negative, we simply evaluate g(n) as ~g(~n,2).

I don't know whether it helps, but another way of calculating k seems to be Math.floor(Math.sqrt(n))*2+1.

@Neil I looked into determining the boundaries and cycle sizes arithmetically and even doing the whole computation that way, but these expressions are lengthy in Python and I found recursion to be shorter.

Python 3, 110 bytes
I still have not figured out how to get a lambda in there
if n is a triangle number [1,3,6,10,15,21,28,etc...] then f(n) is the order in the list multiplied by negative one. if the number is negative, give it 1+the next smallest triangle number. else, increment.
Example: 5 is not a triangle number, so add 1.
Next iteration, we have 6. 6 is a triangle number, and it is the 3rd in the list, so out comes -3.
The program gives these lists
length 1:[0]
length 2:[1,-1]
length 3:[2,3,-2]
length 4:[4,5,6,-3]
length 5:[7,8,9,10,-4]
x=int(input())
if x<0:print((x**2+x)/2+1)
else:
 a=((8*x+1)**.5-1)/2
 if a%1:print(x+1)
 else:print(-a)

Edit: Thanks again to @TuukkaX for removing excess charcters.

You could change 0.5 to .5 and input('') to input().

Python 3,  146 bytes
For every number greater than 0, there are even loops (len 2,4,6,8...), and less than 0, odd loops (1,3,5,7). 0 maps to 0.
(-3,-2,-1),(0),(1,2),(3,4,5,6)
maps to
(-2,-1,-3),(0),(2,1),(6,3,4,5)
f=lambda x:1+2*int(abs(x)**.5)if x<1 else 2*int(x**.5+.5)
x=int(input());n=f(x)
if x>0:b=n*(n-2)/4
else:b=-((n+1)/2)**2
print(b+1+(x-b-2)%n)

Edit: @TuukkaX took off 8 bytes from the previous solution. And another 3.

I think you can remove an whitespace before the if statement at the first line. And mi could be changed to something smaller, such as b.

Here is the same program golfed down: f=lambda x:1+2*int(abs(x)**0.5)if x<1 else 2*int(x**0.5+0.5) x=int(input()) n=f(x) if x>0:b=n*(n-2)/4 else:b=-((n+1)/2)**2 print(b+1+(x-b-2)%n)

Thanks, @TuukkaX . I forgot about the 2 character variable 'mi'.

I also changed input('') to input(). The quotes are useless since we don't have to print anything to the console when we want to just get the input.

Even shorter. Removed the zeroes before the dots. f=lambda x:1+2*int(abs(x)**.5)if x<1 else 2*int(x**.5+.5) x=int(input());n=f(x) if x>0:b=n*(n-2)/4 else:b=-((n+1)/2)**2 print(b+1+(x-b-2)%n)

Matlab(423)
function u=f(n),if(~n)u=n;else,x=abs(n);y=factor(x);for o=1:nnz(y),e=prod(nchoosek(y,o)',1);a=log(x)./log(e);b=find(a-fix(a)<exp(-9),1);if ~isempty(b),k=e(b);l=fix(a(b));break;end;end,if(abs(n)==1)k=2;l=0;end,if(k==2)l=l+1;x=x*2;end,e=dec2base(l,k)-48;o=xor(e,circshift(e,[0 1]));g=~o(end);if(~o|nnz(o==1)~=numel(e)-g),u=n*k;else,if((-1)^g==sign(n)),u=sign(n)*k^(base2dec([e(2:end-1) 1]+48,k)-(k==2));else,u=n*k;end,end,end

Non-competing because it breaks a good record of being condidate for the last ranking, whilst I am struggling to shorten it as possible as i can.
Some nonesensical bugs concerning accuracy in matlab that I couldnt find any way out except making my code sarcatistically big, in other hand the mapping I opt for was in terms of prime facors and n-ary logarithm.

Execution
 f(2)

 1

 f(1)

 2

 f(-2)

 -4

 f(-4)

 -8

 f(-8)

 -1

 f(0)

 0

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

Explanation

Knonwing, first off, that any number can be written as product of exponents of primes N=e1^x1*e2^x2... from this base i chose to map images of cycles C which are extracted from the biggest exponent of the smallest factor (not necessarily prime) that N is a perfect power of.
in simpler words, let N=P^x where P is the smallest perfect root, x denotes precisely two essential terms for the cycle : x=Ʃ(r*P^i), a term P is the base of cycle as well a perfect root for the main number N, and k is the degree of the cycle C=p^k, where i varies between 1 and k, the coeffecient r is incremented by 1 and bounded by P-1 for any following pre-image until all coeffecients are set to r=1, so we move to the start of that cycle.
To avoid collisions between cycles the choice of exponentiation of primes rather than their products is accurate, because as an example of two cycles of bases 3 and 2 a meetpoint between them can be 3*2, so this is avoided since a cycle is defined by its degree more than its base , and for the meetpoint there is another cycle of base 6 and degree 1.
Negative numbers place an exception, as for it, i reserved odd degrees for negative numbers, and even degrees for the rest. How so ?
for any number N embedded within a cycle P^k, is written as P^(a0*P^i0+a1*P^i1+...), the amount (a0*P^i0+a1*P^i1+...) is transalted in P-ary base as a0,a1,.... , to clarify this point if (p=2) the sequence must be in binary base. As is known prealably without setting the condition of positive/negative degrees and the (+/-1) exception, a number N is on the edges of a cycle of degree k if and only if the sequence A is written as 1111..{k+1}..10 or 111..{k}..1 for all bases, otherwise no rotation is needed, thus assigning negative/positive condition for a respective odd/even degrees k/k' for both makes an odd sequence written in the form 101..{k}..100, an even sequence is written in the form 101..{k'}..10 for a beginning edge of a respectively negative/positive number-cycle.
Example:
Taking a number N=2^10, x=10=2^1+2^3 , the sequence A is written A=1010, this type of sequence symptomizes a finite edge of positive number-cycle, which is C=2^3, so the next image is that of beginning edge A=011 which is 8, But, by standarizing this result to (+/-)1 exception 2^10/2 maps to 8/2 and the previous image mustnt be rotated.
Taking a number N=-3^9, x=9=3^2 , the sequence A is written A=100, this type of sequence symptomizes a finite edge of negative number-cycle, which is C=3^1, so the next image is that of beginning edge A=01 which is 3, But, by adapting this result to negative/positive condition -3^9 maps to -3 .
for the couple (-/+)1, i envisaged to intrude it within numbers of cycle-bases 2, in a guise that an ordinary sequence of cyclic groups {2,4}{8,16,32,64}.. are made up in another form {1,2}{4,8,16,32}.., this prevents any loss of previous elements, and the opeation done is just shifting with popping a new element in.

Results:
running this little code-sheet to verify the first reasonable ranges of cyclic numbers:
for (i=1:6)
index=1;if(max(factor(i))>=5) index=0;end
for ind=0:index
j=f(((-1)^ind)*i); while(((-1)^ind)*i~=j)fprintf('%d ',j);j=f(j);end,fprintf('%d \n',(-1)^ind*i),pause,end,
end

This leads to this results
 2 1
 -2 -4 -8 -1
 1 2
 -4 -8 -1 -2
 9 27 3
 -9 -27 -81 -243 -729 -2187 -6561 -19683 -3
 8 16 32 64 128 256 512 4
 -8 -1 -2 -4
 25 125 625 3125 5
 36 216 1296 7776 46656 6
 -36 -216 -1296 -7776 -46656 -279936 -1679616 -10077696 -60466176 -362797056 -2.176782e+009 -1.306069e+010 ??? Error using ==> factor at 27

The last one is segmentation-error but it fits the [-127,127] standard signed-integer range.

I used this technique awhile ago to define hash functions in an old C program of mine, it works neat !

JavaScript (ES6), 73 bytes
f=(n,i=0,j=0,k=0,l=1,m=i<0?-i:~i)=>n-i?f(n,m,k++?j:i,k%=l,l+!k):++k-l?m:j

Works by enumerating the sequence (0, -1, 1, -2, 2, -3, 3, ...) until it finds n, counting cycles as it goes. i contains the current entry; j contains the start of the current cycle, k the index within the cycle, l the length of the current cycle and m the next entry in the sequence. Once we find n we then take j if we're at the end of a cycle or m if not.

source: Stack Exchange

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

sort: votes


text:
AppleSauce Fader
Back in the day, all the 1337 kids used text faders in chatrooms. I don't know about you guys, but I want to feel cool like they did. The only problem is that their old scripts and applications were heavily coupled to the software they were made for, so I can't just make use of this amazing functionality wherever I want. I also want the solution to be easily portable so you're going to need to make the code as small as possible so that it will fit on my floppy disk (I'd rather only carry one floppy but if your source code is too big I can carry more than one :P).
Input

A list of colors (rgb, hex, names, etc)
Text to format

Your program should expect the list of colors to contain at least 2 colors.
Text to format can be any length greater than zero and characters will be limited to printable ascii. (Hint: Longer text inputs may require you to reuse intermediate colors for consecutive characters)
Output
The output text should not differ from the input text in any way other than font  and/or markup/styling (Note: if your output contains html markup then you'll need to html encode the input). You may output text with markup/styling (html style tags, console colors, etc.) or a picture of the faded text. All color hexes should be present in the output unless the input does not contain enough characters to meet this requirement. If this is the case, then consult the priority rules to determine which color hexes should be present in your output. The order or these colors in your output should still be input order.
Color Priority Rules

In the event that the input is one character, the first color will be used
In the event that there are only two characters, the first and last color will be used
In the event that there are more than three colors and more colors than characters, the first and last colors should be prioritized, then the rest of the colors in their inputted order.
In the event that there are more characters than colors, the characters should fade from one color to the next using intermediate colors

Examples (Priority rules 1-3 respectively):
# Colors | Color0 | ... | Colorn | Text
3 ff0000 0000ff ffff00 M ->
3 ff0000 0000ff ffff00 hi ->
4 ff0000 0000ff ffff00 0fff00 sup ->
To be clear, the text color should fade from one color hex to the next. The fade does not have to be perfectly uniform but it shouldn't be an abrupt color change unless there aren't enough characters to fade nicely. Generally this fade is achieved by choosing intermediate colors for each of the characters by incrementing/decrementing the rgb values by some interval determined by the number of characters you have to work with and the difference between the colors. For example if we needed a single color between  (#ff0000) and  (#000000), we might choose  as it sits right in the middle.  Optimal output will look rather pretty.
Example (Priority rule 4):
3 ff0000 ff7f00 f0ff00 To be or not to be, that is the question... ->

-OR-
To be or not to be, that is the question...

In your answer please specify how your output should be displayed (as html, in a console, as an image, etc.).
* All black backgrounds are only for color emphasis and are not required
Scoring
This is code-golf, so the shortest answer (in bytes) wins.
If you manage to add fade to individual characters then I'll forever think you're cool (but no bonus to score as this will not be fair for some langs)

The average of #000000 and #ff0000 is not #800000.

@LeakyNun In RGB space it is near enough, the other option being #7f0000.

Not really. Try to average red and green in this way and see if you get yellow. To do it the right way, take the root-mean-square instead of direct average.

The average of 000000 and ff0000 should be b40000 (255*sqrt((0+1)/2))

@LeakyNun I never said you needed to average the colors. I described an easy method of fading that is sometimes employed for challenges like this. In this case we averaged the reds of the two colors (and rounded). I also noted in the challenge that the fade does not have to be perfectly uniform. It is up to you how you want to implement this fade.

I know you did not say we have to choose a uniform distribution. However, you did say that #800000 lies in the middle of #000000 and #ff0000, which is misleading in its own rights.

Related? Create rainbow text

@LeakyNun Strictly speaking, 0xff = 255 and 0x80 = 128 so 0x800000 is indeed in the middle of 0x000000 and 0xff0000. Taking RMS unnecessarily complicates the challenge.

@manatwork nice find. I didn't see that when writing this challenge. I think this should be different enough since colors can be specified.

JavaScript (ES6), 290 bytes

h=a=>f(a,a.shift());f=
(a,w)=>[...w].map((c,i)=>{l=w.length-1;m=a.length-1;s=o.appendChild(document.createElement('span'));s.textContent=c;s.style.color=`#${i?i-l?a[r=l%m,n=l/m|0,i<r*n+r?++n:i-=r,k=i/n|0,k++].replace(/./g,(c,d)=>((parseInt(c,16)*(n-i%n)+i%n*parseInt(a[k][d],16))/n|0).toString(16)):a[m]:a[0]}`;})
<textarea rows=10 cols=40 oninput="o.textContent='';h(this.value.split`\n`)">Type the text here and the colours on subsequent lines.
FF0000
00FF00
0000FF</textarea>

That's really cool to see it happen in real time with the code snippet. :D

Java, 702 662 characters
Two functions golfed:
import java.awt.*;String f(Color C,char c){return""+c+"";}String c(String t,String[]h){String r="";int l=h.length,e=t.length(),i=0,s=0,g=1,c=-1,p,q,u;double d,m=0,v;char[]T=t.toCharArray();Color C[]=new Color[l],H[],a,b;for(;i<l;)C[i]=Color.decode(h[i++]);if(l>e){H=java.util.Arrays.copyOfRange(C,0,e);H[e-1]=C[l-1];H[0]=C[0];C=H;l=e;}d=--e/(l-1.);for(;++c<e;){a=C[s];b=C[g];p=b.getRed()-a.getRed();q=b.getGreen()-a.getGreen();u=b.getBlue()-a.getBlue();v=m/d;r+=f(new Color(a.getRGB()+((int)(v*p)<<16|(int)(v*q)<<8|(int)(v*u))),T[c]);if(++m>d){m-=d;s=g++;}}return r+f(C[l-1],T[e]);}

As nobody can read this: here are both functions in there ungolfed version in a class:
import java.awt.*;

public class Q80554 {

    static String format(Color color, char character) {
        return "" + character + "";
    }

    static String colorizeB(String text, String[] hexColors) {
        String result = "";
        int colorsLength = hexColors.length, textLength = text.length(), i, currentStartColorPos = 0, currentGoalColorPos = 1, currentCharPos = -1, diffColorRed, diffColorGreen, diffColorBlue;
        double difference, goneDifference = 0, relativeChange;
        char[] textArray = text.toCharArray();
        Color colors[] = new Color[colorsLength], changer[], currentStartColor, currentGoalColor;

        for (i = 0; i < colorsLength;)
            colors[i] = Color.decode(hexColors[i++]);

        if (colorsLength > textLength) {
            changer = Arrays.copyOfRange(colors, 0, textLength);
            changer[textLength - 1] = colors[colorsLength - 1];
            changer[0] = colors[0];

            colors = changer;
            colorsLength = textLength;
        }

        // fade
        difference = --textLength / (colorsLength - 1.); // space between colors

        for (; ++currentCharPos < textLength;) {
            currentStartColor = colors[currentStartColorPos];
            currentGoalColor = colors[currentGoalColorPos];

            diffColorRed = currentGoalColor.getRed() - currentStartColor.getRed();
            diffColorGreen = currentGoalColor.getGreen() - currentStartColor.getGreen();
            diffColorBlue = currentGoalColor.getBlue() - currentStartColor.getBlue();

            relativeChange = goneDifference / difference;

            result += format(new Color(currentStartColor.getRGB() + ((int) (relativeChange * diffColorRed) << 16 | (int) (relativeChange * diffColorGreen) << 8 | (int) (relativeChange * diffColorBlue))), textArray[currentCharPos]);

            if (++goneDifference > difference) {
                goneDifference -= difference;
                currentStartColorPos = currentGoalColorPos++;
            }
        }

        // last character always has last color
        return result + format(colors[colorsLength - 1], textArray[textLength]);
    }
}

Here you have an upper bound for your own code. Usage is by calling colorize (or c in the golfed version) and pass the text and an array of hex color codes. The function will return a String with HTML-tags like the OP did, thus you need some way to render the HTML.
The algorithm is easier as the question looks like. The first character always gets the first color, the last one always the last. If we have more colors than chars in the text we just iterate over the text and colors and apply these. The fun part is the one with the fades: I started of by finding out in what distance the colors are on the text. I basically calculate the red, green and blue difference between two given colors and then add a part of this difference to the first color, depending on where the char is between the colors. If it leaves the interval of two colors we start from new with the next two colors. This is repeated for all but the last character, which we know is always the last color. This gives a very beautiful fading.
That question was very much fun! Thanks!
Updates
Now I don't handle all the cases specially. Instead I trim the colors if there are two much and apply the fade function to every string. If there were more colors than text then the colors will be trimmed and the fading function will work exactly as a simple mapping.

Pyth, 126 bytes
Obligatory root-mean-square average instead of direct arithmetic mean.
L%"%s",smt.H+256s*255@d2ebhbMm+hG*-eGhGcdHH=Q^RL2Q+smsyMC,hdCgRlhdCedC,ctlQPzC,QtQy,ez?tlzeQh

Try it online!
Sample output:

"Try it online!" link is broken

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


text:
Image Hide-and-Seek
In this challenge, you need to find a specific pixel within an photograph (taken with a real camera).
You are passed an (R, G, B) tuple and an image, and you need to return a point (x,y) within the image that matches the RGB color given.  The image may have multiple points that match the color; you only need to find 1.
The challenge is that you need to do it while reading as few pixels as possible.  Your score will be total number of pixels read across all test cases.
If you wish, you can read the entire image into an array of RGB values, as long as you don't do any processing on the pixels.  I allow this purely for efficiency purposes.  For example, in Python, list(Image.open("image_name+".jpg").convert("RGB").getdata()) is ok.
Hardcoding locations is not allowed.  Your algorithm should work well for more than just the test cases listed below.  You are not allowed to save data between test cases.  I've chosen RGB values that appear infrequently (<10) in the image (in case that makes a difference for your algorithm).  If you are using randomness in your algorithm, please set a seed, so that your score is constant.
Images can be found on Github
Test cases:
image_name:
(r, g, b) [all possible answers]

barn:
(143,91,33) [(887,1096),(2226,1397),(2007,1402),(2161,1508),(1187,1702)]
(53,35,59) [(1999,1260)]
(20,24,27) [(1328,1087),(154,1271)]
(167,148,176) [(1748,1204)]
(137,50,7) [(596,1498)]
(116,95,94) [(1340,1123)]
(72,49,59) [(1344,857),(1345,858),(1380,926),(1405,974),(1480,1117)]
(211,163,175) [(1963,745)]
(30,20,0) [(1609,1462),(1133,1477),(1908,1632)]
(88,36,23) [(543,1494),(431,1575)]
daisy:
(21,57,91) [(1440,1935),(2832,2090),(2232,2130),(1877,2131),(1890,2132)]
(201,175,140) [(1537,1749),(2319,1757)]
(169,160,0) [(2124,759)]
(113,123,114) [(1012,994),(2134,1060),(1803,1183),(1119,1335)]
(225,226,231) [(3207,829),(3256,889),(3257,889),(1434,981),(2599,1118),(2656,1348),(2656,1351)]
(17,62,117) [(2514,3874),(2336,3885)]
(226,225,204) [(3209,812)]
(119,124,146) [(2151,974),(2194,1021),(2194,1022),(2202,1034),(2812,1500)]
(2,63,120) [(2165,3881),(2326,3882),(2330,3882),(2228,3887)]
(200,167,113) [(1453,1759)]
dandelion:
(55,2,46) [(667,825),(668,825)]
(95,37,33) [(1637,1721),(1625,1724),(1405,1753),(2026,2276),(2016,2298)]
(27,41,50) [(1267,126),(424,519),(2703,1323),(1804,3466)]
(58,92,129) [(2213,3274)]
(136,159,105) [(1300,2363),(2123,2645),(1429,3428),(1430,3432),(1417,3467),(1393,3490),(1958,3493)]
(152,174,63) [(2256,2556)]
(78,49,19) [(2128,2836)]
(217,178,205) [(2736,3531)]
(69,95,130) [(870,305),(493,460),(2777,1085),(2791,1292),(2634,3100)]
(150,171,174) [(2816,1201),(2724,2669),(1180,2706),(1470,3215),(1471,3215)]
gerbera:
(218,186,171) [(4282,1342)]
(180,153,40) [(4596,1634),(4369,1682),(4390,1708),(4367,1750)]
(201,179,119) [(4282,1876),(4479,1928)]
(116,112,149) [(5884,252),(4168,371),(4169,372),(4164,384),(5742,576)]
(222,176,65) [(4232,1548)]
(108,129,156) [(5341,3574),(5339,3595),(5302,3734)]
(125,99,48) [(4548,1825),(4136,1932),(5054,2013),(5058,2023),(5058,2035),(5055,2050),(5031,2073)]
(170,149,32) [(4461,1630),(4520,1640)]
(156,185,203) [(3809,108)]
(103,67,17) [(4844,1790)]
hot-air:
(48,21,36) [(1992,1029),(2005,1030),(2015,1034),(2018,1036)]
(104,65,36) [(3173,1890),(3163,1893)]
(169,89,62) [(4181,931),(4210,938),(4330,1046),(4171,1056),(3117,1814)]
(68,59,60) [(1872,220),(1874,220),(1878,220),(1696,225),(3785,429)]
(198,96,74) [(4352,1057)]
(136,43,53) [(1700,931)]
(82,42,32) [(4556,961),(4559,973),(4563,989),(4563,990),(4441,1004),(4387,1126),(4378,1128)]
(192,132,72) [(1399,900),(3105,1822),(3104,1824),(3105,1824),(3107,1826),(3107,1827),(3104,1839),(3119,1852)]
(146,21,63) [(1716,993)]
(125,64,36) [(4332,937)]
in-input:
(204,90,1) [(1526,1997),(1385,2145),(4780,2807),(4788,3414)]
(227,163,53) [(1467,1739),(2414,1925),(2441,2198),(134,2446)]
(196,179,135) [(3770,2740),(1110,3012),(3909,3216),(1409,3263),(571,3405)]
(208,59,27) [(1134,1980),(4518,2108),(4515,2142)]
(149,70,1) [(4499,1790),(2416,2042),(1338,2150),(3731,2408),(3722,2409),(4400,3618)]
(168,3,7) [(987,402),(951,432),(1790,1213),(1790,1214),(1848,1217),(4218,1840),(4344,1870),(1511,1898)]
(218,118,4) [(3857,1701),(1442,1980),(1411,2156),(25,2606)]
(127,153,4) [(3710,2813)]
(224,230,246) [(2086,160),(2761,222),(4482,1442)]
(213,127,66) [(4601,1860),(4515,2527),(4757,2863)]
klatschmohn:
(170,133,19) [(1202,2274),(1202,2275),(957,2493),(1034,2633),(3740,3389),(3740,3391),(3683,3439)]
(162,92,4) [(489,2854)]
(159,175,104) [(3095,2475),(3098,2481)]
(199,139,43) [(1956,3055)]
(171,169,170) [(3669,1487),(3674,1490),(3701,1507)]
(184,115,58) [(1958,2404)]
(228,169,5) [(1316,2336),(1317,2336)]
(179,165,43) [(3879,2380),(1842,2497),(1842,2498)]
(67,21,6) [(1959,2197),(2157,2317),(2158,2317),(2158,2318),(2116,2373)]
(213,100,106) [(1303,1816)]
tajinaste-rojo:
(243,56,99) [(1811,2876),(1668,4141),(2089,4518),(1981,4732),(1659,4778),(2221,5373),(1779,5598),(2210,5673),(2373,5860)]
(147,157,210) [(1835,1028),(1431,3358)]
(114,37,19) [(1792,3572),(1818,3592)]
(108,117,116) [(2772,4722),(1269,5672),(2512,5811),(2509,5830),(2186,5842),(2186,5846),(2190,5851),(2211,5884)]
(214,197,93) [(1653,4386)]
(163,102,101) [(2226,2832),(2213,3683),(1894,4091),(1875,4117)]
(192,192,164) [(2175,2962),(2206,3667),(2315,3858),(1561,3977),(3039,5037),(3201,5641)]
(92,118,45) [(1881,1704),(1983,1877),(2254,2126),(3753,5862),(3766,5883)]
(145,180,173) [(1826,1585)]
(181,124,105) [(1969,3892)]
turret-arch:
(116,70,36) [(384,648),(516,669)]
(121,115,119) [(2419,958)]
(183,222,237) [(172,601),(183,601),(110,611),(111,617)]
(237,136,82) [(2020,282),(676,383),(748,406),(854,482),(638,497),(647,661),(1069,838),(1809,895),(1823,911)]
(193,199,215) [(1567,919),(1793,1047)]
(33,30,25) [(1307,861),(309,885),(1995,895),(504,1232),(2417,1494)]
(17,23,39) [(1745,1033),(788,1090),(967,1250)]
(192,139,95) [(1445,1337)]
(176,125,98) [(1197,1030)]
(178,83,0) [(2378,1136)]
water-lilies:
(86,140,80) [(2322,2855),(4542,3005),(4540,3006),(4577,3019)]
(218,124,174) [(1910,2457)]
(191,77,50) [(2076,1588)]
(197,211,186) [(4402,1894)]
(236,199,181) [(2154,1836)]
(253,242,162) [(1653,1430)]
(114,111,92) [(1936,2499)]
(111,93,27) [(2301,2423),(2127,2592),(2137,2717),(2147,2717)]
(139,92,102) [(1284,2243),(1297,2258)]
(199,157,117) [(3096,993)]

Is there any correlation in the images we will be tested on? (Can images be noise) If not, surely the only way will be randomly sampling until the correct pixel is chosen?

@muddyfish the images are taken with real cameras of real objects, so there is optimization to be found.  Your algorithm should definitely be targeting the images, just not the specific colors I give.

"while reading as few pixels as possible" how do you determine this?

Due to differences in libraries and languages, I can't define methods that are considered "accessing". What in particular are you thinking about?

Should a solution output the number of pixels it checked?

@trichoplax you can certainly output that, if it makes counting the number of pixels it tests easier.   For scoring, I'd like algorithms to be deterministic, yes.

The barn.jpg image is 2600x1733 pixels yet you provide an (x,y) list [(1096,887),(1397,2226),(1402,2007),(1508,2161),(1702,1187)] that includes y values larger than 1733. Am I misunderstanding these lists?

@CarpetPython err....maybe I made them (y,x)?  Let me check

For the barn image, I get a pixel list of [(612, 1131), (690, 1155), (784, 1065), (888, 1106), (900, 1729), (903, 1099), (980, 1498), (1581, 1420), (1661, 1529), (1811, 1484), (2140, 1650)] for the (143, 91, 33) colour value. At least one of our programs has an error.

@CarpetPython Mine definitely had an error.  I'm not getting that many, but I am printing out (y,x) values instead of (x,y).  I've also separately verified that (887, 1096) has the correct value of (143, 91, 33)

I am still having problem replicating your result. My code: def findpixels(fname):     im = Image.open(fname+'.jpg');     px = im.load();     print 'TEST', px[(887, 1096)] using barn prints (142, 91, 38). Could you specify the origin (top left?) you are using? Maybe using 1-based rather than 0-based indexing?

You need im.convert('RGB')

I added im.convert('RGB') with same result. Python 2.7.10, Ubuntu Linux 64 bit. Can you verify that my code above (with convert) returns the expected colour on your machine?

Let us continue this discussion in chat.

Python, score: 14,035,624
First thing's first, here's the code:
from heapq import heappush, heappop
from PIL import Image
import random

random.seed(1)

def dist(x, y):
    return sum([(x[i] - y[i]) ** 2 for i in range(3)])

def gradient_descent(image_name, c):
    im = Image.open(image_name + '.jpg').convert('RGB')
    L = im.load()
    sx, sy = im.size
    heap = []
    visited = set()
    count = 0
    points = []
    for i in range(0, sx, sx / 98):
        for j in range(0, sy, sy / 98):
            points.append((i, j))
    for x in points:
        heappush(heap, [dist(c, L[x[0], x[1]]), [x[0], x[1]]])
        visited.add((x[0], x[1]))

    while heap:
        if count % 10 == 0:
            x = random.random()
            if x < 0.5:
                n = heap.pop(random.randint(10, 100))
            else:
                n = heappop(heap)
        else:
            n = heappop(heap)
        x, y = n[1]
        c_color = L[x, y]
        count += 1

        if c_color == c:
            p = float(len(visited)) / (sx * sy) * 100
            print('count: {}, percent: {}, position: {}'.format(len(visited), p, (x, y)))
            return len(visited)

        newpoints = []
        newpoints.append((x + 1, y))
        newpoints.append((x - 1, y))
        newpoints.append((x, y + 1))
        newpoints.append((x, y - 1))
        newpoints.append((x + 1, y + 1))
        newpoints.append((x + 1, y - 1))
        newpoints.append((x - 1, y + 1))
        newpoints.append((x - 1, y - 1))

        for p in newpoints:
            if p not in visited:
                try:
                    d = dist(c, L[p[0], p[1]])
                    heappush(heap, [d, [p[0], p[1]]])
                    visited.add(p)
                except IndexError:
                    pass

and here's a gif showing how the algorithm examines pixels:

So, here's what this code is doing: The variable heap is a priority queue of (x, y) coordinates in the image, sorted by the Euclidean distance of the color at that coordinate to the target color. It gets initialized with 10,200 points which are evenly distributed across the entire image.
With the heap initialized, we then pop off the point with the minimum distance to the target color. If the color at that point has a distance > 0, that is to say, if the color at that point is NOT the target color, we add the 8 surrounding points from it to heap. To ensure that a given point isn't considered more than once, we maintain the variable visited, which is a set of all the points that have been examined so far.
Occasionally, instead of directly taking the point with the minimum color distance, we'll randomly choose some other point from near the top of the queue. This isn't strictly necessary, but in my testing, it shaves off approximately 1,000,000 pixels from the total score. Once the target color is found, we simply return the length of the visited set.
Like @Karl Napf, I ignored the test cases where the specified color was not present in the image. You can find a driver program to run through all the test cases at the GitHub repository I created for this answer.
Here are the results from each specific test case:
barn
color: (143, 91, 33), count: 20388 / 0.452483465755%, position: (612, 1131)
color: (53, 35, 59), count: 99606 / 2.21061742643%, position: (1999, 1260)
color: (72, 49, 59), count: 705215 / 15.6512716943%, position: (1405, 974)

daisy
color: (21, 57, 91), count: 37393 / 0.154770711039%, position: (1877, 2131)
color: (169, 160, 0), count: 10659 / 0.0441179100089%, position: (2124, 759)
color: (113, 123, 114), count: 674859 / 2.79326096545%, position: (1119, 1335)
color: (225, 226, 231), count: 15905 / 0.0658312560927%, position: (3256, 889)
color: (17, 62, 117), count: 15043 / 0.0622634131029%, position: (2514, 3874)
color: (226, 225, 204), count: 138610 / 0.573710808362%, position: (1978, 1179)
color: (119, 124, 146), count: 390486 / 1.61623287435%, position: (2357, 917)
color: (2, 63, 120), count: 10063 / 0.0416510487306%, position: (2324, 3882)
color: (200, 167, 113), count: 16393 / 0.06785110224%, position: (1453, 1759)

dandelion
color: (95, 37, 33), count: 10081 / 0.0686342592593%, position: (1625, 1724)
color: (27, 41, 50), count: 2014910 / 13.7180691721%, position: (1267, 126)
color: (58, 92, 129), count: 48181 / 0.328029684096%, position: (1905, 756)
color: (136, 159, 105), count: 10521 / 0.0716299019608%, position: (1416, 3467)
color: (152, 174, 63), count: 10027 / 0.0682666122004%, position: (2256, 2558)
color: (69, 95, 130), count: 201919 / 1.37472086057%, position: (2708, 2943)
color: (150, 171, 174), count: 29714 / 0.202301198257%, position: (1180, 2706)

gerbera
color: (180, 153, 40), count: 21904 / 0.0906612910062%, position: (4459, 1644)
color: (116, 112, 149), count: 14896 / 0.0616549758413%, position: (5884, 252)
color: (222, 176, 65), count: 76205 / 0.315414704215%, position: (4313, 2097)
color: (108, 129, 156), count: 12273 / 0.0507983027994%, position: (5302, 3734)
color: (125, 99, 48), count: 26968 / 0.111621333814%, position: (5054, 2013)
color: (170, 149, 32), count: 89591 / 0.370819746281%, position: (4478, 1647)
color: (156, 185, 203), count: 177373 / 0.734151989118%, position: (4096, 368)
color: (103, 67, 17), count: 11035 / 0.0456741849093%, position: (4844, 1790)

hot-air
color: (48, 21, 36), count: 49711 / 0.24902994992%, position: (1990, 1095)
color: (104, 65, 36), count: 9927 / 0.0497298447599%, position: (3191, 1846)
color: (68, 59, 60), count: 195418 / 0.978957066918%, position: (3948, 470)
color: (82, 42, 32), count: 12216 / 0.0611967143737%, position: (4559, 984)
color: (192, 132, 72), count: 116511 / 0.583668171938%, position: (3103, 1844)

in-input
color: (204, 90, 1), count: 44058 / 0.248299807393%, position: (4695, 2559)
color: (227, 163, 53), count: 12654 / 0.0713147615132%, position: (221, 2384)
color: (196, 179, 135), count: 181534 / 1.02307996812%, position: (1030, 3486)
color: (208, 59, 27), count: 9956 / 0.0561095120614%, position: (4518, 2108)
color: (149, 70, 1), count: 13698 / 0.0771984829467%, position: (3731, 2408)
color: (168, 3, 7), count: 19381 / 0.10922644167%, position: (942, 398)
color: (218, 118, 4), count: 36648 / 0.206538911011%, position: (25, 2606)
color: (224, 230, 246), count: 1076427 / 6.06647185011%, position: (4482, 1442)
color: (213, 127, 66), count: 62673 / 0.353209265712%, position: (4701, 2579)

klatschmohn
color: (170, 133, 19), count: 11535 / 0.0724321530189%, position: (1034, 2633)
color: (162, 92, 4), count: 103795 / 0.651763790429%, position: (489, 2854)
color: (159, 175, 104), count: 10239 / 0.0642941321856%, position: (3098, 2481)
color: (171, 169, 170), count: 10119 / 0.063540611738%, position: (3674, 1490)
color: (184, 115, 58), count: 22425 / 0.140814133632%, position: (1958, 2404)
color: (228, 169, 5), count: 10449 / 0.0656127929688%, position: (1316, 2336)
color: (179, 165, 43), count: 10285 / 0.0645829816905%, position: (1842, 2498)
color: (67, 21, 6), count: 10206 / 0.0640869140625%, position: (2116, 2373)
color: (213, 100, 106), count: 11712 / 0.073543595679%, position: (1303, 1816)

tajinaste-rojo
color: (243, 56, 99), count: 126561 / 0.5273375%, position: (2241, 5424)
color: (114, 37, 19), count: 11285 / 0.0470208333333%, position: (1818, 3583)
color: (108, 117, 116), count: 33855 / 0.1410625%, position: (1269, 5672)
color: (163, 102, 101), count: 1058090 / 4.40870833333%, position: (1546, 4867)
color: (192, 192, 164), count: 10118 / 0.0421583333333%, position: (1919, 3171)
color: (92, 118, 45), count: 13431 / 0.0559625%, position: (3766, 5883)
color: (145, 180, 173), count: 1207713 / 5.0321375%, position: (1863, 955)

turret-arch
color: (116, 70, 36), count: 145610 / 3.23161258822%, position: (96, 671)
color: (183, 222, 237), count: 11704 / 0.259754094722%, position: (140, 604)
color: (237, 136, 82), count: 60477 / 1.34220338231%, position: (1063, 993)
color: (193, 199, 215), count: 359671 / 7.98240046163%, position: (2259, 953)
color: (33, 30, 25), count: 148195 / 3.28898308846%, position: (1307, 861)
color: (17, 23, 39), count: 10601 / 0.235274535044%, position: (2080, 1097)
color: (192, 139, 95), count: 219732 / 4.87664787607%, position: (1127, 970)
color: (176, 125, 98), count: 2471787 / 54.8578942696%, position: (147, 734)

water-lilies
color: (86, 140, 80), count: 10371 / 0.0717376936238%, position: (4542, 3005)
color: (218, 124, 174), count: 25655 / 0.177459312498%, position: (1910, 2457)
color: (197, 211, 186), count: 1144341 / 7.91557073177%, position: (4402, 1894)
color: (253, 242, 162), count: 14174 / 0.0980435897622%, position: (1672, 1379)
color: (111, 93, 27), count: 10405 / 0.0719728764975%, position: (2147, 2717)
color: (199, 157, 117), count: 10053 / 0.0695380420403%, position: (3096, 993)

Total: 14035624

This is a really good answer. Nice algorithm too.

That nearest neighbour search with multiple seeds is great! I also considered using a BFS over a DFS with a heap just like you, but the quadsearch is too broad.

Python, score: 396,250,646

While there are no PNGs to parse and there are still problems with the testcases, I decided to program anyway.
Those testcases where the value is not present in the image were ignored (checked against a traditional linear search, which had a score of 544,017,431)

from PIL import Image

def dist(x,y):
 d = 0
 for i in range(3):
  d += (x[i]-y[i])**2
 return d

def mid(x,y):
 return (x+y)/2

class Finder:
 def __init__(self, image_name, c):
  self.image_name = image_name,
  self.c = c
  self.found = False
  self.position = None
  self.im = Image.open(image_name+".jpg").convert("RGB")
  self.L = self.im.load()
  self.visited = set()

 def quadsearch(self,x0,x1,y0,y1):
  if x0==x1 and y0==y1: return
  xm=mid(x0,x1)
  ym=mid(y0,y1)
  R = [
   (x0,xm,y0,ym),
   (xm,x1,y0,ym),
   (x0,xm,ym,y1),
   (xm,x1,ym,y1),
   ]
  P = [(mid(t[0],t[1]), mid(t[2],t[3])) for t in R]
  DR = []
  for i in range(len(P)):
   p = P[i]
   if p in self.visited: continue
   self.visited.add(p)
   u = self.L[p[0], p[1]]
   d = dist(u, self.c)
   if d == 0:
    self.found = True
    self.position = (p[0], p[1])
    return
   DR.append((d,R[i]))
  S = sorted(range(len(DR)), key=lambda k: DR[k][0])
  for i in S:
   if self.found == True: return
   r = DR[i][1]
   self.quadsearch(r[0], r[1], r[2], r[3])

 def start(self):
  sx,sy = self.im.size
  self.quadsearch(0,sx,0,sy)

 def result(self):
  if self.found:
   count = len(self.visited)
   sx,sy = self.im.size
   ratio = float(count)/(sx*sy)
   print len(self.visited), ratio, self.position, self.L[self.position[0], self.position[1]], "=", self.c
  else:
   print self.c, "not found"

if __name__ == "__main__":
 image_name="turret-arch"
 c=(116,70,36)
 F = Finder(image_name, c)
 F.start()
 F.result()

It is a recursive quad-section search. Sometimes it finds the correct value in a few percent, sometimes over 75%. Here are the results for all testcases:
pixels_visited, percentage, (position) (RGB at position) = (RGB searched)
tajinaste-rojo
1500765 0.062531875 (2329, 5146) (243, 56, 99) = (243, 56, 99)
(147, 157, 210) not found
335106 0.01396275 (2116, 5791) (114, 37, 19) = (114, 37, 19)
1770396 0.0737665 (1269, 5672) (108, 117, 116) = (108, 117, 116)
(214, 197, 93) not found
8086276 0.336928166667 (1546, 4867) (163, 102, 101) = (163, 102, 101)
12859 0.000535791666667 (1476, 4803) (192, 192, 164) = (192, 192, 164)
7505961 0.312748375 (3766, 5883) (92, 118, 45) = (92, 118, 45)
15057489 0.627395375 (1871, 1139) (145, 180, 173) = (145, 180, 173)
(181, 124, 105) not found
in-input
35754 0.00201500551852 (4695, 2559) (204, 90, 1) = (204, 90, 1)
5029615 0.283456451895 (10, 2680) (227, 163, 53) = (227, 163, 53)
6986547 0.393744217722 (1383, 3446) (196, 179, 135) = (196, 179, 135)
1608341 0.090642053775 (4518, 2108) (208, 59, 27) = (208, 59, 27)
581774 0.0327873194757 (3750, 2798) (149, 70, 1) = (149, 70, 1)
1302581 0.0734101891628 (4374, 1941) (168, 3, 7) = (168, 3, 7)
6134761 0.345739701008 (25, 2606) (218, 118, 4) = (218, 118, 4)
(127, 153, 4) not found
9760033 0.550050913352 (4482, 1442) (224, 230, 246) = (224, 230, 246)
212816 0.0119937745268 (4701, 2579) (213, 127, 66) = (213, 127, 66)
water-lilies
5649260 0.390767412093 (4577, 3019) (86, 140, 80) = (86, 140, 80)
12600699 0.871608412215 (1910, 2457) (218, 124, 174) = (218, 124, 174)
(191, 77, 50) not found
3390653 0.234536328318 (4402, 1894) (197, 211, 186) = (197, 211, 186)
(236, 199, 181) not found
7060220 0.488365537823 (1672, 1379) (253, 242, 162) = (253, 242, 162)
(114, 111, 92) not found
6852380 0.473988947097 (2147, 2717) (111, 93, 27) = (111, 93, 27)
(139, 92, 102) not found
14105709 0.975712111261 (3096, 993) (199, 157, 117) = (199, 157, 117)
dandelion
(55, 2, 46) not found
9094264 0.619162854031 (1637, 1721) (95, 37, 33) = (95, 37, 33)
2358912 0.16060130719 (1526, 3129) (27, 41, 50) = (27, 41, 50)
11729837 0.798600013617 (1905, 756) (58, 92, 129) = (58, 92, 129)
6697060 0.455954520697 (2246, 2685) (136, 159, 105) = (136, 159, 105)
6429635 0.437747480937 (2148, 2722) (152, 174, 63) = (152, 174, 63)
(78, 49, 19) not found
(217, 178, 205) not found
80727 0.00549611928105 (2481, 3133) (69, 95, 130) = (69, 95, 130)
239962 0.0163372821351 (2660, 917) (150, 171, 174) = (150, 171, 174)
turret-arch
210562 0.0467313240712 (725, 655) (116, 70, 36) = (116, 70, 36)
(121, 115, 119) not found
2548703 0.565649385237 (140, 604) (183, 222, 237) = (183, 222, 237)
150733 0.033453104887 (2165, 601) (237, 136, 82) = (237, 136, 82)
3458188 0.767497003862 (2259, 953) (193, 199, 215) = (193, 199, 215)
2430256 0.539361711572 (265, 1222) (33, 30, 25) = (33, 30, 25)
638995 0.141816103689 (1778, 1062) (17, 23, 39) = (17, 23, 39)
2506522 0.556287895601 (1127, 970) (192, 139, 95) = (192, 139, 95)
1344400 0.298370988504 (147, 734) (176, 125, 98) = (176, 125, 98)
(178, 83, 0) not found
hot-air
17474837 0.875411434688 (1992, 1029) (48, 21, 36) = (48, 21, 36)
1170064 0.0586149905099 (3191, 1846) (104, 65, 36) = (104, 65, 36)
(169, 89, 62) not found
11891624 0.595717352134 (3948, 470) (68, 59, 60) = (68, 59, 60)
(198, 96, 74) not found
(136, 43, 53) not found
12476811 0.625032612198 (4387, 1126) (82, 42, 32) = (82, 42, 32)
4757856 0.238347376116 (3105, 1822) (192, 132, 72) = (192, 132, 72)
(146, 21, 63) not found
(125, 64, 36) not found
daisy
5322196 0.220287235367 (2171, 2128) (21, 57, 91) = (21, 57, 91)
(201, 175, 140) not found
22414990 0.9277629343 (2124, 759) (169, 160, 0) = (169, 160, 0)
20887184 0.864526601043 (1119, 1335) (113, 123, 114) = (113, 123, 114)
595712 0.0246566923794 (2656, 1349) (225, 226, 231) = (225, 226, 231)
3397561 0.140626034757 (2514, 3874) (17, 62, 117) = (17, 62, 117)
201068 0.00832226281046 (1978, 1179) (226, 225, 204) = (226, 225, 204)
18693250 0.773719036752 (2357, 917) (119, 124, 146) = (119, 124, 146)
3091040 0.127939041706 (2165, 3881) (2, 63, 120) = (2, 63, 120)
3567932 0.147677739839 (1453, 1759) (200, 167, 113) = (200, 167, 113)
barn
314215 0.0697356740202 (784, 1065) (143, 91, 33) = (143, 91, 33)
2448863 0.543491277908 (1999, 1260) (53, 35, 59) = (53, 35, 59)
(20, 24, 27) not found
(167, 148, 176) not found
(137, 50, 7) not found
(116, 95, 94) not found
2042891 0.453391406631 (1345, 858) (72, 49, 59) = (72, 49, 59)
(211, 163, 175) not found
(30, 20, 0) not found
(88, 36, 23) not found
klatschmohn
3048249 0.191409829222 (3683, 3439) (170, 133, 19) = (170, 133, 19)
1057649 0.0664133456509 (489, 2854) (162, 92, 4) = (162, 92, 4)
2058022 0.129230138206 (3095, 2475) (159, 175, 104) = (159, 175, 104)
(199, 139, 43) not found
2060805 0.129404892156 (3674, 1490) (171, 169, 170) = (171, 169, 170)
7725501 0.485110247577 (1958, 2404) (184, 115, 58) = (184, 115, 58)
2986734 0.187547095028 (1316, 2336) (228, 169, 5) = (228, 169, 5)
497709 0.0312528257017 (3879, 2379) (179, 165, 43) = (179, 165, 43)
3996978 0.250983720944 (2157, 2318) (67, 21, 6) = (67, 21, 6)
3332106 0.209234167028 (1303, 1816) (213, 100, 106) = (213, 100, 106)
gerbera
(218, 186, 171) not found
9445576 0.390955128952 (4377, 1750) (180, 153, 40) = (180, 153, 40)
(201, 179, 119) not found
6140398 0.254152853347 (5742, 576) (116, 112, 149) = (116, 112, 149)
6500717 0.269066561215 (4233, 1541) (222, 176, 65) = (222, 176, 65)
13307056 0.550782905612 (5302, 3734) (108, 129, 156) = (108, 129, 156)
13808847 0.571552180573 (5058, 2023) (125, 99, 48) = (125, 99, 48)
9454870 0.391339810307 (4478, 1647) (170, 149, 32) = (170, 149, 32)
2733978 0.113160142012 (4096, 368) (156, 185, 203) = (156, 185, 203)
11848606 0.490417237301 (4844, 1790) (103, 67, 17) = (103, 67, 17)


text:
Nine Nines of Uptime
Uptime is a very important metric, as we all know, so we'd like to measure the uptime since our service was first launched. The SLA specifies an uptime of a certain number of nines, such as 3 nines for at least 99.9% uptime, or 1 nine for at least 90% uptime, and you're wondering if you've actually met the SLA or not. Since you know the service went down last friday night when someone pushed to production, and since this is basically standard practice here, you figure there's no need for your code to handle 100% uptime as a special case.
Everytime a server stops or starts, Nagios sends you an email. The service in question has some level of fault tolerance, so only m servers have to be online for the service to be available. You just wrote a quick script to extract the important information from these emails. Now it's time for the fun part, and you're in the mood for golfing.
Your task is to write a program or function that analyzes the input, figures out the uptime, and prints the largest integer number of nines achieved by the service.
Input:

The number of servers required to be running for the service to be considered online: m > 0.
Followed by at least one line, one for each server. Each line contains start/stop times for that server. Since we've measured this since the service was launched, the first number is the time the server started the first time. The second time is a stop time, the third another start time etc.
No single server is ever started and stopped at the same time.
This means that if the server is currently running, you haven't gotten an email about it shutting down yet, so the number of numbers on that line would be odd.
The lines are sorted, but the ordering between different lines is not enforced.
The input is EOF-terminated. The last character of the input will be \n followed by EOF (ctrl+D).
The time starts at time 0 and ends at the last recorded start/stop of a single server, since that's all the information we have so far. This can be done by adding max(last number on each line) to the end of all odd-length lines.
Time is discrete.
All input numbers are guaranteed to fit inside a 32bit integer.
The service will never have 100% uptime.
If you would like to add an integer telling you how many servers there are, you may do so. You may also add an integer in the beginning of each server line telling you how many measurements there are for that server. See example in first testcase. You may also use whatever native format you'd like.

Output:
The output consists of a single integer; the highest number of nines that you can guarantee you had in hindsight, i.e. 3 for at least 99.9% uptime or 4 for at least 99.99% uptime.
Testcases:
First:
1
0 5 8 10
0 1 7

-> 1

First, with counts (if you prefer that):
1 2
4 0 5 8 10
3 0 1 7

-> 1

Second:
1
0 999 1001 2000

-> 3

Third:
3
0 42

-> 0

Reference implementation: (Python 2)
"""
Slow and huge, but useful for checking smaller inputs.

input: m, followed by n lines of start and stop times, all servers are turned off in the beginning, all numbers fit inside 32bit signed integers, counts are optional
output: number of nines of uptime

example:
1
0 5 8 9
0 1 7
parsed:
1st node: on 0:5, 7:9
2nd node: on 0:1, 6:9
at least one server is running during:
0:5, 7:9
known time interval: 0:9, only timestep 6 is down, so 90% uptime during the part we can see.
output:
1

"""

import sys

def rangeify(l):
    res = []
    for i in range(0, len(l), 2):
        res += range(l[i], l[i + 1] + 1)
    return res

def parse():
    m = input()
    lines = [map(int, x.split()) for x in sys.stdin.read().split("\n")[:-1]]
    if not lines:
        return [], m
    top = max(map(max, lines))
    nlines = [x + [top] if len(x) % 2 else x for x in lines]

    n2lines = map(rangeify, nlines)
    return n2lines, m

def flatten(ls):
    res = []
    for l in ls:
        res += l
    return sorted(res)

def join(ups):
    res = {}
    for up in ups:
        if up not in res:
            res[up] = 0
        res[up] += 1
    return res

def bin(ups, m):
    res = []
    for up in range(max(ups)+1):
        res += [up in ups and ups[up] >= m]
    return res

def nines(a):
    s = ("%.15f" % a)[2:]
    s2 = s.lstrip("9")
    return len(s) - len(s2)

def solve(l, m):
    if len(l) < m:
        return nines(0)
    b = bin(join(flatten(l)), m)
    return nines(sum(b) / float(len(b)))

print solve(*parse())

A few nitpicks: 1) EOF is not an actual byte in a stream - it's a signal from the I/O library back to the code to inform you that the end of file has been reached. 2) This challenge would be a lot better if you were more flexible with the input format (allowing lists/arrays and such instead of requiring string parsing, which detracts from the actual challenge). You should post challenges in the Sandbox to get feedback before posting on Main.

Thought I'd avoided the cumbersome I/O format by allowing lengths to be inserted, but no. Added clarification allowing any native input format. Thanks @Mego

The first test case only computes to 80% uptime when I try.

@Neil you're trying to figure out the maximum possible uptime. If a service goes down at 12:00 you of course assume that this is 12:00:59, as that might actually have been the case.

Ah, so the time ranges include the whole stop minute? I hadn't understood that before. I've updated my answer appropriately.

JavaScript (ES6), 161 bytes
(m,a)=>a.map(b=>b.map(n=>l=n>l?n:l),l=0)|a.map(b=>c.map((_,i)=>{k=b[j]==i;j+=k;n^=k;c[i]+=n|k},j=n=0),c=Array(++l).fill(0))|Math.log10(l/c.filter(n=>n<m).length)

Accepts an integer representing the minimum number of concurrent servers and an array of arrays representing the start and stop times of each server. Edit: Now uses inclusive ranges, so correctly returns 1 for the first example.

Pyth - 26 bytes
/`.Omgsm%lf<dTk2.QQeSs.Q`9

Try it online here.


text:
Include a JavaScript script with JavaScript
To dynamically include a JavaScript file in a web page, you'd normally insert a <script> tag pointing to your script. For example:
var js_file= document.createElement("script");
js_file.src='http://example.com/js.js';
document.body.appendChild(js_file);

Write JavaScript code will load an external JavaScript file in the current page and:

Shortest valid answer wins
The file is hosted on https://pastebin.com/raw/rV6dDDj9 (content is console.log('Good job!');)
The code must be vanilla JavaScript (no jQuery, etc.)
Answer validity test is done in the web browser console. Criteria:

URL requested and JS file downloaded.
Console prints Good job!

Welcome to PPCG! Unfortunately, I think this challenge has some problems. Are URL shorteners allowed? Do you expect any possible improvement beyond that? I don't know enough about javascript to be sure, but it looks fairly cut-and-dry. Just so you know, we have a Sandbox where you can post to receive feedback on your challenge before posting to the main site.

quite broad....

@FryAmTheEggman Thanks. I originally thought shortners wouldn't be allowed because I specified the exact URL, but I guess it's not an issue since people are using them. @ Bald You're welcome to give specific suggestions on the broad areas so I can try to limit the scope

@FryAmTheEggman This question is pretty trivial...

Can we assume the page is using jQuery? One answer is assuming so, but I think this is a loophole.

I still think this isn't a good question. Currently I'm winning, because I could register a very short domain.

@Bálint You're not winning because your answer isn't valid according to the criteria mentioned in the question. Check my comment under your answer. Also, numerous answers on this site include short domains and shortened URLs, so it seems to be an accepted practice.

Could you please clarify if the jQuery answer is valid? The poster seems to interpret the current page as this page, which differs from my interpretation.

@Dennis I think your interpretation was indeed my original intention. I included that explicitly now. I hadn't anticipated that code-golfing involves using semantic loopholes in the wording of the question. I guess my next question would definitely be better.

You accepted the answer so early!?! You should have given it at least 4 or 5 days or a whole week!

Downvoting because the challenge requires the use of sketchy link shorteners.

77 75 71 bytes

with(document)body.appendChild(createElement`script`).src=`//v.ht/Xa33`

Edit: Saved 2 bytes thanks to @jrich. Saved 4 bytes thanks to @Bálint.

createElement("script") can become createElement\script``

The with(document) is ingenious. I did not think of that!

I wouldn't have imagined that the appendChild would return a reference to the appended Node. This alone saved a lot of bytes. Thanks you very much for teaching something new.

Use this url instead:  v.ht/Xa33

@jrich I think your tip would make a great addition here https://codegolf.stackexchange.com/questions/2682/tips-for-golfing-in-javascript

@Adi http://codegolf.stackexchange.com/a/52204/17602

49 bytes
document.write`<script src=//v.ht/KvtI></script>`

no one clearly said: you should keep current page content

75 bytes
document.body.appendChild(document.createElement`script`).src="//v.ht/Xa33"

@Neil's answer was quite similar to this, but he found an ingenious shortcut involving with(...). I will not copy it here, because he came up with it.
Thanks to @Bálint for the short URL.

OK, I've done it.

72 bytes
(D=document).body.appendChild(D.createElementscript).src="//v.ht/Xa33"
for using more than once(3 call):
92 then always 36
(D=document)[B="body"][A="appendChild"](D[C="createElement"](s="script")).src="//v.ht/Xa33";
D[B][A](D[C](s)).src="//v.ht/Xa33";
D[B][A](D[C](s)).src="//v.ht/Xa33"

93 then always 35
D=document,B=D.body,B.a=B.appendChild,D.c=D.createElement;
B.a(D.c`script`).src="//v.ht/Xa33";
B.a(D.c`script`).src="//v.ht/Xa33";
B.a(D.c`script`).src="//v.ht/Xa33";
99 then always 30
D=document,B=D.body,B.a=B.appendChild,D.c=D.createElement,s="script";
B.a(D.c(s)).src="//v.ht/Xa33";
B.a(D.c(s)).src="//v.ht/Xa33";
B.a(D.c(s)).src="//v.ht/Xa33";

99 then always 26
D=document,A=e=>D.body.appendChild(e),C=e=>D.createElement(e),s="script";
A(C(s)).src="//v.ht/Xa33";
A(C(s)).src="//v.ht/Xa33";
A(C(s)).src="//v.ht/Xa33";

87 then always 15

S=e=>document.body.appendChild(document.createElement("script")).src=e;
S`//v.ht/Xa33`;
S`//v.ht/Xa33`;
S`//v.ht/Xa33`;

88 then always 22
S=e=>document.body.appendChild(document.createElement("script"));
S().src="//v.ht/Xa33";
S().src="//v.ht/Xa33";
S().src="//v.ht/Xa33";

This is only trivially different from the current winning submission, and it's longer.

89 bytes
n=[];for(i in d=document)n.push(i);d.body[n[173]](d[n[41]]`script`).src=`//goo.gl/rPQ0Jk`

This is incredibly browser-dependent. Actually even worse than that, it pretty much only works on codegolf.stackexchange.com, in the browser console, in FireFox. Ah well.
Please don't get too mad when it (likely) doesn't work on your particular browser configuration, since if it is even slightly different from mine it could fail.
(yeah, probably invalid because of that. Not going to win anyway.)

If you're going to limit yourself to Firefox, n=[x for(x in document)] works in Firefox 45 and earlier.

In theory this could get it down to 77 bytes, but I don't have that version to test. n=[x for(x in d=document)];d.body[n[173]](d[n[41]]\script`).src=`//v.ht/Xa33``

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