SHARE
TWEET

Untitled

a guest Feb 21st, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $lista = [3, 29, 18, 10, 8, 15];
  4. $numero = 18;
  5.  
  6. function encuentraPar(array $lista, int $numero)
  7. {
  8.     $par = [];
  9.     foreach ($lista as $valor) {
  10.         if ($valor >= $numero) {
  11.             continue;
  12.         } else {
  13.             $resto = $numero - $valor;
  14.  
  15.             if (in_array($resto, $lista)) {
  16.                 $par = [$valor,  $resto];
  17.                 break;
  18.             }
  19.         }
  20.     }
  21.     return $par;
  22. }
  23.  
  24. print_r(encuentraPar($lista, $numero));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top