fork download
  1. <?php
  2. declare(strict_types=1);
  3.  
  4. function tekaTekiTeko(int $batas) {
  5. if ($batas < 20) {
  6. throw new InvalidArgumentException("Batas minimal adalah 20");
  7. }
  8.  
  9. for ($i = 1; $i <= $batas; $i++) {
  10. $hasil = "";
  11.  
  12. if ($i % 2 == 0) {
  13. $hasil .= "Teka";
  14. }
  15.  
  16. if ($i % 3 == 0) {
  17. $hasil .= "Teki";
  18. }
  19.  
  20. if ($i % 5 == 0) {
  21. $hasil .= "Teko";
  22. }
  23.  
  24. echo ($hasil == "" ? $i : $hasil) . "\n";
  25. }
  26. }
  27.  
  28. tekaTekiTeko(30);
Success #stdin #stdout 0.02s 7448KB
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