-
-
Save yorigustama/210ad165ac1520cd25aff8b463707c8a to your computer and use it in GitHub Desktop.
Backend Engineer Test 1 - Problem Solving
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Validasi dan Format Nomor Telepon</title> | |
</head> | |
<body> | |
<h1>Validasi dan Format Nomor Telepon</h1> | |
<?php | |
// Memeriksa apakah fungsi formatNomorTelepon sudah didefinisikan sebelumnya | |
if (!function_exists('formatNomorTelepon')) { | |
// Fungsi untuk memformat nomor telepon | |
function formatNomorTelepon($nomor) | |
{ | |
$nomor = str_replace("-", "", $nomor); // Menghapus tanda "-" yang mungkin ada pada nomor telepon | |
if (strlen($nomor) > 10 && $nomor[0] != '0') { | |
$nomor = '0' . $nomor; // Menambahkan angka 0 pada posisi pertama jika tidak ada | |
} | |
$nomorTerformat = substr($nomor, 0, 4) . '-' . substr($nomor, 4, 4) . '-' . substr($nomor, 8); // Memisahkan nomor dengan tanda "-" | |
return $nomorTerformat; | |
} | |
} | |
// Memeriksa apakah form telah disubmit | |
if (isset($_POST['submit'])) { | |
$nomorTelepon = $_POST['nomor_telepon']; | |
// Menghapus tanda "-" dari nomor telepon | |
$nomorTelepon = str_replace("-", "", $nomorTelepon); | |
// Memvalidasi nomor telepon | |
if (preg_match('/^\d{10,13}$/', $nomorTelepon) || preg_match('/^\d{2}-\d{4}-\d{4}$/', $nomorTelepon)) { | |
// Nomor telepon valid, format dan tampilkan | |
$nomorTerformat = formatNomorTelepon($nomorTelepon); | |
echo "<p>Nomor telepon terformat: $nomorTerformat</p>"; | |
} else { | |
// Nomor telepon tidak valid, tampilkan pesan error | |
echo "<p>Nomor telepon tidak valid. Pastikan terdiri dari 10, 11, 12, atau 13 digit atau format yang sesuai.</p>"; | |
} | |
} | |
?> | |
<form method="POST" action=""> | |
<label for="nomor_telepon">Nomor Telepon:</label> | |
<input type="text" name="nomor_telepon" id="nomor_telepon" required> | |
<input type="submit" name="submit" value="Format"> | |
</form> | |
</body> | |
</html> |
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 | |
$chat_rooms = array( | |
"backend" => array( | |
array("user" => "Ari", "message" => "Halo"), | |
array("user" => "Ariyanto", "message" => "Halo juga") | |
), | |
"frontend" => array( | |
array("user" => "suryanto", "message" => "Lorem ipsum"), | |
array("user" => "Arindo", "message" => "Helo") | |
) | |
); | |
$output = ''; | |
if (isset($_GET['keyword'])) { | |
$keyword = $_GET['keyword']; | |
$result = array(); | |
foreach ($chat_rooms as $room => $messages) { | |
foreach ($messages as $message) { | |
if (stripos($message['user'], $keyword) !== false || stripos($message['message'], $keyword) !== false) { | |
$result[] = $room; | |
break; | |
} | |
} | |
} | |
if (empty($result)) { | |
$output = "Tidak ada hasil ditemukan."; | |
} else { | |
$output = "Hasil pencarian: " . implode(", ", $result); | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Pencarian Chat Room</title> | |
</head> | |
<body> | |
<h2>Pencarian Chat Room</h2> | |
<form method="GET" action=""> | |
<label for="keyword">Kata kunci:</label> | |
<input type="text" name="keyword" id="keyword" required> | |
<button type="submit">Cari</button> | |
</form> | |
<?php if (!empty($output)) : ?> | |
<h3>Hasil Pencarian</h3> | |
<p><?php echo $output; ?></p> | |
<?php endif; ?> | |
</body> | |
</html> |
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
<html> | |
<body> | |
<form method="POST" action=""> | |
<label for="targetPage">Target Page:</label> | |
<input type="number" id="targetPage" name="targetPage" required><br><br> | |
<label for="bukaDari">Buka Dari:</label> | |
<select id="bukaDari" name="bukaDari" required> | |
<option value="depan">Depan</option> | |
<option value="belakang">Belakang</option> | |
</select><br><br> | |
<input type="submit" value="Hitung"> | |
</form> | |
<?php | |
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
$totalPages = 231; | |
$targetPage = $_POST['targetPage']; | |
$bukaDari = $_POST['bukaDari']; | |
$resFromFront = ceil(($targetPage - 1) / 2); | |
$resFromBack = ceil(($totalPages - $targetPage) / 2); | |
if ($bukaDari == "depan") { | |
echo "From first page flip: " . $resFromFront . "x"; // Jumlah kali halaman harus dibalik dari depan | |
} else if ($bukaDari == "belakang") { | |
if ($targetPage % 2 == 0) { | |
$resFromBack = $resFromBack - 1; | |
} | |
echo "From last page flip: " . $resFromBack . "x"; // Jumlah kali halaman harus dibalik dari belakang | |
} | |
} | |
?> | |
</body> | |
</html> |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Pengingat Jadwal Les Piano</title> | |
</head> | |
<body> | |
<h1>Pengingat Jadwal Les Piano</h1> | |
<?php | |
// Menangani form pengiriman | |
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
$tahun = intval($_POST['tahun']); | |
$tanggal_awal = date_create("$tahun-04-28"); | |
$counter = 0; | |
$tanggal_bertemu = []; | |
// Menghitung tanggal-tanggal les piano untuk setiap individu | |
$tanggal_andi = clone $tanggal_awal; | |
$tanggal_beni = clone $tanggal_awal; | |
$tanggal_ahmad = clone $tanggal_awal; | |
for ($bulan = 1; $bulan <= 12; $bulan++) { | |
$tanggal_andi->add(new DateInterval('P12D')); | |
$tanggal_beni->add(new DateInterval('P14D')); | |
$tanggal_ahmad->add(new DateInterval('P6D')); | |
// Memeriksa apakah tanggal-tanggal tersebut bertepatan | |
if (date_format($tanggal_andi, 'Y-m-d') === date_format($tanggal_beni, 'Y-m-d') && date_format($tanggal_beni, 'Y-m-d') === date_format($tanggal_ahmad, 'Y-m-d')) { | |
$tanggal_bertemu[] = clone $tanggal_andi; | |
$counter++; | |
} | |
} | |
// Menampilkan hasil tanggal bertemu atau pesan jika tidak ada tanggal bertemu | |
if ($counter > 0) { | |
echo "<p>Total tanggal bertemu: $counter</p>"; | |
echo "<p>Tanggal-tanggal bertemu:</p>"; | |
echo "<ul>"; | |
foreach ($tanggal_bertemu as $tanggal) { | |
echo "<li>" . date_format($tanggal, "d F Y") . "</li>"; | |
} | |
echo "</ul>"; | |
} else { | |
echo "<p>Tidak ada tanggal bertemu dalam satu tahun.</p>"; | |
} | |
} | |
?> | |
<form method="post" action=""> | |
<label for="tahun">Masukkan tahun:</label> | |
<input type="number" name="tahun" id="tahun" required> | |
<br> | |
<input type="submit" value="Submit"> | |
</form> | |
</body> | |
</html> |
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 enkripsiText($text) { | |
// Menghapus spasi dari teks | |
$text = str_replace(" ", "", $text); | |
// Menghitung panjang teks setelah spasi dihilangkan | |
$L = strlen($text); | |
// Menghitung jumlah baris dan kolom dari akar panjang teks tanpa spasi | |
$rows = floor(sqrt($L)); | |
$columns = ceil(sqrt($L)); | |
// Membuat matriks berukuran rows x columns | |
$matrix = []; | |
$k = 0; | |
for ($i = 0; $i < $rows; $i++) { | |
$row = []; | |
for ($j = 0; $j < $columns; $j++) { | |
if ($k < $L) { | |
$row[] = substr($text, $k, 1); | |
$k++; | |
} else { | |
$row[] = " "; | |
} | |
} | |
$matrix[] = $row; | |
} | |
// Menggabungkan karakter-karakter dengan spasi setiap 5 karakter | |
$enkripsiText = ""; | |
for ($i = 0; $i < $columns; $i++) { | |
for ($j = 0; $j < $rows; $j++) { | |
$enkripsiText .= $matrix[$j][$i]; | |
} | |
if ($i < ($columns - 1)) { | |
$enkripsiText .= " "; | |
} | |
} | |
return $enkripsiText; | |
} | |
$inputText = ""; | |
$enkripsiText = ""; | |
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
// Menerima input teks dari formulir | |
$inputText = $_POST['input-text']; | |
// Melakukan enkripsi teks | |
$enkripsiText = enkripsiText($inputText); | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Text Encryption</title> | |
</head> | |
<body> | |
<h1>Text Encryption</h1> | |
<form method="POST" action=""> | |
<label for="input-text">Input Text:</label> | |
<input type="text" id="input-text" name="input-text" value="<?php echo $inputText; ?>" required> | |
<button type="submit">Encrypt</button> | |
</form> | |
<?php if (!empty($enkripsiText)): ?> | |
<h2>Encrypted Text:</h2> | |
<p><?php echo $enkripsiText; ?></p> | |
<?php endif; ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment