Created
December 5, 2017 23:20
-
-
Save hersan/2e48c280833a0908b0de89d7a3ab12d0 to your computer and use it in GitHub Desktop.
evaluación técnica para reclutamiento 11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?hp | |
| /***************************** | |
| * | |
| * Prueba para reclutamiento 11 | |
| * | |
| ******************************/ | |
| //P1 | |
| function weight_word($string) { | |
| static $charMap = array( | |
| 'A' => 2, 'B' => 3, 'C' => 5, 'D' => 1, 'E' => 1, 'F' => 8, 'G' => 9, | |
| 'H' => 2, 'I' => 3, 'J' => 5, 'K' => 1, 'L' => 1, 'M' => 8, 'N' => 9, | |
| 'Ñ' => 2, 'O' => 3, 'P' => 5, 'Q' => 1, 'R' => 1, 'S' => 8, 'T' => 9, | |
| 'U' => 2, 'V' => 3, 'W' => 5, 'X' => 1, 'Y' => 1, 'Z' => 8, | |
| ); | |
| $sum = 0; | |
| for($i = 0; $i < strlen($string); $i++) { | |
| $sum += $charMap[ucfirst($string[$i])]; | |
| } | |
| return $sum; | |
| } | |
| //P2 usando P1 y P4 | |
| function get_strongest_word(Array $array) { | |
| $map = transform_to_map($array); | |
| $keys = get_array_keys($map); | |
| $sortKeys = bsort($keys); | |
| return $map[$sortKeys[count($sortKeys)-1]]; | |
| } | |
| function transform_to_map(Array $array) { | |
| $wordMap = []; | |
| foreach($array as $value){ | |
| $wordMap[weight_word($value)] = $value; | |
| } | |
| return $wordMap; | |
| } | |
| function get_array_keys(Array $array) { | |
| $key_array = []; | |
| foreach($array as $key => $value) { | |
| $key_array[] = $key; | |
| } | |
| return $key_array; | |
| } | |
| $array = ['aftab', 'luis', 'casa', 'torito', 'dedo']; | |
| var_dump(get_strongest_word($array)); | |
| //P3 | |
| function isEven($number) { | |
| if($number % 2 == 0) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| var_dump(isEven(5)); | |
| var_dump(isEven(2)); | |
| //P4 | |
| function bsort(Array $array) | |
| { | |
| do | |
| { | |
| $swap = false; | |
| for( $i = 0 ; $i < count( $array ) - 1; $i++ ) | |
| { | |
| if( $array[$i] > $array[$i + 1] ) | |
| { | |
| $temp = $array[$i]; | |
| $array[$i] = $array[$i+1]; | |
| $array[$i+1] = $temp; | |
| $swap = true; | |
| } | |
| } | |
| } while ( $swap ); | |
| return $array; | |
| } | |
| $numeros = [2, 50, 4, 1, 100, 80]; | |
| var_dump(bsort($numeros)); | |
| //P5 | |
| function reverse_string($string) { | |
| $words = explode(' ', $string); | |
| $output = []; | |
| $reverse = null; | |
| foreach($words as $key => $word) { | |
| for($i = strlen($word)-1; $i >= 0 ; $i--) { | |
| $reverse .= $word[$i]; | |
| } | |
| $output[] = $reverse; | |
| $reverse = null; | |
| } | |
| return implode(' ', $output); | |
| } | |
| $string = "tres tristes tigres tragaban trigo en un trigal"; | |
| var_dump(reverse_string($string)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment