# 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 , 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 Jul 21 '15 at 20:48
• @DigitalTrauma But floats. Jul 21 '15 at 20:49
• @Sp3000 pfft, excuses!. Build your own float parsing regex in Retina! Jul 21 '15 at 20:50
• @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. Jul 21 '15 at 21:09
• Hmm, the threshold chosen doesn't quite match Apple's marketing, e.g. for the Retina iMac: 5120 2880 27 Jul 30 '15 at 9:16

## 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. Jul 23 '15 at 9:27
• @isaacg Thanks for the tip, I'll update my answer to take that into account :o)
– Sok
Jul 23 '15 at 10:02

# 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. Jul 23 '15 at 13:26
• You can also avoid the Square root by algebraically moving around some of the terms and raising both sides to the second. Jul 23 '15 at 13:33

# 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: Jul 23 '15 at 11:43
• Wouldn´t removing the brackets in (wxw+hxh) still work? Jul 24 '15 at 8:55
• Yes it would - down to 73 bytes. Cheers! Wood for the trees and all that :-) Will edit the original. Jul 24 '15 at 8:57
• Actually only down by one because one of the brackets needs to become a space :-( Jul 24 '15 at 8:59

## 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.