fork download
  1. <?php
  2. declare(strict_types=1);
  3.  
  4. function tekaTekiTeko(int $batas): void {
  5. if ($batas < 20) {
  6. throw new InvalidArgumentException("Parameter harus minimal 20");
  7. }
  8.  
  9. for ($i = 1; $i <= $batas; ++$i) {
  10. $out = '';
  11. if ($i % 2 === 0) $out .= "Teka";
  12. if ($i % 3 === 0) $out .= "Teki";
  13. if ($i % 5 === 0) $out .= "Teko";
  14. echo $out !== '' ? $out : $i;
  15. echo PHP_EOL;
  16. }
  17. }
  18.  
  19.  
  20. try {
  21. tekaTekiTeko(30);
  22. } catch (Throwable $e) {
  23. echo "Error: " . $e->getMessage();
  24. }
  25.  
Success #stdin #stdout 0.02s 26016KB
stdin
Standard input is empty
stdout
1
Teka
Teki
Teka
Teko
TekaTeki
7
Teka
Teki
TekaTeko
11
TekaTeki
13
Teka
TekiTeko
Teka
17
TekaTeki
19
TekaTeko
Teki
Teka
23
TekaTeki
Teko
Teka
Teki
Teka
29
TekaTekiTeko