text:
Retina or Trash?
We live in a wonderful age of technology where we can have beautifully detailed 8K screens on our TVs, and even 2K displays on our phones for our mobile browsing pleasure. We've come a long way in recent years in terms of screen technology.
One of the products of this is a term that was made popular by Apple, Retina. This is referring to the pixel density of the display in question being so high, that at a viewing distance of 10-12 inches away, individual pixels cannot be easily picked out.
Steve Jobs said that the pixel density where this occurs is right around 300 pixels per inch, and they started employing pixel densities in this range on their devices with the Retina buzzword used for advertising.
Pixel density can be calculated by the following formula:

Where d is the diagonal of the screen in inches, w is the number of pixels on the horizontal axis, and h is the number of pixels on the vertical axis.
Your Task
For this task, you'll be using the Retina standard to decide what products are worth buying. Being the modern consumer that you are, when you shop for devices you want to make sure that you're getting a good product, not some device from the 90s! As such, you want to build a program or function that takes the screen width, height and diagonal length as input or function parameters, and tells you whether the particular screen qualifies as a retina screen (D > 300) by printing to the screen or returning.
Due to your contempt for non-Retina devices, your program or function will output Retina! when the device qualifies, and Trash! when it does not.
You may assume that all of the numbers will be greater than 0. Pixel values for width and height will always be whole numbers. Screen size may be interpreted in any way, as long as it supports decimals. The input may be in any order you choose, and may also be on up to 3 separate lines.
Example I/O
1920 1080 4.95   -> Retina!
2560 1440 5.96   -> Retina!
1920 1080 10.5   -> Trash!
10 10 0.04       -> Retina!
4096 2160 19(.0) -> Trash!
8192 4320 100.00 -> Trash!
3000 1500 11.18  -> Retina!
180 240 1(.0)    -> Trash!

This is code-golf, so the fewest number of bytes wins.

Here's a Stuck solution, a stack based programming language I'm making:
r;`;/300>"Retina!""Trash!"?

Someone, please, do a Retina answer

@DigitalTrauma But floats.

@Sp3000 pfft, excuses!. Build your own float parsing regex in Retina!

@Sp3000 Okay, lets raise the stakes.  I hereby promise to slap a big juicy 500 pt bounty on the shortest legal (community consensus) Retina answer to this question one week from this comment posting timestamp.

Hmm, the threshold chosen doesn't quite match Apple's marketing, e.g. for the Retina iMac: 5120 2880 27

@EdAvis Outside this particular challenge, the Retina criterion is defined as pixels per distance to the eye, not pixels per inch. Phones are held closer to the eye than laptop screens, which are in turn place closer than desktop screens. (For example, in CSS, 1px is the round number of hardware pixels close to 1/2700 viewing distance.) A new challenge that follows the real definition would take into account viewing distance as well.

Pyth - 27 bytes
Uses ternary operator and abs to calculate pythagorean.
?>c.avzQ300"Retina!""Trash!

Takes input in two lines, first line width, height, second line diag.
The rules were relaxed so rolling back.
Try it online here.

Retina, 530 220 210 202 201 193 191 187 185 (184) bytes
Credits to randomra for saving 3 bytes! (And paving the way for a couple more.)
+`\.(\d)(.+)( .+)
$1.$2_$3_
\b
#
+`(\d*)#((((((((((9)|8)|7)|6)|5)|4)|3)|2)|1)|\w)
$1$1$1$1$1$1$1$1$1$1$3$4$5$6$7$8$9$10$11#
\d
11
(?=(1*)\1)[^.]
$1
^(1+)\.\1{90000}1+
Retina!
1.+
Trash!

For byte-counting purposes, each line goes in a separate file, but you can run the above code as is from a single file by invoking Retina with the -s flag.
This expects the density first (which must contain a decimal point, even if it's a trailing one), followed by width and height, i.e. d w h.
This is a bit slow. I wouldn't try most of the given test cases, because it will run for ages. However, you can check that it works correctly with the test cases
19. 4096 2160     -> Trash!
1. 180 240        -> Trash!
1. 181 240        -> Retina!
1. 180 241        -> Retina!
0.04 10 10        -> Retina!

Basically, after multiplying all numbers through to make the density an integer, you don't want the width and height to have more than 4 digits.
While this is slow, it is completely exact... there are no floating point issues or anything like that. All arithmetic is using (unary) integers.
In principle, I could shave off one more byte: the ^ can be omitted, but it will make Trash! test cases horribly slow due to excessive amounts of backtracking.
Explanation
First, let's rearrange the inequality to avoid floating point operations:
√(w2 + h2) / d > 300
√(w2 + h2) > 300 d
w2 + h2 > 90000 d2

We can also notice that this is invariant under multiplying w, h and d by the same number x:
w2 + h2 > 90000 d2
(x w)2 + (x h)2 > 90000 (x d)2
x2 (w2 + h2) > 90000 x2 d2
w2 + h2 > 90000 d2

There are several ways to square a unary number, but we'll be making use of the identity
n2 = Σi=1..2n ⌊i/2⌋

This gives us a way to solve the problem using only integer arithmetic (representing integers in unary).
Let's go through the code. Each pair of lines is a regex substitution.
+`\.(\d)(.+)( .+)
$1.$2_$3_

This repeatedly moves the decimal point in the density to the right while multiplying width and height by 10 (the x above). This is to ensure that all numbers are integers. Instead of appending zeroes, I'm appending _, which I'll be treating as zero later on. (This is a golfing trick, because otherwise I'd need to write ...${3}0 to avoid ambiguity with $30.) The + in front of the regex tells Retina to repeat this substitution until the result stops changing (which is the case when the pattern no longer matches).
\b
#

We're preparing the three numbers for conversion to unary now. In principle, we need a marker (the #) in front of each number, but it's shorter to add one to the end of each number as well, which won't affect the conversion step.
+`(\d*)#((((((((((9)|8)|7)|6)|5)|4)|3)|2)|1)|\w)
$1$1$1$1$1$1$1$1$1$1$3$4$5$6$7$8$9$10$11#

This is the conversion to unary, using a trick that has been developed by dan1111. Essentially I'm translating each digit to a rep-digit of itself, while multiplying the existing digits by 10 (moving the # marker to the right in the process). This binary representation will be quite a jumble of different digits, but the total number will be equal to the value of the original integer. Note the \w at the end - normally this is just 0, but we want to treat _ as zero as well (which is considered a word character in regex).
\d
11

We turn each digit into two 1s, thereby a) ensuring all digits are the same (which will be necessary later) and b) doubling each of the numbers.
(?=(1*)\1)[^.]
$1

This does two things: it squares all numbers (or rather half of each number, by computing a sum over 2n), and adds the resulting squares of the width and the height. Notice that [^.] matches 1s, # markers and spaces. If it's a # or a space, the lookahead won't capture anything, which means all of those are simply removed, i.e. the results for the width and height are concatenated/added. The decimal point . remains to separate the result for d from those. If [^.] matches a 1 instead, then the lookahead ensures that we capture half of the 1s after it (rounded down) in group 1. This computes the sum I mentioned above, which will then yield the square of the original number.
^(1+)\.\1{90000}1+
Retina!

The string is now d2 (in unary), then ., then w2 + h2 (in unary). We want to know if the first unary number times 90000 is shorter than the second. We can easily do this multiplication using a capturing group and {n} repetition syntax. We use 1+ (instead of 1*) afterwards to ensure that the second number is actually greater than that and not just equal. If so, we replace all of that by Retina!.
1.+
Trash!

If the second number wasn't big enough, then the previous step won't have changed anything and the string will still start with a 1. If that's the case, we just replace the entire string by Trash! and are done.

Well, it happened. Now we can all die happy.

As a side note, since this is Retina, does that make all the other answers trash?

Our god has arrived!

OK, so my bounty promise still stands, but I would like to see a thorough explanation (conceptually I think I know how its done, but would like to see the details).  Also I'll award the bounty to the shortest legal Retina answer, so, folks, the bounty is still open to shorter Retina answers!

This is great. You really need to add an operator for int <> string conversions, though (what about ^^ like rs?).

@kirbyfan64sos I have several ideas for how to implement it in Retina (special operators for the replacement string is one of them), but I'm not sure which way to go yet, and in either case, it would need some preparation in the code base. Some day though...

@AlexA. No, because there's another Retina answer.

But in practice the only thing that could beat this is porting Retina to the TRaSh-80.

Here's your bounty.  Only one more upvote needed for the 100 badge too!

Python, 49
lambda w,h,d:"RTertaisnha!!"[w*w+h*h<=9e4*d*d::2]

Uses string interleaving.
It turned out shorter to square both sides than to use the complex norm.
w*w+h*h<=9e4*d*d
abs(w+1j*h)<=300*d

We were supposed to print either Retina! or Trash!! Not retweet @ertaisnha!!

Relevant.

@Mew but that is the opposite ;)

Nice, I haven't yet seen that (ab)use to print one or another string

CJam, 30 29 27 bytes
q~mh300/<"Retina""Trash"?'!

Requires input to be in form of diagonal width height
UPDATE: 1 byte saved thanks to Dennis!
Try it online here

Retina, 312 bytes
(\d+) (\d+) (\d+)(?:\.(\d+))?
a$1bc$2dj300ke$3fg$4h9iiiiiiiii8iiiiiiii7iiiiiii6iiiiii5iiiii4iiii3iii2ii1i0
+`(b.*)(d.*)fg(\d)
0$10$2$4fg
+`(a|c|e|j)(\d)(\d*)(i*)((?:b|d|f|k).*h.*\2(i*))
$1$3$4$4$4$4$4$4$4$4$4$4$6$5
g`(i+)
Q$1R$1
+`Q(i+)Ri
$1Q$1R
+`(j(i*).*e)i(.*f)
$1$3$2
a(i*).*c(i*).*f\1\2.*
Trash!
.*0
Retina!

This does take quite a while to run, but it seems to work.
Probably could be golfed a lot more...
Explanation:
(\d+) (\d+) (\d+)(?:\.(\d+))?
a$1bc$2dj300ke$3fg$4h9iiiiiiiii8iiiiiiii7iiiiiii6iiiiii5iiiii4iiii3iii2ii1i0

Add tags to make the string more convenient to parse, and add some junk to make it easier to convert to base 1, and add a 300 to multiply by later
+`(b.*)(d.*)fg(\d)
0$10$2$4fg

Append 0s to the width and height, while appending the decimal part of the diagonal to the integer part.  When this is done, the diagonal will be an integer, and the width and height will be multiplied by however many 10s were necessary.
+`(a|c|e|j)(\d)(\d*)(i*)((?:b|d|f|k).*h.*\2(i*))
$1$3$4$4$4$4$4$4$4$4$4$4$6$5

Convert all numbers to base 1, using the lookup-table I appended in the first step
g`(i+)
Q$1R$1

Prepare to square all of the numbers
+`Q(i+)Ri
$1Q$1R

Square each number
+`(j(i*).*e)i(.*f)
$1$3$2

Multiply the square of the diagonal by the square of the 300 we inserted in the first step
a(i*).*c(i*).*f\1\2.*
Trash!

If the width appended to the height fits in the product we just computed, the pixel density is too low, and it's Trash!
.*0
Retina!

Otherwise, it's Retina!

JavaScript ES6, 49 bytes
(w,h,d)=>Math.hypot(w,h)/d>300?'Retina!':'Trash!'

I hate that JavaScript has such long math operators. But even if there was a Math.pythagorean this would be shorter.

Someone mind explaining downvote?

Probably for being too long.

Just saw your answer after posting mine... congratulations on beating me to it :-P

@ThomasKwa Python is just 1 byte shorter

@Optimizer This was seventy-something bytes earlier; also the Python answer is better golfed.

@ThomasKwa yeah, I relized that quickly

Instead of calculating the square root, it might be shorter if you compare the squares of the values.

@RetoKoradi Yes, it is shorter: (w,h,d)=>w*w+h*h>9e4*d*d?'Retina!':'Trash!'

APL, 40 36 bytes
Saved 4 bytes thanks to Dennis!
{(9E4×⍵*2)<+/⍺*2:'Retina!'⋄'Trash!'}

This creates an unnamed dyadic function that takes the first two arguments on the left and the third on the right. It checks whether the sum of the squares of the left values is greater than 300^2 times the square of the right one. Output is printed accordingly.
You can try it online!

Should have refreshed before posting... You can save a few bytes byte taking the first two arguments on the left.

@Dennis Thanks for your help! I considered deleting my answer when I saw yours because yours was better. :P

TI-BASIC, 43
Takes width and height through the homescreen as a two-element list, and diagonal through Input.
Input D
If 300D>√(sum(Ans²
Then
Disp "Retina!
Else
"Trash!

TI-BASIC's two-byte lowercase letters add 7 bytes (i, being the imaginary unit, is one byte) cause it to be quite uncompetitive. Thankfully, ! is also one byte because it represents the factorial function.

Excel, 44 bytes
Type your inputs in these cells.

A1 = Width in pixels
B1 = Height in pixels
C1 = Diagonal in inches

And this formula gives your result:
=IF((300*C1)^2<A1^2+B1^2,"Retina!","Trash!")

I attempted to golf 2 bytes out of this by typing 9E4*C1^2 instead of (300*C1)^2 ... this yields a length of 42. However, typing 9E4 in a formula in Excel, will be changed to 90000 as soon as you hit enter. :(

Prolog, 51 bytes
a(W,H,D,R):-9e4*D*D<W*W+H*H,R="Retina!";R="Trash!".

Running a(8192,4320,100.0,R). outputs: R = "Trash!" .
Edit: Thanks to @PaulButcher for correcting an edge case and golfing one byte.

This returns "Retina!", when density is 300 (e.g. 180 240 1 -> Trash!) from the example.  Fortunately, since you can shave off two characters with e notation, changing > to >= leaves it at 52: b(W,H,D,R):-9e4*D*D>=W*W+H*H,R="Trash!";R="Retina!".

@PaulButcher Using 9e4 instead of 90000 actually shaves off 2 characters, not one. So you effectively shortened my answer by one byte as well as correcting this edge case, thanks.

Well done!  It's good to see a reasonably short Prolog example.

@PaulButcher Shaved one more byte by actually using < instead of >= and swapping the two string results...

O, 40 37 bytes

jjjrmd\/'īu>{"Retina!"p}{"Trash!"p}?

A lot of bytes for the input formatting :\
Try it online

JavaScript (ES6), 45 bytes
f=(w,h,d)=>w*w+h*h>d*d*9e4?'Retina!':'Trash!'

CoffeeScript, 47 bytes
No ternary operator, but there is exponentiation (which doesn't help in the latest attempt).
f=(w,h,d)->w*w+h*h>d*d*9e4&&'Retina!'||'Trash!'

# Previous attempt
f=(w,h,d)->(w*w+h*h)**.5/d>300&&'Retina!'||'Trash!'

Per the spec, it isn't necessary to have the function named (f=). You can cut off 2 bytes in all versions.

Pure Bash (no bc/other external commands), 138 136 135 82 83 bytes
a=${3#*.}
d=${a//?/0}
r=(Trash Retina)
echo ${r[$1$d**2+$2$d**2>90000*${3/./}**2]}!

I decided to try doing it in pure bash. I've probably made a few obvious inefficiencies as this is my first time code golfing, but I am VERY familiar with bash and have had fun in the past trying to write things that don't use any external commands (ie pure bash).
The printf statement is the most annoying. Anyone got any better ideas for padding numbers with zeroes?
EDIT: Saved two bytes, turns out printf will take an empty argument for zero. Saved another byte, turns out I'd previously miscounted and just assigning the output of printf to a variable is smaller than using -v.
EDIT2: Thanks to Digital Trauma in the comments, this is now down much more significantly. Tricks: using bash's regex support to replace the string of digits with zeroes instead of counting it then printing that number of zeroes (seems obvious when I put it like that...), storing the strings in a bash array to save an echo, and taking into account a slight change in rules that means you can end all input numbers in .0.
EDIT3: Added a byte to fix bug introduced by Digital Trauma's suggested modification.

Something like this for a score of 102: a=${3#*.};d=${a/./0};((${#a}-${#3}))||d=;r=(Trash Retina);echo ${r[$1$d**2+$2$d**2>90000*${3/./}**2]}!  (you can replace the ; with newlines - I was just trying to get it in a comment).

And if you assume density whole-numbers will end in .0 (ok, I think) then you can score 82: a=${3#*.};d=${a/./0};r=(Trash Retina);echo ${r[$1$d**2+$2$d**2>90000*${3/./}**2]}!

The original example had some that didn't end with .0, but I notice the question has now been modified, so that'll save quite a bit. Thanks for the ideas! I especially like your idea for cutting down the two echo statements; I was trying to work out how to do that, for some reason it didn't occur to me to use an array! For some reason, it ALSO never occurred to me that you could use **... I'll try and verify your answer, I'm a little confused about how $d is working here but I'll figure it out.

The $d is not too tricky.  a contains the digits of the density after the decimal point. d=${a/./0} just replaces all those digits with zeros.  Thus we can concat those zeros to the end of w and h to multiply by the same power of ten that is achieved by removing the decimal point from d.

Ah, I finally see — I couldn't get my head around . being a regex in this context! I was assuming you were trying to remove the point or something, forgetting it had already gone... I don't know the etiquette here, should I edit my answer to include your solution?

I wouldn't have posted the suggestions if I didn't want you to use them :)

Actually the . in ${a/./0} isn't a regular expression.  Its a shell pattern expression - similar function to regular expressions, but different syntax and less powerful. But you're VERY familiar with bash and already knew that :-P

OK, now I'm more confused then... what exactly is that line doing? It looks like it's replacing a dot with a zero, but that doesn't quite make sense since a (should) contain no dots. Surely something like ${a//?/0} would make more sense? I've tried that code out and that line doesn't seem to do anything at all... (that's why I was saying it being a regex confused me, since I assumed it was working by replacing all characters with zero! But . isn't a thing in globbing, as your link points out; only ? is).

Yes, I'm confused too :).  The 2nd line is wrong.  It should be d=${a//?/0}.  1 extra char - sorry.

Cheers, I thought I was going mad for a minute!

dc, 41 bytes
[[Retina!]pq]sr?d*rd*+vr/300<r[Trash!]p

Requires args to be input in d, w, h order - I hope this is OK.
Test output:
$ for t in \
> "4.95 1920 1080" \
> "5.96 2560 1440" \
> "10.5 1920 1080" \
> "0.04 10 10" \
> "19 4096 2160" \
> "100.00 8192 4320" \
> "11.18 3000 1500" ; do \
> echo $t | dc -e'9k[[Retina!]pq]sr?d*rd*+vr/300<r[Trash!]p'
> done
Retina!
Retina!
Trash!
Retina!
Trash!
Trash!
Retina!
$

MATLAB - 49 45 bytes
c={'Trash!','Retina!'};c{(w*w+h*h>9e4*d*d)+1}

I first had to declare a cell array which contains Trash! and Retina! which are stored in locations 1 and 2 in the cell array.  Next, I use the observation observed by many to rearrange the equation so that you are checking for the condition only using integer arithmetic.  I represented 90000 as 9e4 to save some bytes.  If this condition is true, we output a 1, else we output a 0.  I use this output to index directly into the cell array.  Because MATLAB starts indexing at 1, I also had to add 1 to complete the indexing.  What's nice is that adding true with 1 gives 2, while adding false with 1 gives 1.  This will output either Trash! or Retina! in the MATLAB command prompt.
Example
>> w=1920;h=1080;d=4.95;
>> c={'Trash!','Retina!'};c{(w*w+h*h>9e4*d*d)+1}

ans =

Retina!

you do not need int8, true+1 is a double(2).

@Jonas I tried that. It wouldn't change to 2 on MATLAB R2013a... Weird.

@Jonas - I had to encapsulate the logical expression in parentheses for it to work.  Order of operations... d'oh.  Thanks for the tip!

Nice approach! (I tried with hypot but your w*w+h*h>9e4*d*d is shorter). However, does this meet the question requirements? It's a program, not a function. So it should take w, h and d as inputs. I assume that means stdin, as usual in code challenge

@LuisMendo ah I'll have to change that! Thanks

Julia, 46 45 42 bytes
f(w,h,d)=w^2+h^2>9e4d^2?"Retina!":"Trash!"

This creates a function that accepts three numeric values and returns a string.
It's a direct implementation of the formula, just rearranged a bit. Both sides of the inequality were multiplied by d then squared.

R, 59 55 Bytes
As an unnamed function now
function(h,w,d)if(h^2+w^2>9e4*d^2)'Retina!'else'Trash!'

Very simple implementation, that eliminates the need for the index references.
Previous
cat(if((n=scan()^2)[1]+n[2]>9e4*n[3])'Retina!'else'Trash!')

Fairly simple, get the input from scan into a vector (single line, space separated or multi-line).  Square the vector.  Do the calculation and cat the result.

XSLT, 400 bytes
This is the debut of a never-before seen language on PPCG, and I hope to use it more in the future as I get to know it more.
Code:
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="input"><xsl:variable name="n" select="for $i in tokenize(.,'[^\d\.]+')return number($i)" /><xsl:choose><xsl:when test="$n[1]*$n[1]+$n[2]*$n[2]>90000*$n[3]*$n[3]">Retina!</xsl:when><xsl:otherwise>Trash!</xsl:otherwise></xsl:choose></xsl:template></xsl:stylesheet>

Pretty Printed
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="input">
        <xsl:variable name="n" select="for $i in tokenize(.,'[^\d\.]+')return number($i)" />
        <xsl:choose>
            <xsl:when test="$n[1]*$n[1]+$n[2]*$n[2]>90000*$n[3]*$n[3]">
                Retina!
            </xsl:when>
            <xsl:otherwise>
                Trash!
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

Notes:
As XSLT has no way of taking input via STDIN, we have to use an XML file, with the input between two <input> tags. Of course, this method has its limitations but it will work perfectly well for most challenges.
Example I/O
Input file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<input>3000 1500 11.18</input>

Output file:
<?xml version="1.0" encoding="UTF-8"?>Retina!

Input file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<input>1920 1080 10.5</input>

Output file:
<?xml version="1.0" encoding="UTF-8"?>Trash!

Here is my contribution for this problem
Ruby, 67 bytes reading from stdin
w,h,d=ARGV.map{|v|Float(v)}
puts w*w+h*h>d*d*9e4?"Retina!":"Trash!"

Ruby, 56 bytes in a function
A bit shorter
def r(w,h,d)
puts w*w+h*h>d*d*9e4?"Retina!":"Trash!"
end

Thanks to the previous contributors for the 9e4!
code-golfruby

C# 6, 67 Bytes
string D(int w,int h,double d)=>w*w+h*h>9e4*d*d?"Retina!":"Trash!";

This answer is based on Wolfsheads answer. I made it 8 bytes shorter using a new feature of C# 6.

Bash, 85 bytes
if [ $(echo "sqrt($1^2+$2^2)/$3"|bc) -gt 300 ];then
echo Retina!
else
echo Trash!
fi

This doesn't work for "3000 1500 11.18".  By default, bc's precision is 0 decimal places.  You will need to set scale, or you can probably get away with bc -l which implicitly sets scale to 20

Oh ok, I updated my answer. Thanks!

Oh, and check out http://codegolf.stackexchange.com/questions/15279/tips-for-golfing-in-bash. For example ((\bc<<<"sqrt($1^2+$2^2)/$3"`>300))&&echo Retina!||echo Trash!`

C# (81)
string D(int w,int h,double d){return Math.Sqrt(w*w+h*h)/d>300?"Retina":"Trash";}

Ungolfed:
string Density(int width, int height, double diagonal)
{
    return Math.Sqrt(width * width + height * height) / diagonal > 300 ? "Retina" : "Trash";
}

You can shorten this up to 73 with the trick several others have used to re-write the formula and remove the sqrt operation: string D(int w,int h,double d){return w*w+h*h>9e4*d*d?"Retina":"Trash";}. But you also need to add in the ! to each string so that would be back to 75 i think.

Swift, 77 bytes
Function parameter declerations mean this takes up way more characters than it should:
func r(w:Float,h:Float,d:Float){print((w*w+h*h)>9e4*d*d ?"Retina!":"Trash!")}

C++ 72 70 Byte
void F(int w,int h,float d){cout<<w*w+h*h>9e4*d*d?"Retina!":"Trash!";}

Similiar to other solutions, figured out myself to warm up with code golf.

You can shave a couple by writing 90000 as 9e4

PHP, 47,43,40 38 bytes

<?=sqrt($w*$w+$h*$h)/$d>300?'Retina':'Trash'?>!
<?=sqrt($w*$w+$h*$h)/$d>300?Retina:Trash?>!
<?=$w*$w+$h*$h>9e4*$d*$d?Retina:Trash?>!

<?=hypot($w,$h)/$d>300?Retina:Trash?>!

Requires register_globals==true (which it should never be!), with GET values w,h,d
- Saved 4 bytes by removing quotes around string. Bad coding, but it works.
- Moved d and square root to the other side of the equation, saving the sqrt() function
- Saved 2 bytes by switching to hypot() (thank you Lucas Costa)

You should just say that this is a PHP4.1 answer and you don't need the register_globals directive to be set.

Either option is just as bad haha

Swift, 56 bytes
let r={print($0*$0+$1*$1>9e4*$2*$2 ?"Retina!":"Trash!")}

Basically the same as GoatInTheMachine's but with implicit closure parameters
When Code Golfing with Swift, always declare methods like this, it's much shorter

Haskell, 46
f w h d|w^2+h^2>d^2*9e4="Retina!"|0<1="Trash!"

What Haskell system should be used?  It doesn't work with the version of ghci I tried, giving <interactive>:2:8: parse error on input '|'.

@EdAvis: GHCi doesn’t run programs; to try it there, you need let f w h d|….

JavaScript (ES6) 58 54 43 Bytes
43 Bytes
Removed function assignment (as per PPCG rules) (-2), as well as remove square root and comparing to 900 (300^2) (-12)
(w,h,d)=>w*w+h*h/d*d>300?"Retina!":"Trash!"

54 Bytes
Got rid of unnessesary parentheses (-4 bytes)
a=(w,h,d)=>Math.sqrt(w*w+h*h)/d>300?"Retina!":"Trash!"

58 Bytes
a=(w,h,d)=>Math.sqrt((w*w)+(h*h))/d>300?"Retina!":"Trash!"

Explanation here:
a =                           // The function is a
 (w,h,d) =>                   // Accepts the three arguments
   Math.sqrt((w*w)+(h*h))/d   // Calculate pixel density
   > 300                      // Above the threshold
   ? "Retina!"                // If so, return "Retina!"
   : "Trash!"                 // Otherwise return "Trash!"

This uses ternary operators to test the density and kills a couple of bytes by using arrow functions

You can make this shorter by avoiding the square root, and comparing the squares of the values instead.

C#, 74 bytes
string D(int w,int h,double d){return w*w+h*h>9e4*d*d?"Retina!":"Trash!";}

Based on the answer by Abbas, but without the need for the square root or the additional space :-).
Also the original version returned "Retina" and "Trash" without the exclamation marks...
I had to post as a new answer due to lack of reputation :-(

Reduced to 75 bytes by replacing 90000 with scientific notation of 9e4:

Wouldn´t removing the brackets in (wxw+hxh) still work?

Yes it would - down to 73 bytes. Cheers! Wood for the trees and all that :-) Will edit the original.

Actually only down by one because one of the brackets needs to become a space :-(

Pyth, 34 32 31 bytes
My first attempt at golfing with Pyth, comments/criticisms are welcome!
?<.)Jrz7c.aJ300"Retina!""Trash!

Explaination:
     rz7                            Split the input on spaces and eval
    J                               Store the result list in J
  .)                                Take the last element from the list
         .aJ                        Find the vector length of the remaining elements
        c   300                     Divide this by 300
?<             "Retina!""Trash!     Ternary comparison and output

Edit: replaced slice with pop to save 2 bytes
Edit 2: inline assignment to save 1 byte - thanks to isaacg

Hey Sok, I'm glad you're learning Pyth. One nice trick that you can use here is inline assignment. J2+J3 and +J2 3 are equivalent, and likewise you can put the rz7 right after the first J.

@isaacg Thanks for the tip, I'll update my answer to take that into account :o)

Java, 82 74 bytes
String g(int w,int h,double d){return 9e4*d*d>w*w+h*h?"Trash!":"Retina!";}

Call it with g(width,height,diagonal)

You can cut this down by getting rid of the costly double array like: String g(int w,int h,double x){return 9e4*x*x>w*w+h*h?"Trash!":"Retina!";} Sometimes simplest is best :)

@Geobits Thanks, I hadn't took the time to budget out the bytes on the two approach, I'm glad you caught it though!

Javascript, 87 69 bytes
OK, I'm rather late to the party and this isn't a great score, but:
function r(w,h,d){return Math.sqrt(w*w+h*h)/d>300?"Retina!":"Trash!"}

which translates to this in readable code:
function r(w, h, d) {
    return (Math.sqrt(w * w + h * h) / d) > 300     // if term > 300
        ? "Retina!"    // return "Retina!"
        : "Trash"!"    // otherwise return "Trash!"
}

Why would you use Math.pow() just to square the numbers?  w*w is way shorter than m.pow(w,2), and since you'd then only be using Math once (for the sqrt()), you could avoid wasting bytes creating the m variable.

You can also avoid the Square root by algebraically moving around some of the terms and raising both sides to the second.

Clojure, 58 bytes
#(if(>(+(* %1%1)(* %2%2))(* %3%3 90000))"Retina!""Trash!")

Used @Kroltan's fancy math to shorten this. Uses implicit arguments passed in the order of (w, h, d).
First Clojure golf...I was surprised how much whitespace I am allowed to leave out

Groovy, 49 bytes
My first attempt at golfing whatsoever, hello everyone!
def f(w,h,d){h*h*+w*w>9e4*d*d?'Retina!':'Trash!'}

C macro, 73 (56) bytes
73 including "#include"s, 56 excluding them. They are technically unnecessary for the code to compile and run under GCC. I'm going to assume here that macro parameters count as function parameters, and that the result after executing the substituted code counts as its return value.
#include<math.h>
#define r(w,h,d) (hypot(w,h)/(d)>300?"Retina!":"Trash!")

If you make the assumption that this only takes literals, function return values or single variables as parameters (rather than any expressions), and is inserted in a position where it will be either assigned directly to a variable or inserted directly into an argument list, you can drop 4 bytes by removing the enclosing parentheses and those around "d".
Similarly, if it needs to be used as a statement which prints the result instead of substituting it, just add 4 bytes by sticking "puts" before the opening parenthesis before hypot. (And 18 for #include<stdio.h> + newline)
(Lazily-written) test case:
#include <stdio.h>
/* ..golfed code goes here.. */
main() {
    puts(r(1920,1080,4.95));
    puts(r(2560,1440,5.96));
    puts(r(1920,1080,10.5));
    puts(r(10,10,0.04));
    puts(r(4096,2160,19));
    puts(r(8192,4320,100.00));
    puts(r(3000,1500,11.18));
    puts(r(180,240,1));
}

Matlab, 60 bytes
Using an anonymous function:
f=@(w,h,d)char('retina!'+(hypot(w,h)<=300*d)*('epPm]#b'-99))

Examples:
>> f=@(w,h,d)char('retina!'+(hypot(w,h)<=300*d)*('epPm]#b'-99))
f =
    @(w,h,d)char('retina!'+(hypot(w,h)<=300*d)*('epPm]#b'-99))

>> f(1920,1080,4.95)
ans =
retina!

>> f(1920,1080,10.5)
ans =
trash!

Powershell, 69
Using the same approach as many others here..
function d($w,$h,$d){@('Trash!','Retina!')[$w*$w+$h*$h-gt9e4*$d*$d]}

Perl, 43 bytes
print<>**2+<>**2><>**2*9E4?Retina:Trash,v33

Expects width, height and diagonal on STDIN, one per line.


text:
Force an Average on an Image
Write a program that takes in a standard truecolor image and a single 24-bit RGB color (three numbers from 0 to 255). Modify the input image (or output a new image with the same dimensions) such that its average color is exactly the single color that was input. You may modify the pixels in the input image in any way you like to achieve this, but the goal is to make the color changes as visually unnoticeable as possible.
The average color of an RGB image is really a set of three arithmetic means, one for each color channel. The average red value is the sum of the red values across all the pixels in the image divided by the total number of pixels (the image area), rounded down to the nearest integer. The green and blue averages are calculated in the same way.
This Python 2 (with PIL) script can compute the average color of most image file formats:
from PIL import Image
print 'Enter image file'
im = Image.open(raw_input()).convert('RGB')
pixels = im.load()
avg = [0, 0, 0]
for x in range(im.size[0]):
    for y in range(im.size[1]):
        for i in range(3):
            avg[i] += pixels[x, y][i]
print 'The average color is', tuple(c // (im.size[0] * im.size[1]) for c in avg)

(There are similar average color programs here, but they don't necessarily do the exact same calculation.)
The main requirement for your program is that for any input image, its corresponding output's average color must exactly match the color that was input - as judged by the Python snippet or some equivalent code. The output image must also have the exact same dimensions as the input image.
So you could technically submit a program that simply colors the entire input the specified average color (because the average would always be that color), but this is a popularity contest - the submission with the highest number of votes will win, and such a trivial submission will not get you many upvotes. Novel ideas like taking advantage of quirks in human vision, or shrinking the image down and drawing a colored border around it will (hopefully) get you votes.
Note that certain combinations of average colors and images necessitate extremely noticeable color changes. For example, if the average color to match were black (0, 0, 0), any input image would need to be made completely black because if any pixels had non-zero values, they would make the average non-zero as well (barring round-off errors). Keep such limitations in mind when voting.
Test Images
Some images and their default average colors to play around with. Click for full sizes.
A. average (127, 127, 127)
 From fejesjoco's Images with all colors answer. Found original on his blog.
B. average (62, 71, 73)
 Yokohama. Provided by Geobits.
C. average (115, 112, 111)
 Tokyo. Provided by Geobits.
D. average (154, 151, 154)
 Escher's Waterfall. Original.
E. average (105, 103, 102)
 Mount Shasta. Provided by me.
F. average (75, 91, 110)
 The Starry Night
Notes

The exact input and output formats and image file types your program uses does not matter much. Just make sure it is clear how to use your program.
It is probably a good idea (but not technically a requirement) that if an image already has the goal average color, it should be output as is.
Please post test images with the average color input as either (150, 100, 100) or (75, 91, 110), so voters can see the same inputs across different solutions. (Posting more examples than this is fine, even encouraged.)

Participants get to choose the input colors they use to demonstrate the effectiveness of their solution? Doesn't that make it difficult for people to compare the solutions? In the extreme case, somebody could choose input colors that are very similar to the average of the image, and it would look like their solution is very effective.

@vihan1086 If I've understood correctly, the average colour is provided as a 24 bit RGB colour input, not found from an input image.

It might be interesting to use @vihan1086's interpretation, and use the example images as the source of input colours so one image is displayed in the average colour of another. This way different answers can be compared fairly.

The main problem with that is most of them have an average that's very close to grey. Starry Night is probably the furthest from that, but the rest average out pretty flatly.

@RetoKoradi Hopefully voters will be smart enough to take such things into account, though I've added a note on what default average colors to use.

Python 2 + PIL, simple colour scaling
from PIL import Image
import math

INFILE = "street.jpg"
OUTFILE = "output.png"
AVERAGE = (150, 100, 100)

im = Image.open(INFILE)
im = im.convert("RGB")
width, height = prev_size = im.size
pixels = {(x, y): list(im.getpixel((x, y)))
          for x in range(width) for y in range(height)}

def get_avg():
    total_rgb = [0, 0, 0]

    for x in range(width):
        for y in range(height):
            for i in range(3):
                total_rgb[i] += int(pixels[x, y][i])

    return [float(x)/(width*height) for x in total_rgb]

curr_avg = get_avg()

while tuple(int(x) for x in curr_avg) != AVERAGE:
    print curr_avg
    non_capped = [0, 0, 0]
    total_rgb = [0, 0, 0]

    for x in range(width):
        for y in range(height):
            for i in range(3):
                if curr_avg[i] < AVERAGE[i] and pixels[x, y][i] < 255:
                    non_capped[i] += 1
                    total_rgb[i] += int(pixels[x, y][i])

                elif curr_avg[i] > AVERAGE[i] and pixels[x, y][i] > 0:
                    non_capped[i] += 1
                    total_rgb[i] += int(pixels[x, y][i])

    ratios = [1 if z == 0 else
              x/(y/float(z))
              for x,y,z in zip(AVERAGE, total_rgb, non_capped)]

    for x in range(width):
        for y in range(height):
            col = []

            for i in range(3):
                new_col = (pixels[x, y][i] + 0.01) * ratios[i]
                col.append(min(255, max(0, new_col)))

            pixels[x, y] = tuple(col)

    curr_avg = get_avg()

print curr_avg

for pixel in pixels:
    im.putpixel(pixel, tuple(int(x) for x in pixels[pixel]))

im.save(OUTFILE)

Here's a naïve approach which should serve as a good baseline. At each iteration, we compare our current average with the desired average, and scale the RGB of each pixel by the according ratio. We have to be a bit careful though, for two reasons:

Scaling 0 still results in 0, so before we scale we add something small (here 0.01)
RGB values are between 0 and 255, so we need to adjust the ratio accordingly to make up for the fact that scaling capped pixels doesn't do anything.

The images save as PNG because saving as JPG seems to mess up the colour averages.
Sample output
(40, 40, 40)

(150, 100, 100)

(75, 91, 110), Starry Night palette

You definitely want to use a image format with non-lossy compression for this. So JPEG is not a good option.

You can always count on Sp for cool image challenge solutions.

C++, gamma correction
This does a brightness adjustment of the image using a simple gamma correction, with the gamma value determined separately for each component to match the target average.
The high level steps are:

Read image and extract histogram for each color component.
Perform a binary search of the gamma value for each component. A binary search is performed on the gamma values, until the resulting histogram has the desired average.
Read the image a second time, and apply the gamma correction.

All image input/output uses PPM files in ASCII. Images were converted from/to PNG using GIMP. The code was run on a Mac, image conversions were done on Windows.
Code:
#include <cmath>
#include <string>
#include <vector>
#include <sstream>
#include <fstream>
#include <iostream>

static inline int mapVal(int val, float gamma)
{
    float relVal = (val + 1.0f) / 257.0f;
    float newRelVal = powf(relVal, gamma);

    int newVal = static_cast<int>(newRelVal * 257.0f - 0.5f);
    if (newVal < 0)
    {
        newVal = 0;
    }
    else if (newVal > 255)
    {
        newVal = 255;
    }

    return newVal;
}

struct Histogram
{
    Histogram();

    bool read(const std::string fileName);
    int getAvg(int colIdx) const;
    void adjust(const Histogram& origHist, int colIdx, float gamma);

    int pixCount;
    std::vector<int> freqA[3];
};

Histogram::Histogram()
  : pixCount(0)
{
    for (int iCol = 0; iCol < 3; ++iCol)
    {
        freqA[iCol].resize(256, 0);
    }
}

bool Histogram::read(const std::string fileName)
{
    for (int iCol = 0; iCol < 3; ++iCol)
    {
        freqA[iCol].assign(256, 0);
    }

    std::ifstream inStrm(fileName);

    std::string format;
    inStrm >> format;
    if (format != "P3")
    {
        std::cerr << "invalid PPM header" << std::endl;
        return false;
    }

    int w = 0, h = 0;
    inStrm >> w >> h;
    if (w <= 0 || h <= 0)
    {
        std::cerr << "invalid size" << std::endl;
        return false;
    }

    int maxVal = 0;
    inStrm >> maxVal;
    if (maxVal != 255)
    {
        std::cerr << "invalid max value (255 expected)" << std::endl;
        return false;
    }

    pixCount = w * h;

    int sumR = 0, sumG = 0, sumB = 0;
    for (int iPix = 0; iPix < pixCount; ++iPix)
    {
        int r = 0, g = 0, b = 0;
        inStrm >> r >> g >> b;
        ++freqA[0][r];
        ++freqA[1][g];
        ++freqA[2][b];
    }

    return true;
}

int Histogram::getAvg(int colIdx) const
{
    int avg = 0;
    for (int val = 0; val < 256; ++val)
    {
        avg += freqA[colIdx][val] * val;
    }

    return avg / pixCount;
}

void Histogram::adjust(const Histogram& origHist, int colIdx, float gamma)
{
    freqA[colIdx].assign(256, 0);

    for (int val = 0; val < 256; ++val)
    {
        int newVal = mapVal(val, gamma);
        freqA[colIdx][newVal] += origHist.freqA[colIdx][val];
    }
}

void mapImage(const std::string fileName, float gammaA[])
{
    std::ifstream inStrm(fileName);

    std::string format;
    inStrm >> format;

    int w = 0, h = 0;
    inStrm >> w >> h;

    int maxVal = 0;
    inStrm >> maxVal;

    std::cout << "P3" << std::endl;
    std::cout << w << " " << h << std::endl;
    std::cout << "255" << std::endl;

    int nPix = w * h;

    for (int iPix = 0; iPix < nPix; ++iPix)
    {
        int inRgb[3] = {0};
        inStrm >> inRgb[0] >> inRgb[1] >> inRgb[2];

        int outRgb[3] = {0};
        for (int iCol = 0; iCol < 3; ++iCol)
        {
            outRgb[iCol] = mapVal(inRgb[iCol], gammaA[iCol]);
        }

        std::cout << outRgb[0] << " " << outRgb[1] << " "
                  << outRgb[2] << std::endl;
    }
}

int main(int argc, char* argv[])
{
    if (argc < 5)
    {
        std::cerr << "usage: " << argv[0]
                  << " ppmFileName targetR targetG targetB"
                  << std::endl;
        return 1;
    }

    std::string inFileName = argv[1];

    int targAvg[3] = {0};
    std::istringstream strmR(argv[2]);
    strmR >> targAvg[0];
    std::istringstream strmG(argv[3]);
    strmG >> targAvg[1];
    std::istringstream strmB(argv[4]);
    strmB >> targAvg[2];

    Histogram origHist;
    if (!origHist.read(inFileName))
    {
        return 1;
    }

    Histogram newHist(origHist);
    float gammaA[3] = {0.0f};

    for (int iCol = 0; iCol < 3; ++iCol)
    {
        float minGamma = 0.0f;
        float maxGamma = 1.0f;
        for (;;)
        {
            newHist.adjust(origHist, iCol, maxGamma);
            int avg = newHist.getAvg(iCol);
            if (avg <= targAvg[iCol])
            {
                break;
            }
            maxGamma *= 2.0f;
        }

        for (;;)
        {
            float midGamma = 0.5f * (minGamma + maxGamma);

            newHist.adjust(origHist, iCol, midGamma);
            int avg = newHist.getAvg(iCol);
            if (avg < targAvg[iCol])
            {
                maxGamma = midGamma;
            }
            else if (avg > targAvg[iCol])
            {
                minGamma = midGamma;
            }
            else
            {
                gammaA[iCol] = midGamma;
                break;
            }
        }
    }

    mapImage(inFileName, gammaA);

    return 0;
}

The code itself is fairly straightforward. One subtle but important detail is that, while the color values are in the range [0, 255], I map them to the gamma curve as if the range were [-1, 256]. This allows the average to be forced to 0 or 255. Otherwise, 0 would always remain 0, and 255 would always remain 255, which might never allow for an average of 0/255.
To use:

Save the code in a file with extension .cpp, e.g. force.cpp.
Compile with c++ -o force -O2 force.cpp.
Run with ./force input.ppm targetR targetG target >output.ppm.

Sample output for 40, 40, 40
Note that the images for all the larger samples are included as JPEGs since they exceed the SE size limit as PNGs. Since JPEG is a lossy compression format, they may not exactly match the target average. I have the PNG version of all files, which matches exactly.

Sample output for 150, 100, 100:

Sample output for 75, 91, 110:

I had to shrink down the other images to meet the limit - maybe try that?

@Sp3000 Ok, got all the images included now. Also with thumbnails now. I ended up using the JPEG version for the large ones. Actually, one of them was below the size limit, but it looks like it was auto-converted to JPEG. The first and last examples are still PNGs.

Python 2 + PIL
from PIL import Image
import random
import math

SOURCE = 'input.png'
OUTPUT = 'output.png'
AVERAGE = [150, 100, 100]

im = Image.open(SOURCE).convert('RGB')
pixels = im.load()
w = im.size[0]
h = im.size[1]
npixels = w * h

maxdiff = 0.1

# for consistent results...
random.seed(42)
order = range(npixels)
random.shuffle(order)

def calc_sum(pixels, w, h):
    sums = [0, 0, 0]
    for x in range(w):
        for y in range(h):
            for i in range(3):
                sums[i] += pixels[x, y][i]
    return sums

def get_coordinates(index, w):
    return tuple([index % w, index // w])

desired_sums = [AVERAGE[0] * npixels, AVERAGE[1] * npixels, AVERAGE[2] * npixels]

sums = calc_sum(pixels, w, h)
for i in range(3):
    while sums[i] != desired_sums[i]:
        for j in range(npixels):
            if sums[i] == desired_sums[i]:
                break
            elif sums[i] < desired_sums[i]:
                coord = get_coordinates(order[j], w)
                pixel = list(pixels[coord])
                delta = int(maxdiff * (255 - pixel[i]))
                if delta == 0 and pixel[i] != 255:
                    delta = 1
                delta = min(delta, desired_sums[i] - sums[i])

                sums[i] += delta
                pixel[i] += delta
                pixels[coord] = tuple(pixel)
            else:
                coord = get_coordinates(order[j], w)
                pixel = list(pixels[coord])
                delta = int(maxdiff * pixel[i])
                if delta == 0 and pixel[i] != 0:
                    delta = 1
                delta = min(delta, sums[i] - desired_sums[i])

                sums[i] -= delta
                pixel[i] -= delta
                pixels[coord] = tuple(pixel)

# output image
for x in range(w):
    for y in range(h):
        im.putpixel(tuple([x, y]), pixels[tuple([x, y])])

im.save(OUTPUT)

This iterates through each pixel in a random order, and reduces the distance between each component of the color of the pixel and 255 or 0 (depending on whether the current average is less or greater than the desired average). The distance is reduced by a fixed multiplicative factor. This is repeated until the desired average is obtained. The reduction is always at least 1, unless the color is 255 (or 0), to ensure that the processing does not stall once the pixel is close to white or black.
Sample output
(40, 40, 40)

(150, 100, 100)

(75, 91, 110)

Java
An RNG based approach. A bit slow for large input images.
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.*;

import javax.imageio.ImageIO;

public class Averager {
    static Random r;
    static long sigmaR=0,sigmaG=0,sigmaB=0;
    static int w,h;
    static int rbar,gbar,bbar;
    static BufferedImage i;
    private static File file;
    static void upRed(){
        int x=r.nextInt(w);
        int y=r.nextInt(h);
        Color c=new Color(i.getRGB(x, y));
        if(c.getRed()==255)return;
        sigmaR++;
        c=new Color(c.getRed()+1,c.getGreen(),c.getBlue());
        i.setRGB(x, y,c.getRGB());
    }
    static void downRed(){
        int x=r.nextInt(w);
        int y=r.nextInt(h);
        Color c=new Color(i.getRGB(x, y));
        if(c.getRed()==0)return;
        sigmaR--;
        c=new Color(c.getRed()-1,c.getGreen(),c.getBlue());
        i.setRGB(x, y,c.getRGB());
    }
    static void upGreen(){
        int x=r.nextInt(w);
        int y=r.nextInt(h);
        Color c=new Color(i.getRGB(x, y));
        if(c.getGreen()==255)return;
        sigmaG++;
        c=new Color(c.getRed(),c.getGreen()+1,c.getBlue());
        i.setRGB(x, y,c.getRGB());
    }
    static void downGreen(){
        int x=r.nextInt(w);
        int y=r.nextInt(h);
        Color c=new Color(i.getRGB(x, y));
        if(c.getGreen()==0)return;
        sigmaG--;
        c=new Color(c.getRed(),c.getGreen()-1,c.getBlue());
        i.setRGB(x,y,c.getRGB());
    }
    static void upBlue(){
        int x=r.nextInt(w);
        int y=r.nextInt(h);
        Color c=new Color(i.getRGB(x, y));
        if(c.getBlue()==255)return;
        sigmaB++;
        c=new Color(c.getRed(),c.getGreen(),c.getBlue()+1);
        i.setRGB(x, y,c.getRGB());
    }
    static void downBlue(){
        int x=r.nextInt(w);
        int y=r.nextInt(h);
        Color c=new Color(i.getRGB(x, y));
        if(c.getBlue()==0)return;
        sigmaB--;
        c=new Color(c.getRed(),c.getGreen(),c.getBlue()-1);
        i.setRGB(x,y,c.getRGB());
    }
    public static void main(String[]a) throws Exception{
        Scanner in=new Scanner(System.in);
        i=ImageIO.read(file=new File(in.nextLine()));
        rbar=in.nextInt();
        gbar=in.nextInt();
        bbar=in.nextInt();
        w=i.getWidth();
        h=i.getHeight();
        final int npix=w*h;
        r=new Random(npix*(long)i.hashCode());
        for(int x=0;x<w;x++){
            for(int y=0;y<h;y++){
                Color c=new Color(i.getRGB(x, y));
                sigmaR+=c.getRed();
                sigmaG+=c.getGreen();
                sigmaB+=c.getBlue();
            }
        }
        while(sigmaR/npix<rbar){
            upRed();
        }
        while(sigmaR/npix>rbar){
            downRed();
        }
        while(sigmaG/npix<gbar){
            upGreen();
        }
        while(sigmaG/npix>gbar){
            downGreen();
        }
        while(sigmaB/npix<bbar){
            upBlue();
        }
        while(sigmaB/npix>bbar){
            downBlue();
        }
        String k=file.getName().split("\\.")[0];
        ImageIO.write(i,"png",new File(k="out_"+k+".png"));
    }
}

Tests:
(40,40,40)

(150,100,100)

(75,91,110)

source: Stack Exchange

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

sort: votes


text:
Every Possible Cycle Length
A function (or program) which takes inputs and provides outputs can be said to have a cycle if calling the function on its own output repeatedly eventually reaches the original number. For instance, take the following function:
Input:  n    1 2 3 4 5 6
Output: f(n) 5 7 1 3 4 9

If we start with n=1, f(n)=5, f(f(n))=f(5)=4, f(f(f(n)))=f(4)=3, f(f(f(f(n))))=f(3)=1.
This is written (1 5 4 3). Since there are 4 unique numbers in this loop, this is a cycle of length 4.

Your challenge is to write a program or function which has cycles of every possible length. That is, there must be a cycle of length 1, of length 2, and so on.
In addition, your function/program must be from the positive integers to positive integers, and it must be bijective, meaning that there must be a exactly one input value for every possible output value, over all positive integers. To put it another way, the function/program must compute a permutaion of the positive integers.

Details: Any standard input/output system is allowed, including STDIN, STDOUT, function argument, return, etc. Standard loopholes prohibited.
You do not need to worry about the limitations of your data types - the above properties need only hold under the assumption that an int or float can hold any value, for instance.
There are no restrictions on the behavior of the function on inputs which are not positive integers, and those inputs/outputs will be ignored.

Scoring is code golf in bytes, shortest code wins.

"there must be a cycle of length 1, of length 2, and so on" Should this be interpreted as "there must be at least a cycle of length 1, at least one of length 2, and so on" or "there must be exactly a cycle of length 1, one of length 2, and so on".

@Bakuriu At least one cycle of each positive length.

Pyth, 11 8 bytes
.<W-0zz1

A lot more boring than my previous answer.
Every number that contains a 0 digit maps to itself. Any other number maps to the number that has its digits rotated by 1. So for example:
1 -> 1
10 -> 10
15 -> 51 -> 15
104 -> 104
123 -> 231 -> 312 -> 123

Python 2, 56 55 54 bytes
n=input()
a=b=1
while a+b<=n:a+=b;b+=1
print(n+~a)%b+a

Here's the first 21 outputs:
[1, 3, 2, 6, 4, 5, 10, 7, 8, 9, 15, 11, 12, 13, 14, 21, 16, 17, 18, 19, 20]

The pattern is obvious if we break the list up into chunks like so:
 1    2  3    4  5  6    7  8  9  10    11  12  13  14  15    16  17  18  19  20  21
[1]  [3, 2]  [6, 4, 5]  [10, 7, 8, 9]  [15, 11, 12, 13, 14]  [21, 16, 17, 18, 19, 20]

Damn, this is the pattern I also was going for, but with a closed form.

Interesting.. the a-values follow the sequence A000124. But I guess you already knew that :P

Note that this sequence is http://oeis.org/A066182.

Pyth, 25 bytes
+hK/*J/h@h*8tQ2 2tJ2%-QKJ

This is the same sequence as @Sp3000, but with a closed form. The closed form is:

Python3, 40 bytes
n=input();print([n[1:]+n[0],n]['0'in n])

Every number that contains a 0 digit maps to itself. Any other number maps to the number that has its digits rotated by 1. So for example:
1 -> 1
10 -> 10
15 -> 51 -> 15
104 -> 104
123 -> 231 -> 312 -> 123

Déjà vu! Cool to see it in two languages!

Ruby, 16+1=17
With command-line flag -p, run
$_=$_[/.0*$/]+$`

This is a more complicated function than my other answer, but happens to be more golfable (and tolerant to trailing newlines). It takes the last nonzero digit of the input, plus any trailing zeroes, and moves it to the beginning of the number. So 9010300 becomes 3009010. Any number with n nonzero digits will be part of an n-length cycle.
Input is a string in any base via STDIN, output is a string in that base.

Ruby, 22+1=23
With command-line flag -p, run
~/(.)(.?)/
$_=$1+$'+$2

When given as input a string representation of a number (with no trailing newline), it keeps the first digit constant, then rotates the remainder left, so 1234 becomes 1342.
This can be reduced to 21 characters with
$_=$1+$'+$2if/(.)(.)/, but prints a warning.

Pyth, 15 bytes
The shortest answer so far that uses numeric operations rather than string operations.
.|.&Q_=.&_=x/Q2

    Q                input
            /Q2      input div 2
           x   Q     that XOR input
          =          assign that to Q
         _           negate that
       .&       Q    that AND Q
      =              assign that to Q
     _               negate that
  .&                 input AND that
.|               Q   that OR Q

The effect of this function on the binary representation is to extend the rightmost block of 1s into the next 0; or if there is no 0, to reset it back to a single 1:
10010110100000 ↦
10010110110000 ↦
10010110111000 ↦
10010110111100 ↦
10010110111110 ↦
10010110111111 ↦
10010110100000

Pyth, 26 bytes, fun variant
.|.&Q_h.&/Q2+Qy=.&/Q2_h.|y

    Q                           input
         /Q2                    input div 2
             Q                  input
                  /Q2           input div 2
                         yQ     twice input
                       .|  Q    that OR input
                     _h         NOT that
                .&              (input div 2) AND that
               =                assign that to Q
              y                 twice that
            +                   input plus that
       .&                       (input div 2) AND that
     _h                         NOT that
  .&                            input AND that
.|                          Q   that OR Q

Performs the above operation simultaneously to all blocks of 1s, not just the rightmost one—still using only bitwise and arithmetic operations.
1000010001001 ↦
1100011001101 ↦
1110011101001 ↦
1111010001101 ↦
1000011001001 ↦
1100011101101 ↦
1110010001001 ↦
1111011001101 ↦
1000011101001 ↦
1100010001101 ↦
1110011001001 ↦
1111011101101 ↦
1000010001001

Python, 43
The inverse of Sp3000's function, implemented recursively.
f=lambda n,k=1:n>k and k+f(n-k,k+1)or n%k+1

The function is a one-cycle followed by a two-cycle followed by a three-cycle, ...
(1)(2 3)(4 5 6)(7 8 9 10)(11 12 13 14 15)...

The operation n%k+1 acts as a k-cycle on the numbers 1..k. To find the appropriate k to use, shift everything down by k=1, then k=2, and so on, until n<=k.

Brachylog, 5 bytes
∋0&|↺

Try it online!
Port of @orlp's Pyth answer. Comes out simple and neat:
∋0    % If input contains a 0 (since input is a single number, "contains" ∋ treats it as an array
      %   of its digits, so this means "if any of input's digits are 0")
&     % Then output is the input
|     % Otherwise
↺     % Circularly shift the input once, and unify that with the output

I originally wanted to port @Sp3000's Python solution, but that took a whopping 23 bytes:
⟧∋B-₁⟦++₁A≤?;A--₁;B%;A+

Try it online!

x86 32-bit machine code, 16 bytes
0F BC C1 0F B3 C1 E3 01 40 0F AB C1 91 14 00 C3

Try it online!
Uses the fastcall calling convention – argument in ECX, result in EAX.
This function leaves values with only one 1 bit (powers of 2) unchanged; other values are modified by moving the lowest 1 bit one place up, or to the bottom if the position above it is already 1. Thus, a non-power-of-2 is in a cycle of length equal to the position of its second-lowest 1 bit.
In assembly:
.global f
f:
    bsf eax, ecx    # Set EAX to the position of the lowest 1 bit in ECX.
    btr ecx, eax    # Remove that 1 bit from ECX.
    jecxz s         # Jump if ECX is 0 (had only one 1 bit).
    inc eax         # (Otherwise) Increase EAX by 1.
s:  bts ecx, eax    # Set to 1 the bit in ECX at position EAX,
                    #  and set the carry flag (CF) to its former value.
    xchg ecx, eax   # Exchange registers, moving the number into EAX.
    adc al, 0       # Add 0+CF to the low byte of EAX.
    ret             # Return.

Swift 1.2, 66 bytes
func a(b:Int){var c=0,t=1,n=b
while n>c{n-=c;t+=c++}
print(n%c+t)}

Input:  1,   2, 3,  4, 5, 6,   7, 8, 9, 10,   11, 12, 13, 14, 15
Output: 1,   3, 2,  5, 6, 4,   8, 9, 10, 7,   12, 13, 14, 15, 11

JavaScript (ES6), 43 bytes
f=(n,i=1,j=1)=>n>j?f(n,++i,j+i):n++<j?n:n-i

Matlab(189)
  function u=f(n),if(~n|n==1)u=n;else,u=n;y=factor(n);z=y(y~=2);if ~isempty(z),t=y(y~=max(y));if isempty(t),u=y(end)*2^(nnz(y)-1);else,g=max(t);e=primes(g*2);u=n/g*e(find(e==g)+1);end,end,end

The function:
Maps any integer according to its prime factors, if the number is nil or factorised into 2 or 1, the number is mapped to itself, otherwise we pick the biggest prime factor of this number, then we increment the remaining different prime factors by the closest bigger prime factor until we reach the number biggest_prime^n where n is the sum of all exponents of all factors, once we reach that amount, we turn to max_prime*2^(n-1) and we reproduce the same cycle again.

Matlab(137)
  function u=h(n),if(~n|n==1)u=n;else,u=n;y=factor(n);z=y(y~=2);if~isempty(z),e=nnz(y);f=nnz(z);if(~mod(e,f)&e-f)u=n/2^(e-f);else,u=u*2;end

A slightly similar approach, multiplying gradually any number not equal to {0,1,2^n} by 2 until we stumble upon an exponent of 2 which is divisible by sum of exponents of other prime factors. then we move to the beginning of the cycle dividing by 2^(sum of exponents of other primes). the other numbes are mapped to themselves.

05AB1E, 4 bytes
WĀiÁ

Port of @orlp's Pyth answer, so make sure to upvote him/her as well.
Try it online or verify some test cases.
Explanation:
W     # Push the smallest digit of the (implicit) input-integer (without popping)
 Āi   # If this is NOT 0:
   Á  #  Rotate the integer once towards the right
      # (after which the resulting integer is output implicitly)

x86 32-bit machine code, 11 bytes
0F BD C8 D1 E8 73 FC 0F AB C8 C3

Try it online!
Uses the regparm(1) calling convention – argument in EAX, result in EAX.
This function takes a number's binary digits (without leading zeroes) and rotates them right until the highest one is again a 1.
In assembly:
f:  bsr ecx, eax    # Set ECX to the highest position of a 1 bit in EAX.
r:  shr eax, 1      # Shift EAX right by 1 bit, with the lowest bit going into CF.
    jnc r           # Repeat if CF=0.
    bts eax, ecx    # Set to 1 the bit in EAX at position ECX.
    ret             # Return.

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

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


text:
Code close to the challenge: Inception
This is a sequel to this challenge: Code close to the challenge: Sum of integers
The challenge in this one is a bit harder, and also makes for a cool title (Which is why I picked it):

Calculate the Levenshtein distance between two strings

Just like last challenge, your score in this challenge is the Levenshtein distance between your code and the quote above.
So now for the details!
Your program will take 2 inputs, both strings with no trailing spaces or newlines, and will output the Levenshtein distance between them. Levenshtien distance is defined as the number of of additions, deletions, and substitutions necessary to transform one string to another. For more information on how to calculate it, see the Wikipedia page linked above. To test if your program works, use this calculator.
Your program must output nothing but the Levenshtein distance between the two strings. It will be disqualified if anything else is outputted.
Example I/O:
Inputs:
test
test2
Output:
1

Inputs:
222
515
Output:
3

Inputs:
Test
test
Output:
1

Your code may not have no-ops or comments.

Frink, distance 24
Calculate[the,Levenshtein]:=editDistance[the,Levenshtein]

To use this, you would call Calculate with the two strings, and since this is returning, you also need to surround the call with print[]. If this isn't allowed, my score is 30.
Example:
Calculate["kitten","spork"]        -> returns 6
print[Calculate["kitten","spork"]] -> prints 6.

You need to download Frink, as the web interpreter doesn't allow defining functions. It should run on all systems, considering it's a Java applet. Download instructions here..

Psst. Hey! Here's a Levenshtein implementation in Symbolic, something I'm working on: k=λ:Δ(ί,ί).

Interesting language, reminds me of Mathematica.

This counts as using a built-in function to solve the challenge, which could be considered a standard loophole (but so seem to 90℅ of all answers to this challenge)

@JanDvorak Built-ins are kind of a gray area since the vote breakdown on the meta answer listing built-ins as a standard loophole is near half and half.

R, distance 35
Calculate=function(the,Levenshtein)adist(between<-the,two<-Levenshtein)

This creates a function Calculate with parameters the and Levenshtein. It uses the R built-in function adist to compute the distance. The string parameters in adist are essentially the and Levenshtein renamed to between and two.

PHP4.1, distance 32 22 15 14
Very basic one, nothing exciting.
<?=$Calculate_the=Levenshtein($distance,$between_two_strings);

Or a shorter version:
<?=$ulatethe=Levenshtein($istance,$etweentwostrin);

For this to work, you need to send/set a POST/GET/COOKIE/session variable with the keys:

distance (istance for the shorter one)
between_two_strings (etweentwostrin for the shorter one)

The arguments are in that order.
Test the score on http://ideone.com/QzNZ8T
Example:
http://localhost/distance.php?distance=string1&between_two_strings=string2

@AboveFire Sorry, but I can't accept your edit. Quoting the O.P.: "Your code may not have no-ops or comments." and your edit simply added an HTML comment.

PHP, distance 44
function Calculate($two,$strings){echo levenshtein($two,$strings);}

Use the built-in levenshtein function from PHP standard library and named the arguments in order to try to minimize the distance.

Shouldn't it be $two,$strings?

indeed, it should.

Also, you are missing a ;

I offer you a solution with a distance of 28: echo$Calculate_the=levenshtein($_GET[distance_between_two],$_GET[strings]);

Pip, distance 50
Uses no builtin Levenshtein function!
xINg?#JgMN[1+(fac:b@>1)1+(fe:a@>1b)(a@0NEb@0)+(fec)]

This code implements the recursive Levenshtein algorithm; as such, it is extremely slow, taking a few seconds even for strings of length 5. I wouldn't recommend running the program through itself to check it!
Here's my base code, with whitespace and comments:
; Note: a Pip program is an implicit function f, which is called with the command-line
; arguments. The args are stored in the list g, as well as being assigned to the local
; variables a-e.

; Is one of the args the empty string? (NB x is initialized to "")
x IN g ?
 ; If so, join args together and take the length (i.e., length of the non-empty string).
 # J g
 ; If not, take the min of the following:
 MN [
  ; Recursively call f with the first character of a removed; add 1 to the result
  (f a@>1 b) + 1
  ; Recursively call f with the first character of b removed; add 1 to the result
  (f a b@>1) + 1
  ; Recursively call f with the first characters of both removed; iff the two characters
  ; were not equal, add 1 to the result
  (f a@>1 b@>1) + (a@0 NE b@0)
 ]

The main change in the final version is assigning some values to temporary variables c and e, which appear in the challenge string and thus reduce the Levenshtein distance a bit.


text:
Minimizing Covering Arrays
This is the followup question to this previous CodeGolf question about Covering Arrays (the details of what Covering Arrays are and how they are formatted at the NIST website are there).
In this challenge, we won't just be validating covering arrays - we will try to minimize them. Finding minimal Covering Arrays, in general, is a very tough research-level question, and is of interest due to their applications in software/hardware testing, among other fields.
What we will do here is, given some Covering Arrays from NIST, try to minimize them as much as possible. I picked the following covering arrays (with their .txt.zip files as the links - unzipping the file gives the .txt desired file):

CA(13; 2, 100, 2)
CA(159; 3, 100, 3)
CA(2337; 4, 100, 4)
CA(29963; 5, 50, 5)
CA(125683; 6, 25, 5)

What you will do is try to minimize the N in each CA to get the smallest possible for each. There are a number of possible techniques:

Combining other CAs to form the desired CA
Metaheuristics, such as simulated annealing or tabu search
Any other technique!

Scoring
Your score will be the sum of the N of all 5 CAs that you create. For example, if I did not do anything and turned in the 5 CAs given above, my score would be 13+159+2337+29963+125683 = 158155.
The winner will be the person with the lowest score. Any method of generating the CAs works - you should provide the source code you used to generate the CA as well as say which CA verifier you used (either on the linked question or somewhere else online). Also, any programming language is allowed.
Formatting
You also need to provide the CAs that you generate, in the same format as the NIST CAs. Don't worry about finding the "don't care" positions that are in the original CAs. Since some of the CAs are large, you will need to host the files somewhere for other users to download and verify correctness.


text:
Merging a dict compression referencing the original list into 1 line
Background
A question wanted to solve a problem in a way that made it unreasonably complex: https://stackoverflow.com/a/31551257/29347
The problem in the original question is:

Take a list of (key, value) and produce a dict such that {key: sum(value)}

My Problem
I want to use dict compression with list.count or str.count but constructing the iterable, iterating and referencing it in one motion has me stumped.
a = [("a",1), ("b",3), ("a",5)]

# b = "abbbaaaaa"
b = "".join(b[0] * b[1] for b in a)

# dict_a = {'a': 6, 'b': 3}
dict_a = {e[0]: b.count(e) for e in b}

Goal
Remove the need for the variable b thus merging the two lines whilst staying true to the solution.

Welcome to Programming Puzzles & Code Golf Stack Exchange! This site is for programming contests / challenges, not general programming questions. For those, try [so], but be sure you read their help center first to make sure your question is of high quality and on-topic.

dict_a = {t[0] : sum(tp[1] for tp in a if tp[0] == t[0]) for t in a}

Horribly slow, but hey it's a one liner!

Haha I literally just updated my original example with the almost  identical: dict_a = {e[0]: sum(map(itemgetter(1), filter(lambda a: a[0] == e[0], a))) for e in a}