emotrend

treasure finder

Dec 15th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php
  2.  
  3. $key = array_map("intval", explode(" ", readline()));
  4. $input = readline();
  5.  
  6. $finalResult = "";
  7. $finalResults = [];
  8. while ($input !== "find") {
  9. $input = str_split($input);
  10.  
  11. for ($j = 0; $j < count($input); $j++){
  12. for ($i = 0; $i < count($key); $i++){
  13. if ($i === count($key)) {
  14. break;
  15. }
  16. $input[$i] = chr(ord($input[$i]) - $key[$i]);
  17. }
  18. $finalResult .= substr(implode("", $input), 0, count($key));
  19. array_splice($input,0, count($key));
  20. }
  21.  
  22. if (count($input) !== 0) {
  23. for ($n = 0; $n < count($input);$n++){
  24. if ($n >= count($key)) {
  25. $n = 0;
  26. array_splice($input, 0, count($key));
  27. }
  28. $finalResult .= chr(ord($input[$n]) - $key[$n]);
  29. }
  30. }
  31.  
  32. $finalResults[] = $finalResult;
  33. $finalResult = "";
  34. $input = readline();
  35. }
  36.  
  37. foreach ($finalResults as $result) {
  38. list($randomWord, $treasureName, $coordinates) = explode("&", $result);
  39. if (preg_match("/(?<=\<)\w+(?=\>)/", $coordinates, $matches)) {
  40. $matched = $matches[0];
  41. }
  42. echo "Found $treasureName at " . $matched . PHP_EOL;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment