Last active
October 6, 2019 00:20
-
-
Save dikiwidia/3f97eb1502f3215e056bdc5d28ad3674 to your computer and use it in GitHub Desktop.
Fibonacci jumlahkan angka genap dan pergantian string, Rat Maze cari jalan keluar untuk tikus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Fungsi Fibonacci | |
function Fibonacci($batas){ | |
echo "Hasil Deret : "; | |
$angkaPertama = 1; | |
$angkaKedua = 2; | |
//$nKe = 0; | |
while ($angkaPertama < $batas){ | |
$output = $angkaPertama; | |
//Golongkan Angka Genap (Even) | |
if($output % 2 == 0){ | |
$output = '<strong>'.$angkaPertama.'</strong>'; | |
$jumlahGenap += $angkaPertama; | |
} | |
//Hasil Deret | |
echo $output.', '; | |
//Deret Selanjutnya | |
$hasil = $angkaPertama + $angkaKedua; | |
$angkaPertama = $angkaKedua; | |
$angkaKedua = $hasil; | |
//$nKe = $nKe + 1; | |
} | |
echo "<br /><br /> Total Penjumlahan Genap : ".$jumlahGenap; | |
} | |
// Hasil Akhir | |
$n = 4000000; //Input Angka 4.000.000 | |
Fibonacci($n); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ratMaze($input){ | |
$count_x = count($input); | |
$count_y = count($input[0]); | |
echo "Input Soal Labirin <br /> <br />"; | |
echo "<table border=1>"; | |
for ($x = 0; $x < $count_x; $x++) { | |
echo "<tr>"; | |
for ($y = 0; $y < $count_y; $y++){ | |
echo "<td>".$input[$x][$y]."</td>"; | |
} | |
echo "<tr />"; | |
} | |
echo "</table>"; | |
//TEST | |
echo "<br />Uji Coba Jalan <br /><br />"; | |
if($input[0][0] == 0){ | |
echo "Tidak ada Jalan"; | |
} else { | |
$base = | |
[ | |
[0,0,0,0], | |
[0,0,0,0], | |
[0,0,0,0], | |
[0,0,0,0] | |
]; | |
$base[0][0] = $input[0][0]; | |
$uji = $input[0][0]; | |
$x = 0; | |
$y = 0; | |
while ($uji > 0) { | |
//finished | |
if ($x == $count_x-1 && $y == $count_y-1) { | |
$base[$x][$y] = 1; | |
$uji = 0; | |
} | |
//Uji | |
if($input[$x][$y+1] == 1 && $input[$x+1][$y] == 0){ | |
$base[$x][$y+1] = 1; | |
$x = $x; | |
$y = $y+1; | |
$uji = 1; | |
} elseif($input[$x][$y+1] == 0 && $input[$x+1][$y] == 1){ | |
$base[$x+1][$y] = 1; | |
$x = $x+1; | |
$y = $y; | |
$uji = 1; | |
} elseif($input[$x][$y+1] == 1 && $input[$x+1][$y] == 1){ | |
if(findWay($input,$x+1,$y)){ | |
$base[$x+1][$y] = 1; | |
$x = $x+1; | |
$y = $y; | |
$uji = 1; | |
} elseif(findWay($input,$x,$y+1)){ | |
$base[$x][$y+1] = 1; | |
$x = $x; | |
$y = $y+1; | |
$uji = 1; | |
} else { | |
$uji = 0; | |
} | |
} else { | |
$uji = 0; | |
} | |
} | |
echo "<table border=1>"; | |
//$base[1][3] = "X"; //x = Row y = Column | |
for ($x = 0; $x < $count_x; $x++) { | |
echo "<tr>"; | |
for ($y = 0; $y < $count_y; $y++){ | |
echo "<td>".$base[$x][$y]."</td>"; | |
} | |
echo "<tr />"; | |
} | |
echo "</table>"; | |
} | |
} | |
function findWay($input, $x, $y) | |
{ | |
$xc = count($input); | |
$yc = count($input[0]); | |
if ($x == $xc-1 && $y == $yc-1) { | |
return true; | |
} | |
if($input[$x][$y+1] == 1 && $input[$x+1][$y] == 0){ | |
return true; | |
} elseif($input[$x][$y+1] == 0 && $input[$x+1][$y] == 1){ | |
return true; | |
} elseif($input[$x][$y+1] == 1 && $input[$x+1][$y] == 1){ | |
if(findWay($input, $x+1, $y)){ | |
return true; | |
} elseif(findWay($input, $x, $y+1)) { | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
return false; | |
} | |
return false; | |
} | |
//Uji Jalan Keluar | |
$maze = | |
[ | |
[1,1,1,1], | |
[1,0,1,0], | |
[1,1,0,0], | |
[0,1,1,1] | |
]; | |
ratMaze($maze); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function LetterChanges($string){ | |
$ubah_huruf = strtr($string, 'abcdefghijklmnopqrstuvwxyz', 'bcdefghijklmnopqrstuvwxyza'); | |
$ubah_vokal = strtr($ubah_huruf, 'aiueo', 'AIUEO'); | |
echo "Input : ".$string."<br />"; | |
echo "Output : ".$ubah_vokal; | |
} | |
$input = "Testing untuk program"; | |
LetterChanges($input); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment