-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.php
58 lines (47 loc) · 1.51 KB
/
function.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
class Perhitungan
{
private $aod,$yod,$bornonyear,$villagersnumber,$peoplekilled;
function __construct($aod,$yod){
$this->aod = $aod;
$this->yod = $yod;
}
function perhitunganBornOnYear(){
$bornonyear = $this->yod - $this->aod;
if ($bornonyear < 0) {
return -1;
}else{
return $bornonyear;
}
}
function perhitunganVillager () {
# string untuk menyimpan bilangan fibonacci
$fibonacci = 0;
$satuBilanganSebelumnya = 0;
$duaBilanganSebelumnya = 1;
$bornonyear = $this->yod - $this->aod;
if ($bornonyear < 0) {
return -1;
}else{
for ($i = 1; $i <= $bornonyear; $i++) {
if ($i < 1) {
$bilangan = $i;
} else {
$bilangan = $satuBilanganSebelumnya + $duaBilanganSebelumnya;
# update variabel untuk bilangan sebelumnya
$duaBilanganSebelumnya = $satuBilanganSebelumnya;
$satuBilanganSebelumnya = $bilangan;
}
# tambahkan bilangan ke dalam string
$fibonacci += $bilangan;
}
$this->villagersnumber = $fibonacci;
return $this->villagersnumber;
}
}
function average($perhitunganVillagerA,$perhitunganVillagerB,$banyakData){
$average = ($perhitunganVillagerA+$perhitunganVillagerB)/$banyakData;
return $average;
}
}
?>