-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weighing.php
42 lines (38 loc) · 894 Bytes
/
Weighing.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Created by IntelliJ IDEA.
* User: kfuntov
* Date: 26.12.12
* Time: 16:26
* To change this template use File | Settings | File Templates.
*/
class Weighing {
/**
* @var CoinGroup
*/
private $group1;
/**
* @var CoinGroup
*/
private $group2;
const EQUALS=0;
const LEFT_IS_HEAVIER=1;
const RIGHT_IS_HEAVIER=2;
public function __construct(CoinGroup $group1, CoinGroup $group2)
{
$this->group1=$group1;
$this->group2=$group2;
}
public function result()
{
$w1=$this->group1->getWeight();
$w2=$this->group2->getWeight();
if($w1===$w2)
return self::EQUALS;
if($w1>$w2)
return self::LEFT_IS_HEAVIER;
if($w1<$w2)
return self::RIGHT_IS_HEAVIER;
throw new Exception("WHAT?".var_export(array($w1,$w2),true));
}
}