fork download
  1. <?php
  2.  
  3. $numbers = array(1, 15, 7, 3, 8, 8, 19, 5, 12, 8, 2, 6, 8);
  4. // $numbers = array(1, 15, 8, 8, 8, 8, 7, 3, 19, 5, 12, 2, 6);
  5.  
  6. $counter = 1;
  7. $index = 0;
  8. if (count($numbers) > 0) {
  9. $prev = $numbers[$index++];
  10. }
  11.  
  12. while ($index < count($numbers) && $counter < 4) {
  13. $next = $numbers[$index++];
  14. if ($prev == $next) {
  15. $counter++;
  16. }
  17. else {
  18. $counter = 1;
  19. $prev = $next;
  20. }
  21. }
  22.  
  23. if ($counter == 4) {
  24. print("Found four times repeated number");
  25. }
  26. else {
  27. print("No four times repeated number found");
  28. }
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
No four times repeated number found