Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for($i = 0; $i <= 100; $i++){
- $array[] = rand(-50,50);
- }
- $hashmap = array();
- $pairs = array();
- for($i = 0; $i < count($array); $i++){
- $toGiveTen = 10 - $array[$i];
- if(array_key_exists ($toGiveTen, $hashmap)){
- $pairs[] = $hashmap[$toGiveTen] . " + " . $array[$i] . " = 10";
- unset($hashmap[$toGiveTen]);
- } else {
- $hashmap[$array[$i]] = $array[$i];
- }
- }
- print_r($pairs);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement