[Question]
  [
You are given a set of positive integers. You must arrange them into pairs such that:
* Each pair contains 2 numbers, one of which is a multiple of another. For example, 8 is a multiple of 4, and 9 is a multiple of 9.
* If the same number occurs many times in the initial set, it can be used that many times in the pairs; a number can even be paired with another occurence of the same number
* The maximum possible number of pairs is obtained.
Output must be the number of pairs. **Shortest code wins.**
**Sample data**
`2,3,4,8,9,18` -> `3`
`7,14,28,42,56` -> `2`
`7,1,9,9,4,9,9,1,3,9,8,5` -> `6`
`8,88,888,8888,88888,888888` -> `3`
`2,6,7,17,16,35,15,9,83,7` -> `2`
  
[Answer]
## Haskell, ~~109~~ ~~107~~ ~~76~~ 70 bytes
*Thanks to nimi for saving 33 bytes and teaching me some more Haskell.* :)  
*Thanks to xnor for saving another 6 bytes.*
```
import Data.List
f l=maximum$0:[1+f t|a:b:t<-permutations l,a`mod`b<1]
```
Yay, my first Haskell golf. It works the same as all the answers so far (well, not quite: it only counts the length of the longest prefix of valid pairs in each permutation, but that's equivalent and is actually what my original CJam code did).
For extra golfitude it's also extra inefficient by recursively generating all permutations of the suffix each time the first two elements of a permutation are a valid pair.
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-h`](https://codegolf.meta.stackexchange.com/a/14339/), 11 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
**My 1000th Japt solution!** (According to SEDE)  
I *had* wanted to do something epic to mark the occasion but I couldn't find a suitable challenge and, also, realised I don't have the time or brainspace these days for epic. So, instead I shall "celebrate" with a victory over Jelly :) And a bag of cans, of course!
```
á ®ò xr'vÃñ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LWg&code=4SCu8iB4cid2w/E&input=WzIsMyw0LDgsOSwxOF0)
```
á ®ò xr'vÃñ     :Implicit input of array
á               :Permutations
  ®             :Map
   ò            :  Partitions of length 2
     x          :  Reduce by addition after
      r         :    Reducing each by
       'v       :    Testing divisibility
         Ã      :End map
          ñ     :Sort
                :Implicit output of last element
```
The `'v` trick saves a byte over the more straightforward method of using a function which would be `xÈrvÃ` instead of `xr'v`, although we *could* get that byte back by replacing the `ÃÃ` with a newline.
[Answer]
## CJam, ~~22~~ 18 bytes
```
q~e!{2/::%0e=}%:e>
```
[Try it online.](http://cjam.tryitonline.net/#code=cX5lIXsyLzo6JTBlPX0lOmU-&input=WzcgMSA5IDkgNCA5IDkgMSAzIDkgOCAxXQ)
Expects input in the form of a CJam-style list.
This is a *bit* inefficient for larger lists (and Java will probably run out of memory unless you give it more).
### Explanation
```
q~     e# Read and evaluate input.
e!     e# Get all distinct permutations.
{      e# Map this block onto each permutation...
  2/   e#   Split the list into (consecutive) pairs. There may be a single element at the
       e#   end, which doesn't participate in any pair.
  ::%  e#   Fold modulo onto each chunk. If it's a pair, this computes the modulo, which
       e#   yields 0 if the first element is a multiple of the second. If the list has only
       e#   one element, it will simply return that element, which we know is positive.
  0e=  e#   Count the number of zeroes (valid pairs).
}%
:e>    e# Find the maximum of the list by folding max() onto it.
```
[Answer]
# Pyth, 13 bytes
```
eSm/%Mcd2Z.pQ
```
The time and storage complexity is really terrible. The first thing I do is to create a list with all permutations of the originally list. This takes `n*n!` storage. Input lists with length 9 already take quite a long time. 
Try it online: [Demonstration](http://pyth.herokuapp.com/?test_suite_input=1%2C2%0A7%2C14%2C28%2C42%2C56%0A8%2C88%2C888%2C8888%2C88888%2C888888&input=8%2C88%2C888%2C8888%2C88888%2C888888&code=eSm/%25Mcd2Z.pQ&test_suite=0) or [Test Suite](http://pyth.herokuapp.com/?test_suite_input=1%2C2%0A7%2C14%2C28%2C42%2C56%0A8%2C88%2C888%2C8888%2C88888%2C888888&input=8%2C88%2C888%2C8888%2C88888%2C888888&code=eSm/%25Mcd2Z.pQ&test_suite=1)
### Explanation:
```
eSm/%Mcd2Z.pQ
            Q   read the list of integer
          .p    create the list of all permutations
  m             map each permutation d to:
      cd2          split d into lists of length 2
    %M             apply modulo to each of this lists
   /     Z         count the zeros (=number of pairs with the first 
                   item divisible by the second)
 S              sort these values
e               and print the last one (=maximum)
```
[Answer]
## Mathematica, ~~95~~ ~~93~~ ~~87~~ ~~83~~ ~~79~~ ~~60~~ 58 bytes
```
Max[Count[#~Partition~2,{a_,b_}/;a∣b]&/@Permutations@#]&
```
Takes a few seconds for the larger examples.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
```
Œ!s2ḍ/€ċ1Ʋ€Ṁ
```
[Try it online!](https://tio.run/##y0rNyan8///oJMVio4c7evUfNa050m14bBOQfriz4f/hdiDj//9oIx1jHRMdCx1LHUOLWJ1ocx1DEx0jCx0TIx1Ts1gA "Jelly – Try It Online")
Uses the same method as Jakube's Pyth answer and Martin's CJam answer, which seems to be the best method
## How it works
```
Œ!s2ḍ/€ċ1Ʋ€Ṁ - Main link. Takes a list l on the left
Œ!           - All permutations of l
         Ʋ€  - Do the following over each permutation:
  s2         -   Split into pairs
      €      -   Over each pair:
     /       -     Reduce the pair by:
    ḍ        -       x divides y?
       ċ1    -   Count the 1s
           Ṁ - Take the maximum
```
[Answer]
# [Scala](http://www.scala-lang.org/), ~~71~~ 67 bytes
```
_.permutations.map(_.grouped(2)count(x=>x.size>1&&x(0)%x(1)<1)).max
```
[Try it online!](https://tio.run/##bY1Pb8IwDMXvfApfhhLJqkj6hxTRShx32IkjmlBWwtSppKFNUbSJz17cbRcE1vPzwc8/95Vu9Nh@fJnKw5uuLZjgjT30sHHuZwZUF93AcQVbc969Wv8ORQk0oRj3kTPdafDa163to5N2bB99du3gzIFJXrWD9SwUZYj6@tuUYj4PbMFfAhN8LTingzC6rra@sezIiM8kxpigwhyF4pzP7rdLFAlKhYnENHu6psOcAJMLQuWESh@DCtWk3/6zf3/yU2KGBCZlGKco0gka43JKXscb "Scala – Try It Online")
* -4 thanks to [user](https://codegolf.stackexchange.com/users/95792/user)!
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 8 bytes
```
œεüÖιO}à
```
[Try it online!](https://tio.run/##yy9OTMpM/V9Waa@koGunoGRf@f/o5HNbD@85PO3cTv/awwv@6/yPjjbSMdYx0bHQsdQxtIjVUYg21zE00TGy0DEx0jE1AwlY6FiAEBhDCChpERsLAA "05AB1E – Try It Online")
**Commented:**
```
œ          # get all permutations
 ε    }    # map over the permutations ... ex: [8, 4, 9, 9]
  üÖ       #   pairwise divisibility           [1, 0, 1]
           #     [8%4==0, 4%9==0, 9%9==0]
    ι      #   de-interleave                   [[1, 1], [0]]
           #     split into two alternating lists
     O     #   sum both lists                  [2, 0]
       à   # get the maximum
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 10 bytes
```
▲mȯ#IĊ2Ẋ¦P
```
[Try it online!](https://tio.run/##ASkA1v9odXNr///ilrJtyK8jScSKMuG6isKmUP///1s3LDE0LDI4LDQyLDU2XQ "Husk – Try It Online")
**How?**
```
▲mȯ#IĊ2Ẋ¦P      
▲               # maximum of
 m              # map function over list:
  ȯ             # function: 3 functions combined
   #I           #   number of truthy elements of
     Ċ2         #   every second element of
       Ẋ        #   result of applying to every pair
        ¦       #   a divides b?
         P      # list: all permutations of input
```
[Answer]
## Matlab (120+114=234)
```
  function w=t(y,z),w=0;for i=1:size(z,1),w=max(w,1+t([y,z(i,:)],feval(@(d)z(d(:,1)&d(:,2),:),~ismember(z,z(i,:)))));end
```
**main:**
```
  a=input('');h=bsxfun(@mod,a,a');v=[];for i=1:size(h,1) b=find(~h(i,:));v=[v;[(2:nnz(b))*0+i;b(b~=i)]'];end;t([],v)
```
---
* the topper function is called by the main part.
* the input is in the form `[. . .]`
[Answer]
## Matlab(365)
```
  j=@(e,x)['b(:,' num2str(e(x)) ')'];r=@(e,y)arrayfun(@(t)['((mod(' j(e,1) ',' j(e,t) ')==0|mod(' j(e,t) ',' j(e,1) ')==0)&',(y<4)*49,[cell2mat(strcat(r(e(setdiff(2:y,t)),y-2),'|')) '0'],')'],2:y,'UniformOutput',0);a=input('');i=nnz(a);i=i-mod(i,2);q=0;while(~q)b=nchoosek(a,i);q=[cell2mat(strcat((r(1:i,i)),'|')) '0'];q=nnz(b(eval(q(q~=0)),:));i=i-2;end;fix((i+2)/2)
```
---
* This apparently is longer, but oneliner and executive, and I managed to escape `perms` function because it takes forever.
* This function takes many reprises to run quiet well due to anonymous functions, I m open to suggestions here :)
]