Advertisement
Guest User

Untitled

a guest
May 29th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. Problem statement :
  2. A luminous portal at the far end of the vault draws your attention. That must be your final destination! Cross n... Oh, stop!
  3.  
  4. Looks like the sine generator that powers the destination aligner is malfunctioned.
  5.  
  6. You wouldn't want to be transported into deep space, would you?
  7.  
  8. The signal from the sine generator appears to suffer from random interruptions. You can GET the generator output from http://challenge.five.agency/portal/generator. Fill in the missing values and POST it to the same endpoint in the same format. You have 3 seconds!
  9.  
  10. My code :
  11. var all_n = [];
  12. var selection= [];
  13. var solution = [];
  14. var start = new Date().getTime();
  15. var end = 0;
  16. var req = $.ajax({
  17. url: "portal/generator",
  18. method: "GET",
  19. async: false,
  20. dataType: "text"
  21. });
  22. req.done(
  23. function(data){
  24. var d = data.split(",");
  25. for(var i=0;i<d.length;i++){
  26. if(d[i]!="x.xx"){
  27. if(selection.indexOf(Math.abs(parseFloat(d[i]))) == -1){
  28. if(Math.abs(parseFloat(d[i]))!=0.0){
  29. selection.push(parseFloat(d[i]))
  30. selection.push(-parseFloat(d[i]))
  31. }
  32. else{
  33. selection.push(0.0)
  34. }
  35. }
  36. }
  37. }
  38. selection.sort(function(a,b){return a-b});
  39. for(var i=0;i<d.length;i++){
  40. if(d[i]=="x.xx"){
  41. p = parseFloat(d[i-1]);
  42. n = parseFloat(d[i+1]);
  43. if(p==n){
  44. if(p>0){
  45. solution.push(parseFloat(selection[selection.length - 1]).toFixed(2));
  46. }else{
  47. solution.push(parseFloat(selection[0]).toFixed(2));
  48. }
  49. }else{
  50. solution.push(parseFloat(selection[(selection.indexOf(p) + selection.indexOf(n))/2]).toFixed(2));
  51. }
  52. }else{
  53. solution.push(parseFloat(d[i]).toFixed(2));
  54. }
  55. }
  56. var request = $.ajax({
  57. url: "portal/generator",
  58. method: "POST",
  59. async: false,
  60. data: { data : solution.join(",") },
  61. dataType: "text"
  62. });
  63. request.done(function( msg ) {
  64. console.log( msg );
  65. });
  66.  
  67. end = new Date().getTime();
  68. console.log(end - start);
  69. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement