[Question]
  [
## Similar figures
Two rectangles are *similar* if the ratios of their sides are the same.
Consider these two rectangles; a rectangle 5 lines tall and 11 chars wide:
```
===========
===========
===========
===========
===========
```
and a rectangle 10 lines tall and 22 chars wide:
```
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
```
These shapes are similar because the ratios of their sides are the same. To put it
formally (with \$h\$ being the shortest side and \$w\$ being the longest side):
$$
\frac{h\_1}{w\_1} = \frac{h\_2}{w\_2}
$$
You can also do:
$$
\frac{h\_1}{h\_2} = \frac{w\_1}{w\_2}
$$
## The challenge
Write a program or function that takes a "main" rectangle and some "other"
rectangles and prints which of "others" are similar to "main".
## The input
A shape and a list of shapes. Each shape consists of 2 non-zero positive integers, which denote the
width and height of the rectangle. For instance, this:
```
(4,2), (3,9)
```
denotes two rectangles, a 4x2 and a 3x9. The exact format of the input may be
however you desire.
## The output
The indices of the "other" shapes that are similar to "main". You may 
choose whether the indices are 0- or 1-based, as well as the exact format 
and order of the output.
## Sample program
In Python:
```
main = eval(raw_input()) # The main rectangle.
rects = eval(raw_input()) # The list of rectangles.
similar = set()
for i, rect in enumerate(rects):
    if max(main)*min(rect) == min(main)*max(rect): # Cross-multiply
        # They are similar.
        similar.add(i)
print similar
```
## Sample input and output
Input:
```
(1, 2)
[(1, 2), (2, 4)]
```
Output:
```
set([0, 1])
```
Input:
```
(1, 2)
[(1, 9), (2, 5), (16, 8)]
```
Output:
```
set([2])
```
## Winning
This is code-golf, so the shortest submission wins.
## Notes
* This should go without saying, but **standard loopholes are banned**.
* **No builtins for locating similar figures may be used.** (I don't even know if that exists, but I would't be surprised!)
  
[Answer]
## Python, 61 bytes
```
lambda a,b,l:[i for i,(x,y)in enumerate(l)if x/y in[a/b,b/a]]
```
Yes, I'm using spending 9 chars to write `enumerate`. Takes input like `1, 2, [(1, 9), (3,6), (2, 5), (16, 8)]`. For Python 2, input values need to be written as floats.
One char longer (62) in Python 3:
```
def f(a,b,l,i=0):
 for x,y in l:b/a!=x/y!=a/b or print(i);i+=1
```
[Answer]
# CJam, ~~22~~ ~~20~~ 19 bytes
```
{:$::/_0=f=ee::*0-}
```
The above is an anonymous function that pops a single array of floating point pairs (first pair is needle) from the stack and pushes the array of 1-based indexes in return.
Try it online in the [CJam interpreter](http://cjam.aditsu.net/#code=q~%7B%3A%24%3A%3A%2F_0%3Df%3Dee%3A%3A*0-%7D~p&input=%5B%5B1.0%202.0%5D%20%5B1.0%209.0%5D%20%5B2.0%205.0%5D%20%5B16.0%208.0%5D%5D).
### How it works
```
:$                e# Sort each pair.
  ::/             e# [a b] -> a/b
     _0=          e# Push a copy of the array and extract the first float (needle).
        f=        e# Check which floats are equal to the needle.
          ee      e# Enumerate the resulting Booleans.
            ::*   e# Multiply each Boolean by its index.
                  e# This yields 0 for the needle (index 0) and for non-matching
                  e# haystack pairs (Boolean 0).
               0- e# Remove all zeroes from the array.
```
[Answer]
# [Haskell](https://www.haskell.org/), 48 bytes
```
(a!b)l=[i|(i,(x,y))<-zip[0..]l,x/y+y/x==a/b+b/a]
```
[Try it online!](https://tio.run/##FcVBCsIwEAXQq/yCixk6NqZiqWBOErJIQHAwlqJdJOLdI32b94if5z3n1ih2ibPz@iMVKlKZb8evrv40DCFLMbWvpjgXTeqTiaG9oi5wWN@6bDiAOobFCE9WcGUBnWXaGwWXfTsJZg7tDw "Haskell – Try It Online")
Call this like `(!) 1 2 [(1, 9), (3,6), (2, 5), (16, 8)]`.
A near-port of my [Python answer](https://codegolf.stackexchange.com/a/56040/20260). The expression `zip[0..]l` enumerates the list with its indices.
The expression `x/y+y/x==a/b+b/a` checks that the ratio `x/y` is either `a/b` or `b/a`, since the function `f(z) = z + 1/z` has `f(z) = f(1/z)` and no other collisions.
[Answer]
## [Snowman 1.0.2](https://github.com/KeyboardFire/snowman-lang/releases/tag/v1.0.2-beta), 61 chars
```
}vgvgaC"[0-9]+"sM:10sB;aM2aG:AsO:nD;aF;aM0AAgaA*|:#eQ;AsItSsP
```
Pure gibberish (unless you happen to know Snowman), a.k.a. [exactly in line with the language's design goal](https://github.com/KeyboardFire/snowman-lang/blob/57913d7894b744914d8ec660dcb70adfc5d3035b/doc/snowman.md) of being as confusing as possible.
Input format is same as in the post, output format is also the same minus `set(` and `)`.
Ungolfed (or unminified, really):
```
}vgvgaC     // read two lines of input, concatenate
"[0-9]+"sM  // use a regex to grab all numbers
:10sB;aM    // essentially map(parseInt)
2aG         // take groups of 2 (i.e. all the ordered pairs)
// now map over each ordered pair...
:
  AsO       // sort
  :nD;aF    // fold with division - with 2 array elements, this is just a[0]/a[1]
;aM
// we now have an array of short side to long side ratios
// take out the first one
0AAgaA      // active vars beg, b=array[0], g=the rest
*|          // store first ordered pair in permavar, bring the rest to top
// select indices where...
:
  #         // retrieve first ordered pair
  eQ        // equal?
;AsI
tSsP  // to-string and output
```
I'm pretty proud of some of the tricks I used in this one:
* I used the same input format as in the post. But instead of trying to parse it somehow, which would get really messy, I just concatenated the two lines and then used a regex to extract all the numbers into one big array (with which I then did `2aG`, i.e. get every group of 2).
* `:nD;aF` is pretty fancy. It simply takes an array of two elements and divides the first one by the second one. Which seems pretty simple, but doing it the intuitive way (`a[0]/a[1]`) would be far, far longer in Snowman: `0aa`NiN`aA|,nD` (and that's assuming we don't have to worry about messing with other existing variables). Instead, I used the "fold" method with a predicate of "divide," which, for an array of two elements, achieves the same thing.
* `0AAgaA` looks innocuous enough, but what it actually does is store a `0` to the variables, then takes all variables with an index greater than that (so, all variables except for the first one). But the trick is, instead of `AaG` (which would get rid of the original array and the `0`), I used `AAg`, which keeps both. Now I use `aA`, at-index, using the *very same `0`* to get the first element of the array—furthermore, this is in consume-mode (`aA` instead of `aa`), so it gets rid of the `0` and original array too, which are now garbage for us.
Alas, `0AAgaA*|` does essentially the same thing that GolfScript does in one character: `(`. However, I still think it's pretty nice, by Snowman standards. :)
[Answer]
# Pyth, 15 bytes
```
fqcFS@QTcFSvzUQ
```
[Answer]
# Mathematica, 41 bytes
```
Position[a=Sort@#;Sort@#/a&/@#2,{x_,x_}]&
```
Usage:
```
Position[a = Sort@#; Sort@#/a & /@ #2, {x_, x_}] &[{1, 2}, {{1, 2}, {2, 5}, {16, 8}}]
(* {{1}, {3}} *)
```
[Answer]
# Pyth - 14 bytes
Filters by comparing quotients, then maps `indexOf`.
```
xLQfqcFSTcFvzQ
```
[Test Suite](http://pyth.herokuapp.com/?code=xLQfqcFSTcFvzQ&input=%281%2C+2%29%0A%5B%281%2C+2%29%2C+%282%2C+4%29%5D&test_suite=1&test_suite_input=%281%2C+2%29%0A%5B%281%2C+2%29%2C+%282%2C+4%29%5D%0A%281%2C+2%29%0A%5B%281%2C+9%29%2C+%282%2C+5%29%2C+%2816%2C+8%29%5D&debug=0&input_size=2).
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~16~~ 13 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
```
(=.×∘⌽∨=.×)⍤1
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///X8NW7/D0Rx0zHvXsfdSxAsTRfNS7xPB/2qO2CY96@x71TfX0f9TVfGi98aO2iUBecJAzkAzx8Az@b6hgpJCmYKpg9Kh3C4htpGCiYKhgCaRNFQzNFCwA "APL (Dyalog Unicode) – Try It Online")
-3 thanks to @ngn!
Explanation:
```
(=.×∘⌽∨=.×)⍤1
(     ∨   )   ⍝ "OR" together...
 =.    =.     ⍝ ...fold by equality of:
   ×∘⌽        ⍝ - the arguments multiplied by itself reversed
         x    ⍝ - the argument multiplied by itself
           ⍤1 ⍝ Applied at rank 1 (traverses)
```
Output format is a binary vector like `1 1 0 0 1` of which "other" rectangle is a look-a-like.
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 11 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
```
=/-×⍥(⌈/)¨⌽
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/31Zf9/D0R71LNR71dOhrHlrxqGfv/7RHbRMe9fY96pvq6f@oq/nQeuNHbROBvOAgZyAZ4uEZ/D9NQcNQwUhTQcNUwehR7xYgGwhNFAwVLIG0qYKhmYKFJgA "APL (Dyalog Extended) – Try It Online")
Explanation:
```
=/-×⍥(⌈/)¨⌽ ⍝ takes only a right argument: ⍵, shape: (main (other...))
          ⌽ ⍝ two transformations:
  -         ⍝ - left (L) vectorized negation: -⍵
          ⌽ ⍝ - right (R): reverse. (main other) => (other main)
     (⌈/)¨  ⍝ transformation: calculate the max (since L is negated, it calculates the min)
            ⍝ (/ reduces over ⌈ max)
            ⍝ this vectorizes, so the "main" side (with only one rect) will get repeated once for each "other" rect on both sides
   ×⍥       ⍝ over multiplication: apply the transformation to both sides. F(L)×F(R)
=/          ⍝ reduce the 2-element matrix (the "main" that's now the side of the "other") to check which are equal
```
Output format is the same as the main Dyalog answer.
Thanks to Adám for the help golfing + Extended.
[Answer]
# Julia, 62 bytes
```
f(m,o)=find([(t=sort(m).*sort(i,rev=true);t[1]==t[2])for i=o])
```
The `find` function locates true elements in a boolean vector. `.*` performs elementwise multiplication of vectors.
Ungolfed:
```
function f(m::Array, o::Array)
    find([(t = sort(m) .* sort(i, rev=true); t[1] == t[2]) for i in o])
end
```
Usage:
```
f([1,2], {[1,9], [2,5], [16,8]})
```
[Answer]
# K5, 19 bytes
I think this will do the trick:
```
&(*t)=1_t:{%/x@>x}'
```
Takes a list of pairs where the first is the "main". Computes the ratio by dividing the sorted dimensions of each pair. Returns a list of the 0-indexed positions of the matching pairs. (arguably the input format I chose makes this -1 indexed- if this is considered invalid tack on a `1+` to the beginning and add two characters to the size of my program.)
Usage example:
```
  &(*t)=1_t:{%/x@>x}'(1 2;1 2;2 4;2 5;16 8)
0 1 3
```
This runs in [oK](http://johnearnest.github.io/ok/index.html)- note that I implicitly depend on division always producing floating point results. It would work in Kona if you added a decimal point to all the numbers in the input and added a space after the `_`.
[Answer]
# Octave / Matlab, 44 bytes
Using an anonymous function:
```
@(x,y)find((max(x))*min(y')==min(x)*max(y'))
```
The result is in 1-based indexing.
To use it, define the function
```
>> @(x,y)find((max(x))*min(y')==min(x)*max(y'));
```
and call it with the following format
```
>> ans([1 2], [1 9; 2 5; 16 8])
ans =
     3
```
You can [try it online](http://ideone.com/cURDeg).
---
If the result can be in **logical indexing** (`0` indicates not similar, `1` indicates similar): **38 bytes**:
```
@(x,y)(max(x))*min(y')==min(x)*max(y')
```
Same example as above:
```
>> @(x,y)(max(x))*min(y')==min(x)*max(y')
ans = 
    @(x,y)(max(x))*min(y')==min(x)*max(y')
>> ans([1 2], [1 9; 2 5; 16 8])
ans =
 0     0     1
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 14 bytes
```
z{iXhpᵐ/ᵛ∧Xt}ᵘ
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3wv6o6MyKjAMjSf7h19qOO5RElQOEZ//9HA4GhjlFsrA6E1ok20jGJBXORxC3B4qZA0tBMxwIoHQsA "Brachylog – Try It Online")
Takes input as a list *containing a list containing* the main rectangle and the list of other rectangles (so test case 1 is `[[[1,2]],[[1,2],[2,4]]]`), and outputs a list of 0-based indices through the output variable.
```
z                 Zip the elements of the input, pairing every "other" rectangle with the main rectangle.
 {          }ᵘ    Find (and output) every unique possible output from the following:
  iX              X is an element of the zip paired with its index in the zip.
    h             That element
      ᵐ           with both of its elements
     p            permuted
        ᵛ         produces the same output for both elements
       /          when the first element of each is divided by the second.
         ∧Xt      Output the index.
```
If that sort of odd and specific input formatting is cheating, it's a bit longer...
# [Brachylog](https://github.com/JCumin/Brachylog), 18 bytes
```
{hpX&tiYh;X/ᵛ∧Yt}ᶠ
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3wvzqjIEKtJDMywzpC/@HW2Y86lkeW1D7ctuD//@joaEMdo1gdGGWkYxIbi@ACKUuwqCmQNDTTsQBKxgIA "Brachylog – Try It Online")
Takes input as a list containing the main rectangle and the list of other rectangles (so test case 1 is the more obvious `[[1,2],[[1,2],[2,4]]]`), and outputs a list of 0-based indices through the output variable.
```
{               }ᵘ    Find (and output) every possible output from the following:
  p                   A permutation of
 h                    the first element of the input
   X                  is X,
    &                 and
      i               a pair [element, index] from
     t                the last element of the input
       Y              is Y,
        h             the first element of which
            ᵛ         produces the same output from
           /          division
         ;            as
          X           X.
             ∧Yt      Output the index.
```
To determine if two width-height pairs represent similar rectangles, it just takes the four bytes `pᵐ/ᵛ` (which outputs the shared ratio or its reciprocal). All the rest is handling the multiple rectangles to compare, and the output being indices.
[Answer]
# [dzaima/APL](https://github.com/dzaima/APL), 7 bytes
```
=/⍤÷⍥>¨
```
[Try it online!](https://tio.run/##SyzI0U2pSszMTfyf9qhtgsZ/W/1HvUsOb3/Uu9Tu0Ir/mv81HnU1GSoYaSqkKWiAaQ0jBRNNENsSzDYFsc0ULDT/5ReUZObnFf/XLQYA "APL (dzaima/APL) – Try It Online")
[8 bytes](https://tio.run/##SyzI0U2pSszMTfyf9qhtgsb/R707bPUf9S45vP1R71K7Qyv@a/7XeNTVZKhgpKmQpqABpjWMFEw0QWxLMNsUxDZTsND8l19QkpmfV/xftxgA) outputting a list of indices instead of a boolean vector
```
      ¨ for each (pairing the left input with each of the right)
    ⍥>    do the below over sorting the arguments
=/          equals reduce
  ⍤         after
   ÷        vectorized division of the two
```
[Answer]
# Haskell, 75 bytes
```
import Data.List
a(x,y)=max x y/min x y
s r=elemIndices(True).map((==a r).a)
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 57 bytes
```
$args|%{$x,$y=$_|sort
($i++)[$r-$y/$x]
if(!$r){$r=$y/$x}}
```
[Try it online!](https://tio.run/##jYxhS8MwEIa/51ec2U0SlqId61ChkP8hMuJ6nYGydUnEjra/va6Zrvsk3pe7e3iftz58kfMfVFUDlnk7oHE7381bbBSectx0/uACE2gXC/mKLsHTAzZvzJbiDp1s0eWR9P3QMzYDuy/sljwYR5Am78ZTwbRgcB4ltEjVUq2kgnhNW4uItcjU8@VLpbxKY3CcSVqqbIyla/V0k/tn@QgnaXVTnv0hPUZLQgdzaKON1NS0DVQoQAM54OaCHfnPKpzBPZagDczA15UJwe53McBR8J8QT@jIrz1cvvzanPVs@AY "PowerShell – Try It Online")
Indices are 1-based.
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~58~~ 56 bytes
-2 bytes thanks to mazzy x2 
```
param($x,$y,$b)$b|%{($i++)[$x/$y-($z=$_|sort)[0]/$z[1]]}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfmvkmZb/b8gsSgxV0OlQkelUkclSVMlqUa1WkMlU1tbM1qlQl@lUldDpcpWJb6mOL@oRDPaIFZfpSraMDa29n8tF5eaSpqCoYKRgoaGoY6Rpo6GkY4JkDTVsQSSIBFNLiUlJEVGOqYgCTMdC3QZgtpNsSsyAKn6DwA "PowerShell – Try It Online")
This slightly abuses the `input may be however you desire` clause by having the first shape's components come separately to save 3 bytes. 
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~61~~ 59 bytes
```
param($a,$b)$b|%{($i++)[$a[0]/$a[1]-($x=$_|sort)[0]/$x[1]]}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfmvkmZb/b8gsSgxV0MlUUclSVMlqUa1WkMlU1tbM1olMdogVh9IGsbqaqhU2KrE1xTnF5VogkUrgKKxtf9rubjUVNIUNAx1jDQVNMCUjoaRjgmQNNWxBJJmOsaamlxKSijKjHRMgVKGZjoWmHKYRoBEiFX2HwA "PowerShell – Try It Online")
Uses conditional indexing to swap between the current zero-based index and null based on whether or not the ratios line up. Luckily in this case, `$i` increments regardless of it being printed or not.
[Answer]
# Javascript (ES6), 75
```
(a,b)=>b.filter(e=>e.l*a.h==a.l*e.h||e.l*a.l==a.h*e.h).map(e=>b.indexOf(e))
```
Alternative, also 75
```
(a,b)=>b.map((e,i)=>e.l*a.h==a.l*e.h||e.l*a.l==a.h*e.h?i:-1).filter(e=>e+1)
```
Input is taken as a JSON object, and an array of JSON objects
```
{
    l: length of rectangle,
    h: height of rectangle
}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~15~~ 14 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ʒ‚ε{ü/}Ë}J¹Jsk
```
[Try it online](https://tio.run/##yy9OTMpM/f//1KRHDbPOba0@vEe/9nB3rdehnV7F2f//R0cb6hjF6kQb6ZjExnKBOQA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9WmWCvpJCYl6KgZA9kPGqbBGRUJoS6hP0/NSniUcOsc1urD@/Rrz3cXesV6VWc/V/nfzQQGOoYxepEG@mYxMbqKIB5QFoBLGEJljAFkoZmOhYI@VgA).
**Explanation:**
```
ʒ               # Filter the (implicit) input-list by:
 ‚              #  Pair the current width/height with the (implicit) input width/height
  ε             #  Map both width/height pairs to:
   {            #   Sort from lowest to highest
    ü/          #   Pair-wise divide them from each other
      }Ë        #  After the map: check if both values in the mapped list are equals
        }J      # After the filter: join all remaining pairs together to a string
          ¹J    # Also join all pairs of the first input together to a string
            s   # Swap to get the filtered result again
             k  # And get it's indices in the complete input-list
                # (which is output implicitly)
```
The `J`oins are there because 05AB1E can't determine the indices on multidimensional lists a.f.a.i.k.
---
If outputting the width/height pairs that are truthy, or outputting a list of truthy/falsey values based on the input-list, it could be **8 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)** instead:
```
ʒ‚ε{ü/}Ë
```
[Try it online](https://tio.run/##yy9OTMpM/f//1KRHDbPOba0@vEe/9nD3///R0YY6lrE60UY6pkDS0EzHIjaWCyhmFAsA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9WmWCvpJCYl6KgZA9kPGqbBGRUJoS6hP0/NSniUcOsc1urD@/Rrz3c/b9W5380EBjqGMXqRBvpmMTG6iiAeUBaASxhCZYwBZKGZjoWCPlYAA).
```
ε‚ε{ü/}Ë
```
[Try it online](https://tio.run/##yy9OTMpM/f//3NZHDbPOba0@vEe/9nD3///R0YY6lrE60UY6pkDS0EzHIjaWCyhmFAsA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9WmWCvpJCYl6KgZA9kPGqbBGRUJoS6hP0/tzXiUcOsc1urD@/Rrz3c/b9W5380EBjqGMXqRBvpmMTG6iiAeUBaASxhCZYwBZKGZjoWCPlYAA).
[Answer]
# [Uiua](https://www.uiua.org/), 10 bytes
```
⊚↥∩/=⊃×÷⊙⍉
```
[Try it online!](https://www.uiua.org/pad?src=ZiDihpAg4oqa4oi6KOKGpeKIqS894oqDJ8OX4oeMw5cpCmYg4oaQIOKKmuKIuigvPcOX4oa74omF4oip4o2PLCwpCmYg4oaQIOKKmuKGpeKIqS894oqDJ8OX4oeMw5fiipnijYkKZiDihpAg4oqa4oi6KOKGpeKIqS894oqDw5fDtykKZiDihpAg4oqa4oal4oipLz3iioPDl8O34oqZ4o2JCmYgMV8yIFsxXzIgMl80IDNfNSAxNl84XQpmIDNfNSBbMV8yIDE1XzkgM181IDE2Xzhd)
-2 if I can take the second input transposed.
```
⊚↥∩/=⊃×÷⊙⍉    input: a shape S, a list of shapes M (2d matrix with two columns)
          ⊙⍉    transpose the 2nd input
      ⊃×÷        fork(mul, div): take S and M and give S*M and S/M
                  the operations are done between each item of S and each row of M
   ∩/=            both(reduce by equal): for each of the two matrices,
                  compare the two rows elementwise and give 1 when equal
                  for similar shapes, * gives 1 if in reverse order, / otherwise
  ↥               boolean OR of the two vectors
⊚                vector of indices of ones
```
]